From ca1206be9a340b874a1f6e47f9028c22dda5a9f9 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 26 Apr 2016 17:03:08 +0200 Subject: [PATCH] match.pd: u + 3 < u is u > UINT_MAX - 3 2016-04-26 Marc Glisse gcc/ * match.pd (X + CST CMP X): New transformation. gcc/testsuite/ * gcc.dg/tree-ssa/overflow-1.c: New testcase. From-SVN: r235448 --- gcc/ChangeLog | 4 ++++ gcc/match.pd | 26 ++++++++++++++++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/overflow-1.c | 16 +++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/overflow-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e45f9c95c993..325eb874a988 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-04-26 Marc Glisse + + * match.pd (X + CST CMP X): New transformation. + 2016-04-26 Marc Glisse * genmatch.c (write_predicate): Add ATTRIBUTE_UNUSED. diff --git a/gcc/match.pd b/gcc/match.pd index 5f22b13b6907..476818709cf0 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 70baf0605617..b77a17b1c602 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-04-26 Marc Glisse + + * gcc.dg/tree-ssa/overflow-1.c: New testcase. + 2016-04-26 Marek Polacek 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 000000000000..e126609c53d9 --- /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 4294967263;" "optimized" } } */ -- 2.43.5