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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to