| Issue |
54736
|
| Summary |
Suboptimal code generation regarding stack variables (arm64)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
uncleasm
|
As in https://godbolt.org/z/zq81hEb3K, there are multiple opportunities for improvement in the generated code for
```
void foo(int stack, int k, int j) {
int my_stack[stack * 4];
my_stack[k] = j;
asm(""::"r"(my_stack):"memory");
}
stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
mov x29, sp
lsl w8, w0, #2
sub x8, sp, w8, uxtw #2
mov sp, x8
str w2, [x8, w1, sxtw #2]
mov sp, x29
ldp x29, x30, [sp], #16
```
1) missed opportunity to merge
`lsl w8, w0, #2`
`sub x8, sp, w8, uxtw #2` to `sub x8, sp, w0, uxtw #4`
2) disregard of the `-fomit-frame-pointer`
a) no need to spill/restore LR
b) no need to use `x29`
c) no need to compute the address of `my_stack` to separate register as any element can be accessed through `sp`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs