[Bug middle-end/115551] [missed optimization] "c1 << (a + c2)" not optimized into "(c1 << c2) << a"

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 20 07:21:13 GMT 2024


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

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
As we want to have a >= 0, I tried to convey it differently for the example in
comment 0:

(a) __attribute__((assume(ch >= 0)));
(b) 'unsigned ch' (instead of 'int ch')

but it didn't help.  Thus, it looks as if it could be implemented for:
  c1 << (a + c2)
if (a >= 0 and c2 >= 0) doing then the conversion
  (c1 << c2) << a

Whether Ranger handles abs(c2) > c3 >= 0 → a >= 0 for 'c1 << (a*c2 + c3)', I
don't know, but the variant above with unsigned and 'assume(a >= 0)' should be
implementable and seems to make sense.


More information about the Gcc-bugs mailing list