Index: llvm/lib/IR/AutoUpgrade.cpp =================================================================== --- llvm/lib/IR/AutoUpgrade.cpp +++ llvm/lib/IR/AutoUpgrade.cpp @@ -937,6 +937,12 @@ 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 @@ } 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,30 @@ CI->eraseFromParent(); return; + case Intrinsic::ptr_annotation: + // Upgrade from versions that lacked the annotation attribute argument. + assert(CI->getNumArgOperands() == 4); + // 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); + // 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)}); Index: llvm/test/Bitcode/upgrade-ptr-annotation.ll =================================================================== --- /dev/null +++ llvm/test/Bitcode/upgrade-ptr-annotation.ll @@ -0,0 +1,37 @@ +; Test upgrade of ptr.annotation intrinsics. +; +; RUN: llvm-dis < %s.bc | FileCheck %s + +; Unused return values +define void @f1() { + %t0 = call i8* @llvm.ptr.annotation.p0i8(i8* undef, i8* undef, i8* undef, i32 undef) +;CHECK: call i8* @llvm.ptr.annotation.p0i8(i8* undef, i8* undef, i8* undef, i32 undef, i8* null) + + %t1 = call i16* @llvm.ptr.annotation.p0i16(i16* undef, i8* undef, i8* undef, i32 undef) +;CHECK: call i16* @llvm.ptr.annotation.p0i16(i16* undef, i8* undef, i8* undef, i32 undef, i8* null) + + %t2 = call i256* @llvm.ptr.annotation.p0i256(i256* undef, i8* undef, i8* undef, i32 undef) +;CHECK: call i256* @llvm.ptr.annotation.p0i256(i256* undef, i8* undef, i8* undef, i32 undef, 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*) Index: llvm/test/Bitcode/upgrade-var-annotation.ll =================================================================== --- /dev/null +++ llvm/test/Bitcode/upgrade-var-annotation.ll @@ -0,0 +1,14 @@ +; Test upgrade of var.annotation intrinsics. +; +; RUN: llvm-dis < %s.bc | FileCheck %s + + +define void @f() { + call void @llvm.var.annotation(i8* undef, i8* undef, i8* undef, i32 undef) +;CHECK: call void @llvm.var.annotation(i8* undef, i8* undef, i8* undef, i32 undef, 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*)