public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/113871] New: psrlq is not used for PERM<a,{0},1,2,3,4>
Date: Sun, 11 Feb 2024 05:23:04 +0000	[thread overview]
Message-ID: <bug-113871-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 113871
           Summary: psrlq is not used for PERM<a,{0},1,2,3,4>
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64

Take:
```
#define vect64 __attribute__((vector_size(8)))

void f(vect64unsigned short *a)
{
  *a = __builtin_shufflevector(*a,(vect64 unsigned short){0}, 1,2,3, 4);
}
```

This should just produce:
```
        movq   (%rdi), %xmm0
        psrlq  $16, %xmm0, %xmm0
        movq   %xmm0, (%rdi)
        retq
```

But instead we get:
```
        movzwl  6(%rdi), %eax
        movzwl  4(%rdi), %edx
        salq    $16, %rax
        orq     %rdx, %rax
        movzwl  2(%rdi), %edx
        salq    $16, %rax
        orq     %rdx, %rax
        movq    %rax, (%rdi)
        ret
```

With AVX enabled we get slightly better:
```
f:
.LFB0:
        .cfi_startproc
        vmovq   (%rdi), %xmm0
        vpxor   %xmm1, %xmm1, %xmm1
        vpshufb .LC1(%rip), %xmm1, %xmm1
        vpshufb .LC0(%rip), %xmm0, %xmm0
        vpor    %xmm1, %xmm0, %xmm0
        vmovq   %xmm0, (%rdi)
        ret
```

Note LLVM is able to catch this for x86_64 (for aarch64, GCC is able to use
`ushr d31, d31, 16` while LLVM does not).

I suspect vec_shr_<mode> pattern is missing and once it is added, it will just
work.

             reply	other threads:[~2024-02-11  5:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-11  5:23 pinskia at gcc dot gnu.org [this message]
2024-02-11  5:32 ` [Bug target/113871] " pinskia at gcc dot gnu.org
2024-02-11  5:56 ` pinskia at gcc dot gnu.org
2024-02-12  8:46 ` rguenth at gcc dot gnu.org
2024-02-13 18:27 ` ubizjak at gmail dot com
2024-02-14  8:16 ` ubizjak at gmail dot com
2024-02-14 19:44 ` cvs-commit at gcc dot gnu.org
2024-02-14 19:48 ` ubizjak at gmail dot com
2024-02-27 17:42 ` cvs-commit 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-113871-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).