https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128724
Bug ID: 128724
Summary: [16/17 Regression] aarch64: SVE shifts by the element
size are folded as shifts by zero in streaming
functions
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: dezhen.lu at student dot uni-tuebingen.de
Target Milestone: ---
Target: aarch64*-*-*
#include <arm_sve.h>
__attribute__((noinline)) uint8_t
lsr (void) __arm_streaming
{
svuint8_t r = svlsr_n_u8_x (svptrue_b8 (), svdup_n_u8 (0x80), 8);
return svlastb_u8 (svptrue_b8 (), r);
}
__attribute__((noinline)) int32_t
asr (void) __arm_streaming
{
svint32_t r = svasr_n_s32_m (svptrue_b32 (), svdup_n_s32 (-5), 32);
return svlastb_s32 (svptrue_b32 (), r);
}
__attribute__((noinline)) int8_t
sra (void) __arm_streaming
{
svint8_t r = svsra_n_s8 (svdup_n_s8 (2), svdup_n_s8 (50), 8);
return svlastb_s8 (svptrue_b8 (), r);
}
__arm_locally_streaming int
main (void)
{
if (lsr () != 0)
__builtin_abort ();
if (asr () != -1)
__builtin_abort ();
if (sra () != 2)
__builtin_abort ();
return 0;
}
gcc -O1 -march=armv9-a+sme2 (16.1 and trunk 17.0.0 20261113 on Compiler
Explorer, aarch64-linux-gnu) folds the three results to the unshifted values:
lsr: mov z31.b, #-128
asr: mov z31.s, #-5
sra: mov z31.b, #52
GCC 14.3 and 15.2 emit "lsr z31.b, z31.b, #8", "asr z31.s, z31.s, #32" and
"ssra z31.b, z30.b, #8" for the same source, and so does 16.1 at -O0 or when
the functions are not streaming.
On an SME CPU with GCC 16.2.0 the program aborts at -O1 and -O2 and passes at
-O0; clang passes.
I used Claude, an AI coding assistant, to find this and to write this report.