[Bug middle-end/60962] b+(-2.f)*a generates multiplication instruction while b-2.f*a simplifies to addition&subtraction

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Apr 25 12:46:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60962

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-04-25
                 CC|                            |rguenth at gcc dot gnu.org
          Component|c++                         |middle-end
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We retain + -2.f*point[] until RTL expansion where then somewhere following
we have special code expanding 2.f * point[] but not -2.f * point[].

Confirmed.

We should optimize A + -2.*B to A - 2. * B.  I believe we did so at some
point in the past.


Looks like we do

    case PLUS_EXPR:
      /* A + (-B) -> A - B */
      if (TREE_CODE (arg1) == NEGATE_EXPR
          && (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)
        return fold_build2_loc (loc, MINUS_EXPR, type,

Which matches NEGATE_EXPR and doesn't use negate_expr_p for some reason
(and sanitize check w/o checking we are processing integer types ...)

But negate_expr_p has

    case REAL_CST:
      /* We want to canonicalize to positive real constants.  Pretend
         that only negative ones can be easily negated.  */
      return REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));



More information about the Gcc-bugs mailing list