Index: llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -40,6 +40,14 @@ AArch64_MC::initLLVMToCVRegMapping(this); } +static bool hasSVEArgsorReturn(const MachineFunction *MF) { + const Function &F = MF->getFunction(); + return isa(F.getReturnType()) || + any_of(F.args(), [](const Argument &Arg) { + return isa(Arg.getType()); + }); +} + const MCPhysReg * AArch64RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { assert(MF && "Invalid MachineFunction pointer."); @@ -75,6 +83,8 @@ // This is for OSes other than Windows; Windows is a separate case further // above. return CSR_AArch64_AAPCS_X18_SaveList; + if (hasSVEArgsorReturn(MF)) + return CSR_AArch64_SVE_AAPCS_SaveList; return CSR_AArch64_AAPCS_SaveList; } Index: llvm/test/CodeGen/AArch64/sve-calling-convention.ll =================================================================== --- llvm/test/CodeGen/AArch64/sve-calling-convention.ll +++ llvm/test/CodeGen/AArch64/sve-calling-convention.ll @@ -1,4 +1,5 @@ ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -stop-after=finalize-isel < %s 2>%t | FileCheck %s +; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -stop-after=prologepilog < %s 2>%t | FileCheck %s --check-prefix=CHECKCSR ; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t ; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it. @@ -123,3 +124,25 @@ %res = call @sve_signature_pred( %arg2, %arg1) ret %res } + +; Test that functions returning or taking SVE arguments use the correct +; callee-saved set when using the default C calling convention (as opposed +; to aarch64_sve_vector_pcs) + +; CHECKCSR-LABEL: name: sve_signature_vec_ret_callee +; CHECKCSR: callee-saved-register: '$z8' +; CHECKCSR: callee-saved-register: '$p4' +; CHECKCSR: RET_ReallyLR +define @sve_signature_vec_ret_callee() nounwind { + call void asm sideeffect "nop", "~{z8},~{p4}"() + ret zeroinitializer +} + +; CHECKCSR-LABEL: name: sve_signature_vec_arg_callee +; CHECKCSR: callee-saved-register: '$z8' +; CHECKCSR: callee-saved-register: '$p4' +; CHECKCSR: RET_ReallyLR +define void @sve_signature_vec_arg_callee( %v) nounwind { + call void asm sideeffect "nop", "~{z8},~{p4}"() + ret void +}