| Issue |
165634
|
| Summary |
[LLVM][MIPS] `-mcompact-branches` is not honored for `J` and `JAL`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
ameisen
|
With `-mcompact-branches=always`, for the following code: `JAL` is not converted into `BALC` nor is `J` converted into `BC`.
Secondarily, a call to a `[[noreturn]]` function is also emitting `JAL` when one would expect it to emit a non-linking branch (such as `BC`) due to the link register being unused, though this is of lesser importance.
```c++
__attribute__((noinline))
int foo0()
{
volatile int a;
return a;
}
int bar0()
{
return foo0();
}
```
Clang output (`-std=gnu++23 -O3 -march=mips32r6 -mcompact-branches=always -fno-PIC`):
```asm
foo0():
$func_begin0 = $tmp0
addiu $sp, $sp, -8
lw $2, 4($sp)
addiu $sp, $sp, 8
jrc $ra
bar0():
$func_begin1 = $tmp3
addiu $sp, $sp, -24
sw $ra, 20($sp)
jal foo0()
nop
lw $ra, 20($sp)
addiu $sp, $sp, 24
jrc $ra
```
GCC output (`-std=gnu++23 -O3 -march=mips32r6 -mcompact-branches=always -fno-PIC -fno-optimize-sibling-calls`):
_`-fno-optimize-sibling-calls` added because Clang is also unable to optimize this into a single jump wheras GCC trivially does - see #57795_
```asm
foo0():
addiu $sp,$sp,-16
lw $2,8($sp)
addiu $sp,$sp,16
jrc $31
bar0():
addiu $sp,$sp,-32
sw $31,28($sp)
balc foo0()
lw $31,28($sp)
addiu $sp,$sp,32
jrc $31
```
LLVM/Clang emits `JAL`, whereas GCC properly emits `BALC`. Worse, Clang emits `JAL` with a `nop` in the delay slot.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs