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

    <tr>
        <th>Summary</th>
        <td>
            Reassociatable fmul by constants unnecessarily requires nsz
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            missed-optimization,
            floating-point
      </td>
    </tr>

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

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

<pre>
    These reassociatable fmuls by constants should preserve signed zero behavior, but do not fold unless nsz is attached to both multiplies

```
; RUN: opt -S -passes=instcombine %s

; Can't reassociate anyway
define float @fmul(float %x) {
  %fmul0 = fmul float %x, 2.0
  %fmul1 = fmul float %fmul0, 4.0
  ret float %fmul1
}

; Should be able to reassociate without nsz
; (+0 * 2) * 4 = +0
; (-0 * 2) * 4 = -0

; (+0 * 8) = +0
; (-0 * 8) = -0
define float @fmul_reassoc(float %x) {
  %fmul0 = fmul reassoc float %x, 2.0
 %fmul1 = fmul reassoc float %fmul0, 4.0
  ret float %fmul1
}

; (+0 * 2) * -4 = -0
; (-0 * 2) * -4 = +0

; (+0 * -8) = -0
; (-0 * -8) = +0
define float @fmul_reassoc_negative_0(float %x) {
  %fmul0 = fmul reassoc float %x, 2.0
  %fmul1 = fmul reassoc float %fmul0, -4.0
 ret float %fmul1
}

; (+0 * -2) * 4 = -0
; (-0 * -2) * 4 = +0

; (+0 * -8) = -0
; (-0 * -8) = +0
define float @fmul_reassoc_negative_1(float %x) {
  %fmul0 = fmul reassoc float %x, -2.0
  %fmul1 = fmul reassoc float %fmul0, 4.0
  ret float %fmul1
}

; Does reassociate already, unnecessarily requires nsz on both multiplies.
define float @fmul_reassoc_nsz(float %x) {
  %fmul0 = fmul nsz reassoc float %x, 2.0
  %fmul1 = fmul nsz reassoc float %fmul0, 4.0
  ret float %fmul1
}

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lk9v4zYQxT8NdRnIoKg_tg462DF87GG3PQekNLZYUKTKobJ1Pn0h2buJbGXRZIMFghii3zzz_WZAShLpk0WsWL5j-T6SQ2idr6QntF2kXHOu_myREDxKIldrGaQyCMduMATqDLWzFKQNBNS6wTTQeyT0TwiTcQPP6B0obOWTdp6JB1BDgMaBdQGOzjQwWINEYOkZNIEMQdYtNhAcKBda6AYTdG80EuN7xrfX_wW__l0e0x18-esPlm7B9QHirxD3kgiJpXttKdSuU9oiMJHPbdIdPEjLxDq8Sogg7fmbPF80DR7H0qNxMgDL-Bidic31WeT_MlECW-8uahiXRgkHlu4nTvBa-gBixW-kyYJ0shjl2YvcY5gLkmuK9f421NdLMxTC1K7gZvG-6dC6IYzMX0qY2DCx48DEFsSUSWwhm7Y2rs-E8aIs5rfbeO25mcQ_cfsh-O6zRP7xmuN9HbgWvdmJ-0bcVfxiQxbpxjfcluHGd01YdI3v-M394oUG_Izwo8WTDPoJH_nnwn4X7fgF9wdpx29N6ZzO2yP_m2knn0E7_iDujw333iHNz0_jUTbn0XGwFmskkl6bM3j8Z9AeL8e9s7dH_Or_gKLn9xEaf-oDM7lY9iugvl9ZUVOlTZmWMsIqKUpR8iLZ5FFbyYY3KlF8XWyyVBVNw9dHmWNSiiLfFHiMdCW4SPlGZEmZpTxfqVzWWYZ1ovI1x1qxjGMntVkZ89StnD9FmmjAqsjKYh0ZqdDQdNULMSpYun11OzIhmHhgQnSaCJvY9UF3-lkG7eyP76ag2p7i3mkbxuV8H_lqdIvVcCKWcaMp0MsOgg4Gqy_37w_z14e35yQavKnaEHpi6ZaJAxOHkw7toFa165g4TEkuH3Hv3d9YByYOU3Bi4jBl_y8AAP__y_aH_g">