public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/99259] New: aarch64 inline asm: miscompilation depending on function parameters order
@ 2021-02-24 19:59 jacob.benoit.1 at gmail dot com
  2021-02-24 20:01 ` [Bug inline-asm/99259] " jacob.benoit.1 at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jacob.benoit.1 at gmail dot com @ 2021-02-24 19:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99259
           Summary: aarch64 inline asm: miscompilation depending on
                    function parameters order
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jacob.benoit.1 at gmail dot com
  Target Milestone: ---

compiler explorer link: https://godbolt.org/z/9oE5Ta

Note: Clang has the same bug: https://bugs.llvm.org/show_bug.cgi?id=49343

code:

#include <arm_neon.h>

// output:
//         smlal   v0.4s, v1.4h, v2.4h  
int32x4_t good(int32x4_t acc, int16x4_t x, int16x4_t y) {
    asm("smlal %[acc].4s, %[x].4h, %[y].4h"
        : [acc]"=w"(acc)
        : [x]"w"(x),
          [y]"w"(y)
        :);
    return acc;
}

// output:
//         smlal   v0.4s, v0.4h, v1.4h
// bug: v0 is used for both x and y arguments!
int32x4_t bad(int16x4_t x, int16x4_t y, int32x4_t acc) {
    asm("smlal %[acc].4s, %[x].4h, %[y].4h"
        : [acc]"=w"(acc)
        : [x]"w"(x),
          [y]"w"(y)
        :);
    return acc;
}

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

* [Bug inline-asm/99259] aarch64 inline asm: miscompilation depending on function parameters order
  2021-02-24 19:59 [Bug inline-asm/99259] New: aarch64 inline asm: miscompilation depending on function parameters order jacob.benoit.1 at gmail dot com
@ 2021-02-24 20:01 ` jacob.benoit.1 at gmail dot com
  2021-02-24 20:46 ` jakub at gcc dot gnu.org
  2021-02-25 17:19 ` jacob.benoit.1 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jacob.benoit.1 at gmail dot com @ 2021-02-24 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

Benoit Jacob <jacob.benoit.1 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Benoit Jacob <jacob.benoit.1 at gmail dot com> ---
Sorry, as Craig mentioned on the LLVM bug, I had the wrong constraint (=w
instead of +w).

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

* [Bug inline-asm/99259] aarch64 inline asm: miscompilation depending on function parameters order
  2021-02-24 19:59 [Bug inline-asm/99259] New: aarch64 inline asm: miscompilation depending on function parameters order jacob.benoit.1 at gmail dot com
  2021-02-24 20:01 ` [Bug inline-asm/99259] " jacob.benoit.1 at gmail dot com
@ 2021-02-24 20:46 ` jakub at gcc dot gnu.org
  2021-02-25 17:19 ` jacob.benoit.1 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-02-24 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
v0 wasn't used for x and y, but for acc and x.  As you said, when acc is both
input and output, you need +w or "=w" (acc) ..... "0" (acc), but even if it was
output only and couldn't clash with x or y, you'd need early-clobber - "=&w"
which would make sure that the input operands get different registers from that
output one.

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

* [Bug inline-asm/99259] aarch64 inline asm: miscompilation depending on function parameters order
  2021-02-24 19:59 [Bug inline-asm/99259] New: aarch64 inline asm: miscompilation depending on function parameters order jacob.benoit.1 at gmail dot com
  2021-02-24 20:01 ` [Bug inline-asm/99259] " jacob.benoit.1 at gmail dot com
  2021-02-24 20:46 ` jakub at gcc dot gnu.org
@ 2021-02-25 17:19 ` jacob.benoit.1 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jacob.benoit.1 at gmail dot com @ 2021-02-25 17:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Benoit Jacob <jacob.benoit.1 at gmail dot com> ---
Thanks for bringing up the topic of early-clobber. I had to look up some
explanation of that concept, but I found that and now I get what you're saying
- thanks!
https://stackoverflow.com/questions/15819794/when-to-use-earlyclobber-constraint-in-extended-gcc-inline-assembly

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

end of thread, other threads:[~2021-02-25 17:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 19:59 [Bug inline-asm/99259] New: aarch64 inline asm: miscompilation depending on function parameters order jacob.benoit.1 at gmail dot com
2021-02-24 20:01 ` [Bug inline-asm/99259] " jacob.benoit.1 at gmail dot com
2021-02-24 20:46 ` jakub at gcc dot gnu.org
2021-02-25 17:19 ` jacob.benoit.1 at gmail dot com

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