llvm / llvm/llvm-project

[PowerPC] Extracting the low half of a PowerPC64LE `long double` (PPCDoubleDouble) returns the high half

Open
#222,495 2 comments 0 reactions 0 assignees View on GitHub
backend:PowerPC confirmed floating-point miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`powerpc64`: https://godbolt.org/z/b7q11o73E

`powerpc64le`: https://godbolt.org/z/KzrM9b4zn

The LLVM IR looks ok, but `lo_part()` returns the high half on the `powerpc64le` target (outputting the exact same code as `hi_part()`. `powerpc64` appears to be ok.
```c++
struct DoubleDouble {
double hi;
double lo;
};
double hi_part(long double x) {
return __builtin_bit_cast(DoubleDouble, x).hi;
}
double lo_part(long double x) {
// incorrectly returns the high half
return __builtin_bit_cast(DoubleDouble, x).lo;
}
```

Discovered while working on adding PowerPC tests for https://github.com/llvm/llvm-project/issues/188079

Contributor guide

Open the contributing guide

Research direction

Start with the C++ reproducer and compare the PowerPC64 and PowerPC64LE output from the linked Godbolt examples, then inspect the LLVM IR and PPCDoubleDouble lowering involved in hi_part() and lo_part(). Done means lo_part() returns the low half on powerpc64le while hi_part() remains correct.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.