From 48eeefe59f2d2ab44eb771e8ae315cd15f97f57b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 8 Feb 2022 16:50:11 +0100 Subject: [PATCH] [AutoUpgrade] Handle remangling upgrade for ptr.annotation The code assumed that the upgrade would happen due to the argument count changing from 4 to 5. However, a remangling upgrade is also possible here. --- llvm/lib/IR/AutoUpgrade.cpp | 7 +++++-- ...pgrade.ll => opaque-ptr-intrinsic-remangling.ll} | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) rename llvm/test/Assembler/{invoke-intrinsic-upgrade.ll => opaque-ptr-intrinsic-remangling.ll} (75%) diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 8102e176407e..6803fdb5d600 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -3886,8 +3886,11 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) { case Intrinsic::ptr_annotation: // Upgrade from versions that lacked the annotation attribute argument. - assert(CI->arg_size() == 4 && - "Before LLVM 12.0 this intrinsic took four arguments"); + if (CI->arg_size() != 4) { + DefaultCase(); + return; + } + // Create a new call with an added null annotation attribute argument. NewCall = Builder.CreateCall( NewFn, diff --git a/llvm/test/Assembler/invoke-intrinsic-upgrade.ll b/llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll similarity index 75% rename from llvm/test/Assembler/invoke-intrinsic-upgrade.ll rename to llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll index eb24dfd238ee..c885897f3155 100644 --- a/llvm/test/Assembler/invoke-intrinsic-upgrade.ll +++ b/llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll @@ -1,11 +1,12 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -opaque-pointers < %s | FileCheck %s -; Make sure that an intrinsic remangling upgrade works for invokes as well. +; Make sure that opaque pointer intrinsic remangling upgrade works. declare i32* @fake_personality_function() declare void @func() +; Upgrading of invoked intrinsic. define void @test_invoke(i32 addrspace(1)* %b) gc "statepoint-example" personality i32* ()* @fake_personality_function { ; CHECK-LABEL: @test_invoke( ; CHECK-NEXT: entry: @@ -33,4 +34,14 @@ unwind_dest: ret void } +define i8* @test_ptr_annotation(i8* %p) { +; CHECK-LABEL: @test_ptr_annotation( +; CHECK-NEXT: [[P2:%.*]] = call ptr @llvm.ptr.annotation.p0(ptr [[P:%.*]], ptr undef, ptr undef, i32 undef, ptr undef) +; CHECK-NEXT: ret ptr [[P2]] +; + %p2 = call i8* @llvm.ptr.annotation.p0i8(i8* %p, i8* undef, i8* undef, i32 undef, i8* undef) + ret i8* %p2 +} + declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) +declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*)