From 9eb5d484235b97ed6e4e5f153dd7f159d7365f38 Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Mon, 16 Oct 2017 14:24:10 +0100
Subject: [PATCH 1/3] simplify-AopCst-cmp-A-20171006.txt
---
gcc/match.pd | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
@@ -3518,7 +3518,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* 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' */
+ A + CST CMP A -> A CMP' CST'
+
+ For type with undefined overflow behavior, the expression can also be
+ simplified by assuming overflow won't happen.
+ A + CST cmp A -> CST cmp zero. */
(for cmp (lt le ge gt)
out (gt gt le le)
(simplify
@@ -3530,7 +3534,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(with { unsigned int prec = TYPE_PRECISION (TREE_TYPE (@0)); }
(out @0 { wide_int_to_tree (TREE_TYPE (@0),
wi::max_value (prec, UNSIGNED)
- - wi::to_wide (@1)); })))))
+ - wi::to_wide (@1)); }))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+ (with
+ {
+ tree zero = build_zero_cst (TREE_TYPE (@1));
+
+ fold_overflow_warning (("assuming signed overflow does not occur "
+ "when simplifying A + CST cmp A"),
+ WARN_STRICT_OVERFLOW_CONDITIONAL);
+ }
+ (cmp @1 { zero; }))))))
/* To detect overflow in unsigned A - B, A < B is simpler than A - B > A.
However, the detection logic for SUB_OVERFLOW in tree-ssa-math-opts.c
--
1.9.1