Re: [PATCH GCC][1/3]Simplify (A + CST cmp A -> CST cmp zero) for undefined overflow type

2017-10-19 Thread Bin.Cheng
On Thu, Oct 19, 2017 at 4:22 PM, Marc Glisse  wrote:
> On Thu, 19 Oct 2017, Bin Cheng wrote:
>
>> * match.pd (A + CST cmp A  ->  CST cmp zero): New simplification
>> for undefined overflow types in (A + CST CMP A  ->  A CMP' CST').
>
>
> Could you check if you still need that? I recently added something very
> similar (search for "X + Y < Y" in match.pd).
Ah, yes indeed, the two patterns are unnecessary now on TOT.  I will drop this.

Thanks,
bin
>
> --
> Marc Glisse


Re: [PATCH GCC][1/3]Simplify (A + CST cmp A -> CST cmp zero) for undefined overflow type

2017-10-19 Thread Marc Glisse

On Thu, 19 Oct 2017, Bin Cheng wrote:


* match.pd (A + CST cmp A  ->  CST cmp zero): New simplification
for undefined overflow types in (A + CST CMP A  ->  A CMP' CST').


Could you check if you still need that? I recently added something very 
similar (search for "X + Y < Y" in match.pd).


--
Marc Glisse


[PATCH GCC][1/3]Simplify (A + CST cmp A -> CST cmp zero) for undefined overflow type

2017-10-19 Thread Bin Cheng
Hi,
This is a rework of patch set at 
https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01036.html
and https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01037.html.  The patch set 
improves niters
bound analysis for split loop.  Instead of feeding bound computation to generic 
folder, this
patch simplifies (A + CST cmp A  ->  CST cmp zero) for types with undefined 
overflow behavior.
Bootstrap and test for patch set on x86_64 and AArch64.  Comments?

Thanks,
bin
2017-10-16  Bin Cheng  

* match.pd (A + CST cmp A  ->  CST cmp zero): New simplification
for undefined overflow types in (A + CST CMP A  ->  A CMP' CST').From 9eb5d484235b97ed6e4e5f153dd7f159d7365f38 Mon Sep 17 00:00:00 2001
From: Bin Cheng 
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(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index f2c4373..64b023d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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