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

    <tr>
        <th>Summary</th>
        <td>
            Miscompile with opt -passes='module(float2int)'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    llvm commit: b8e49fdcb14
Reproduce with:
 opt -passes='module(float2int)' bbi-68023_red.ll -S -o -

With the above we get
define i16 @src() {
entry:
  %cmp = icmp eq i32 2147483647, -1
  br i1 %cmp, label %if.end, label %if.then

if.then:                                          ; preds = %entry
  ret i16 0

if.end:                                           ; preds = %entry
  ret i16 1
}

However, if we remove the dead instruction
   %conv39 = fptoui double %add to i32
in %if.end and rerun we instead get

define i16 @src() {
entry:
  %cmp = icmp eq i32 -1, -1
  br i1 %cmp, label %if.end, label %if.then

if.then:                                          ; preds = %entry
  ret i16 0

if.end:                                           ; preds = %entry
  ret i16 1
}

Note the differences in the icmp instruction.

The first case where we get
  %cmp = icmp eq i32 2147483647, -1
is wrong.

I think the following example in alive2 show it's a miscompile
[bbi-68023_red.ll.gz](https://github.com/llvm/llvm-project/files/8388066/bbi-68023_red.ll.gz)
 as well:
https://alive2.llvm.org/ce/z/ndLkRs

This seems to be old. I see the erroneous behavior with old saved binaries from 2016.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVd9vmzAQ_mvIyykIDCHwwEO7qlqlbQ_dpD1OBh_Bq7GZbZJ1f_3OkKZJNWmttMdFSYD79d19dz4aIx5rpfYDtGYYpI-yK2hKzKtOtE2aR8lNlFzd42iNmFqEg_Q9mSxiMKOH9cidQxdlNxHbDmSlMGJlpwz3TGofsYrk0DRyXZQJy75ZFLFSsP4MawPrJdDy_5Vig-8ReGP2BIWwQ7-oBHZSI8i0gChPnG0JgiJDtL1eDFB7-_icGERs0w4jUFYgww3-AJkxYGm-zcusyLcRewfr9Mm8sRT76BQ0ijeowrPsYtTipYiS1OeZP4mIu1d_ouwaRiLDzUlS3KWEY0IW_Vxt8gImJPMWlFfCHImItjfneO_NAfdoQ_WyC_2wOITOhB4J5AKkdt5OrZdGP0WcSTR6n1UzYDd6M0kQZmoUBh0XArwJzTjWpJ9pBk4_i3bSASwEDyCnIfi3o0DN_z8Cfx2BT8Yf-y27Di3qFh11ZhbNbJ6NQHzu-IUMOmmdh5Y7Osw9OV8c6TeeUengYI3eXYDcUR5SP8zZdEYpc5B6B_iTD6MKAwRcyT0ycL05AO02tnXAYZCOdt0oaVEtsTbXL9dTvPsVbWihlb33owvDxG7pu6MNNTUxedNDWJrHy5rW43dsCeC2o7COrmVWlklR0N2fYtNSXEjgVBYqdRrXS7wl_ThAxMbuSNLScr0l_1stPjzcu0vGiSOHOLhwwBoEo0QMd0E0E4SW-EMzOdL1fC-Nnbd5MAPH9yigkZpbSQ3urBmAJWkRr0SdiSqr-MpLr7D-eOLu6PzaN8Bqsqp-M5vSuWmmc5MXRbXq6zzdcsHKtsiSrGVNWW5YUjUN5-mmShmmq_mMupp6Sg1cyZoljCVZliZVniZ5LLqk3RabtE0Zqwqe0wrBgUt14nhl57fhupl2jpRKOu-elVSo3GnEp_h88r2x9SAfOKreqAH1as65nhP-Dat2GmQ">