From: Richard Biener <richard.guenther@gmail.com>
To: Andrew Pinski <apinski@marvell.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 4/5] Try inverted comparison for match_simplify in phiopt
Date: Mon, 5 Jul 2021 13:18:02 +0200 [thread overview]
Message-ID: <CAFiYyc0RSoY4M9K1p65axoL4okLe270vbTv2TQNc8oR=XSF0Ow@mail.gmail.com> (raw)
In-Reply-To: <1625423864-20417-4-git-send-email-apinski@marvell.com>
On Sun, Jul 4, 2021 at 8:38 PM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> Since match and simplify does not have all of the inverted
> comparison patterns, it make sense to just have
> phi-opt try to do the inversion and try match and simplify again.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu.
OK.
> Thanks,
> Andrew Pinski
>
> gcc/ChangeLog:
>
> * tree-ssa-phiopt.c (gimple_simplify_phiopt):
> If "A ? B : C" fails to simplify, try "(!A) ? C : B".
> ---
> gcc/tree-ssa-phiopt.c | 27 ++++++++++++++++++++++++++-
> 1 file changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
> index d4449afcdca..fec8c02c062 100644
> --- a/gcc/tree-ssa-phiopt.c
> +++ b/gcc/tree-ssa-phiopt.c
> @@ -844,7 +844,8 @@ phiopt_early_allow (enum tree_code code)
> with parts pushed if EARLY_P was true. Also rejects non allowed tree code
> if EARLY_P is set.
> Takes the comparison from COMP_STMT and two args, ARG0 and ARG1 and tries
> - to simplify CMP ? ARG0 : ARG1. */
> + to simplify CMP ? ARG0 : ARG1.
> + Also try to simplify (!CMP) ? ARG1 : ARG0 if the non-inverse failed. */
> static tree
> gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt,
> tree arg0, tree arg1,
> @@ -877,6 +878,30 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt,
> return result;
> }
> }
> + /* Try the inverted comparison, that is !COMP ? ARG1 : ARG0. */
> + comp_code = invert_tree_comparison (comp_code, HONOR_NANS (cmp0));
> +
> + if (comp_code == ERROR_MARK)
> + return NULL;
> +
> + cond = build2_loc (loc,
> + comp_code, boolean_type_node,
> + cmp0, cmp1);
> + gimple_match_op op1 (gimple_match_cond::UNCOND,
> + COND_EXPR, type, cond, arg1, arg0);
> +
> + if (op1.resimplify (early_p ? NULL : seq, follow_all_ssa_edges))
> + {
> + /* Early we want only to allow some generated tree codes. */
> + if (!early_p
> + || op1.code.is_tree_code ()
> + || phiopt_early_allow ((tree_code)op1.code))
> + {
> + result = maybe_push_res_to_seq (&op1, seq);
> + if (result)
> + return result;
> + }
> + }
>
> return NULL;
> }
> --
> 2.27.0
>
next prev parent reply other threads:[~2021-07-05 11:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-04 18:37 [PATCH 1/5] Fix 101256: Wrong code due to range incorrect from PHI-OPT apinski
2021-07-04 18:37 ` [PATCH 2/5] Fix PR 101237: Remove element_type call when used with the functions from real apinski
2021-07-05 11:18 ` Richard Biener
2021-07-04 18:37 ` [PATCH 3/5] Allow match-and-simplified phiopt to run in early phiopt apinski
2021-07-05 11:26 ` Richard Biener
2021-07-04 18:37 ` [PATCH 4/5] Try inverted comparison for match_simplify in phiopt apinski
2021-07-05 11:18 ` Richard Biener [this message]
2021-07-04 18:37 ` [PATCH 5/5] Port most of the A CMP 0 ? A : -A to match apinski
2021-07-05 11:26 ` Richard Biener
2021-07-05 11:25 ` [PATCH 1/5] Fix 101256: Wrong code due to range incorrect from PHI-OPT Richard Biener
2021-07-05 22:54 ` 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='CAFiYyc0RSoY4M9K1p65axoL4okLe270vbTv2TQNc8oR=XSF0Ow@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).