GlobalISel: translate the @llvm.objectsize intrinsic.

llvm-svn: 284527
This commit is contained in:
Tim Northover 2016-10-18 20:03:51 +00:00
parent 55782222c0
commit 6e9043009e
2 changed files with 24 additions and 0 deletions

View File

@ -392,6 +392,13 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI,
case Intrinsic::smul_with_overflow: Op = TargetOpcode::G_SMULO; break;
case Intrinsic::memcpy:
return translateMemcpy(CI);
case Intrinsic::objectsize: {
// If we don't know by now, we're never going to know.
const ConstantInt *Min = cast<ConstantInt>(CI.getArgOperand(1));
MIRBuilder.buildConstant(getOrCreateVReg(CI), Min->isZero() ? -1ULL : 0);
return true;
}
}
LLT Ty{*CI.getOperand(0)->getType(), *DL};

View File

@ -881,3 +881,20 @@ define void @test_memcpy(i8* %dst, i8* %src, i64 %size) {
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %size, i32 1, i1 0)
ret void
}
declare i64 @llvm.objectsize.i64(i8*, i1)
declare i32 @llvm.objectsize.i32(i8*, i1)
define void @test_objectsize(i8* %addr0, i8* %addr1) {
; CHECK-LABEL: name: test_objectsize
; CHECK: [[ADDR0:%[0-9]+]](p0) = COPY %x0
; CHECK: [[ADDR1:%[0-9]+]](p0) = COPY %x1
; CHECK: {{%[0-9]+}}(s64) = G_CONSTANT -1
; CHECK: {{%[0-9]+}}(s64) = G_CONSTANT 0
; CHECK: {{%[0-9]+}}(s32) = G_CONSTANT -1
; CHECK: {{%[0-9]+}}(s32) = G_CONSTANT 0
%size64.0 = call i64 @llvm.objectsize.i64(i8* %addr0, i1 0)
%size64.intmin = call i64 @llvm.objectsize.i64(i8* %addr0, i1 1)
%size32.0 = call i32 @llvm.objectsize.i32(i8* %addr0, i1 0)
%size32.intmin = call i32 @llvm.objectsize.i32(i8* %addr0, i1 1)
ret void
}