+2017-04-28 Marc Glisse <marc.glisse@inria.fr>
+
+ * match.pd (X+Z OP Y+Z, X-Z OP Y-Z, Z-X OP Z-Y): New transformations.
+
2017-04-28 Bernd Edlinger <bernd.edlinger@hotmail.de>
* configure.ac (SYSTEM_HEADER_DIR, BUILD_SYSTEM_HEADER_DIR,
(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,
/* { 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;
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" } } */