public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113871] New: psrlq is not used for PERM<a,{0},1,2,3,4>
@ 2024-02-11  5:23 pinskia at gcc dot gnu.org
  2024-02-11  5:32 ` [Bug target/113871] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-11  5:23 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2024-02-27 17:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-11  5:23 [Bug target/113871] New: psrlq is not used for PERM<a,{0},1,2,3,4> pinskia at gcc dot gnu.org
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

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