From 9a827906cb95e7c3ae94627558da67b47ffde249 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Wed, 3 Feb 2021 18:16:04 -0800 Subject: [PATCH] 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 --- llvm/lib/IR/AutoUpgrade.cpp | 42 +++++++++++++++++++++++ llvm/test/Bitcode/upgrade-ptr-annotation.ll | 45 +++++++++++++++++++++++++ llvm/test/Bitcode/upgrade-ptr-annotation.ll.bc | Bin 0 -> 1524 bytes llvm/test/Bitcode/upgrade-var-annotation.ll | 15 +++++++++ llvm/test/Bitcode/upgrade-var-annotation.ll.bc | Bin 0 -> 1232 bytes 5 files changed, 102 insertions(+) create mode 100644 llvm/test/Bitcode/upgrade-ptr-annotation.ll create mode 100644 llvm/test/Bitcode/upgrade-ptr-annotation.ll.bc create mode 100644 llvm/test/Bitcode/upgrade-var-annotation.ll create mode 100644 llvm/test/Bitcode/upgrade-var-annotation.ll.bc diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 21a97cd..a4ec538 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -937,6 +937,12 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { Intrinsic::getDeclaration(F->getParent(), Intrinsic::prefetch, Tys); return true; } + } else if (Name.startswith("ptr.annotation.") && F->arg_size() == 4) { + rename(F); + NewFn = Intrinsic::getDeclaration(F->getParent(), + Intrinsic::ptr_annotation, + F->arg_begin()->getType()); + return true; } break; @@ -947,6 +953,16 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { } break; + case 'v': { + if (Name == "var.annotation" && F->arg_size() == 4) { + rename(F); + NewFn = Intrinsic::getDeclaration(F->getParent(), + Intrinsic::var_annotation); + return true; + } + break; + } + case 'x': if (UpgradeX86IntrinsicFunction(F, Name, NewFn)) return true; @@ -3730,6 +3746,32 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { CI->eraseFromParent(); return; + case Intrinsic::ptr_annotation: + // Upgrade from versions that lacked the annotation attribute argument. + assert(CI->getNumArgOperands() == 4 && + "Before LLVM 12.0 this intrinsic took four arguments"); + // Create a new call with an added null annotation attribute argument. + NewCall = Builder.CreateCall( + NewFn, + {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), + CI->getArgOperand(3), Constant::getNullValue(Builder.getInt8PtrTy())}); + NewCall->takeName(CI); + CI->replaceAllUsesWith(NewCall); + CI->eraseFromParent(); + return; + + case Intrinsic::var_annotation: + // Upgrade from versions that lacked the annotation attribute argument. + assert(CI->getNumArgOperands() == 4 && + "Before LLVM 12.0 this intrinsic took four arguments"); + // Create a new call with an added null annotation attribute argument. + NewCall = Builder.CreateCall( + NewFn, + {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), + CI->getArgOperand(3), Constant::getNullValue(Builder.getInt8PtrTy())}); + CI->eraseFromParent(); + return; + case Intrinsic::x86_xop_vfrcz_ss: case Intrinsic::x86_xop_vfrcz_sd: NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(1)}); diff --git a/llvm/test/Bitcode/upgrade-ptr-annotation.ll b/llvm/test/Bitcode/upgrade-ptr-annotation.ll new file mode 100644 index 0000000..aeacc6f --- /dev/null +++ b/llvm/test/Bitcode/upgrade-ptr-annotation.ll @@ -0,0 +1,45 @@ +; Test upgrade of ptr.annotation intrinsics. +; +; RUN: llvm-dis < %s.bc | FileCheck %s + +; Unused return values +; The arguments passed to the intrinisic wouldn't normally be arguments to +; the function, but that makes it easier to test that they are handled +; correctly. +define void @f1(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) { +;CHECK: @f1(i8* [[ARG0:%.*]], i8* [[ARG1:%.*]], i8* [[ARG2:%.*]], i32 [[ARG3:%.*]]) + %t0 = call i8* @llvm.ptr.annotation.p0i8(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) +;CHECK: call i8* @llvm.ptr.annotation.p0i8(i8* [[ARG0]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null) + + %arg0_p16 = bitcast i8* %arg0 to i16* + %t1 = call i16* @llvm.ptr.annotation.p0i16(i16* %arg0_p16, i8* %arg1, i8* %arg2, i32 %arg3) +;CHECK: [[ARG0_P16:%.*]] = bitcast +;CHECK: call i16* @llvm.ptr.annotation.p0i16(i16* [[ARG0_P16]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null) + + %arg0_p256 = bitcast i8* %arg0 to i256* + %t2 = call i256* @llvm.ptr.annotation.p0i256(i256* %arg0_p256, i8* %arg1, i8* %arg2, i32 %arg3) +;CHECK: [[ARG0_P256:%.*]] = bitcast +;CHECK: call i256* @llvm.ptr.annotation.p0i256(i256* [[ARG0_P256]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null) + ret void +} + +; Used return values +define i16* @f2(i16* %x, i16* %y) { + %t0 = call i16* @llvm.ptr.annotation.p0i16(i16* %x, i8* undef, i8* undef, i32 undef) + %t1 = call i16* @llvm.ptr.annotation.p0i16(i16* %y, i8* undef, i8* undef, i32 undef) + %cmp = icmp ugt i16* %t0, %t1 + %sel = select i1 %cmp, i16* %t0, i16* %t1 + ret i16* %sel +; CHECK: [[T0:%.*]] = call i16* @llvm.ptr.annotation.p0i16(i16* %x, i8* undef, i8* undef, i32 undef, i8* null) +; CHECK: [[T1:%.*]] = call i16* @llvm.ptr.annotation.p0i16(i16* %y, i8* undef, i8* undef, i32 undef, i8* null) +; CHECK: %cmp = icmp ugt i16* [[T0]], [[T1]] +; CHECK: %sel = select i1 %cmp, i16* [[T0]], i16* [[T1]] +; CHECK: ret i16* %sel +} + +declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32) +; CHECK: declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*) +declare i16* @llvm.ptr.annotation.p0i16(i16*, i8*, i8*, i32) +; CHECK: declare i16* @llvm.ptr.annotation.p0i16(i16*, i8*, i8*, i32, i8*) +declare i256* @llvm.ptr.annotation.p0i256(i256*, i8*, i8*, i32) +; CHECK: declare i256* @llvm.ptr.annotation.p0i256(i256*, i8*, i8*, i32, i8*) diff --git a/llvm/test/Bitcode/upgrade-ptr-annotation.ll.bc b/llvm/test/Bitcode/upgrade-ptr-annotation.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..5db0810ff88515d1fc40abe7fc20275d8cfb83aa GIT binary patch literal 1524 zcmZ`(Z%h+s7=QcsPAJzK64#Dva|M=kPVri#UTM3uJ*U-?Sa2U$CRwl4iVNcLXIOAC zN3Z5^>xUwkbQv)=AtruU(q(AOGz;aBG1nM$ZgCqUG*om34O3^#X5!vf_wR#Ga_>Fw zd(S=Z@ArG&=k+p^3-uKMr~m*#4OO%Aov*^Jf1ce{+Qc`?;F?JTfDbyQaubll`8xO@ zgVn>HS>+BjZnYnm#Wb&~P`y$4ageWgQ|>)p>K(_e6*Q`QtHjzoSl`yp{3Ar_d0${131Lt`+#LjRNqBsS*34;mHQ=$hRBm)`gM_zZ@J$o;-4) zwc}Bu1V>@iKPJ;PuaOsY_}fUpte5ZR!M{<;fbY^?4PMM%jN*aj%pJGzzZiE=a5tR> zfNz2Nj=-=wlqaThM7Toc8e-^}6!-E-e+21Cc4?M@_AZV+vOK zDzggLEaQqRT-ivxmqQMtNWV|yIAnlR^hHFD6!qDcu$2UsqqLorc4-w`^<#DTv|+(S z+%OrYSYwzv=C~+0<{0~g!g*0}#uSe1YDHfFIoytHX&1ZU$ctP;a8R>hhf@u%& z;(Msrr4zf8Vt;aQ!@X7P-Xiwk3C&(tN#Ns^2~;&{@fmW?WE^CsWQm;~0WdDSoL0G8GR& zJSZ|?M!J)OdzNr)WfHsT#~x7CnQIZ=wrDAgV4XV2h~#c?MevXzwnnS4r(nN_&&kKJsIoIJQJ#aQa|T{p%u@_hXMK zCij!cu$&@RWkuxdw(CDiG%QwH+H`|y$TAH>Oao*+$Gic~z_YD~XR5TM+YD=k476}b z#swu$Gxj+tx=hTZ%5HlKM`_t)c&5R+%}W97mLE#1%@+jL-tuD))BGUPZ!T6oB0|&! z-YwjiL{G>ZBw{JV_5M_qDd6G74NK?Flf(0zgmrg zXkbzoBbCoxVwyswGB2tAu1vr?a7GRSYEMI``|v^;X!&uR*U|F}kI|J8TJCJ39If)N;MuwQOhS!Ctm^|G~~$j@nPZ zVBKPS!3S%-&0?vw)KX*}OIvAc-4hcjsMxaqoauRFGh#!<^TWy literal 0 HcmV?d00001 diff --git a/llvm/test/Bitcode/upgrade-var-annotation.ll b/llvm/test/Bitcode/upgrade-var-annotation.ll new file mode 100644 index 0000000..30f692c --- /dev/null +++ b/llvm/test/Bitcode/upgrade-var-annotation.ll @@ -0,0 +1,15 @@ +; Test upgrade of var.annotation intrinsics. +; +; RUN: llvm-dis < %s.bc | FileCheck %s + + +define void @f(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) { +;CHECK: @f(i8* [[ARG0:%.*]], i8* [[ARG1:%.*]], i8* [[ARG2:%.*]], i32 [[ARG3:%.*]]) + call void @llvm.var.annotation(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) +;CHECK: call void @llvm.var.annotation(i8* [[ARG0]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null) + ret void +} + +; Function Attrs: nofree nosync nounwind willreturn +declare void @llvm.var.annotation(i8*, i8*, i8*, i32) +; CHECK: declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) diff --git a/llvm/test/Bitcode/upgrade-var-annotation.ll.bc b/llvm/test/Bitcode/upgrade-var-annotation.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..c5f88855fb171b5a787b5637ee62834e30edeca4 GIT binary patch literal 1232 zcmYLJaZDRk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