Skip to content

Commit 1e15425

Browse files
committed
[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
1 parent d96295e commit 1e15425

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,8 +3565,8 @@ bool InstCombiner::run() {
35653565
LLVM_DEBUG(dbgs() << "IC: Old = " << *I << '\n'
35663566
<< " New = " << *Result << '\n');
35673567

3568-
if (I->getDebugLoc())
3569-
Result->setDebugLoc(I->getDebugLoc());
3568+
Result->copyMetadata(*I,
3569+
{LLVMContext::MD_dbg, LLVMContext::MD_annotation});
35703570
// Everything uses the new instruction now.
35713571
I->replaceAllUsesWith(Result);
35723572

llvm/test/Transforms/InstCombine/annotations.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
; instruction has !annotation metadata.
88
define i1 @fold_to_new_instruction(i8* %a, i8* %b) {
99
; CHECK-LABEL: define {{.+}} @fold_to_new_instruction({{.+}}
10-
; CHECK-NEXT: [[C:%.*]] = icmp uge i8* [[A:%.*]], [[B:%[a-z]*]]
10+
; CHECK-NEXT: [[C:%.*]] = icmp uge i8* [[A:%.*]], [[B:%[a-z]*]], !annotation [[ANN:![0-9]+]]
1111
; CHECK-NEXT: ret i1 [[C]]
1212
;
1313
%a.c = bitcast i8* %a to i32*, !annotation !0

0 commit comments

Comments
 (0)