https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114074
Bug ID: 114074
Summary: wrong code at -O1 and above on x86_64-linux-gnu
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zhendong.su at inf dot ethz.ch
Target Milestone: ---
This seems to be quite long-latent and affects 8.1 and later.
Compiler Explorer: https://godbolt.org/z/vbM6zsq1b
[511] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/14.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.1 20240223 (experimental) (GCC)
[512] %
[512] % gcctk -O0 small.c; ./a.out
0
0
[513] % gcctk -O1 small.c
[514] % ./a.out
0
[515] % cat small.c
int printf(const char *, ...);
int a, b;
int main() {
for (a = 0; a > -3; a -= 2) {
int c = a;
b = 2000000000;
a = ~c * b;
printf("0\n");
if (!a)
break;
a = c;
}
return 0;
}