public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/101021] New: PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4
@ 2021-06-10 18:07 ubizjak at gmail dot com
  2021-06-11  7:35 ` [Bug target/101021] " ubizjak at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2021-06-10 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101021
           Summary: PSHUFB is emitted instead of PSHUFD, PSHUFLW and
                    PSHUFHW with -msse4
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Following testcase:

--cut here--
typedef char S;
typedef S VV __attribute__((vector_size(16 * sizeof(S))));

VV ref_perm_pshufd (VV x, VV y)
{
  return __builtin_shuffle (x, y, (VV) { 8,9,10,11, 8,9,10,11, 8,9,10,11,
12,13,14,15 });
}

VV ref_perm_pshuflw (VV x)
{
  return __builtin_shuffle (x, (VV) { 0,1, 2,3, 2,3, 6,7, 8,9,10,11,12,13,14,15
});
}

VV ref_perm_pshufhw (VV x)
{
  return __builtin_shuffle (x, (VV) { 0,1,2,3,4,5,6,7, 8,9, 10,11, 10,11, 14,15
});
--cut here--

compiles with -O2 -msse2 to:

<ref_perm_pshufd>:

     pshufd $0xea,%xmm0,%xmm0
     retq   

<ref_perm_pshuflw>:

     pshuflw $0xd4,%xmm0,%xmm0
     retq   

<ref_perm_pshufhw>:

     pshufhw $0xd4,%xmm0,%xmm0
     retq   

Using -msse4 (or higher ISA), the compiler is too eager to emit less optimal
PSHUFB:

<ref_perm_pshufd>:

     pshufb 0x0(%rip),%xmm0
     retq   

<ref_perm_pshuflw>:

     pshufb 0x0(%rip),%xmm0
     retq   

<ref_perm_pshufhw>:

     pshufb 0x0(%rip),%xmm0
     retq

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

* [Bug target/101021] PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4
  2021-06-10 18:07 [Bug target/101021] New: PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4 ubizjak at gmail dot com
@ 2021-06-11  7:35 ` ubizjak at gmail dot com
  2021-06-11 10:32 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2021-06-11  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-06-11
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |ubizjak at gmail dot com
             Status|UNCONFIRMED                 |ASSIGNED

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

Effectively one liner patch with:

+  /* Try to avoid variable permutation instruction.  */
+  if (canonicalize_vector_int_perm (d, &nd) && expand_vec_perm_1 (&nd))
+    return false;

in a strategic place.

Survives:

GCC_TEST_RUN_EXPENSIVE=1 make check-gcc RUNTESTFLAGS='--target_board=unix/-mavx
dg-torture.exp=vshuf*.c'

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

* [Bug target/101021] PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4
  2021-06-10 18:07 [Bug target/101021] New: PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4 ubizjak at gmail dot com
  2021-06-11  7:35 ` [Bug target/101021] " ubizjak at gmail dot com
@ 2021-06-11 10:32 ` cvs-commit at gcc dot gnu.org
  2021-06-11 10:35 ` ubizjak at gmail dot com
  2021-06-13 19:51 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-11 10:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS 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:1fa991d1d74cb1ce96c48ede70ae0be7a9683ce3

commit r12-1384-g1fa991d1d74cb1ce96c48ede70ae0be7a9683ce3
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Fri Jun 11 12:31:42 2021 +0200

    i386: Try to avoid variable permutation instruction [PR101021]

    Some permutations can be implemented without costly PSHUFB instruction,
e.g.:

    { 8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7 } with PALIGNR,

    { 0,1,2,3, 4,5,6,7, 4,5,6,7, 12,13,14,15 } with PSHUFD,

    { 0,1, 2,3, 2,3, 6,7, 8,9,10,11,12,13,14,15 } with PSHUFLW and

    { 0,1,2,3,4,5,6,7, 8,9, 10,11, 10,11, 14,15 } with PSHUFHW.

    All these instructions have constant shuffle control mask and do not
    need to load shuffle mask from a memory to a temporary XMM register.

    2021-06-11  Uroš Bizjak  <ubizjak@gmail.com>

    gcc/
            PR target/101021
            * config/i386/i386-expand.c (expand_vec_perm_pshufb): Return
            false if the permutation can be implemented with constant
            permutation instruction in wider mode.
            (canonicalize_vector_int_perm): Move above expand_vec_perm_pshufb.
            Handle V8QImode and V4HImode.

    gcc/testsuite/

            PR target/101021
            * gcc.target/i386/pr101021-1.c: New test.
            * gcc.target/i386/pr101021-2.c: Ditto.

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

* [Bug target/101021] PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4
  2021-06-10 18:07 [Bug target/101021] New: PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4 ubizjak at gmail dot com
  2021-06-11  7:35 ` [Bug target/101021] " ubizjak at gmail dot com
  2021-06-11 10:32 ` cvs-commit at gcc dot gnu.org
@ 2021-06-11 10:35 ` ubizjak at gmail dot com
  2021-06-13 19:51 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2021-06-11 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
Fixed.

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

* [Bug target/101021] PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4
  2021-06-10 18:07 [Bug target/101021] New: PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4 ubizjak at gmail dot com
                   ` (2 preceding siblings ...)
  2021-06-11 10:35 ` ubizjak at gmail dot com
@ 2021-06-13 19:51 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-13 19:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS 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:681143b9b94d7f1c88a7c34e2250865c31191959

commit r12-1413-g681143b9b94d7f1c88a7c34e2250865c31191959
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Sun Jun 13 21:50:51 2021 +0200

    i386: Improve variable permutation insn avoidance [PR101021]

    Emit constant permutation insn directly from expand_vec_perm_shufb.

    2021-06-13  Uroš Bizjak  <ubizjak@gmail.com>

    gcc/
            PR target/101021
            * config/i386/i386-expand.c (expand_vec_perm_pshufb):
            Emit constant permutation insn directly from here.

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

end of thread, other threads:[~2021-06-13 19:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 18:07 [Bug target/101021] New: PSHUFB is emitted instead of PSHUFD, PSHUFLW and PSHUFHW with -msse4 ubizjak at gmail dot com
2021-06-11  7:35 ` [Bug target/101021] " ubizjak at gmail dot com
2021-06-11 10:32 ` cvs-commit at gcc dot gnu.org
2021-06-11 10:35 ` ubizjak at gmail dot com
2021-06-13 19:51 ` 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).