[Bug tree-optimization/70527] Missed fold for "(long int) x * 12 - (long int)(x + 1) * 12"

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Apr 4 12:38:00 GMT 2016


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-04-04
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note the issue is (non-)canonicalization of (long)(x + 1).  For optimal
re-assoc you'd want to canonicalize this to (long)x + 1L (with x + 1
having undefined behavior on overflow) and then to (long)x * 12 + 12.

But generally you do _not_ want to do this because you lose value-range info
and carry out the op in a larger mode (the former means the reverse transform
is not valid).

Generic folding has very limited capabilities here and GIMPLE reassoc currently
refuses to associate signed ops at all.


More information about the Gcc-bugs mailing list