public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "asd0025 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/104145] New: Extra instructions generated for dual float return on ARM64.
Date: Thu, 20 Jan 2022 13:05:43 +0000	[thread overview]
Message-ID: <bug-104145-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 104145
           Summary: Extra instructions generated for dual float return on
                    ARM64.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asd0025 at gmail dot com
  Target Milestone: ---

In the following code snippet, inefficient code is generated when returning 2
floats on ARM64/AArch64: https://godbolt.org/z/3G8nMT8W4

```
typedef float f32;
typedef double f64;

template <class A, class B = A>
struct duo
{
    A a;
    B b;
};

duo<f32> stream_load2(const f32* p)
{
    f32 a, b;
    asm("ldnp %s0, %s1, %2" : "=w"(a), "=w"(b) : "m"(*(const f32(*)[2])p));
    return {a, b}; // NOTE: many extra instuctions are generated!
}

duo<f32> stream_load2_ldp(const f32* p)
{
    return {p[0], p[1]}; // NOTE: inefficient code is generated for this!
}

duo<f64> stream_load2(const f64* p)
{
    f64 a, b;
    asm("ldnp %d0, %d1, %2" : "=w"(a), "=w"(b) : "m"(*(const f64(*)[2])p));
    return {a, b}; // NOTE: works as expected!
}
```

GCC output (v6.4+):
```
stream_load2(float const*):
        ldnp s1, s0, [x0]
        fmov    w2, s1
        fmov    w0, s0
        mov     x1, 0
        bfi     x1, x2, 0, 32
        bfi     x1, x0, 32, 32
        lsr     x0, x1, 32
        lsr     w1, w1, 0
        fmov    s1, w0
        fmov    s0, w1
        ret

stream_load2_ldp(float const*):
        ldr     d0, [x0]
        fmov    x1, d0
        lsr     x0, x1, 32
        fmov    s1, w0
        lsr     w0, w1, 0
        fmov    s0, w0
        ret

stream_load2(double const*):
        ldnp d0, d1, [x0]
        ret
```

Clang output:
```
stream_load2(float const*):
        ldnp    s0, s1, [x0]
        ret

stream_load2_ldp(float const*):
        ldp     s0, s1, [x0]
        ret

stream_load2(double const*):
        ldnp    d0, d1, [x0]
        ret
```

             reply	other threads:[~2022-01-20 13:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 13:05 asd0025 at gmail dot com [this message]
2022-01-20 13:12 ` [Bug middle-end/104145] " pinskia at gcc dot gnu.org
2022-01-20 13:12 ` pinskia at gcc dot gnu.org
2022-01-21  1:13 ` pinskia 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-104145-4@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).