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

    <tr>
        <th>Summary</th>
        <td>
            [DebugInfo][LICM] Debug value loss caused by hoisting the cmp instructions
        </td>
    </tr>

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

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

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

<pre>
    In the function `hoistMinMax()` in LICM, after replacing the comparisons in loop with the hoisted compared result, the optimization erases the replaced comparison (i.e., `Cond1` and `Cond2` in the following code, which are the two operands of the logical operation instruction `I`) without salvaging the debug values.

https://github.com/llvm/llvm-project/blob/2599a9aeb543f01cb20e3fdc2713aa8c8cb20fbf/llvm/lib/Transforms/Scalar/LICM.cpp#L2491-L2494

**Here is an example:** https://godbolt.org/z/M38xhTY3a
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUU8tu4zoM_Rp5I9Sw6UfshRdpAuMGaFa3m1lSD9saKJIhyUnbrx9IadNidgMIFkyKh4eHJHqvZiPlQJpn0hwz3MJi3bBfLV-k8Rmz4n04GRoWSafN8KCsoaQtFqt8OCtzxjcCHYGetAVVhr6cDmcCB4pTkI46uWrkyswpntvLik55a3x8qq1d6U2FJTkToBSfj6SgTvpNh4gV3XYN6qI-MOWXDr30yX7P8IiL4JRAp3KZx1DSFgdrRBnZoRFf__DJNlVltba3yJFbIWPQbVF8oehk8oebpXaVDo3w1E7Jpu2sOOq7PVFSxge3PeQ5kbYg0Kfy7BaoR33F-UsIIdk20yvqTfqcFHtS7JcQVk-qPYGRwDirsGws5_ZCYNT6-nU9rc7-ljwQGJm2jMAITd9jj5I1dTUVJWdQyGoSHHZlhdjxLlomNv3AUTHu1aHxk3UXT2D8n6NGR2CM3cv5uhKoXqDuy6f4re8MCcTzn3SSKk_RUPmGl1XLRDoe-lcNVjCrQ27dTGD8IDCeq-5tef1VYSaGSvRVj5kcyl1T1lC3XZUtQwu7HVZ1hyC6pmKsaUSHVdN10zTtOHaZGqCAptgV8SqhyhtgrOO870QvcDe1pC7kBZXOY7Uxd6a83-RQ1m0LZaaRSe3TsAPEAUxzRQAIHAhAaowyk31YkmjVPvyQC-KeuCH1g22zJ3WhlQ_-O2VQQaeNOka8U8RrjqR5TsvRHOnxu_9UW-8px81LQdn7fQ0eC3NZfw6Wzzanh3-elCRAbPOnBtcB_gQAAP__dM9JBQ">