[llvm] 089106f - [DebugInfo][LoopStrengthReduce] Salvage the debug value of the dead cmp instruction (#147241)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 13 18:45:40 PDT 2025
Author: Shan Huang
Date: 2025-07-14T09:45:37+08:00
New Revision: 089106fdfb853c83cf5d35a37bdd8e663094e6a2
URL: https://github.com/llvm/llvm-project/commit/089106fdfb853c83cf5d35a37bdd8e663094e6a2
DIFF: https://github.com/llvm/llvm-project/commit/089106fdfb853c83cf5d35a37bdd8e663094e6a2.diff
LOG: [DebugInfo][LoopStrengthReduce] Salvage the debug value of the dead cmp instruction (#147241)
Fix #147238
Added:
Modified:
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/test/Transforms/LoopStrengthReduce/optimizemax_debugloc.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 845afa6d4228b..9e8d2f2230acc 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -2559,8 +2559,10 @@ ICmpInst *LSRInstance::OptimizeMax(ICmpInst *Cond, IVStrideUse* &CondUse) {
Instruction *Cmp = cast<Instruction>(Sel->getOperand(0));
Cond->eraseFromParent();
Sel->eraseFromParent();
- if (Cmp->use_empty())
+ if (Cmp->use_empty()) {
+ salvageDebugInfo(*Cmp);
Cmp->eraseFromParent();
+ }
return NewCond;
}
diff --git a/llvm/test/Transforms/LoopStrengthReduce/optimizemax_debugloc.ll b/llvm/test/Transforms/LoopStrengthReduce/optimizemax_debugloc.ll
index d2d5550c3d68f..d3f68f2305165 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/optimizemax_debugloc.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/optimizemax_debugloc.ll
@@ -1,7 +1,18 @@
; RUN: opt < %s -loop-reduce -S 2>&1 | FileCheck %s
+
;; This test case checks that whether the new icmp instruction preserves
;; the debug location of the original instruction for %exitcond
-; CHECK: icmp uge i32 %indvar.next, %n, !dbg ![[DBGLOC:[0-9]+]]
+
+;; This test case also checks that the debug value of the dead icmp
+;; instruction is salvaged.
+
+; CHECK-LABEL: bb.nph:
+; CHECK: #dbg_value(i32 %n, ![[META1:[0-9]+]], !DIExpression(DW_OP_lit0, DW_OP_eq, DW_OP_stack_value), ![[META2:[0-9]+]])
+; CHECK-LABEL: bb:
+; CHECK: icmp uge i32 %indvar.next, %n, !dbg ![[DBGLOC:[0-9]+]]
+
+; CHECK: ![[META1]] = !DILocalVariable(name: "1",
+; CHECK: ![[META2]] = !DILocation(line: 1, column: 1,
; CHECK: ![[DBGLOC]] = !DILocation(line: 6, column: 1, scope
; ModuleID = 'simplified-dbg.bc'
More information about the llvm-commits
mailing list