Issue |
135736
|
Summary |
[DebugInfo][ConstraintElimination] Potential debug value loss in replacing comparisons with the speculated constants
|
Labels |
debuginfo,
llvm:transforms
|
Assignees |
|
Reporter |
Apochens
|
In ConstraintElimination, the pass first collects instructions that could be replaced with a speculated constant in function [`checkAndReplaceCondition()`](https://github.com/llvm/llvm-project/blob/fe54d1afcca055f464840654dd2ec3fd83aea688/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp#L1431), and then it removes the collected instruction in [ConstraintElimination-L1964](https://github.com/llvm/llvm-project/blob/fe54d1afcca055f464840654dd2ec3fd83aea688/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp#L1964).
```c++
1963 for (Instruction *I : ToRemove)
1964 I->eraseFromParent();
```
However, I found that this process leads to _**poison debug values**_ in the optimzied IR. [Here](https://godbolt.org/z/78aMxx6En) is an example where the ConstraintElimination is performed on an LLVM IR function in the regression test (and.ll) of the pass. The debug information is obtained by `opt -passes=debugify`. Poison debug values are produced in the basic block `bb1`:
```llvm ir
; Before the optimization
bb1: ; preds = %entry
%t.1 = icmp ule i4 %x, %z, !dbg !31
#dbg_value(i1 %t.1, !13, !DIExpression(), !31)
%t.2 = icmp ule i4 %x, %y, !dbg !32
#dbg_value(i1 %t.2, !14, !DIExpression(), !32)
%r.1 = xor i1 %t.1, %t.2, !dbg !33
```
```llvm ir
; After the optimization
bb1: ; preds = %entry
#dbg_value(i1 poison, !13, !DIExpression(), !31)
#dbg_value(i1 poison, !14, !DIExpression(), !32)
%r.1 = xor i1 true, true, !dbg !33
```
I think these poison debug values, which corresponds to the erased `icmp` instructions, **_could be prevented_** according to [rules-for-updating-debug-values](https://llvm.org/docs/HowToUpdateDebugInfo.html#rules-for-updating-debug-values). Specifically, we can use either `salvageDebugInfo()` (i.e., using the DIExpression) or `replaceAllDbgUsesWith()` (i.e., refering the debug value to the speculated constrant) to save the debug value information for the erased `imp` instructions.
Moreover, could this issue be caused by the missed debug information salvage in `Value::replaceUsesWithIf()` used in `checkAndReplaceCondition()`? (`Value::replaceAllUsesWith` handles the debug value information for the replaced instruction.)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs