Closed
Description
We have an internal test that recently started producing incorrect output which I bisected back to commit 3aae916.
Consider the following code:
static void init(unsigned char pred, volatile void *data, unsigned size) {
unsigned char *bytes = (unsigned char *)data;
for (unsigned i = 0; i != size; ++i) {
bytes[i] = pred + i;
}
}
#define INIT(PRED, VAR) init(PRED, &VAR, sizeof(VAR))
#include <x86intrin.h>
int main(int argc, char *argv[])
{
__m256 id7702;
INIT(243, id7702);
__m256 id7701 = _mm256_sqrt_ps(id7702);
volatile int id7700 = _mm256_movemask_ps(id7701);
//printf("id7700:%x\n", id7700);
return id7700;
}
If compiled with optimizations and -mavx
and the resulting binary is run, the return value changes after 3aae916:
$ ~/src/upstream/3aae916ff7fe9d0953aa63b2ba1d0e871f6f76fc-linux/bin/clang -O2 -mavx repro.cpp -o repro.bad.out
$ ~/src/upstream/f658d84e01bcdd49e27dc9ef80e1a6cc5f9417fe-linux/bin/clang -O2 -mavx repro.cpp -o repro.good.out
$ ./repro.good.out
$ echo $?
7
$ ./repro.bad.out
$ echo $?
0
You can also see the difference on godbolt comparing with 18.1.0:
https://godbolt.org/z/KPbK4jcGc