public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2887] MATCH: Add `a == b | a cmp b` and `a != b & a cmp b` simplifications
@ 2023-07-31 17:12 Andrew Pinski
0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-07-31 17:12 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ac0e0966ebf08c454d53042a649403e2880ccbc1
commit r14-2887-gac0e0966ebf08c454d53042a649403e2880ccbc1
Author: Andrew Pinski <apinski@marvell.com>
Date: Sat Jul 29 21:52:31 2023 -0700
MATCH: Add `a == b | a cmp b` and `a != b & a cmp b` simplifications
Even though these are done by combine_comparisons, we can add them to match
to allow simplifcations during match rather than just during reassoc/ifcombine.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
gcc/ChangeLog:
PR tree-optimization/106164
* match.pd (`a != b & a <= b`, `a != b & a >= b`,
`a == b | a < b`, `a == b | a > b`): Handle these cases
too.
gcc/testsuite/ChangeLog:
PR tree-optimization/106164
* gcc.dg/tree-ssa/cmpbit-2.c: New test.
Diff:
---
gcc/match.pd | 32 ++++++++++++++++++++++++--
gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c | 39 ++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index fe4c2453fd3..74f0a84f31d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2830,7 +2830,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(switch
(if (code1 == EQ_EXPR && val) @3)
(if (code1 == EQ_EXPR && !val) { constant_boolean_node (false, type); })
- (if (code1 == NE_EXPR && !val) @4)))))))
+ (if (code1 == NE_EXPR && !val) @4)
+ (if (code1 == NE_EXPR
+ && code2 == GE_EXPR
+ && cmp == 0)
+ (gt @0 @1))
+ (if (code1 == NE_EXPR
+ && code2 == LE_EXPR
+ && cmp == 0)
+ (lt @0 @1))
+ )
+ )
+ )
+ )
+ )
+)
/* Convert (X OP1 CST1) && (X OP2 CST2).
Convert (X OP1 Y) && (X OP2 Y). */
@@ -2915,7 +2929,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(switch
(if (code1 == EQ_EXPR && val) @4)
(if (code1 == NE_EXPR && val) { constant_boolean_node (true, type); })
- (if (code1 == NE_EXPR && !val) @3)))))))
+ (if (code1 == NE_EXPR && !val) @3)
+ (if (code1 == EQ_EXPR
+ && code2 == GT_EXPR
+ && cmp == 0)
+ (ge @0 @1))
+ (if (code1 == EQ_EXPR
+ && code2 == LT_EXPR
+ && cmp == 0)
+ (le @0 @1))
+ )
+ )
+ )
+ )
+ )
+)
/* Convert (X OP1 CST1) || (X OP2 CST2).
Convert (X OP1 Y) || (X OP2 Y). */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c
new file mode 100644
index 00000000000..c4226ef01af
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-reassoc -fdump-tree-optimized-raw" } */
+
+_Bool f(int a, int b)
+{
+ _Bool c = a == b;
+ _Bool d = a > b;
+ return c | d;
+}
+
+_Bool f1(int a, int b)
+{
+ _Bool c = a != b;
+ _Bool d = a >= b;
+ return c & d;
+}
+
+_Bool g(int a, int b)
+{
+ _Bool c = a == b;
+ _Bool d = a < b;
+ return c | d;
+}
+
+_Bool g1(int a, int b)
+{
+ _Bool c = a != b;
+ _Bool d = a <= b;
+ return c & d;
+}
+
+
+/* We should be able to optimize these without reassociation too. */
+/* { dg-final { scan-tree-dump-not "bit_and_expr," "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr," "optimized" } } */
+/* { dg-final { scan-tree-dump-times "gt_expr," 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "ge_expr," 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "lt_expr," 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "le_expr," 1 "optimized" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-31 17:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-31 17:12 [gcc r14-2887] MATCH: Add `a == b | a cmp b` and `a != b & a cmp b` simplifications Andrew Pinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).