[llvm] 16ad6ee - [IR] Don't copy profile metadata in createCallMatchingInvoke()

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 17 02:18:42 PDT 2020


Author: Hans Wennborg
Date: 2020-06-17T11:18:23+02:00
New Revision: 16ad6eeb94ff0619288fb9b3a2287076d5f32ae1

URL: https://github.com/llvm/llvm-project/commit/16ad6eeb94ff0619288fb9b3a2287076d5f32ae1
DIFF: https://github.com/llvm/llvm-project/commit/16ad6eeb94ff0619288fb9b3a2287076d5f32ae1.diff

LOG: [IR] Don't copy profile metadata in createCallMatchingInvoke()

The invoke instruction can have profile metadata with branch_weights,
which does not make sense for a call instruction and will be
rejected by the verifier.

Differential revision: https://reviews.llvm.org/D81996

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/Local.cpp
    llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 7c0cb51e3144..d0f0c8f1565c 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1985,6 +1985,11 @@ CallInst *llvm::createCallMatchingInvoke(InvokeInst *II) {
   NewCall->setAttributes(II->getAttributes());
   NewCall->setDebugLoc(II->getDebugLoc());
   NewCall->copyMetadata(*II);
+
+  // If the invoke had profile metadata, drop it.
+  if (NewCall->hasMetadata(LLVMContext::MD_prof))
+    NewCall->setMetadata(LLVMContext::MD_prof, nullptr);
+
   return NewCall;
 }
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll b/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
index b11b7c15fa34..5758b67a55b5 100644
--- a/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
+++ b/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
@@ -7,9 +7,10 @@ declare void @bar()
 define i32 @test1() personality i32 (...)* @__gxx_personality_v0 {
 ; CHECK-LABEL: @test1(
 ; CHECK-NEXT: call void @bar()
+; CHECK-NOT: !prof
 ; CHECK-NEXT: ret i32 0
         invoke void @bar( )
-                        to label %1 unwind label %Rethrow
+                        to label %1 unwind label %Rethrow, !prof !0
         ret i32 0
 Rethrow:
         %exn = landingpad {i8*, i32}
@@ -17,6 +18,8 @@ Rethrow:
         resume { i8*, i32 } %exn
 }
 
+!0 = !{!"branch_weights", i32 369, i32 0}
+
 define i32 @test2() personality i32 (...)* @__gxx_personality_v0 {
 ; CHECK-LABEL: @test2(
 ; CHECK-NEXT: call void @bar() [ "foo"(i32 100) ]


        


More information about the llvm-commits mailing list