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

    <tr>
        <th>Summary</th>
        <td>
            Incorrect `fsub -0, %x` -> `fneg %x`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            llvm:instcombine
      </td>
    </tr>

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

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

<pre>
    Per the discussion in https://discourse.llvm.org/t/semantics-of-nan/66729/30, we want to consider the following InstCombine transformation as a bug:
```llvm
define float @src(float %x) {
  %s = fsub float 0x80000000, %x
  ret float %s
}
=>
define float @src(float %x) {
  %s = fneg float %x
  ret float %s
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
float %x = #x7f800100 (SNaN)

Source:
float %s = #x7f808000 (QNaN)

Target:
float %s = #xff800100 (SNaN)
Source value: #x7f808000 (QNaN)
Target value: #xff800100 (SNaN)
```

The optimization is correct if `nnan` is used.

cc @arsenm @jcranmer-intel @jyknight @rotateright
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVEtv3CAQ_jX4gnZlYP06-JBkUymXtE2i3jHGNimGFeBk01_fwXY3WaWJKtXyA-b5zfhjGtu-1N-kw2GQuFVeTN4ra7AyeAjh4BG7QPQL3FFnJ-flVuuncWtdD8IAj5cjN0EJv7HdxnADojwvaAVfliJ6hZ8lfgYLHCwW1njVrtk6q7V9VqbHN8aHKzs2ykgcHDe-s27kIeLgHnPcTH3Eke5ReoHydLkjjEXUyi56dtrygNEu9U4gWq5bmh0RrTAqLhdjHEUeI7bHnZ-a1Ss9lulyRcSz02rtZMCnUH7FUOzXBdsjdv2fKIzs8Ruzf8n7cN6k1koPfS8CfpJOdS-IktVhfl_f3X29gwbiH1xPEo_Kg58YzkyOfDxoeeryK54ZI6LsWHTQIpKmsCnvb_kt1PM2wj2QQ_wlgD8LELscA3x_H-CBu16GzwJ0HyFYcuOnWF6s89NsS55z4w8jn9h2hhTIaw9BjerX0n_lgdnOSRGw6jBYm3gO8jQqJi_b7VtvISI7OJwkM8bVo4CfOUq3USZIPUtefhrVDzOLnA08wE-FbSJrkudVnrOK0KStWVuxiidBBS3rG_MHAeSdib15pTIg2QBPZ1Vk2ypMJqfr81PeqzBMzVbYETbzCVs-m4OzjxAdtsr7SXpYZBVlZTLUomkIyUgqC1lmRFAuO1blVVuW1W7HszLRvJHa1yi7RJSOcY6MB6Xn1oFgQUnnZOxCwSgQyyiIumyfqJqmlBJCS1Ixwspt1tCWsXbXkLwoOrKDLsEIUvo0mBJXz5hhbHhQauWDf1VyGHC9kXLGA_H5FAbrajMZe9D2IH0yV1jP5f0GJy6AMg">