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
This commit is contained in:
Marc Glisse 2016-04-26 17:03:08 +02:00 committed by Marc Glisse
parent b02a5e265d
commit ca1206be9a
4 changed files with 50 additions and 0 deletions

View File

@ -1,3 +1,7 @@
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.

View File

@ -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

View File

@ -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

View File

@ -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" } } */