https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90796
Bug ID: 90796
Summary: GCC: O2 vs O3 output differs on simple test
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: konstantin.vladimirov at gmail dot com
Target Milestone: ---
Reproduction:
---
#include <stdio.h>
unsigned b[11];
unsigned c;
int d, e, f;
char en;
int main() {
for (; e < 100; e += 3) {
printf("b[0] = %u\n", b[0]);
for (; c < 9; c++)
for (d = 2; d < 11; d++) {
f = b[c + 2] ^ 9;
b[c] = f;
}
}
}
---
Compiler information:
---
> gcc -v
Using built-in specs.
COLLECT_GCC=/apps/bin/gcc
COLLECT_LTO_WRAPPER=/apps/9fafffe/bin/../libexec/gcc/x86_64-pc-linux-gnu/10.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /srcs/gcc/configure --disable-bootstrap --prefix=/apps/9fafffe
Thread model: posix
gcc version 10.0.0 20190608 (experimental) (GCC)
---
Compile and run like this:
> gcc -O2 min.c -o corr
> ./corr >& corr.log
> gcc -O3 min.c -o wrong
> ./wrong >& wrong.log
Correct output:
b[0] = 0
b[0] = 9
....
b[0] = 9
Wrong output:
b[0] = 0
b[0] = 0
....
b[0] = 0
O0 and O1 modes agree with O2.