On Tue, Feb 1, 2022 at 5:54 AM Arjun Shankar via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Expressions of the form "X + CST < Y + CST" where X and Y are of int > type and CST is of unsigned type with only the MSB on can be simplified > to "X < Y" because "X + 0x80000000" increases monotonically with X.
+/* As a special case, X + C < Y + C is the same as X < Y even with wrapping + overflow if X and Y are signed integers of the same size, and C is an + unsigned constant with all bits except MSB set to 0 and size >= that of + X/Y. */ +(for op (lt le ge gt) + (simplify + (op (plus:c (convert@0 @1) @4) (plus:c (convert@2 @3) @4)) + (if (CONSTANT_CLASS_P (@4) + && TYPE_UNSIGNED (TREE_TYPE (@4)) why include (convert ..) here? It looks like you could do without, merging the special case with the preceding pattern and let a followup pattern simplify (lt (convert @1) (convert @2)) instead? > gcc/ > * match.pd (X + C < Y + C -> X < Y, if C is 0x80000000): New > simplification. > gcc/testsuite/ > * gcc.dg/pr94899.c: New test. > --- > gcc/match.pd | 18 ++++++++++++++++++ > gcc/testsuite/gcc.dg/pr94899.c | 28 ++++++++++++++++++++++++++++ > 2 files changed, 46 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/pr94899.c