[Bug tree-optimization/94899] Failure to optimize out add before compare with INT_MIN
cvs-commit at gcc dot gnu.org
Tue Jun 21 10:22:15 GMT 2022
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <firstname.lastname@example.org>:
Author: Arjun Shankar <email@example.com>
Date: Tue Jun 21 12:12:11 2022 +0200
match.pd: Remove "+ 0x80000000" in int comparisons [PR94899]
Expressions of the form "X + CST < Y + CST" where:
* CST is an unsigned integer constant with only the MSB set, and
* X and Y's types have integer conversion ranks <= CST's
can be simplified to "(signed) X < (signed) Y".
This is because, assuming a 32-bit signed numbers,
(unsigned) INT_MIN + 0x80000000 is 0, and
(unsigned) INT_MAX + 0x80000000 is UINT_MAX.
i.e. the result increases monotonically with signed input.
((signed) X < (signed) Y) iff (X + 0x80000000 < Y + 0x80000000)
* match.pd (X + C < Y + C -> (signed) X < (signed) Y, if C is
0x80000000): New simplification.
* gcc.dg/pr94899.c: New test.
More information about the Gcc-bugs