Files
clang-p2996/llvm/test/CodeGen/AArch64/reverse-csr-restore-seq.mir
Momchil Velikov 17e85cd410 [AArch64] Async unwind - Always place the first LDP at the end when ReverseCSRRestoreSeq is true
This patch is in preparation for the async unwind CFI.

Put the first `LDP` the end, so that the load-store optimizer can run
and merge the `LDP` and the `ADD` into a post-index `LDP`.

Do this always and as early as at the time of the initial creation of
the CSR restore instructions, even if that `LDP` is not guaranteed to
be mergeable with a subsequent `SP` increment.

This greatly simplifies the CFI generation for prologue, as otherwise
we have to take extra steps to ensure reordering does not cross CFI
instructions.

Reviewed By: danielkiss

Differential Revision: https://reviews.llvm.org/D112328
2022-02-24 18:48:07 +00:00

102 lines
3.1 KiB
YAML

# RUN: llc -run-pass=prologepilog -reverse-csr-restore-seq -o - -mtriple=aarch64-- %s | FileCheck %s --check-prefixes=CHECK
# RUN: llc -start-before=prologepilog -stop-after=aarch64-ldst-opt -reverse-csr-restore-seq -o - -mtriple=aarch64-- %s | FileCheck %s --check-prefixes=CHECK
#
--- |
define void @foo() nounwind { entry: unreachable }
define void @bar() nounwind { entry: unreachable }
define void @baz() nounwind { entry: unreachable }
...
---
name: foo
# CHECK-LABEL: name: foo
tracksRegLiveness: true
body: |
bb.0:
$x19 = IMPLICIT_DEF
$x20 = IMPLICIT_DEF
$x21 = IMPLICIT_DEF
$x22 = IMPLICIT_DEF
$x23 = IMPLICIT_DEF
$x24 = IMPLICIT_DEF
$x25 = IMPLICIT_DEF
$x26 = IMPLICIT_DEF
; The local stack size is 0, so the last ldp in the sequence will also
; restore the stack.
; CHECK: $x24, $x23 = frame-destroy LDPXi $sp, 2
; CHECK-NEXT: $x22, $x21 = frame-destroy LDPXi $sp, 4
; CHECK-NEXT: $x20, $x19 = frame-destroy LDPXi $sp, 6
; The ldp and the stack increment get merged even before
; the load-store optimizer.
; CHECK-NEXT: early-clobber $sp, $x26, $x25 = frame-destroy LDPXpost $sp, 8
RET_ReallyLR
...
---
name: bar
# CHECK-LABEL: name: bar
tracksRegLiveness: true
stack:
- { id : 0, size: 8, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
local-offset: -4, debug-info-variable: '', debug-info-expression: '',
debug-info-location: '' }
body: |
bb.0:
$x19 = IMPLICIT_DEF
$x20 = IMPLICIT_DEF
$x21 = IMPLICIT_DEF
$x22 = IMPLICIT_DEF
$x23 = IMPLICIT_DEF
$x24 = IMPLICIT_DEF
$x25 = IMPLICIT_DEF
$x26 = IMPLICIT_DEF
; The local stack size is not 0, and we can combine the CSR stack size with
; the local stack size. This results in rewriting the offsets for all the
; save/restores and forbids us to merge the stack adjustment and the last pop.
; In this case, there is no point of moving the first CSR pair at the end.
; We do it anyway, as it's a small price to pay for the resulting
; simplification in the epilogue emission code.
; CHECK: $x24, $x23 = frame-destroy LDPXi $sp, 4
; CHECK-NEXT: $x22, $x21 = frame-destroy LDPXi $sp, 6
; CHECK-NEXT: $x20, $x19 = frame-destroy LDPXi $sp, 8
; CHECK-NEXT: $x26, $x25 = frame-destroy LDPXi $sp, 2
; CHECK-NEXT: $sp = frame-destroy ADDXri $sp, 80, 0
RET_ReallyLR
...
---
# Check that the load from the offset 0 is moved at the end even when hasFP is
# false.
name: baz
# CHECK-LABEL: name: baz
alignment: 4
tracksRegLiveness: true
frameInfo:
adjustsStack: true
hasCalls: true
body: |
bb.0:
successors: %bb.1
$x0 = IMPLICIT_DEF
$x20 = IMPLICIT_DEF
$x21 = IMPLICIT_DEF
ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
BL @foo, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit-def $sp, implicit-def $x0
ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
B %bb.1
bb.1:
; CHECK: $x21, $x20 = frame-destroy LDPXi $sp, 2
; CHECK-NEXT: early-clobber $sp, $lr = frame-destroy LDRXpost $sp, 32
RET_ReallyLR
...