public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94522] New: Enhancement request: asm goto with outputs
@ 2020-04-07 16:02 bp at alien8 dot de
  2020-04-07 21:22 ` [Bug inline-asm/94522] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bp at alien8 dot de @ 2020-04-07 16:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94522
           Summary: Enhancement request: asm goto with outputs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bp at alien8 dot de
  Target Milestone: ---

Hi all,

this came up recently on the kernel ML (see
https://lkml.kernel.org/r/20200402134051.GC9352@zn.tnic) and we thought it
might be a good idea to support it. In the same "fallthrough" fashion like
clang:

https://reviews.llvm.org/rG50cac248773

Micha (CCed) says that it should be relatively easy to do that in gcc too so in
case someone feels bored in the future... :)

Some other useful scenarios, courtesy of Linus, would be exception handling, to
avoid register pressure and in the alternatives patching we do in the kernel.
And in general, an output value from the asm goto("") in the fallthrough case
might come in handy.

Thx.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
@ 2020-04-07 21:22 ` pinskia at gcc dot gnu.org
  2020-04-07 21:24 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-07 21:22 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2020-04-07
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
          Component|c                           |inline-asm

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Take:
asm goto ("" : "=r"(*m) :....);

Where does the store to *m happen?  Do you replicate it on to the label side
too?

What are the semantics for the above case on clang?  My bet is it is not well
defined and really broken.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
  2020-04-07 21:22 ` [Bug inline-asm/94522] " pinskia at gcc dot gnu.org
@ 2020-04-07 21:24 ` pinskia at gcc dot gnu.org
  2020-04-08  4:27 ` matz at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-07 21:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also reload (and IRA) does not handle output on jumps because of the same
reason why I mention.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
  2020-04-07 21:22 ` [Bug inline-asm/94522] " pinskia at gcc dot gnu.org
  2020-04-07 21:24 ` pinskia at gcc dot gnu.org
@ 2020-04-08  4:27 ` matz at gcc dot gnu.org
  2020-04-08  6:30 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: matz at gcc dot gnu.org @ 2020-04-08  4:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Michael Matz <matz at gcc dot gnu.org> ---
See the llvm link of the respective patch.  They specify that the outputs are
reliable only on the fallthrough (i.e. no goto taken) path (in particular the
outputs might or might not have been changed on the jump paths).  That avoids
all
the problems reload and it's replacements traditionally have with outputs on
jump insns, so it'd be relatively easy for us to support that as well.

This restriction, if documented, isn't even unreasonable and still allows some
interesting uses of goto asms with outputs.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
                   ` (2 preceding siblings ...)
  2020-04-08  4:27 ` matz at gcc dot gnu.org
@ 2020-04-08  6:30 ` rguenth at gcc dot gnu.org
  2020-04-08 20:30 ` torvalds@linux-foundation.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-08  6:30 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
                   ` (3 preceding siblings ...)
  2020-04-08  6:30 ` rguenth at gcc dot gnu.org
@ 2020-04-08 20:30 ` torvalds@linux-foundation.org
  2020-04-08 20:56 ` torvalds@linux-foundation.org
  2021-09-01  1:04 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: torvalds@linux-foundation.org @ 2020-04-08 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

Linus Torvalds <torvalds@linux-foundation.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |torvalds@linux-foundation.o
                   |                            |rg

--- Comment #4 from Linus Torvalds <torvalds@linux-foundation.org> ---
(In reply to Andrew Pinski from comment #1)
> Take:
> asm goto ("" : "=r"(*m) :....);
> 
> Where does the store to *m happen?  Do you replicate it on to the label side
> too?
> 
> What are the semantics for the above case on clang?  My bet is it is not
> well defined and really broken.

The outputs are defined to have values only in the fallthrough case.

On the label side, the outputs (whether memory or register) are explicitly
undefined. 

The outputs may obviously not even be in scope except in the fallthrough.

Now, with memory ops, it's obviously quite possible that the programmer then
knows that they wrote an inline asm that did the write to memory before it did
the goto. 

But that's no different from a _non_output_ "asm goto" that you pass a memory
pointer to, so I don't think that's something that is new to this situation.

As to whether this is simple or not to do in gcc - the clang implementation has
been buggy so far, altough it's good enough for testing ;)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
                   ` (4 preceding siblings ...)
  2020-04-08 20:30 ` torvalds@linux-foundation.org
@ 2020-04-08 20:56 ` torvalds@linux-foundation.org
  2021-09-01  1:04 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: torvalds@linux-foundation.org @ 2020-04-08 20:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Linus Torvalds <torvalds@linux-foundation.org> ---
Btw, Nick (who is doing this on the clang side, tells me that the tcmalloc
people are looking at using the asm goto with outputs too, so it's not just the
kernel.

If somebody wants to play with it, I do have a patch to use it in the kernel as
a test-case.

HOWEVER - I'm working on cleaning up some of the infrastructure around it, but
at least for now, that patch is a "all or nothing" thing: it unconditionally
requires asm goto w/ inputs support, so there's no fallback to "older compiler
without asm goto with inputs" codepath.

With the cleanups, I hope to have a patch that can swing both ways, but right
now it's very much for testing only, and I don't want to make that patch too
public because it will just break for anybody with a non-experimental compiler.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug inline-asm/94522] Enhancement request: asm goto with outputs
  2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
                   ` (5 preceding siblings ...)
  2020-04-08 20:56 ` torvalds@linux-foundation.org
@ 2021-09-01  1:04 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-01  1:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.0
             Status|NEW                         |RESOLVED

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 11 by r11-5002.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-01  1:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 16:02 [Bug c/94522] New: Enhancement request: asm goto with outputs bp at alien8 dot de
2020-04-07 21:22 ` [Bug inline-asm/94522] " pinskia at gcc dot gnu.org
2020-04-07 21:24 ` pinskia at gcc dot gnu.org
2020-04-08  4:27 ` matz at gcc dot gnu.org
2020-04-08  6:30 ` rguenth at gcc dot gnu.org
2020-04-08 20:30 ` torvalds@linux-foundation.org
2020-04-08 20:56 ` torvalds@linux-foundation.org
2021-09-01  1:04 ` pinskia at gcc dot gnu.org

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).