<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [Matrix] LowerMatrixIntrinsics should preserve existing fast-math flags during lowering"
   href="https://bugs.llvm.org/show_bug.cgi?id=49738">49738</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[Matrix] LowerMatrixIntrinsics should preserve existing fast-math flags during lowering
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>florian_hahn@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Currently LowerMatrixIntrinsics does not add existing fast-math flags from
matrix intrinsics & other instructions with shape information to the lowered
instructions.

For the example below, `opt -lower-matrix-intrinsics` creates fmuladd/fadd/fmul
instructions without `fast`: <a href="https://godbolt.org/z/1o48Tx1bP">https://godbolt.org/z/1o48Tx1bP</a>

This also means we fail to fold redundant FP instructions. In this case, we end
up with fmuladd calls with operands that are zero and can be simplified with
`fast`:  <a href="https://godbolt.org/z/5oWs1oh91">https://godbolt.org/z/5oWs1oh91</a>

define <4 x float> @foo(<4 x float> %m, float %x, float %y) {
  %i1 = insertelement <4 x float> <float poison, float 0.000000e+00, float
0.000000e+00, float poison>, float %x, i64 0
  %i2 = insertelement <4 x float> %i1, float %y, i64 3
  %res = tail call fast <4 x float> @llvm.matrix.multiply.v4f32.v4f32.v4f32(<4
x float> %m, <4 x float> %i1, i32 2, i32 2, i32 2)
  %res.2 = fadd fast <4 x float> %res, %m
  ret <4 x float> %res
}

declare <4 x float> @llvm.matrix.multiply.v4f32.v4f32.v4f32(<4 x float>, <4 x
float>, i32, i32, i32)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>