summaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-05-08 09:32:20 +0200
committerJakub Jelinek <jakub@redhat.com>2020-05-08 09:32:20 +0200
commitff33680165346cb291667f38dd2e9f25a74cc3c3 (patch)
tree357d4e2d6b76e6805659de387b7d161523eaceae /gcc/match.pd
parentaf1634f1b555004753a22d1124dbb8419ee095cb (diff)
match.pd: Simplify unsigned A - B - 1 >= A to B >= A [PR94913]
Implemented thusly. The TYPE_OVERFLOW_WRAPS is there just because the pattern above it has it too, if you want, I can throw it away from both. 2020-05-08 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/94913 * match.pd (A - B + -1 >= A to B >= A): New simplification. (A - B > A to A < B): Don't test TYPE_OVERFLOW_WRAPS which is always true for TYPE_UNSIGNED integral types. * gcc.dg/tree-ssa/pr94913.c: New test.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd11
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 9259dd4ddaa..cfe96975d80 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4787,10 +4787,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cmp:c (minus@2 @0 @1) @0)
(if (single_use (@2)
&& ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
- && TYPE_UNSIGNED (TREE_TYPE (@0))
- && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
+ && TYPE_UNSIGNED (TREE_TYPE (@0)))
(cmp @1 @0))))
+/* Optimize A - B + -1 >= A into B >= A for unsigned comparisons. */
+(for cmp (ge lt)
+ (simplify
+ (cmp:c (plus (minus @0 @1) integer_minus_onep) @0)
+ (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (cmp @1 @0))))
+
/* Testing for overflow is unnecessary if we already know the result. */
/* A - B > A */
(for cmp (gt le)