mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
e9cd01d82d
In RISC-V there is a single addressing mode of the form imm(reg) where imm is a signed integer of 12-bit with a range of [-2048..2047] bytes from reg. The test MultiSource/UnitTests/C++11/frame_layout of the LLVM test-suite exercises several scenarios with the stack, including function calls where the stack will need to be realigned to to a local variable having a large alignment of 4096 bytes. In situations of large stacks, the RISC-V backend (in RISCVFrameLowering) reserves an extra emergency spill slot which can be used (if no free register is found) by the register scavenger after the frame indexes have been eliminated. PrologEpilogInserter already takes care of keeping the emergency spill slots as close as possible to the stack pointer or frame pointer (depending on what the function will use). However there is a final alignment step to honour the maximum alignment of the stack that, when using the stack pointer to access the emergency spill slots, has the side effect of setting them farther from the stack pointer. In the case of the frame_layout testcase, the net result is that we do have an emergency spill slot but it is so far from the stack pointer (more than 2048 bytes due to the extra alignment of a variable to 4096 bytes) that it becomes unreachable via any immediate offset. During elimination of the frame index, many (regular) offsets of the stack may be immediately unreachable already. Their address needs to be computed using a register. A virtual register is created and later RegisterScavenger should be able to find an unused (physical) register. However if no register is available, RegisterScavenger will pick a physical register and spill it onto an emergency stack slot, while we compute the offset (restoring the chosen register after all this). This assumes that the emergency stack slot is easily reachable (this is, without requiring another register!). This is the assumption we seem to break when we perform the extra alignment in PrologEpilogInserter. We can "float" the emergency spill slots by increasing (in absolute value) their offsets from the incoming stack pointer. This way the emergency spill slots will remain close to the stack pointer (once the function has allocated storage for the stack, including the needed realignment). The new size computed in PrologEpilogInserter is padding so it should be OK to move the emergency spill slots there. Also because we're increasing the alignment, the new location should stay aligned for the purpose of the emergency spill slots. Note that this change also impacts other backends as shown by the tests. Changes are minor adjustments to the emergency stack slot offset. Differential Revision: https://reviews.llvm.org/D89239
79 lines
2.9 KiB
YAML
79 lines
2.9 KiB
YAML
# NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
# REQUIRES: asserts
|
|
# RUN: llc -mtriple riscv64 -start-before=prologepilog -o - \
|
|
# RUN: -verify-machineinstrs %s | FileCheck %s
|
|
#
|
|
# RUN: llc -mtriple riscv64 -start-before=prologepilog -o /dev/null \
|
|
# RUN: -debug-only=prologepilog -verify-machineinstrs %s 2>&1 \
|
|
# RUN: | FileCheck --check-prefix=DEBUG %s
|
|
#
|
|
# DEBUG: Adjusting emergency spill slots!
|
|
# DEBUG: Adjusting offset of emergency spill slot #4 from -4112 to -8192
|
|
|
|
--- |
|
|
; ModuleID = 'reduced.ll'
|
|
source_filename = "frame_layout-1253b1.cpp"
|
|
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
|
|
target triple = "riscv64"
|
|
|
|
; Function Attrs: nounwind
|
|
define weak_odr dso_local void @foo(i8* %ay) nounwind {
|
|
; CHECK-LABEL: foo:
|
|
; CHECK: # %bb.0: # %entry
|
|
; CHECK-NEXT: addi sp, sp, -2032
|
|
; CHECK-NEXT: sd ra, 2024(sp) # 8-byte Folded Spill
|
|
; CHECK-NEXT: sd s0, 2016(sp) # 8-byte Folded Spill
|
|
; CHECK-NEXT: addi s0, sp, 2032
|
|
; CHECK-NEXT: sd a1, 0(sp)
|
|
; CHECK-NEXT: lui a1, 2
|
|
; CHECK-NEXT: addiw a1, a1, -2032
|
|
; CHECK-NEXT: sub sp, sp, a1
|
|
; CHECK-NEXT: srli a1, sp, 12
|
|
; CHECK-NEXT: slli sp, a1, 12
|
|
; CHECK-NEXT: lui a1, 1
|
|
; CHECK-NEXT: addiw a1, a1, -8
|
|
; CHECK-NEXT: add a1, sp, a1
|
|
; CHECK-NEXT: sd a0, 0(a1)
|
|
; CHECK-NEXT: ld a1, 0(sp)
|
|
; CHECK-NEXT: call foo@plt
|
|
; CHECK-NEXT: lui a0, 2
|
|
; CHECK-NEXT: sub sp, s0, a0
|
|
; CHECK-NEXT: lui a0, 2
|
|
; CHECK-NEXT: addiw a0, a0, -2032
|
|
; CHECK-NEXT: add sp, sp, a0
|
|
; CHECK-NEXT: ld s0, 2016(sp) # 8-byte Folded Reload
|
|
; CHECK-NEXT: ld ra, 2024(sp) # 8-byte Folded Reload
|
|
; CHECK-NEXT: addi sp, sp, 2032
|
|
; CHECK-NEXT: ret
|
|
entry:
|
|
ret void
|
|
}
|
|
|
|
|
|
...
|
|
---
|
|
name: foo
|
|
alignment: 2
|
|
tracksRegLiveness: false
|
|
frameInfo:
|
|
maxAlignment: 4096
|
|
stack:
|
|
- { id: 0, size: 8, alignment: 4096 }
|
|
- { id: 1, type: spill-slot, size: 8, alignment: 8 }
|
|
machineFunctionInfo: {}
|
|
body: |
|
|
bb.0.entry:
|
|
liveins: $x1, $x5, $x6, $x7, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x28, $x29, $x30, $x31
|
|
|
|
; This is to store something to the (non-emergency) spill slot %stack.1.
|
|
SD $x10, %stack.1, 0
|
|
; This is here just to make all the eligible registers live at this point.
|
|
; This way when we replace the frame index %stack.1 with its actual address
|
|
; we have to allocate a virtual register to compute it.
|
|
; A later run of the the register scavenger won't find an available register
|
|
; either so it will have to spill one to the emergency spill slot.
|
|
PseudoCALL target-flags(riscv-plt) @foo, csr_ilp32_lp64, implicit-def $x1, implicit-def $x2, implicit $x1, implicit $x5, implicit $x6, implicit $x7, implicit $x10, implicit $x11, implicit $x12, implicit $x13, implicit $x14, implicit $x15, implicit $x16, implicit $x17, implicit $x28, implicit $x29, implicit $x30, implicit $x31
|
|
PseudoRET
|
|
|
|
...
|