https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128930
Bug ID: 128930
Summary: wrong code at -O1: a _BitInt(129) set to -1 by an
inlined _BitInt(256) negation compares greater than a
_BitInt(192) zero
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: shimizu2486 at gmail dot com
Target Milestone: ---
Live reproducer: https://godbolt.org/z/Mv7srs9n6
$ cat t1.c
#include <stdio.h>
_BitInt(256) neg(_BitInt(256) a) { return -a; }
__attribute__((noipa)) int f(int t, _BitInt(192) y) {
_BitInt(129) l = neg(t);
return l > y;
}
int main(void) { printf("%d\n", f(1, 0)); }
l is -1 and y is 0, so l > y is false and f returns 0.
$ gcc -O0 t1.c -o t1 && ./t1
0 (correct)
$ gcc -O1 t1.c -o t1 && ./t1
1 (wrong)
x86_64 trunk (4abe2b137f26) wrong
x86_64 16.2.0, 15.3.0, 14.4.0 wrong
-O1 is wrong. -O0, -O2, -O3, -Os and -Og are correct. -fno-inline gives 0
correctly.
riscv64, loongarch64, aarch64 and powerpc64le are wrong as well.