llvm / llvm/llvm-project

[PowerPC] Wrong code at O1

Open
#172,694 2 comments 0 reactions 0 assignees View on GitHub
backend:PowerPC miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Testcase:
```c
void printf(char *, ...);
typedef long uint64_t;
int safe_lshift_func_int16_t_s_u_right, g_2322 = 2, g_3554;
static int g_939 = 2;
uint64_t g_1577;
short func_2___trans_tmp_4;
void func_2(signed char p_3, int p_4, uint64_t p_5)
{
g_3554 = (p_3 && p_5) | p_4;
for (;;)
{
uint64_t l_3564;
__asm goto("" : : : : BS_LABEL_3);
p_4 = p_3;
if (p_5) break;
func_2___trans_tmp_4 = p_3 < 0 ?: safe_lshift_func_int16_t_s_u_right;
BS_LABEL_3:
}
g_1577 = p_5 && p_4;
}
int main()
{
func_2(g_2322, 6, g_939);
g_939 = 0;
int crc = g_1577;
printf("checksum = %X\n", crc);
}
```

Command:
```
> clang --target=powerpc64le-unknown-linux-musl --sysroot=/opt/ppc64/powerpc64le-unknown-linux-musl/sysroot --gcc-toolchain=/opt/ppc64 -O1 -static a.c
> qemu-ppc64le a.out
checksum = 0

> clang --target=powerpc64le-unknown-linux-musl --sysroot=/opt/ppc64/powerpc64le-unknown-linux-musl/sysroot --gcc-toolchain=/opt/ppc64 -O0 -static a.c
> qemu-ppc64le a.out
checksum = 1
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling a.c with the provided clang PowerPC64LE commands at -O1 and -O0, then compare the outputs under qemu-ppc64le. Investigate PowerPC code generation around the inline asm goto, loop, and conditional assignments. Done means the optimized build produces the same checksum as the unoptimized build without regressing the reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.