public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Tamar Christina <tamar.christina@arm.com>, gcc-patches@gcc.gnu.org
Cc: nd@arm.com, rguenther@suse.de
Subject: Re: [PATCH]middle-end fix floating out of constants in conditionals
Date: Sat, 24 Sep 2022 14:44:06 -0600	[thread overview]
Message-ID: <d82ccc7e-97fd-cad5-1b12-42cd166c37c8@gmail.com> (raw)
In-Reply-To: <patch-15680-tamar@arm.com>


On 9/23/22 03:21, Tamar Christina wrote:
> Hi All,
>
> The following testcase:
>
> int zoo1 (int a, int b, int c, int d)
> {
>     return (a > b ? c : d) & 1;
> }
>
> gets de-optimized by the front-end since somewhere around GCC 4.x due to a fix
> that was added to fold_binary_op_with_conditional_arg.
>
> The folding is supposed to succeed only if we have folded at least one of the
> branches, however the check doesn't tests that all of the values are
> non-constant.  So if one of the operators are a constant it accepts the folding.
>
> This ends up folding
>
>     return (a > b ? c : d) & 1;
>
> into
>
>     return (a > b ? c & 1 : d & 1);
>
> and thus performing the AND twice.
>
> change changes it to reject the folding if one of the arguments are a constant
> and if the operations being performed are the same.
>
> Secondly it adds a new match.pd rule to now also fold the opposite direction, so
> it now also folds:
>
>     return (a > b ? c & 1 : d & 1);
>
> into
>
>     return (a > b ? c : d) & 1;
>
> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> and <on-goin> issues.
>
> Ok for master?
>
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
> 	* fold-const.cc (fold_binary_op_with_conditional_arg): Add relaxation.
> 	* match.pd: Add ternary constant fold rule.
> 	* tree-cfg.cc (verify_gimple_assign_ternary): RHS1 of a COND_EXPR isn't
> 	a value but an expression itself.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/aarch64/if-compare_3.c: New test.

OK

jeff



  reply	other threads:[~2022-09-24 20:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23  9:21 Tamar Christina
2022-09-24 20:44 ` Jeff Law [this message]
2022-09-26 10:28 ` Richard Biener
2022-09-26 11:08   ` Eric Botcazou
2022-09-26 11:12     ` Eric Botcazou
2022-10-17  9:17   ` Tamar Christina

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=d82ccc7e-97fd-cad5-1b12-42cd166c37c8@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nd@arm.com \
    --cc=rguenther@suse.de \
    --cc=tamar.christina@arm.com \
    /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).