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

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 07:50:27 PST 2020


fhahn created this revision.
fhahn added reviewers: thegameg, spatel, jdoerfert, RKSimon, lebedev.ri.
Herald added a subscriber: hiraditya.
fhahn requested review of this revision.
Herald added a project: LLVM.

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 <https://reviews.llvm.org/D91444>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93399

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


Index: llvm/test/Transforms/InstCombine/annotations.ll
===================================================================
--- llvm/test/Transforms/InstCombine/annotations.ll
+++ llvm/test/Transforms/InstCombine/annotations.ll
@@ -6,7 +6,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
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3693,8 +3693,8 @@
         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);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93399.312213.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201216/9aeba99c/attachment.bin>


More information about the llvm-commits mailing list