[Bug target/126784] New: Sub-optimal code sequence for __builtin_convertvector

"hjl.tools at gmail dot com via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126784

            Bug ID: 126784
           Summary: Sub-optimal code sequence for __builtin_convertvector
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: liuhongt at gcc dot gnu.org
  Target Milestone: ---
            Target: x86

GCC generates the optimal code sequence for this:

[hjl@gnu-zen4-1 vect-1]$ cat x.C
typedef int  v2si __attribute__((vector_size (8)));
typedef long long v2di __attribute__((vector_size (16)));
v2si
f (v2si a, v2si b)
{
  v2di x = __builtin_convertvector (a, v2di);
  v2di y = __builtin_convertvector (b, v2di);
  v2di z = x < y ? x : y;
  return __builtin_convertvector (z, v2si);
}
[hjl@gnu-zen4-1 vect-1]$ make x.s
/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/ -O2
-msse4 -S x.C
[hjl@gnu-zen4-1 vect-1]$ cat x.s
        .file   "x.C"
        .text
        .p2align 4
        .globl  _Z1fDv2_iS_
        .type   _Z1fDv2_iS_, @function
_Z1fDv2_iS_:
.LFB0:
        .cfi_startproc
        pminsd  %xmm1, %xmm0
        ret
        .cfi_endproc
.LFE0:
        .size   _Z1fDv2_iS_, .-_Z1fDv2_iS_
        .ident  "GCC: (GNU) 17.0.0 20260810 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-zen4-1 vect-1]$ 

but generates sub-optimal code sequence for slightly modified source:

[hjl@gnu-zen4-1 vect-1]$ cat y.C
typedef int v2si __attribute__((vector_size (8)));
typedef long long v2di __attribute__((vector_size (16)));

v2si
f (v2si a, v2si b, v2di *p)
{
  v2di x = __builtin_convertvector (a, v2di);
  v2di y = __builtin_convertvector (b, v2di);
  v2di z = x < y ? x : y;
  *p = z;
  return __builtin_convertvector (z, v2si);
}
[hjl@gnu-zen4-1 vect-1]$ make y.s
/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/ -O2
-msse4 -S y.C
[hjl@gnu-zen4-1 vect-1]$ cat y.s
        .file   "y.C"
        .text
        .p2align 4
        .globl  _Z1fDv2_iS_PDv2_x
        .type   _Z1fDv2_iS_PDv2_x, @function
_Z1fDv2_iS_PDv2_x:
.LFB0:
        .cfi_startproc
        movdqa  %xmm0, %xmm2
        pmovsxdq        %xmm1, %xmm1
        pmovsxdq        %xmm2, %xmm2
        movdqa  %xmm2, %xmm0
        pcmpgtq %xmm1, %xmm0
        pand    %xmm0, %xmm1
        pandn   %xmm2, %xmm0
        por     %xmm1, %xmm0
        movaps  %xmm0, (%rdi)
        shufps  $232, %xmm0, %xmm0
        ret
        .cfi_endproc
.LFE0:
        .size   _Z1fDv2_iS_PDv2_x, .-_Z1fDv2_iS_PDv2_x
        .ident  "GCC: (GNU) 17.0.0 20260810 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-zen4-1 vect-1]$
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.