public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1134] match.pd: Improve y == MIN || x < y optimization [PR105983] Date: Thu, 16 Jun 2022 12:37:47 +0000 (GMT) [thread overview] Message-ID: <20220616123747.6BEA83836643@sourceware.org> (raw) https://gcc.gnu.org/g:9642d07c35f14b9917cd115e8a9f0210fbcdcf4f commit r13-1134-g9642d07c35f14b9917cd115e8a9f0210fbcdcf4f Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Jun 16 14:37:06 2022 +0200 match.pd: Improve y == MIN || x < y optimization [PR105983] On the following testcase, we only optimize bar where this optimization is performed at GENERIC folding time, but on GIMPLE it doesn't trigger anymore, as we actually don't see (bit_and (ne @1 min_value) (ge @0 @1)) but (bit_and (ne @1 min_value) (le @1 @0)) genmatch handles :c modifier not just on commutative operations, but also comparisons and in that case it means it swaps the comparison. 2022-06-16 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/105983 * match.pd (y == XXX_MIN || x < y -> x <= y - 1, y != XXX_MIN && x >= y -> x > y - 1): Use :cs instead of :s on non-equality comparisons. * gcc.dg/tree-ssa/pr105983.c: New test. Diff: --- gcc/match.pd | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/pr105983.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index ae5dc820fa5..3e9572e4c9c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2460,14 +2460,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* y == XXX_MIN || x < y --> x <= y - 1 */ (simplify - (bit_ior:c (eq:s @1 min_value) (lt:s @0 @1)) + (bit_ior:c (eq:s @1 min_value) (lt:cs @0 @1)) (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) (le @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))) /* y != XXX_MIN && x >= y --> x > y - 1 */ (simplify - (bit_and:c (ne:s @1 min_value) (ge:s @0 @1)) + (bit_and:c (ne:s @1 min_value) (ge:cs @0 @1)) (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) (gt @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr105983.c b/gcc/testsuite/gcc.dg/tree-ssa/pr105983.c new file mode 100644 index 00000000000..46418c25d1f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr105983.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/105983 */ +/* { dg-do compile } */ +/* { dg-options "-O2 --param=logical-op-non-short-circuit=1 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-not " != 0;" "optimized" } } */ +/* { dg-final { scan-tree-dump-not " & " "optimized" } } */ + +int +foo (unsigned a, unsigned b) +{ + return b != 0 && a >= b; +} + +int +bar (unsigned a, unsigned b) +{ + return b != 0 & a >= b; +}
reply other threads:[~2022-06-16 12:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220616123747.6BEA83836643@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).