diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2016-04-26 17:03:08 +0200 |
---|---|---|
committer | Marc Glisse <glisse@gcc.gnu.org> | 2016-04-26 15:03:08 +0000 |
commit | ca1206be9a340b874a1f6e47f9028c22dda5a9f9 (patch) | |
tree | a20377d202cdfae0362b32db059864c23e70cdad /gcc | |
parent | b02a5e265db4d32cf1e67ee142bf337c185873ea (diff) | |
download | gcc-ca1206be9a340b874a1f6e47f9028c22dda5a9f9.zip gcc-ca1206be9a340b874a1f6e47f9028c22dda5a9f9.tar.gz gcc-ca1206be9a340b874a1f6e47f9028c22dda5a9f9.tar.bz2 |
match.pd: u + 3 < u is u > UINT_MAX - 3
2016-04-26 Marc Glisse <marc.glisse@inria.fr>
gcc/
* match.pd (X + CST CMP X): New transformation.
gcc/testsuite/
* gcc.dg/tree-ssa/overflow-1.c: New testcase.
From-SVN: r235448
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/match.pd | 26 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/overflow-1.c | 16 |
4 files changed, 50 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e45f9c9..325eb87 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2016-04-26 Marc Glisse <marc.glisse@inria.fr> + * match.pd (X + CST CMP X): New transformation. + +2016-04-26 Marc Glisse <marc.glisse@inria.fr> + * genmatch.c (write_predicate): Add ATTRIBUTE_UNUSED. * fold-const.c (fold_binary_loc): Remove 2 transformations superseded by match.pd. diff --git a/gcc/match.pd b/gcc/match.pd index 5f22b13..4768187 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2482,6 +2482,32 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) replace if (x == 0) with tem = ~x; if (tem != 0) which is clearly less optimal and which we'll transform again in forwprop. */ +/* When one argument is a constant, overflow detection can be simplified. + Currently restricted to single use so as not to interfere too much with + ADD_OVERFLOW detection in tree-ssa-math-opts.c. + A + CST CMP A -> A CMP' CST' */ +(for cmp (lt le ge gt) + out (gt gt le le) + (simplify + (cmp (plus@2 @0 INTEGER_CST@1) @0) + (if (TYPE_UNSIGNED (TREE_TYPE (@0)) + && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)) + && wi::ne_p (@1, 0) + && single_use (@2)) + (out @0 { wide_int_to_tree (TREE_TYPE (@0), wi::max_value + (TYPE_PRECISION (TREE_TYPE (@0)), UNSIGNED) - @1); })))) +/* A CMP A + CST -> A CMP' CST' */ +(for cmp (gt ge le lt) + out (gt gt le le) + (simplify + (cmp @0 (plus@2 @0 INTEGER_CST@1)) + (if (TYPE_UNSIGNED (TREE_TYPE (@0)) + && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)) + && wi::ne_p (@1, 0) + && single_use (@2)) + (out @0 { wide_int_to_tree (TREE_TYPE (@0), wi::max_value + (TYPE_PRECISION (TREE_TYPE (@0)), UNSIGNED) - @1); })))) + /* Simplification of math builtins. These rules must all be optimizations as well as IL simplifications. If there is a possibility that the new diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70baf06..b77a17b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-04-26 Marc Glisse <marc.glisse@inria.fr> + + * gcc.dg/tree-ssa/overflow-1.c: New testcase. + 2016-04-26 Marek Polacek <polacek@redhat.com> PR c/67784 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/overflow-1.c b/gcc/testsuite/gcc.dg/tree-ssa/overflow-1.c new file mode 100644 index 0000000..e126609 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/overflow-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +int f(unsigned a){ + unsigned b=5; + unsigned c=a-b; + return c>a; +} +int g(unsigned a){ + unsigned b=32; + unsigned c=a+b; + return c<a; +} + +/* { dg-final { scan-tree-dump "a_\[0-9\]+.D. <= 4;" "optimized" } } */ +/* { dg-final { scan-tree-dump "a_\[0-9\]+.D. > 4294967263;" "optimized" } } */ |