https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120584
Bug ID: 120584
Summary: wrong code at -O{1,s,2} 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: ---
Compiler Explorer: https://godbolt.org/z/Moaae67bc
- works: 10.* and earlier
- fails: 11.* and later
* trunk: -O{1,s,2}
* 15.1: -O1 and above
* 14.*, 13.*, 12.*: -O{s,2,3}
* 11.*: -O{s,3}
It is fixed by -fno-tree-slsr.
[537] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/home/suz/suz-local/software/local/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/16.0.0/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 16.0.0 20250607 (experimental) (GCC)
[538] %
[538] % gcctk -O1 -fno-tree-slsr small.c; ./a.out
[539] %
[539] % gcctk -O1 small.c
[540] % ./a.out
Aborted
[541] %
[541] % cat small.c
int a, b;
int h(int i) {
int g;
unsigned e = -3 * a - 3 * i;
if (-b - 2 >= 0 || -999 * i + a >= 0)
i = 0;
int a[5] = {0, 0, 0, i, 0};
for (int f = 0; f < 5; f++)
e = g = e ^ a[f];
return g;
}
int main() {
if (h(2149633) != -4368900)
__builtin_abort();
}