diff mbox series

[2/3] Simplify ((A +- CST1 CMP A +- CST2)) for undefined overflow type

Message ID DB5PR0801MB2742708FDDCEA2716C4589E1E7420@DB5PR0801MB2742.eurprd08.prod.outlook.com
State New
Headers show
Series [1/3] Simplify (A + CST cmp A -> CST cmp zero) for undefined overflow type | expand

Commit Message

Bin Cheng Oct. 19, 2017, 1:26 p.m. UTC
Hi,
This patch adds pattern simplifying (A +- CST1 CMP A +- CST2) for undefined overflow types.
Bootstrap and test for patch set on x86_64 and AArch64.  Comments?

Thanks,
bin
2017-10-16  Bin Cheng  <bin.cheng@arm.com>

	* match.pd (A +- CST1 CMP A +- CST2): New pattern.

Comments

Marc Glisse Oct. 19, 2017, 3:33 p.m. UTC | #1
On Thu, 19 Oct 2017, Bin Cheng wrote:

> 	* match.pd (A +- CST1 CMP A +- CST2): New pattern.

Similarly, this has a very large overlap with "X + Z < Y + Z" transforms 
already in match.pd. It may handle X - CST CMP X + CST that the other 
doesn't (?), but we tend to canonicalize X-5 to X+-5 anyway.
Bin.Cheng Oct. 19, 2017, 4:18 p.m. UTC | #2
On Thu, Oct 19, 2017 at 4:33 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Thu, 19 Oct 2017, Bin Cheng wrote:
>
>>         * match.pd (A +- CST1 CMP A +- CST2): New pattern.
>
>
> Similarly, this has a very large overlap with "X + Z < Y + Z" transforms
> already in match.pd. It may handle X - CST CMP X + CST that the other
> doesn't (?), but we tend to canonicalize X-5 to X+-5 anyway.
And drop this one.

Thanks,
bin
>
> --
> Marc Glisse
diff mbox series

Patch

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(-)

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