AAPCS64 reserves any of X9-X15 for a compiler to choose to use for this purpose, and says not to use X16 or X18 like GCC (and the previous implementation) chose to use. The X18 register may need to get used by the kernel in some circumstances, as specified by the platform ABI, so it is generally an unwise choice. Simply choosing a different register fixes the problem of this being broken on any platform that actually follows the platform ABI (which is all of them except EABI, if I am reading this linux kernel bug correctly https://lkml2.uits.iu.edu/hypermail/linux/kernel/2001.2/01502.html). As a side benefit, also generate slightly better code and avoids needing the compiler-rt to be present. I did that by following the XCore implementation instead of PPC (although in hindsight, following the RISCV might have been slightly more readable). That X18 is wrong to use for this purpose has been known for many years (e.g. https://www.mail-archive.com/gcc@gcc.gnu.org/msg76934.html) and also known that fixing this to use one of the correct registers is not an ABI break, since this only appears inside of a translation unit. Some of the other temporary registers (e.g. X9) are already reserved inside llvm for internal use as a generic temporary register in the prologue before saving registers, while X15 was already used in rare cases as a scratch register in the prologue as well, so I felt that seemed the most logical choice to choose here.
28 lines
867 B
LLVM
28 lines
867 B
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
|
|
; RUN: llc -disable-post-ra -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s
|
|
|
|
; Tests that the 'nest' parameter attribute causes the relevant parameter to be
|
|
; passed in the right register.
|
|
|
|
define ptr @nest_receiver(ptr nest %arg) nounwind {
|
|
; CHECK-LABEL: nest_receiver:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: mov x0, x15
|
|
; CHECK-NEXT: ret
|
|
|
|
ret ptr %arg
|
|
}
|
|
|
|
define ptr @nest_caller(ptr %arg) nounwind {
|
|
; CHECK-LABEL: nest_caller:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
|
|
; CHECK-NEXT: mov x15, x0
|
|
; CHECK-NEXT: bl nest_receiver
|
|
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
|
|
; CHECK-NEXT: ret
|
|
|
|
%result = call ptr @nest_receiver(ptr nest %arg)
|
|
ret ptr %result
|
|
}
|