[Bug target/126784] Sub-optimal code sequence for __builtin_convertvector
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Aug 18 10:01:02 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126784
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:
https://gcc.gnu.org/g:a6173e867de7f9e7a6f060e5a208a4290d19ba51
commit r17-3355-ga6173e867de7f9e7a6f060e5a208a4290d19ba51
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Aug 18 17:57:08 2026 +0800
match.pd: Change the MIN/MAX narrowing to MIN/MAX + convert
"(type) minmax ((wide_type) a, (wide_type) b) to minmax (a, b)" is limited
to the single use of the result. It doesn't support:
typedef int v2si __attribute__((vector_size (8)));
typedef long long v2di __attribute__((vector_size (16)));
v2si
func (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);
}
Change it to
minmax ((wide_type) a, (wide_type) b) -> (wide_type) minmax (a, b)
instead. Now we generate
pminsd %xmm1, %xmm0
pmovsxdq %xmm0, %xmm1
movaps %xmm1, (%rdi)
instead of
pmovsxdq %xmm0, %xmm2
pmovsxdq %xmm1, %xmm1
movdqa %xmm2, %xmm0
movdqa %xmm2, %xmm3
pcmpgtq %xmm1, %xmm0
pblendvb %xmm0, %xmm1, %xmm3
movdqa %xmm3, %xmm0
movaps %xmm3, (%rdi)
shufps $232, %xmm3, %xmm0
gcc/
PR middle-end/126784
* match.pd ((type) minmax ((wide_type) a, (wide_type) b)): Changed
to ...
(minmax ((wide_type) a, (wide_type) b)): This.
gcc/testsuite/
PR middle-end/126784
* g++.target/i386/pr126784-1.C: New test.
* g++.target/i386/pr126784-2.C: Likewise.
* gcc.target/i386/pr126784-1.c: Likewise.
* gcc.target/i386/pr126784-2.c: Likewise.
* gcc.target/i386/pr126784-3.c: Likewise.
* gcc.target/i386/pr126784-4.c: Likewise.
* gcc.target/i386/pr126784-5.c: Likewise.
* gcc.target/i386/pr126784-6.c: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
More information about the Gcc-bugs
mailing list