1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/test/CodeGen/AArch64/arm64-custom-call-saved-reg.ll
Amara Emerson 74c92ba816 [AArch64][GlobalISel] Split G_GLOBAL_VALUE into ADRP + G_ADD_LOW and optimize.
The concept of G_GLOBAL_VALUE is nice and simple, but always using it as the
representation for global var addressing until selection time creates some
problems in optimizing accesses in certain code/relocation models.

The problem comes from trying to optimize adrp -> add -> load/store sequences
in the most common "small" code model. These accesses can be optimized into an
adrp -> load with the add offset being folded into the load's immediate field.
If we try to keep all global var references as a single generic instruction
then by the time we get to the complex operand trying to match these, we end up
generating an adrp at the point of use. The real issue here is that we don't
have any form of CSE during selection, so the code size will bloat from many
redundant adrp's.

This patch custom legalizes small code mode non-GOT G_GLOBALs into target ADRP
and a new "target specific generic opcode" G_ADD_LOW. We also teach the
localizer to localize these instructions via the custom hook that was added
recently. Finally, the complex pattern for indexed loads/stores is extended to
try to fold these G_ADD_LOW instructions into the load immediate.

On -O0 CTMark, we see a 0.8% geomean code size improvement. We should also see
some minor performance improvements too.

Differential Revision: https://reviews.llvm.org/D78465
2020-06-01 16:00:56 -07:00

153 lines
4.6 KiB
LLVM

; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x8 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X8
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x9 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X9
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x10 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X10
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x11 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X11
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x12 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X12
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x13 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X13
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x14 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X14
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x15 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X15
; RUN: llc -mtriple=arm64-linux-gnu -mattr=+call-saved-x18 -o - %s \
; RUN: | FileCheck %s --check-prefix=CHECK-SAVED-X18
; Test all call-saved-x# options together.
; RUN: llc -mtriple=arm64-linux-gnu \
; RUN: -mattr=+call-saved-x8 \
; RUN: -mattr=+call-saved-x9 \
; RUN: -mattr=+call-saved-x10 \
; RUN: -mattr=+call-saved-x11 \
; RUN: -mattr=+call-saved-x12 \
; RUN: -mattr=+call-saved-x13 \
; RUN: -mattr=+call-saved-x14 \
; RUN: -mattr=+call-saved-x15 \
; RUN: -mattr=+call-saved-x18 \
; RUN: -o - %s | FileCheck %s \
; RUN: --check-prefix=CHECK-SAVED-ALL
; Test GlobalISel.
; RUN: llc -mtriple=arm64-linux-gnu \
; RUN: -mattr=+call-saved-x8 \
; RUN: -mattr=+call-saved-x9 \
; RUN: -mattr=+call-saved-x10 \
; RUN: -mattr=+call-saved-x11 \
; RUN: -mattr=+call-saved-x12 \
; RUN: -mattr=+call-saved-x13 \
; RUN: -mattr=+call-saved-x14 \
; RUN: -mattr=+call-saved-x15 \
; RUN: -mattr=+call-saved-x18 \
; RUN: -global-isel \
; RUN: -o - %s | FileCheck %s \
; RUN: --check-prefix=CHECK-SAVED-ALL-GISEL
; Used to exhaust the supply of GPRs.
@var = global [30 x i64] zeroinitializer
; Check that callee preserves additional CSRs.
define void @callee() {
; CHECK-LABEL: callee
; CHECK-SAVED-X8: str x8, [sp
; CHECK-SAVED-X9: str x9, [sp
; CHECK-SAVED-X10: str x10, [sp
; CHECK-SAVED-X11: str x11, [sp
; CHECK-SAVED-X12: str x12, [sp
; CHECK-SAVED-X13: str x13, [sp
; CHECK-SAVED-X14: str x14, [sp
; CHECK-SAVED-X15: str x15, [sp
; CHECK-SAVED-X18: str x18, [sp
; CHECK-SAVED-ALL: str x18, [sp
; CHECK-SAVED-ALL-NEXT: stp x15, x14, [sp
; CHECK-SAVED-ALL-NEXT: stp x13, x12, [sp
; CHECK-SAVED-ALL-NEXT: stp x11, x10, [sp
; CHECK-SAVED-ALL-NEXT: stp x9, x8, [sp
%val = load volatile [30 x i64], [30 x i64]* @var
store volatile [30 x i64] %val, [30 x i64]* @var
; CHECK-SAVED-ALL: ldp x9, x8, [sp
; CHECK-SAVED-ALL-NEXT: ldp x11, x10, [sp
; CHECK-SAVED-ALL-NEXT: ldp x13, x12, [sp
; CHECK-SAVED-ALL-NEXT: ldp x15, x14, [sp
; CHECK-SAVED-ALL-NEXT: ldr x18, [sp
; CHECK-SAVED-X8: ldr x8, [sp
; CHECK-SAVED-X9: ldr x9, [sp
; CHECK-SAVED-X10: ldr x10, [sp
; CHECK-SAVED-X11: ldr x11, [sp
; CHECK-SAVED-X12: ldr x12, [sp
; CHECK-SAVED-X13: ldr x13, [sp
; CHECK-SAVED-X14: ldr x14, [sp
; CHECK-SAVED-X15: ldr x15, [sp
; CHECK-SAVED-X18: ldr x18, [sp
ret void
}
; Check that caller doesn't shy away from allocating additional CSRs.
define void @caller() {
; CHECK-LABEL: caller
%val = load volatile [30 x i64], [30 x i64]* @var
; CHECK-SAVED-X8: adrp x8, var
; CHECK-SAVED-X9: adrp x9, var
; CHECK-SAVED-X10: adrp x10, var
; CHECK-SAVED-X11: adrp x11, var
; CHECK-SAVED-X12: adrp x12, var
; CHECK-SAVED-X13: adrp x13, var
; CHECK-SAVED-X14: adrp x14, var
; CHECK-SAVED-X15: adrp x15, var
; CHECK-SAVED-X18: adrp x18, var
; CHECK-SAVED-ALL: adrp x8, var
; CHECK-SAVED-ALL-DAG: ldr x9
; CHECK-SAVED-ALL-DAG: ldr x10
; CHECK-SAVED-ALL-DAG: ldr x11
; CHECK-SAVED-ALL-DAG: ldr x12
; CHECK-SAVED-ALL-DAG: ldr x13
; CHECK-SAVED-ALL-DAG: ldr x14
; CHECK-SAVED-ALL-DAG: ldr x15
; CHECK-SAVED-ALL-DAG: ldr x18
; CHECK-SAVED-ALL-GISEL: adrp x16, var
; CHECK-SAVED-ALL-GISEL-DAG: ldr x8
; CHECK-SAVED-ALL-GISEL-DAG: ldr x9
; CHECK-SAVED-ALL-GISEL-DAG: ldr x10
; CHECK-SAVED-ALL-GISEL-DAG: ldr x11
; CHECK-SAVED-ALL-GISEL-DAG: ldr x12
; CHECK-SAVED-ALL-GISEL-DAG: ldr x13
; CHECK-SAVED-ALL-GISEL-DAG: ldr x14
; CHECK-SAVED-ALL-GISEL-DAG: ldr x15
; CHECK-SAVED-ALL-GISEL-DAG: ldr x18
call void @callee()
; CHECK: bl callee
store volatile [30 x i64] %val, [30 x i64]* @var
; CHECK-SAVED-ALL-DAG: str x9
; CHECK-SAVED-ALL-DAG: str x10
; CHECK-SAVED-ALL-DAG: str x11
; CHECK-SAVED-ALL-DAG: str x12
; CHECK-SAVED-ALL-DAG: str x13
; CHECK-SAVED-ALL-DAG: str x14
; CHECK-SAVED-ALL-DAG: str x15
; CHECK-SAVED-ALL-DAG: str x18
ret void
}