[Bug tree-optimization/126760] New: Wrong code at -O2 on x86_64-pc-linux-gnu
"xintong.zhou1 at uwaterloo dot ca via Gcc-bugs" <[email protected]>
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126760
Bug ID: 126760
Summary: Wrong code at -O2 on x86_64-pc-linux-gnu
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: xintong.zhou1 at uwaterloo dot ca
Target Milestone: ---
Compiler Explorer: https://godbolt.org/z/hnc73djc5
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=/data/x27zhou/compiler-nightly/install/gcc/bin/gcc
COLLECT_LTO_WRAPPER=/data/x27zhou/compiler-nightly/install/gcc/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /data/x27zhou/compiler-nightly/src/gcc/configure CC='ccache
clang' CXX='ccache clang++' --enable-checking=yes --disable-bootstrap
--disable-multilib --enable-languages=c,c++
--prefix=/data/x27zhou/compiler-nightly/install/gcc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20260809 (experimental) (GCC)
$
$ gcc-trunk -O0 small.c && ./a.out
3
$ gcc-trunk -O2 small.c && ./a.out
90
$
$ cat small.c
#include <stdio.h>
short a;
int b;
int main() {
long c = a;
unsigned f;
int d = 0, e;
for (; d < 6; d++) {
e = 0;
while (e < 6) {
e++;
f = c;
switch (f) {
case 1:
c = c + d;
case 3:
break;
default:
c = c + d;
}
}
}
b = c;
printf("%d\n", b);
}