<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - fp-contract (FMA) isn't always captured in LLVM IR"
   href="https://llvm.org/bugs/show_bug.cgi?id=25721">25721</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>fp-contract (FMA) isn't always captured in LLVM IR
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </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>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat contract.c 
float foo(float x, float y, float z) {
  return x * y + z;
}

$ ./clang -O1 -ffp-contract=fast contract.c -o - -S  -march=haswell | grep ss
    vfmadd213ss    %xmm2, %xmm1, %xmm0

$ ./clang -O1 -ffp-contract=fast contract.c -o - -S  -emit-llvm | ./llc -o -
-mcpu=haswell |grep ss
    vmulss    %xmm1, %xmm0, %xmm0
    vaddss    %xmm2, %xmm0, %xmm0


The problem is fp-contraction isn't serialized in the IR; it's just a target
option. That won't work in LTO builds.

A possible solution is discussed in <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Generalize support for FMA contraction"
   href="show_bug.cgi?id=13118">bug 13118</a>: add IR-level-flags for
fp-contract. 

I'm not sure yet why "-ffp-contract=fast" doesn't produce the llvm.fmuladd
intrinsic like "-ffp-contract=on" does. Ie, this works like I would expect:

$ cat contract2.c 
#pragma STDC FP_CONTRACT ON
float foo(float x, float y, float z) {
  return x*y+z;
}

$ ./clang -O1 -ffp-contract=on contract2.c -o - -S  -emit-llvm | ./llc -o -
-mcpu=haswell |grep ss
    vfmadd213ss    %xmm2, %xmm1, %xmm0

Because:
$ ./clang -O1 -ffp-contract=on contract2.c -o - -S  -emit-llvm |grep mul
  %0 = tail call float @llvm.fmuladd.f32(float %x, float %y, float %z)</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>