Skip to content

[DebugInfo][ConstraintElimination] Potential debug value loss in replacing comparisons with the speculated constants #135736

Closed
@Apochens

Description

@Apochens

In ConstraintElimination, the pass first collects instructions that could be replaced with a speculated constant in function checkAndReplaceCondition(), and then it removes the collected instruction in ConstraintElimination-L1964.

1963  for (Instruction *I : ToRemove)
1964    I->eraseFromParent();

However, I found that this process leads to poison debug values in the optimzied IR. Here 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:

; 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
; 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. 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.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions