https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128556
Bug ID: 128556
Summary: [17 Regression] aarch64: wrong code for vaba_s8
followed by vshr_n_s8
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
#include <arm_neon.h>
#include <stdint.h>
__attribute__((noipa)) int8x8_t a(int8x8_t acc, int8x8_t x, int8x8_t y)
{
return vshr_n_s8(vaba_s8(acc, x, y), 1);
}
int main(void)
{
int8_t acc[8] = {100, 0, 0, 0, 0, 0, 0, 0};
int8_t xs[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int8_t ys[8] = {100, 0, 0, 0, 0, 0, 0, 0};
int8x8_t r = a(vld1_s8(acc), vld1_s8(xs), vld1_s8(ys));
if (vget_lane_s8(r, 0) != -28)
__builtin_abort();
return 0;
}
vaba_s8 wraps to 8 bits: (int8_t)(100 + 100) = -56, and -56 >> 1 = -28, so main
must return normally.
With -O1 and above on trunk the program aborts. a is compiled to sabd + shadd,
which adds without truncating to 8 bits and returns 100. GCC 16.1.0 generates
saba + sshr and passes. -fwrapv avoids the problem.
trunk, -O2:
a:
sabd v1.8b, v1.8b, v2.8b
shadd v0.8b, v1.8b, v0.8b
ret
Compiler Explorer:
https://godbolt.org/z/c6ofqb4Yb