From 6e31cde6560366242c15039a5b3032f5425750e0 Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Thu, 10 Aug 2017 17:29:22 +0100
Subject: [PATCH 2/3] simplify-AopCst1-cmp-AopCst2-20170806.txt
---
gcc/match.pd | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
@@ -3485,7 +3485,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (cmp == LE_EXPR)
(ge (convert:st @0) { build_zero_cst (st); })
(lt (convert:st @0) { build_zero_cst (st); }))))))))))
-
+
+/* A +- CST1 CMP A +- CST2 in type with undefined overflow behavior. */
+(for cmp (lt gt le ge)
+ (for xop (plus minus)
+ (for yop (plus minus)
+ (simplify
+ (cmp (xop @0 INTEGER_CST@1) (yop @0 INTEGER_CST@2))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+ && types_compatible_p (TREE_TYPE (@1), TREE_TYPE (@2)))
+ (with
+ {
+ tree cst1 = @1, cst2 = @2, zero = build_zero_cst (TREE_TYPE (@1));
+ if (xop == MINUS_EXPR)
+ cst1 = int_const_binop (MINUS_EXPR, zero, cst1);
+ if (yop == MINUS_EXPR)
+ cst2 = int_const_binop (MINUS_EXPR, zero, cst2);
+
+ fold_overflow_warning (("assuming signed overflow does not occur "
+ "when simplifying A +- CST cmp A +- CST"),
+ WARN_STRICT_OVERFLOW_CONDITIONAL);
+ }
+ (cmp { cst1; } { cst2; })))))))
+
(for cmp (unordered ordered unlt unle ungt unge uneq ltgt)
/* If the second operand is NaN, the result is constant. */
(simplify
--
1.9.1