[PowerPC][SDAG] `fabs` on known bits of `ppc_f128` is wrong
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The program below gives different results for clang with `-O0` versus `-O2`, where the `-O0` result agrees with GCC. So, LLVM optimizes incorrectly on LE targets.
https://godbolt.org/z/sz5n5qKj9
I'm pretty sure this is wrong, the sign bit changes position on BE versus LE, and on LE it is not the most significant bit of the 128-bit value, but only of the hi double (bit 63 on LE, bit 127 on BE).
https://github.com/llvm/llvm-project/blob/83d95d89c520656306130b461252cd0ed9b4f542/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L4160-L4164
```c
/// Make this value non-negative.
void makeNonNegative() {
Zero.setSignBit();
}
/// Set the sign bit to 1.
void setSignBit() { setBit(BitWidth - 1); }
```
does not take the endianness into account.
Contributor guide
Research direction
Reproduce the O0/O2 difference from the linked Compiler Explorer example, then inspect llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp around makeNonNegative and setSignBit. Compare the sign-bit handling on little- and big-endian PowerPC targets, and verify that the reproducer agrees across optimization levels once the issue is addressed.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100