Skip to content

Commit eccac5a

Browse files
Andy Kaylortstellar
authored andcommitted
Add auto-upgrade support for annotation intrinsics
The llvm.ptr.annotation and llvm.var.annotation intrinsics were changed since the 11.0 release to add an additional parameter. This patch auto-upgrades IR containing the four-parameter versions of these intrinsics, adding a null pointer as the fifth argument. Differential Revision: https://reviews.llvm.org/D95993 (cherry picked from commit 9a82790)
1 parent 1c0a0c7 commit eccac5a

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,12 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
937937
Intrinsic::getDeclaration(F->getParent(), Intrinsic::prefetch, Tys);
938938
return true;
939939
}
940+
} else if (Name.startswith("ptr.annotation.") && F->arg_size() == 4) {
941+
rename(F);
942+
NewFn = Intrinsic::getDeclaration(F->getParent(),
943+
Intrinsic::ptr_annotation,
944+
F->arg_begin()->getType());
945+
return true;
940946
}
941947
break;
942948

@@ -947,6 +953,16 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
947953
}
948954
break;
949955

956+
case 'v': {
957+
if (Name == "var.annotation" && F->arg_size() == 4) {
958+
rename(F);
959+
NewFn = Intrinsic::getDeclaration(F->getParent(),
960+
Intrinsic::var_annotation);
961+
return true;
962+
}
963+
break;
964+
}
965+
950966
case 'x':
951967
if (UpgradeX86IntrinsicFunction(F, Name, NewFn))
952968
return true;
@@ -3730,6 +3746,32 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
37303746
CI->eraseFromParent();
37313747
return;
37323748

3749+
case Intrinsic::ptr_annotation:
3750+
// Upgrade from versions that lacked the annotation attribute argument.
3751+
assert(CI->getNumArgOperands() == 4 &&
3752+
"Before LLVM 12.0 this intrinsic took four arguments");
3753+
// Create a new call with an added null annotation attribute argument.
3754+
NewCall = Builder.CreateCall(
3755+
NewFn,
3756+
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
3757+
CI->getArgOperand(3), Constant::getNullValue(Builder.getInt8PtrTy())});
3758+
NewCall->takeName(CI);
3759+
CI->replaceAllUsesWith(NewCall);
3760+
CI->eraseFromParent();
3761+
return;
3762+
3763+
case Intrinsic::var_annotation:
3764+
// Upgrade from versions that lacked the annotation attribute argument.
3765+
assert(CI->getNumArgOperands() == 4 &&
3766+
"Before LLVM 12.0 this intrinsic took four arguments");
3767+
// Create a new call with an added null annotation attribute argument.
3768+
NewCall = Builder.CreateCall(
3769+
NewFn,
3770+
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
3771+
CI->getArgOperand(3), Constant::getNullValue(Builder.getInt8PtrTy())});
3772+
CI->eraseFromParent();
3773+
return;
3774+
37333775
case Intrinsic::x86_xop_vfrcz_ss:
37343776
case Intrinsic::x86_xop_vfrcz_sd:
37353777
NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(1)});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; Test upgrade of ptr.annotation intrinsics.
2+
;
3+
; RUN: llvm-dis < %s.bc | FileCheck %s
4+
5+
; Unused return values
6+
; The arguments passed to the intrinisic wouldn't normally be arguments to
7+
; the function, but that makes it easier to test that they are handled
8+
; correctly.
9+
define void @f1(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) {
10+
;CHECK: @f1(i8* [[ARG0:%.*]], i8* [[ARG1:%.*]], i8* [[ARG2:%.*]], i32 [[ARG3:%.*]])
11+
%t0 = call i8* @llvm.ptr.annotation.p0i8(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3)
12+
;CHECK: call i8* @llvm.ptr.annotation.p0i8(i8* [[ARG0]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null)
13+
14+
%arg0_p16 = bitcast i8* %arg0 to i16*
15+
%t1 = call i16* @llvm.ptr.annotation.p0i16(i16* %arg0_p16, i8* %arg1, i8* %arg2, i32 %arg3)
16+
;CHECK: [[ARG0_P16:%.*]] = bitcast
17+
;CHECK: call i16* @llvm.ptr.annotation.p0i16(i16* [[ARG0_P16]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null)
18+
19+
%arg0_p256 = bitcast i8* %arg0 to i256*
20+
%t2 = call i256* @llvm.ptr.annotation.p0i256(i256* %arg0_p256, i8* %arg1, i8* %arg2, i32 %arg3)
21+
;CHECK: [[ARG0_P256:%.*]] = bitcast
22+
;CHECK: call i256* @llvm.ptr.annotation.p0i256(i256* [[ARG0_P256]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null)
23+
ret void
24+
}
25+
26+
; Used return values
27+
define i16* @f2(i16* %x, i16* %y) {
28+
%t0 = call i16* @llvm.ptr.annotation.p0i16(i16* %x, i8* undef, i8* undef, i32 undef)
29+
%t1 = call i16* @llvm.ptr.annotation.p0i16(i16* %y, i8* undef, i8* undef, i32 undef)
30+
%cmp = icmp ugt i16* %t0, %t1
31+
%sel = select i1 %cmp, i16* %t0, i16* %t1
32+
ret i16* %sel
33+
; CHECK: [[T0:%.*]] = call i16* @llvm.ptr.annotation.p0i16(i16* %x, i8* undef, i8* undef, i32 undef, i8* null)
34+
; CHECK: [[T1:%.*]] = call i16* @llvm.ptr.annotation.p0i16(i16* %y, i8* undef, i8* undef, i32 undef, i8* null)
35+
; CHECK: %cmp = icmp ugt i16* [[T0]], [[T1]]
36+
; CHECK: %sel = select i1 %cmp, i16* [[T0]], i16* [[T1]]
37+
; CHECK: ret i16* %sel
38+
}
39+
40+
declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32)
41+
; CHECK: declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*)
42+
declare i16* @llvm.ptr.annotation.p0i16(i16*, i8*, i8*, i32)
43+
; CHECK: declare i16* @llvm.ptr.annotation.p0i16(i16*, i8*, i8*, i32, i8*)
44+
declare i256* @llvm.ptr.annotation.p0i256(i256*, i8*, i8*, i32)
45+
; CHECK: declare i256* @llvm.ptr.annotation.p0i256(i256*, i8*, i8*, i32, i8*)
1.49 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; Test upgrade of var.annotation intrinsics.
2+
;
3+
; RUN: llvm-dis < %s.bc | FileCheck %s
4+
5+
6+
define void @f(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) {
7+
;CHECK: @f(i8* [[ARG0:%.*]], i8* [[ARG1:%.*]], i8* [[ARG2:%.*]], i32 [[ARG3:%.*]])
8+
call void @llvm.var.annotation(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3)
9+
;CHECK: call void @llvm.var.annotation(i8* [[ARG0]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null)
10+
ret void
11+
}
12+
13+
; Function Attrs: nofree nosync nounwind willreturn
14+
declare void @llvm.var.annotation(i8*, i8*, i8*, i32)
15+
; CHECK: declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*)
1.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)