diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -5997,21 +5997,6 @@ } -/// Returns true if the Function has ZA state and contains at least one call to -/// a function that requires setting up a lazy-save buffer. -static bool requiresBufferForLazySave(const Function &F) { - SMEAttrs CallerAttrs(F); - if (!CallerAttrs.hasZAState()) - return false; - - for (const BasicBlock &BB : F) - for (const Instruction &I : BB) - if (const CallInst *Call = dyn_cast(&I)) - if (CallerAttrs.requiresLazySave(SMEAttrs(*Call))) - return true; - return false; -} - int AArch64TargetLowering::allocateLazySaveBuffer(SDValue &Chain, const SDLoc &DL, SelectionDAG &DAG) const { @@ -6427,8 +6412,8 @@ if (Subtarget->hasCustomCallingConv()) Subtarget->getRegisterInfo()->UpdateCustomCalleeSavedRegs(MF); - if (requiresBufferForLazySave(MF.getFunction())) { - // Set up a buffer once and store the buffer in the MachineFunctionInfo. + // Conservatively assume that the function may require the lazy-save mechanism. + if (SMEAttrs(MF.getFunction()).hasZAState()) { int TPIDR2Obj = allocateLazySaveBuffer(Chain, DL, DAG); FuncInfo->setLazySaveTPIDR2Obj(TPIDR2Obj); } @@ -7025,9 +7010,6 @@ SDValue NN = DAG.getNode(ISD::MUL, DL, MVT::i64, N, N); int TPIDR2Obj = *FuncInfo->getLazySaveTPIDR2Obj(); - if (!TPIDR2Obj) - TPIDR2Obj = allocateLazySaveBuffer(Chain, DL, DAG); - MachinePointerInfo MPI = MachinePointerInfo::getStack(MF, TPIDR2Obj); SDValue TPIDR2ObjAddr = DAG.getFrameIndex(TPIDR2Obj, DAG.getTargetLoweringInfo().getFrameIndexTy(DAG.getDataLayout())); diff --git a/llvm/test/CodeGen/AArch64/sme-disable-gisel-fisel.ll b/llvm/test/CodeGen/AArch64/sme-disable-gisel-fisel.ll --- a/llvm/test/CodeGen/AArch64/sme-disable-gisel-fisel.ll +++ b/llvm/test/CodeGen/AArch64/sme-disable-gisel-fisel.ll @@ -310,12 +310,12 @@ ; CHECK-COMMON-NEXT: sub x9, x9, x8 ; CHECK-COMMON-NEXT: mov sp, x9 ; CHECK-COMMON-NEXT: sub x10, x29, #16 -; CHECK-COMMON-NEXT: sturh w8, [x29, #-8] ; CHECK-COMMON-NEXT: stur x9, [x29, #-16] +; CHECK-COMMON-NEXT: sturh w8, [x29, #-8] ; CHECK-COMMON-NEXT: msr TPIDR2_EL0, x10 ; CHECK-COMMON-NEXT: bl __addtf3 ; CHECK-COMMON-NEXT: smstart za -; CHECK-COMMON-NEXT: add x0, x29, #0 +; CHECK-COMMON-NEXT: sub x0, x29, #16 ; CHECK-COMMON-NEXT: mrs x8, TPIDR2_EL0 ; CHECK-COMMON-NEXT: cbnz x8, .LBB8_2 ; CHECK-COMMON-NEXT: // %bb.1: diff --git a/llvm/test/CodeGen/AArch64/sme-shared-za-interface.ll b/llvm/test/CodeGen/AArch64/sme-shared-za-interface.ll --- a/llvm/test/CodeGen/AArch64/sme-shared-za-interface.ll +++ b/llvm/test/CodeGen/AArch64/sme-shared-za-interface.ll @@ -48,12 +48,12 @@ ; CHECK-NEXT: sub x9, x9, x8 ; CHECK-NEXT: mov sp, x9 ; CHECK-NEXT: sub x10, x29, #16 -; CHECK-NEXT: sturh w8, [x29, #-8] ; CHECK-NEXT: stur x9, [x29, #-16] +; CHECK-NEXT: sturh w8, [x29, #-8] ; CHECK-NEXT: msr TPIDR2_EL0, x10 ; CHECK-NEXT: bl __addtf3 ; CHECK-NEXT: smstart za -; CHECK-NEXT: add x0, x29, #0 +; CHECK-NEXT: sub x0, x29, #16 ; CHECK-NEXT: mrs x8, TPIDR2_EL0 ; CHECK-NEXT: cbnz x8, .LBB1_2 ; CHECK-NEXT: // %bb.1: