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.
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
--- /dev/null
+/* { 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" } } */