Skip to content

[DebugInfo][Float2Int] Erasing the operands of dead instructions without updating debug values #147123

Open
@Apochens

Description

@Apochens

In Float2Int, the optimization deletes the "root" instructions after converting the float-point operations into integer operations.

// Perform dead code elimination on the instructions we just modified.
void Float2IntPass::cleanup() {
for (auto &I : reverse(ConvertedInsts))
I.first->eraseFromParent();
}

However, the optimization only RAUWs the "root" instructions with the converted instructions:

// If we're a root instruction, RAUW.
if (Roots.count(I))
I->replaceAllUsesWith(NewV);

As a result, the debug values of the operands of the RAUWed dead instructions may be lost. Here is an example: https://godbolt.org/z/fqde9nbW4

; after optimization
define i16 @simple1(i8 %a) !dbg !5 {
  %1 = zext i8 %a to i32, !dbg !14
    #dbg_value(float poison, !9, !DIExpression(), !14)
  %t21 = add i32 %1, 1, !dbg !15
    #dbg_value(float poison, !11, !DIExpression(), !15)
  %2 = trunc i32 %t21 to i16, !dbg !16
    #dbg_value(i16 %2, !12, !DIExpression(), !16)
  ret i16 %2, !dbg !17
}

So, in this case, should we use SalvageDebugInfo or replaceAllDbgUses on these operands?

CC @OCHyams

Metadata

Metadata

Assignees

No one assigned

    Labels

    debuginfollvm:transformsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions