public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Carlotti <andrew.carlotti@arm.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org>,
	Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: [PATCH v2 1/2] aarch64: Don't return invalid GIMPLE assign statements
Date: Fri, 15 Jul 2022 15:18:01 +0100	[thread overview]
Message-ID: <YtF3Ge/+IalcJqlp@e124511.cambridge.arm.com> (raw)
In-Reply-To: <CAFiYyc0PPxT18W70zMjwZ_R5jFLa5ERfMnAMq3nFj6D3HnP3JQ@mail.gmail.com>

On Wed, Jul 13, 2022 at 02:32:16PM +0200, Richard Biener wrote:
> On Wed, Jul 13, 2022 at 12:50 PM Andrew Carlotti
> <andrew.carlotti@arm.com> wrote:
> > I specifically wanted to avoid not folding the call, because always
> > folding means that the builtin doesn't need to be implemented anywhere
> > else (which isn't relevant here, but may become relevant when folding
> > newly defined builtins in the future).
> >
> > I considered dropping the statement, but I wasn't sure at the time that
> > I could do it safely. I could send a patch to instead replace new_stmt
> > with a GIMPLE_NOP.
> 
> If you can be sure there's no side-effect on the RHS then I think
> I'd prefer that over allocating an SSA name for something that's
> going to be DCEd anyway.
> 
> Richard.

I discussed this off-list with Richard Sandiford, and we agreed that it
would be better to leave this code as it is.

The only time this form is likely to arise is if the statement has
side-effects (e.g. reading from volatile memory or triggering
floating-point exceptions), in which case we can't just replace it with
a nop. On the other hand, in the event that someone has written an
entirely redundant statement, then it will quickly get eliminated
anyway.

Adding code to distinguish between the two cases here, or to handle
the hard case, is unnecessary and wouldn't be worthwhile.

> > > >> gcc/ChangeLog:
> > > >>
> > > >>  * config/aarch64/aarch64-builtins.cc
> > > >>  (aarch64_general_gimple_fold_builtin): Add fixup for invalid GIMPLE.
> > > >>
> > > >> gcc/testsuite/ChangeLog:
> > > >>
> > > >>  * gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c: New test.
> > > >>
> > > >> ---
> > > >>
> > > >> diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc
> > > >> index e0a741ac663188713e21f457affa57217d074783..5753988a9964967c27a03aca5fddb9025fd8ed6e 100644
> > > >> --- a/gcc/config/aarch64/aarch64-builtins.cc
> > > >> +++ b/gcc/config/aarch64/aarch64-builtins.cc
> > > >> @@ -3022,6 +3022,16 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt,
> > > >>      default:
> > > >>        break;
> > > >>      }
> > > >> +
> > > >> +  /* GIMPLE assign statements (unlike calls) require a non-null lhs. If we
> > > >> +     created an assign statement with a null lhs, then fix this by assigning
> > > >> +     to a new (and subsequently unused) variable. */
> > > >> +  if (new_stmt && is_gimple_assign (new_stmt) && !gimple_assign_lhs (new_stmt))
> > > >> +    {
> > > >> +      tree new_lhs = make_ssa_name (gimple_call_return_type (stmt));
> > > >> +      gimple_assign_set_lhs (new_stmt, new_lhs);
> > > >> +    }
> > > >> +
> > > >>    return new_stmt;
> > > >>  }
> > > >>
> > > >> diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c
> > > >> new file mode 100644
> > > >> index 0000000000000000000000000000000000000000..345307456b175307f5cb22de5e59cfc6254f2737
> > > >> --- /dev/null
> > > >> +++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c
> > > >> @@ -0,0 +1,9 @@
> > > >> +/* { dg-do compile { target { aarch64*-*-* } } } */
> > > >> +
> > > >> +#include <arm_neon.h>
> > > >> +
> > > >> +int8_t *bar();
> > > >> +
> > > >> +void foo() {
> > > >> +  __builtin_aarch64_ld1v16qi(bar());
> > > >> +}

      reply	other threads:[~2022-07-15 14:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 14:38 Andrew Carlotti
2022-07-13  7:41 ` Richard Biener
2022-07-13  8:10   ` Richard Sandiford
2022-07-13 10:50     ` Andrew Carlotti
2022-07-13 12:32       ` Richard Biener
2022-07-15 14:18         ` Andrew Carlotti [this message]

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=YtF3Ge/+IalcJqlp@e124511.cambridge.arm.com \
    --to=andrew.carlotti@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    --cc=richard.sandiford@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).