[llvm] [CorrelatedValuePropagation] Drop stale debug records on context-only rewrites (PR #218498)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 20:12:00 PDT 2026


================
@@ -814,6 +814,11 @@ static bool narrowSDivOrSRem(BinaryOperator *Instr, const ConstantRange &LCR,
     if (BinOp->getOpcode() == Instruction::SDiv)
       BinOp->setIsExact(Instr->isExact());
 
+  // This narrowing is only valid at the uses of the result. A debug record
+  // can describe the value outside that range, where the narrow computation
+  // does not have the source-level value. Do not transfer those records to the
+  // sign-extended replacement.
+  Instr->dropDbgRecords();
----------------
MrEven132 wrote:

I don't think we should drop the debug records here. It should be straightforward to represent the original value with a DIExpression. Also, dropping this dbg_value does not necessarily make the variable unavailable. If the same variable has an earlier dbg_value, that earlier value may remain in effect here, causing the debugger to report a stale and incorrect value. Therefore, dropping the record does not fully fix the problem.

https://github.com/llvm/llvm-project/pull/218498


More information about the llvm-commits mailing list