public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Richard Biener <rguenther@suse.de>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	 Jeff Law <jeffreyalaw@gmail.com>
Subject: Re: [PATCH v2] combine: Fix ICE in try_combine on pr112494.c [PR112560]
Date: Mon, 18 Mar 2024 16:29:25 +0100	[thread overview]
Message-ID: <CAFULd4Y7+xVS+dKB+5KpcU2HBZZUYaqU1gzWefvurshnGH7d1A@mail.gmail.com> (raw)
In-Reply-To: <20240318144442.GY19790@gate.crashing.org>

On Mon, Mar 18, 2024 at 3:46 PM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Thu, Mar 07, 2024 at 11:27:28PM +0100, Uros Bizjak wrote:
> > On Thu, Mar 7, 2024 at 11:07 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> > > > >  (unspec:DI [
> > > > >          (reg:CC 17 flags)
> > > > >      ] UNSPEC_PUSHFL)
> > > >
> > > > But that is invalid RTL?  The only valid use of a CC is written as
> > > > cc-compared-to-0.  It means "the result of something compared to 0,
> > > > stored in that cc reg".
> > > >
> > > > (And you can copy a CC reg around, but that is not a use ;-) )
> >
> > Hm... under this premise, we can also say that any form that is not
> > cc-compared-to-0 is not a use.
>
> Well, no.  All uses of CC are written as comparisons to 0, or are pure
> dataflow.  Anything else is not "not a use" but just invalid.
>
> > Consequently, if it is not a use, then
> > the CC reg should not be updated at its use location, so my v1 patch,
> > where we simply skip the update (but retain the combined insn),
> > actually makes sense.
>
> With more asserts, perhaps.
>
> > In this concrete situation, we don't care about CC register mode in
> > the PUSHFL insn. And we should not change CC reg mode of the use,
> > because any other mode than the generic CCmode won't be recognized by
> > the insn pattern.
>
> You always care about the CC mode, that is why you always write it as
> comparison, so the backend can choose a mode based on what the flag bits
> mean in this context.  For an extreme example look at 390, but on pretty
> much any target both signed and unsigned comparisons use the same flag
> bits, and maybe fp comparisons as well.

After some more thoughts, I came up with v3 [1], where the mode is
updated also in non-comparison use. But instead of a blind SUBST, we
find the correct use location and update the mode accordingly. If the
new mode is not recognized in the use insn, then the whole combination
is cancelled. Since x86 pushfl does not care about CCmode, I have
changed it to handle all CCmodes. Please note, that with this
approach, the backend can choose a mode.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2024-March/647634.html

> But pushfl does sound like pure dataflow.  Why is this a builtin, is
> it ever a good idea if the user writes stuff the compiler can do a
> better job doing itself, not to mention it is way easier for the
> compiler anyway?  :-)

The mode of the pushfl has to be correct, because it operates on
stack. Unfortunately, the plain move can't do this due to
WORDmode/CCmode mismatch in the rtx, so UNSPEC is necessary. But it IS
a pure dataflow instruction - it is a PUSH.

Uros.

      reply	other threads:[~2024-03-18 15:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07  9:16 Uros Bizjak
2024-03-07  9:55 ` Richard Biener
2024-03-07 10:11   ` Uros Bizjak
2024-03-07 10:22     ` Richard Biener
2024-03-07 17:44       ` Segher Boessenkool
2024-03-07 10:37     ` Jakub Jelinek
2024-03-07 10:45       ` Richard Biener
2024-03-07 11:22         ` Uros Bizjak
2024-03-07 17:51           ` Segher Boessenkool
2024-03-07 17:49         ` Segher Boessenkool
2024-03-07 10:57       ` Uros Bizjak
2024-03-07 17:36   ` Segher Boessenkool
2024-03-07 21:04     ` Uros Bizjak
2024-03-07 21:08       ` Uros Bizjak
2024-03-07 21:35       ` Segher Boessenkool
2024-03-07 22:07         ` Uros Bizjak
2024-03-07 22:27           ` Segher Boessenkool
2024-03-07 22:46             ` Uros Bizjak
2024-03-18 14:49               ` Segher Boessenkool
2024-03-18 15:44                 ` Uros Bizjak
2024-03-07 22:27           ` Uros Bizjak
2024-03-18 14:44             ` Segher Boessenkool
2024-03-18 15:29               ` Uros Bizjak [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=CAFULd4Y7+xVS+dKB+5KpcU2HBZZUYaqU1gzWefvurshnGH7d1A@mail.gmail.com \
    --to=ubizjak@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=rguenther@suse.de \
    --cc=segher@kernel.crashing.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).