[llvm-bugs] [Bug 25721] New: fp-contract (FMA) isn't always captured in LLVM IR

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 2 12:28:18 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25721

            Bug ID: 25721
           Summary: fp-contract (FMA) isn't always captured in LLVM IR
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

$ 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 bug 13118: 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)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151202/eedbf93c/attachment.html>


More information about the llvm-bugs mailing list