[Bug tree-optimization/126085] If a in (-CST, 1-CST), then a + CST to a == (CST + 1)

kaelfandrew at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jul 3 01:28:34 GMT 2026


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

--- Comment #3 from Kael Franco <kaelfandrew at gmail dot com> ---
(In reply to Drea Pinski from comment #2)
> I think we should do the opposite way around and convert `(type)(a == (CST +
> 1))` into `a+CST` instead. Adding is almost always simplier than comparsion.

/* (type)([0,1]@a != 0) -> (type)a
   (type)([0,1]@a == 1) -> (type)a
   (type)([0,1]@a == 0) -> a ^ 1
   (type)([0,1]@a != 1) -> a ^ 1.  */
(for eqne (eq ne)
 (simplify
  (convert (eqne zero_one_valued_p@0 INTEGER_CST@1))

This PR seems to be general version of above match pattern.

(type) ([CST,CST + 1]a == CST) -> (a - CST) ^ 1
(type) ([CST,CST + 1]a != CST) -> a - CST


More information about the Gcc-bugs mailing list