Skip to content

Commit 089106f

Browse files
authored
[DebugInfo][LoopStrengthReduce] Salvage the debug value of the dead cmp instruction (#147241)
Fix #147238
1 parent 60b168c commit 089106f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,8 +2559,10 @@ ICmpInst *LSRInstance::OptimizeMax(ICmpInst *Cond, IVStrideUse* &CondUse) {
25592559
Instruction *Cmp = cast<Instruction>(Sel->getOperand(0));
25602560
Cond->eraseFromParent();
25612561
Sel->eraseFromParent();
2562-
if (Cmp->use_empty())
2562+
if (Cmp->use_empty()) {
2563+
salvageDebugInfo(*Cmp);
25632564
Cmp->eraseFromParent();
2565+
}
25642566
return NewCond;
25652567
}
25662568

llvm/test/Transforms/LoopStrengthReduce/optimizemax_debugloc.ll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
; RUN: opt < %s -loop-reduce -S 2>&1 | FileCheck %s
2+
23
;; This test case checks that whether the new icmp instruction preserves
34
;; the debug location of the original instruction for %exitcond
4-
; CHECK: icmp uge i32 %indvar.next, %n, !dbg ![[DBGLOC:[0-9]+]]
5+
6+
;; This test case also checks that the debug value of the dead icmp
7+
;; instruction is salvaged.
8+
9+
; CHECK-LABEL: bb.nph:
10+
; CHECK: #dbg_value(i32 %n, ![[META1:[0-9]+]], !DIExpression(DW_OP_lit0, DW_OP_eq, DW_OP_stack_value), ![[META2:[0-9]+]])
11+
; CHECK-LABEL: bb:
12+
; CHECK: icmp uge i32 %indvar.next, %n, !dbg ![[DBGLOC:[0-9]+]]
13+
14+
; CHECK: ![[META1]] = !DILocalVariable(name: "1",
15+
; CHECK: ![[META2]] = !DILocation(line: 1, column: 1,
516
; CHECK: ![[DBGLOC]] = !DILocation(line: 6, column: 1, scope
617

718
; ModuleID = 'simplified-dbg.bc'

0 commit comments

Comments
 (0)