https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126696

            Bug ID: 126696
           Summary: Fold a fused multiply-add by one into an  addition
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: easyhack, missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

Multiplying by one is exact, so the single rounding of the fused
operation is the rounding of the sum, and the same holds for minus one
and a subtraction.  Dropping the fma also drops the materialisation of
the constant.

When both operands are NaN the result is a NaN either way, but which one
is returned can change.  IEEE 754 leaves that unspecified, and GCC
already folds x * 1.0 into x on the same basis.

  double f (double x, double y) { return __builtin_fma (x, 1.0, y); }

Can generate just:
f:
        fadd    d0, d0, d1
        ret

which Clang already does. GCC does:
f:
        fmov    d31, 1.0e+0
        fmadd   d0, d0, d31, d1
        ret

Reply via email to