[llvm-branch-commits] [llvm] eba09a2 - [InstCombine] Preserve !annotation for newly created instructions.

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Dec 17 01:12:20 PST 2020


Author: Florian Hahn
Date: 2020-12-17T09:06:51Z
New Revision: eba09a2db9eab46832cb7ec7ef0d2c227747772a

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

LOG: [InstCombine] Preserve !annotation for newly created instructions.

When replacing an instruction with !annotation with a newly created
replacement, add the !annotation metadata to the replacement.

This mostly covers cases where the new instructions are created using
the ::Create helpers. Instructions created by IRBuilder will be handled
by D91444.

Reviewed By: thegameg

Differential Revision: https://reviews.llvm.org/D93399

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
    llvm/test/Transforms/InstCombine/annotations.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 9306e99f5d52..770d58b31664 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3693,8 +3693,8 @@ bool InstCombinerImpl::run() {
         LLVM_DEBUG(dbgs() << "IC: Old = " << *I << '\n'
                           << "    New = " << *Result << '\n');
 
-        if (I->getDebugLoc())
-          Result->setDebugLoc(I->getDebugLoc());
+        Result->copyMetadata(*I,
+                             {LLVMContext::MD_dbg, LLVMContext::MD_annotation});
         // Everything uses the new instruction now.
         I->replaceAllUsesWith(Result);
 

diff  --git a/llvm/test/Transforms/InstCombine/annotations.ll b/llvm/test/Transforms/InstCombine/annotations.ll
index 1530b867bfb6..3b0989402823 100644
--- a/llvm/test/Transforms/InstCombine/annotations.ll
+++ b/llvm/test/Transforms/InstCombine/annotations.ll
@@ -7,7 +7,7 @@
 ; instruction has !annotation metadata.
 define i1 @fold_to_new_instruction(i8* %a, i8* %b) {
 ; CHECK-LABEL: define {{.+}} @fold_to_new_instruction({{.+}}
-; CHECK-NEXT:    [[C:%.*]] = icmp uge i8* [[A:%.*]], [[B:%[a-z]*]]
+; CHECK-NEXT:    [[C:%.*]] = icmp uge i8* [[A:%.*]], [[B:%[a-z]*]], !annotation [[ANN:![0-9]+]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %a.c = bitcast i8* %a to i32*, !annotation !0


        


More information about the llvm-branch-commits mailing list