From: Richard Biener <richard.guenther@gmail.com>
To: Andrew Pinski <apinski@marvell.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 2/3] MATCH: `a | C -> C` when we know that `a & ~C == 0`
Date: Fri, 25 Aug 2023 08:36:15 +0200 [thread overview]
Message-ID: <CAFiYyc2=F_Cq_iT_=PT01BwvHtxuGcWR57_4pLrSg1n2XJBbpg@mail.gmail.com> (raw)
In-Reply-To: <20230824191455.3547513-2-apinski@marvell.com>
On Thu, Aug 24, 2023 at 9:16 PM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Even though this is handled by other code inside both VRP and CCP,
> sometimes we want to optimize this outside of VRP and CCP.
> An example is given in PR 106677 where phiopt will happen
> after VRP (which removes a cast for a comparison) and then
> phiopt will optimize the phi to be `a | 1` which can then
> be optimized to `1` due to this patch.
Also works for xor, no?
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
OK with or without adding XOR.
Richard.
> Note Similar code already exists in simplify_rtx for the RTL level;
> it was moved from combine to simplify_rtx in r0-72539-gbd1ef757767f6d.
> gcc/ChangeLog:
>
> * match.pd (`a | C -> C`): New pattern.
> ---
> gcc/match.pd | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index c87a0795667..3bbeceb37b4 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1456,6 +1456,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
> && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0)
> @0))
> +/* x | C -> C if we know that x & ~C == 0. */
> +(simplify
> + (bit_ior SSA_NAME@0 INTEGER_CST@1)
> + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
> + && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0)
> + @1))
> #endif
>
> /* ~(~X - Y) -> X + Y and ~(~X + Y) -> X - Y. */
> --
> 2.31.1
>
next prev parent reply other threads:[~2023-08-25 6:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 19:14 [PATCH 1/3] MATCH: Move `a ? one_zero : one_zero` matching after min/max matching Andrew Pinski
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 [this message]
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='CAFiYyc2=F_Cq_iT_=PT01BwvHtxuGcWR57_4pLrSg1n2XJBbpg@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=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).