llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

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

Open Apochens opened this issue 1 year ago • 6 comments

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

https://github.com/llvm/llvm-project/blob/0e9571df982fb0527cac2c6a6d21ff502f5d4668/llvm/lib/Transforms/Scalar/Float2Int.cpp#L475-L479

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

https://github.com/llvm/llvm-project/blob/0e9571df982fb0527cac2c6a6d21ff502f5d4668/llvm/lib/Transforms/Scalar/Float2Int.cpp#L467-L469

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

Apochens avatar Jul 05 '25 03:07 Apochens

@llvm/issue-subscribers-debuginfo

Author: Shan Huang (Apochens)

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

https://github.com/llvm/llvm-project/blob/0e9571df982fb0527cac2c6a6d21ff502f5d4668/llvm/lib/Transforms/Scalar/Float2Int.cpp#L475-L479

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

https://github.com/llvm/llvm-project/blob/0e9571df982fb0527cac2c6a6d21ff502f5d4668/llvm/lib/Transforms/Scalar/Float2Int.cpp#L467-L469

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

llvmbot avatar Jul 05 '25 03:07 llvmbot

Hi @Apochens , I like to work on this Transforms module since there is no good first issue, let me work and learn. I'm going to assign it.

shahidiqbal13 avatar Jul 13 '25 06:07 shahidiqbal13

@Apochens , how can I ask for the commit access, earlier I had but something changed Do I need to mail anyone?

shahidiqbal13 avatar Jul 13 '25 06:07 shahidiqbal13

@Apochens , how can I ask for the commit access, earlier I had but something changed Do I need to mail anyone?

You can request commit access according to this doc. By the way, this issue is not confirmed right now. So, it may not be suitable for you.

Apochens avatar Jul 13 '25 07:07 Apochens

@Apochens , Thanks for the clarification, once this issue gets accepted then only I will procced for the fix.

shahidiqbal13 avatar Jul 13 '25 07:07 shahidiqbal13

Sorry for the slow response on this. I think your analysis looks right @Apochens, it does look like we needlessly drop variable location coverage here. Thanks for the report and details.

OCHyams avatar Oct 02 '25 13:10 OCHyams