https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127586
Bug ID: 127586
Summary: powerpc64: wrong code at -O1: v & 1 of an unsigned
_BitInt(2) evaluates to 2
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: shimizu2486 at gmail dot com
Target Milestone: ---
$ cat t1.c
#include <stdio.h>
int c, d, g, i;
unsigned _BitInt(2) v;
int main(void) {
v = 2;
for (; i; i++) {
if (d) {
g = 0;
if (c)
continue;
}
g = v;
}
printf("%d\n", (int)(v & 1));
}
The program should print 0.
$ powerpc64-linux-gnu-gcc -O0 -static t1.c -o t1 && qemu-ppc64 ./t1
0 (correct)
$ powerpc64-linux-gnu-gcc -O1 -static t1.c -o t1 && qemu-ppc64 ./t1
2 (wrong)
powerpc64 trunk (5b0a952c) wrong
powerpc64 trunk (a0b77a14) wrong
-O0 is correct; -O1, -O2, -O3 and -Os are wrong. powerpc64le, x86-64 and
aarch64 print 0.