<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 - narrow casted FMA op?"
   href="https://bugs.llvm.org/show_bug.cgi?id=43841">43841</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>narrow casted FMA op?
          </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>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>float fmaf(float x, float y, float z) {
        return (((double)x * (double)y) + (double)z);
}

$ clang -O3 -march=haswell -ffp-contract=on
fmaf(float, float, float):
        vcvtss2sd       xmm0, xmm0, xmm0
        vcvtss2sd       xmm1, xmm1, xmm1
        vcvtss2sd       xmm2, xmm2, xmm2
        vfmadd231sd     xmm2, xmm0, xmm1 # xmm2 = (xmm0 * xmm1) + xmm2
        vcvtsd2ss       xmm0, xmm2, xmm2
        ret


Or as IR:

define float @fmaf(float %0, float %1, float %2) {
  %4 = fpext float %0 to double
  %5 = fpext float %1 to double
  %6 = fpext float %2 to double
  %7 = tail call double @llvm.fmuladd.f64(double %4, double %5, double %6)
  %8 = fptrunc double %7 to float
  ret float %8
}

declare double @llvm.fmuladd.f64(double, double, double)

<a href="https://gcc.godbolt.org/z/FxOJlh">https://gcc.godbolt.org/z/FxOJlh</a>

-------------------------------------------------------------------------------

Can we remove all of the casts and reduce this to a float (f32 - "vfmadd231ss")
math instruction because the intermediate rounding steps can be proven to not
affect the result?

InstCombiner::visitFPTrunc() has a section dedicated to this kind of transform,
but it does not include FMA. It only includes the FP binops (fmul, fadd, fsub,
fdiv, frem).

The existing transforms reference:
Figueroa's 2000 PhD thesis, "A Rigorous Framework for Fully Supporting the IEEE
Standard ..."</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>