diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp index cd532671f50189..cf617c7e92a70a 100644 --- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp @@ -431,8 +431,16 @@ bool AArch64FrameLowering::canUseRedZone(const MachineFunction &MF) const { const AArch64FunctionInfo *AFI = MF.getInfo(); uint64_t NumBytes = AFI->getLocalStackSize(); + // If neither NEON or SVE are available, a COPY from one Q-reg to + // another requires a spill -> reload sequence. We can do that + // using a pre-decrementing store/post-decrementing load, but + // if we do so, we can't use the Red Zone. + bool LowerQRegCopyThroughMem = Subtarget.hasFPARMv8() && + !Subtarget.isNeonAvailable() && + !Subtarget.hasSVE(); + return !(MFI.hasCalls() || hasFP(MF) || NumBytes > RedZoneSize || - getSVEStackSize(MF)); + getSVEStackSize(MF) || LowerQRegCopyThroughMem); } /// hasFP - Return true if the specified function should have a dedicated frame diff --git a/llvm/test/CodeGen/AArch64/arm64-redzone.ll b/llvm/test/CodeGen/AArch64/arm64-redzone.ll index fe30a1a98521e1..d001bc2a8dbe4e 100644 --- a/llvm/test/CodeGen/AArch64/arm64-redzone.ll +++ b/llvm/test/CodeGen/AArch64/arm64-redzone.ll @@ -16,3 +16,16 @@ define i32 @foo(i32 %a, i32 %b) nounwind ssp { %tmp2 = load i32, ptr %x, align 4 ret i32 %tmp2 } + +; We disable red-zone if NEON is available because copies of Q-regs +; require a spill/fill and dynamic allocation. But we only need to do +; this when FP registers are enabled. +define void @bar(fp128 %f) "target-features"="-fp-armv8" { +; CHECK-LABEL: bar: +; CHECK: // %bb.0: +; CHECK-NEXT: stp x0, x1, [sp, #-16] +; CHECK-NEXT: ret + %ptr = alloca fp128 + store fp128 %f, ptr %ptr + ret void +}