https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127390
Bug ID: 127390
Summary: [15/16/17 Regression] arm64: wrong code vectorizing
signed _BitInt(24) comparison at -O3
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: shimizu2486 at gmail dot com
Target Milestone: ---
Target: arm64
Live Reproducer: https://godbolt.org/z/sT3rKbM4j
A signed _BitInt(24) comparison is miscompiled on aarch64 at -O3. Disabling
tree vectorization with -fno-tree-vectorize produces the correct result.
$ cat t1.c
#include <stdint.h>
typedef signed _BitInt(24) i24;
static volatile int16_t in2 = -1;
int8_t m0[2];
int main(void) {
int16_t x2 = in2;
int n = 0;
for (n = 0; n < 8; n++) {
if (((i24)(m0[1] ? m0[1] * 2 : 1) >= (i24)(x2 - 1))) break;
}
return n;
}
m0[1] is 0 and x2 is -1, so the condition on the first iteration is
(i24)1 >= (i24)-2
which is true. Hence main should return 0.
$ gcc -O3 t1.c -o t1 && ./t1
$ echo $?
8 (wrong)
$ gcc -O3 -fno-tree-vectorize t1.c -o t1 && ./t1
$ echo $?
0 (correct)
14.3 correct
15.2 wrong
17 (trunk, 69df283e) wrong