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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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 ` pinskia at gcc dot gnu.org
  2024-02-11  5:56 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-11  5:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://github.com/llvm/llv
                   |                            |m-project/issues/81393

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note LLVM is not able to handle this for aarch64; file
https://github.com/llvm/llvm-project/issues/81393 for that.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-11  5:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note `PERM<{0},a,{1,2,3,4}>` should be handled too, that means defining
`vec_shl_` patterns too.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-02-12  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|x86_64                      |x86_64-*-* i?86-*-*
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-02-12

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2024-02-13 18:27 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ubizjak at gmail dot com
             Status|NEW                         |ASSIGNED

--- Comment #4 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 57417
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57417&action=edit
Proposed patch

Patch in testing.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2024-02-14  8:16 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #57417|0                           |1
        is obsolete|                            |

--- Comment #5 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 57419
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57419&action=edit
Proposed v2 patch

New version in testing, also handles 32-bit vectors.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-14 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:2c2f57e4158924467afbf4c2fd3938e507287dab

commit r14-8989-g2c2f57e4158924467afbf4c2fd3938e507287dab
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Wed Feb 14 20:41:42 2024 +0100

    i386: psrlq is not used for PERM<a,{0},1,2,3,4> [PR113871]

    Introduce vec_shl_<mode> and vec_shr_<mode> expanders to improve

            '*a = __builtin_shufflevector(*a, (vect64){0}, 1, 2, 3, 4);'

    and
            '*a = __builtin_shufflevector((vect64){0}, *a, 3, 4, 5, 6);'

    shuffles.  The generated code improves from:

            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)

    to:
            movq    (%rdi), %xmm0
            psrlq   $16, %xmm0
            movq    %xmm0, (%rdi)

    and to:
            movq    (%rdi), %xmm0
            psllq   $16, %xmm0
            movq    %xmm0, (%rdi)

    in the second case.

    The patch handles 32-bit vectors as well and improves generated code from:

            movd    (%rdi), %xmm0
            pxor    %xmm1, %xmm1
            punpcklwd       %xmm1, %xmm0
            pshuflw $230, %xmm0, %xmm0
            movd    %xmm0, (%rdi)

    to:
            movd    (%rdi), %xmm0
            psrld   $16, %xmm0
            movd    %xmm0, (%rdi)

    and to:
            movd    (%rdi), %xmm0
            pslld   $16, %xmm0
            movd    %xmm0, (%rdi)

            PR target/113871

    gcc/ChangeLog:

            * config/i386/mmx.md (V248FI): New mode iterator.
            (V24FI_32): DItto.
            (vec_shl_<V248FI:mode>): New expander.
            (vec_shl_<V24FI_32:mode>): Ditto.
            (vec_shr_<V248FI:mode>): Ditto.
            (vec_shr_<V24FI_32:mode>): Ditto.
            * config/i386/sse.md (vec_shl_<V_128:mode>): Simplify expander.
            (vec_shr_<V248FI:mode>): Ditto.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr113871-1a.c: New test.
            * gcc.target/i386/pr113871-1b.c: New test.
            * gcc.target/i386/pr113871-2a.c: New test.
            * gcc.target/i386/pr113871-2b.c: New test.
            * gcc.target/i386/pr113871-3a.c: New test.
            * gcc.target/i386/pr113871-3b.c: New test.
            * gcc.target/i386/pr113871-4a.c: New test.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2024-02-14 19:48 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Uroš Bizjak <ubizjak at gmail dot com> ---
Implemented for gcc-14.

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

* [Bug target/113871] psrlq is not used for PERM<a,{0},1,2,3,4>
  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
                   ` (6 preceding siblings ...)
  2024-02-14 19:48 ` ubizjak at gmail dot com
@ 2024-02-27 17:42 ` cvs-commit at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-27 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:15d1dae0d4d1be88d28ad7578a60fd3e36de36d8

commit r14-9198-g15d1dae0d4d1be88d28ad7578a60fd3e36de36d8
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Tue Feb 27 18:41:24 2024 +0100

    i386: psrlq is not used for PERM<a,{0},1,2,3,4> [PR113871]

    Also handle V2BF mode.

            PR target/113871

    gcc/ChangeLog:

            * config/i386/mmx.md (V248FI): Add V2BF mode.
            (V24FI_32): Ditto.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr113871-5a.c: New test.
            * gcc.target/i386/pr113871-5b.c: New test.

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