https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122695
Bug ID: 122695
Summary: LoongArch: Wrong code with __builtin_shuffle and
-mlasx
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: xry111 at gcc dot gnu.org
Target Milestone: ---
Test case 1:
[[gnu::vector_size (32)]] char a, b, c;
[[gnu::noipa]] void
test (void)
{
a = __builtin_shuffle (a, a, c);
}
int
main (void)
{
a = (typeof (a)){} + 5;
c = (typeof (a)){} + 64;
test ();
if (a[0] != 5)
__builtin_trap ();
}
results:
test:
la.local $r12,.LANCHOR0
xvld $xr0,$r12,0
xvld $xr2,$r12,32
xvpermi.d $xr1,$xr0,68
xvpermi.d $xr0,$xr0,238
xvshuf.b $xr0,$xr0,$xr1,$xr2
xvst $xr0,$r12,0
jr $r1
It invokes unpredictable result of xvshuf.b, producing wrong result on at least
Loongson 3C5000L-LL.
Test case 2:
[[gnu::vector_size(32)]] short a, b, c;
[[gnu::noipa]] void
test (void)
{
a = __builtin_shuffle(a, b, c) + c;
}
int
main (void)
{
a = (typeof (a)){} + 1;
b = (typeof (b)){} + 2;
c = (typeof (c)){} + 128;
test ();
if (a[0] != 129)
__builtin_trap ();
}
results:
test:
la.local $r12,.LANCHOR0
xvrepli.h $xr3,31
...
xvand.v $xr0,$xr0,$xr3
...
xvadd.h $xr0,$xr1,$xr0
xvst $xr0,$r12,32
jr $r1
i.e. it's now __builtin_shuffle (a, b, c) + (c & 31).