https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127583
Bug ID: 127583
Summary: powerpc64: wrong code at -O1: rotate-and-insert with a
wrap-around mask
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: shimizu2486 at gmail dot com
Target Milestone: ---
Target: powerpc64-linux-gnu
Live reproducer: https://godbolt.org/z/cc17ovWYd
$ cat t1.c
#include <stdint.h>
#include <stdio.h>
uint32_t x = 0xffffffff;
int main(void) {
printf("%x\n", ((x << 2 | x >> 30) & ~2u) | (x & 2));
}
The program should print ffffffff.
$ powerpc64-linux-gnu-gcc -O0 -static t1.c -o t1 && qemu-ppc64le ./t1
ffffffff (correct)
$ powerpc64-linux-gnu-gcc -O1 -static t1.c -o t1 && qemu-ppc64le ./t1
fffffffe (wrong)
powerpc64 trunk (a0b77a14) wrong
powerpc64 16.1.0 wrong
-O0 is correct; -O1, -O2, -O3 and -Os are wrong, on both endiannness (le).
x86-64 and aarch64 print ffffffff.