This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH GCC][2/3]Simplify ((A +- CST1 CMP A +- CST2)) for undefined overflow type
- From: Bin Cheng <Bin dot Cheng at arm dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: nd <nd at arm dot com>
- Date: Thu, 19 Oct 2017 13:26:26 +0000
- Subject: [PATCH GCC][2/3]Simplify ((A +- CST1 CMP A +- CST2)) for undefined overflow type
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bin dot Cheng at arm dot com;
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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.
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