[AArch64][FrameLowering] Redundant predicate register load/store spills to stack
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Reduced.ll
```llvm
define aarch64_sve_vector_pcs void @z_consecutive_reg_spill() {
call void asm sideeffect "", "~{z8},~{z9}"()
ret void
}
```
### Command Args
`./bin/llc --mtriple=aarch64-linux-gnu --mattr=+sve2p1`
### Outcome
```asm
.file "reduced.ll"
.text
.globl z_consecutive_reg_spill // -- Begin function z_consecutive_reg_spill
.p2align 2
.type z_consecutive_reg_spill,@function
.variant_pcs z_consecutive_reg_spill
z_consecutive_reg_spill: // @z_consecutive_reg_spill
.cfi_startproc
// %bb.0:
str x29, [sp, #-16]! // 8-byte Folded Spill
addvl sp, sp, #-3
str p8, [sp, #7, mul vl] // 2-byte Spill
str z9, [sp, #1, mul vl] // 16-byte Folded Spill
str z8, [sp, #2, mul vl] // 16-byte Folded Spill
.cfi_escape 0x0f, 0x08, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x48, 0x1e, 0x22 // sp + 16 + 24 * VG
.cfi_offset w29, -16
.cfi_escape 0x10, 0x48, 0x09, 0x92, 0x2e, 0x00, 0x11, 0x78, 0x1e, 0x22, 0x40, 0x1c // $d8 @ cfa - 8 * VG - 16
.cfi_escape 0x10, 0x49, 0x09, 0x92, 0x2e, 0x00, 0x11, 0x70, 0x1e, 0x22, 0x40, 0x1c // $d9 @ cfa - 16 * VG - 16
//APP
//NO_APP
ldr p8, [sp, #7, mul vl] // 2-byte Reload
ldr z9, [sp, #1, mul vl] // 16-byte Folded Reload
ldr z8, [sp, #2, mul vl] // 16-byte Folded Reload
addvl sp, sp, #3
ldr x29, [sp], #16 // 8-byte Folded Reload
ret
.Lfunc_end0:
.size z_consecutive_reg_spill, .Lfunc_end0-z_consecutive_reg_spill
.cfi_endproc
// -- End function
```
### Issue
There is no need for the predicate register (p8) to be emitted, I believe this is due to loose conditions for checking whether st1b/ld1b will be emitted. This is because st1b and ld1b require a predicate register and regular stores do not.
The code that tells the stack to spill this predicate is in 'AArch64FrameLowering.cpp' in function `determineCalleeSaves`.
Contributor guide
Research direction
Run the provided Reduced.ll with ./bin/llc --mtriple=aarch64-linux-gnu --mattr=+sve2p1 and inspect the generated assembly. Start in AArch64FrameLowering.cpp at determineCalleeSaves, focusing on the conditions that account for st1b/ld1b predicate-register requirements. Done means the redundant p8 spill and reload are absent while the required z-register spills remain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100