From: Marc Glisse Date: Fri, 28 Apr 2017 20:51:05 +0000 (+0200) Subject: Drop Z from X + Z < Y + Z X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d35256b6c1c2d52d3539ef8a1c700b69342acd19;p=gcc.git Drop Z from X + Z < Y + Z 2017-04-28 Marc Glisse gcc/ * match.pd (X+Z OP Y+Z, X-Z OP Y-Z, Z-X OP Z-Y): New transformations. gcc/testsuite/ * gcc.dg/tree-ssa/cmpexactdiv-2.c: Update for X-Z OP Y-Z. From-SVN: r247398 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9f885b429de..d1204f18311 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2017-04-28 Marc Glisse + + * match.pd (X+Z OP Y+Z, X-Z OP Y-Z, Z-X OP Z-Y): New transformations. + 2017-04-28 Bernd Edlinger * configure.ac (SYSTEM_HEADER_DIR, BUILD_SYSTEM_HEADER_DIR, diff --git a/gcc/match.pd b/gcc/match.pd index 44745df9afa..e3d98baa12f 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1042,6 +1042,54 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (wi::gt_p(@2, 0, TYPE_SIGN (TREE_TYPE (@2)))) (cmp @0 @1)))) +/* X + Z < Y + Z is the same as X < Y when there is no overflow. */ +(for op (lt le ge gt) + (simplify + (op (plus:c @0 @2) (plus:c @1 @2)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + (op @0 @1)))) +/* For equality and subtraction, this is also true with wrapping overflow. */ +(for op (eq ne minus) + (simplify + (op (plus:c @0 @2) (plus:c @1 @2)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) + || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))) + (op @0 @1)))) + +/* X - Z < Y - Z is the same as X < Y when there is no overflow. */ +(for op (lt le ge gt) + (simplify + (op (minus @0 @2) (minus @1 @2)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + (op @0 @1)))) +/* For equality and subtraction, this is also true with wrapping overflow. */ +(for op (eq ne minus) + (simplify + (op (minus @0 @2) (minus @1 @2)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) + || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))) + (op @0 @1)))) + +/* Z - X < Z - Y is the same as Y < X when there is no overflow. */ +(for op (lt le ge gt) + (simplify + (op (minus @2 @0) (minus @2 @1)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + (op @1 @0)))) +/* For equality and subtraction, this is also true with wrapping overflow. */ +(for op (eq ne minus) + (simplify + (op (minus @2 @0) (minus @2 @1)) + (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) + || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))) + (op @1 @0)))) + /* ((X inner_op C0) outer_op C1) With X being a tree where value_range has reasoned certain bits to always be zero throughout its computed value range, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 499f7808a1e..92db79cded7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-04-28 Marc Glisse + + * gcc.dg/tree-ssa/cmpexactdiv-2.c: Update for X-Z OP Y-Z. + 2017-04-28 Tom de Vries * g++.dg/abi/bitfield3.C: Remove superfluous "" in diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c index e7f11b988c0..a41811cf571 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O -fdump-tree-optimized-raw" } */ +/* { dg-options "-O -fstrict-overflow -fdump-tree-optimized-raw" } */ int f (long *a, long *b, long *c) { __PTRDIFF_TYPE__ l1 = b - a; @@ -7,5 +7,5 @@ int f (long *a, long *b, long *c) { return l1 < l2; } -/* Eventually we also want to remove all minus_expr. */ +/* { dg-final { scan-tree-dump-not "minus_expr" "optimized" } } */ /* { dg-final { scan-tree-dump-not "exact_div_expr" "optimized" } } */