llvm / llvm/llvm-project

Wrong code at -O2/3/s on x86_64-linux_gnu

Open
#224,024 0 comments 0 reactions 0 assignees View on GitHub
confirmed miscompilation regression:22 vectorizers
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Compiler Explorer: https://godbolt.org/z/cKnafWYP7
- fail: trunk, 23.1.0, 22.1.0
- work: 21.1.0 or earlier

small.c

```c
#include
int a, c, d, b, l, o;
short m, p;
unsigned n;
long q;
long r[] = {2902710, 3689655, 1423138, 857618, 3453997, 2089602,
2854081, 2229918, 1512490, 2546041, 3777381, 1591363,
3428393, 2076113, 2, 1190718};
char s[] = {1, 104, 1, 54, 1, 174, 3, 128, 4, 246, 8, 40, 6, 87, 2, 103};
short t[] = {0, 8029, 0, 61};
long v(long *w, unsigned char *x, short *y) {
unsigned long e = 2258;
int j = (y[3] & 15) + 1;
d = 0;
b = 1;
while (d < j) {
e = e + w[d] + x[b * 7 & 15];
e = e * (-5 * w[d] | 1);
d++;
b += 2;
c = 0;
for (; c < 4; c++)
e = e * 31 ^ w[c * 5] + 1;
}
return e * 2654435761 >> 9;
}
int z(long w, long x) {
short k;
long f = w, g = w, h = w;
int i = 6 + (x & 3);
while (i) {
h = h + (f & 31);
f = f - (w & 15);
i--;
}
g = x - g;
k = g ^ h;
return k;
}
void aa(char w, char x) {
for (; p < 12; p++)
;
unsigned u = (p & 7) + 1;
for (; q < u; q++) {
m = o * w & 4095;
n <<= 8;
o = z(u + 1750, u + 169110) + u + w + x - 32438 + o | 255;
n++;
l = v(r, s, t);
}
if ((short)(l + p + x + m + u + n - 127006698))
a = 10;
}
int main() {
aa(66, 37);
printf("%d\n", a);
}
```

Reproduce:
```
$ clang-trunk -O0 small.c && ./a.out
10
$ clang-trunk -O2 small.c && ./a.out
0
$ clang-trunk -O3 small.c && ./a.out
0
```

Contributor guide

Open the contributing guide

Research direction

Use small.c and the Compiler Explorer link as the reproducer; run clang-trunk at -O0, -O2, and -O3 and compare the output with the listed known-good versions. Trace the optimized behavior to identify the responsible compiler pass, then verify that optimized builds preserve the expected 10 result.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.