| Issue |
241885
|
| Summary |
[PowerPC] sign extension of a `_BitInt(33)` argument truncated to `int` is dropped
|
| Labels |
new issue,
generated by fuzzer
|
| Assignees |
|
| Reporter |
hazohelet
|
Live Reproducer: [https://godbolt.org/z/36ac5h5E8](<https://godbolt.org/z/36ac5h5E8>)
Compiling the following C code for `powerpc64le` with `clang -O1` and running it prints the wrong result.
```c
#include <stdio.h>
static volatile long long X = 0x80000000;
int g, c;
__attribute__((noinline)) long f(_BitInt(33) p) {
int t = p;
g = t;
if (c)
return 0;
return t;
}
int main(void) {
printf("%ld\n", f(X));
}
```
clang command:
```sh
clang --target=powerpc64le-linux-gnu -static -O1 repro.c && qemu-ppc64le ./a.out
```
Output (wrong):
```text
2147483648
```
Expected (what -O0 prints, and what x86-64 prints):
```text
-2147483648
```
`p` is 0x80000000, so `t = (int)p` is -2147483648, and `f` must return it sign-extended. `f` returns `p`'s register as it came in, with no `extsw`:
```asm
f:
...
stw 3, g@toc@l(4)
addis 4, 2, c@toc@ha
lwz 4, c@toc@l(4)
cmplwi 4, 0
li 4, 0
iseleq 3, 3, 4
blr
```
Notes:
* Correct at -O0; -O1, -O2, -O3 and -Os are wrong
* Also wrong for `powerpc64`
* Correct with `-mllvm -ppc-eliminate-signext=false`, which keeps an `extsw 3, 3` after the `iseleq`
* Possibly related to #222694, but `-mllvm -ppc-eliminate-signext=false` does not fix that one, so I assume they have different root causes, thus creating this new issue
clang version:
```text
clang version 24.0.0git (https://github.com/llvm/llvm-project 7d25e4f9cd72686727beaf0b661ce3e910ee1349)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs