<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/147123>147123</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [DebugInfo][Float2Int] Erasing the operands of dead instructions without updating debug values
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            question,
            debuginfo,
            llvm:transforms
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Apochens
      </td>
    </tr>
</table>

<pre>
    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

```llvm
; 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 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVd1u4zYTfRr6ZhCDGv1f6EKJV0iAAB_wpYu9LChxJLOgSS1JOT9PX1C2E2-66LZ3BQxT0gx5Dg8PZ4T3ajJEDctvWb7biCXsrWva2Q57Mn7TW_naPBjotBUBH0xgeAdhT2DnoA7qTQRlDUjSFMivAYborA0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