From: Andrew Pinski <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH 1/3] MATCH: Move `a ? one_zero : one_zero` matching after min/max matching
Date: Thu, 24 Aug 2023 12:14:53 -0700 [thread overview]
Message-ID: <20230824191455.3547513-1-apinski@marvell.com> (raw)
In PR 106677, I noticed that on the trunk we were producing:
```
_25 = SR.116_117 == 0;
_27 = (unsigned char) _25;
_32 = _27 | SR.116_117;
```
From `SR.115_117 != 0 ? SR.115_117 : 1`
Rather than:
```
_119 = MAX_EXPR <1, SR.115_117>;
```
Or (rather)
```
_119 = SR.115_117 | 1;
```
Due to the order of the patterns.
OK? Bootstrapped and tested on x86_64-linux-gnu with no
regressions.
gcc/ChangeLog:
* match.pd (`a ? one_zero : one_zero`): Move
below detection of minmax.
---
gcc/match.pd | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index 890f050cbad..c87a0795667 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4950,24 +4950,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
)
)
-(simplify
- (cond @0 zero_one_valued_p@1 zero_one_valued_p@2)
- (switch
- /* bool0 ? bool1 : 0 -> bool0 & bool1 */
- (if (integer_zerop (@2))
- (bit_and (convert @0) @1))
- /* bool0 ? 0 : bool2 -> (bool0^1) & bool2 */
- (if (integer_zerop (@1))
- (bit_and (bit_xor (convert @0) { build_one_cst (type); } ) @2))
- /* bool0 ? 1 : bool2 -> bool0 | bool2 */
- (if (integer_onep (@1))
- (bit_ior (convert @0) @2))
- /* bool0 ? bool1 : 1 -> (bool0^1) | bool1 */
- (if (integer_onep (@2))
- (bit_ior (bit_xor (convert @0) @2) @1))
- )
-)
-
/* Optimize
# x_5 in range [cst1, cst2] where cst2 = cst1 + 1
x_5 ? cstN ? cst4 : cst3
@@ -5298,6 +5280,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& integer_nonzerop (fold_build2 (GE_EXPR, boolean_type_node, @3, @1)))
(max @2 @4))))))
+#if GIMPLE
+(simplify
+ (cond @0 zero_one_valued_p@1 zero_one_valued_p@2)
+ (switch
+ /* bool0 ? bool1 : 0 -> bool0 & bool1 */
+ (if (integer_zerop (@2))
+ (bit_and (convert @0) @1))
+ /* bool0 ? 0 : bool2 -> (bool0^1) & bool2 */
+ (if (integer_zerop (@1))
+ (bit_and (bit_xor (convert @0) { build_one_cst (type); } ) @2))
+ /* bool0 ? 1 : bool2 -> bool0 | bool2 */
+ (if (integer_onep (@1))
+ (bit_ior (convert @0) @2))
+ /* bool0 ? bool1 : 1 -> (bool0^1) | bool1 */
+ (if (integer_onep (@2))
+ (bit_ior (bit_xor (convert @0) @2) @1))
+ )
+)
+#endif
+
/* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */
(simplify
(cond (ne @0 INTEGER_CST@1) (negate@3 @0) INTEGER_CST@2)
--
2.31.1
next reply other threads:[~2023-08-24 19:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 19:14 Andrew Pinski [this message]
2023-08-24 19:14 ` [PATCH 2/3] MATCH: `a | C -> C` when we know that `a & ~C == 0` Andrew Pinski
2023-08-25 6:36 ` Richard Biener
2023-08-25 7:40 ` Andrew Pinski
2023-08-24 19:14 ` [PATCH 3/3] PHIOPT: Allow BIT_AND and BIT_IOR in early phiopt Andrew Pinski
2023-08-25 6:46 ` Richard Biener
2023-08-25 23:11 ` Andrew Pinski
2023-08-25 6:38 ` [PATCH 1/3] MATCH: Move `a ? one_zero : one_zero` matching after min/max matching Richard Biener
2023-08-25 18:11 ` Andrew Pinski
2023-08-25 18:18 ` Andrew Pinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230824191455.3547513-1-apinski@marvell.com \
--to=apinski@marvell.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).