public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rsandifo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/94873] [8/9/10/11 Regression] wrong code with -O -fno-merge-constants -fno-split-wide-types -fno-tree-fre
Date: Mon, 04 May 2020 19:58:57 +0000	[thread overview]
Message-ID: <bug-94873-4-NsBX2Ur5WJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94873-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94873

--- Comment #11 from rsandifo at gcc dot gnu.org <rsandifo at gcc dot gnu.org> ---
(In reply to Segher Boessenkool from comment #9)
> "clobber" is a red herring; it is impossible to make a REG_EQ* note for
> a clobber, a clobber does not set a new value (that is the whole point
> of a clobber).

It's not possible to attach a REG_EQ* note to an auto-inc-dec
either though (that was my point).  So a clobber doesn't seem
any less of a red herring than the auto-inc-dec itself.  Both
set registers in the sense of changing them, and neither can
be described by a REG_EQ* note.

> I think we could allow auto-modify, sure, just as long as it stays clear
> what lhs the REG_EQ* note is talking about; and, as you say, everything
> needs to be audited for it :-/

Yeah.  But to be clear: I don't think this is more obviously
a change from the status quo than going in the other direction
would be.  The point is that the status quo is ambiguous:
the documentation can be read either way, and the
implementation isn't consistent (hence the bug).

So it's a question of how we resolve the ambiguity.
If we want passes to be able to assume without checking
that insns with REG_EQ* notes don't also include auto
inc-dec, we'll need to audit places that create the notes,
or that update insns with existing notes.

I think it comes down to what the REG_EQ* notes are supposed
to achieve (conceptually, ignoring documentation and the
current implementation for now).  The "weak" guarantee is
that the SET_DEST has the specified value after the
instruction.  The "strong" guarantee extends the weak guarantee
by saying that the SET_SRC of the definition can be replaced
by the REG_EQ* note without changing behaviour.

Having auto-inc-dec in the SET_SRC of the definition is
OK for the weak guarantee but not the strong guarantee.
But the same would be true of any SET_SRC with side effects.
So to frame the question in a different way: let's assume
there's a target-specific intrinsic that has side effects
that can be described using unspec_volatile, and that the
intrinsic also sets a register.  Normally this would be
described as:

  (set (reg X) (unspec_volatile ...))

But if, in a particular context, the target could predict
what the value of X was, could it attach a REG_EQ* note
to say that?  It would then be valid to simplify later
uses of X, even though the definition of X can't change.

IMO this is easier to answer for REG_EQUIV.  That mostly
exists to allow the RA to rematerialise a value instead
of reloading it.  So it's all about replacing the uses
of the register rather than about replacing the definition.
(I'm not saying that the RA would handle a REG_EQUIV note
on the above unspec_volatile correctly -- haven't checked
either way -- but in principle it could.)

The weak guarantee makes life harder for consumers of the
notes that want the strong guarantee, since they then have
to check for side effects themselves.  The weak guarantee
is easy for producers of the notes and for consumers that
only care about users of the register.

The strong guarantee makes life harder for producers of the
notes, or for optimisations that modify insns with existing
notes.  The strong guarantee is easy for consumers of the notes
because it's more conservative.

The weak guarantee potentially allows more optimisation
than the strong guarantee.

I don't think there's much in it.  But I guess I personally
prefer the weak guarantee for the "more optimisation" reason.
There's also a very tenuous analogy with REG_RETURNED,
which is explicitly for saying what the return value is,
rather than saying how the definition can be rewritten.

But whichever we go for, I think it should be a decision
about side effects vs. no side effects, with auto inc-dec
being just one of several potential side effects.  I don't
see any reason why the auto-inc-dec case would be different
from the unspec_volatile case.

  parent reply	other threads:[~2020-05-04 19:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 10:44 [Bug rtl-optimization/94873] New: [8/9/10 " zsojka at seznam dot cz
2020-04-30 12:36 ` [Bug rtl-optimization/94873] " jakub at gcc dot gnu.org
2020-04-30 12:42 ` jakub at gcc dot gnu.org
2020-04-30 12:46 ` jakub at gcc dot gnu.org
2020-04-30 15:00 ` jakub at gcc dot gnu.org
2020-05-01 15:11 ` [Bug rtl-optimization/94873] [8/9/10/11 " jakub at gcc dot gnu.org
2020-05-01 15:21 ` law at redhat dot com
2020-05-01 17:17 ` rsandifo at gcc dot gnu.org
2020-05-01 18:31 ` segher at gcc dot gnu.org
2020-05-01 18:52 ` rsandifo at gcc dot gnu.org
2020-05-04 19:09 ` segher at gcc dot gnu.org
2020-05-04 19:26 ` segher at gcc dot gnu.org
2020-05-04 19:58 ` rsandifo at gcc dot gnu.org [this message]
2020-05-04 20:47 ` rsandifo at gcc dot gnu.org
2020-05-04 22:12 ` ebotcazou at gcc dot gnu.org
2020-05-04 23:16 ` segher at gcc dot gnu.org
2020-05-05  7:24 ` ebotcazou at gcc dot gnu.org
2020-05-05  7:34 ` jakub at gcc dot gnu.org
2020-05-05  8:04 ` ebotcazou at gcc dot gnu.org
2020-05-05 10:22 ` jakub at gcc dot gnu.org
2020-05-05 15:02 ` segher at gcc dot gnu.org
2020-05-06  7:34 ` cvs-commit at gcc dot gnu.org
2020-05-06 11:50 ` [Bug rtl-optimization/94873] [8/9/10 " jakub at gcc dot gnu.org
2020-05-07 13:28 ` cvs-commit at gcc dot gnu.org
2020-05-07 13:33 ` [Bug rtl-optimization/94873] [8/9 " jakub at gcc dot gnu.org
2020-09-16 19:21 ` cvs-commit at gcc dot gnu.org
2020-09-17 17:49 ` jakub at gcc dot gnu.org

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=bug-94873-4-NsBX2Ur5WJ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).