[llvm-bugs] [Bug 43841] New: narrow casted FMA op?

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 29 11:56:02 PDT 2019


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

            Bug ID: 43841
           Summary: narrow casted FMA op?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org

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)

https://gcc.godbolt.org/z/FxOJlh

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

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 ..."

-- 
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/20191029/4bef1dc5/attachment.html>


More information about the llvm-bugs mailing list