https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129248
Bug ID: 129248
Summary: wrong code at -O3 with -msse4.2: a signed vector
element with value -56 is printed as 200
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: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <stdio.h>
typedef unsigned char U __attribute__((vector_size(16)));
typedef signed char S __attribute__((vector_size(16)));
__attribute__((noinline))
void f(U a, int *out)
{
out[0] = a[0];
out[1] = ((S)a)[1];
}
int main(void)
{
U a = { 1, 200 };
int out[2];
f(a, out);
printf("%d %d\n", out[0], out[1]);
}
godbolt: https://godbolt.org/z/T4dhhW6h8
At -O0 -msse4.2 the program prints "1 -56", while at -O3 -msse4.2 it prints "1
200". The second element is read through a signed-char vector, so "1 -56" is
correct on this target.