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

            Bug ID: 31626
           Summary: [DAGCombine] enableAggressiveFMAFusion incorrectly
                    uses associativity of addition
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedb...@nondot.org
          Reporter: nhaeh...@gmail.com
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

The following transforms:

    // fold (fadd (fma x, y, (fmul u, v)), z) -> (fma x, y (fma u, v, z))
    // fold (fadd x, (fma y, z, (fmul u, v)) -> (fma y, z (fma u, v, x))
    // fold (fsub (fma x, y, (fmul u, v)), z)
    //   -> (fma x, y (fma u, v, (fneg z)))
    // fold (fsub x, (fma y, z, (fmul u, v)))
    //   -> (fma (fneg y), z, (fma (fneg u), v, x))

make use of associativity of addition (and the last one probably even more).
Other parts of the compiler take pains not to use associativity unless
UnsafeFPMath is enabled.

However, these transforms are only guarded by: ((AllowFusion || HasFMAD) &&
Aggressive).

Aggressive is defined by

  /// Return true if target always beneficiates from combining into FMA for a
  /// given value type. This must typically return false on targets where FMA
  /// takes more cycles to execute than FADD.

i.e. it is only about the relative performance of different code sequences
which produce the same result.

I think the guard for the transforms above should instead be: ((AllowFusion ||
HasFMAD) && Options.UnsafeFPMath && Aggressive)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to