Index: lib/Target/Mips/MipsISelLowering.h =================================================================== --- lib/Target/Mips/MipsISelLowering.h +++ lib/Target/Mips/MipsISelLowering.h @@ -370,6 +370,8 @@ bool isJumpTableRelative() const override { return getTargetMachine().isPositionIndependent(); } + + void finalizeLowering(MachineFunction &MF) const override; protected: SDValue getGlobalReg(SelectionDAG &DAG, EVT Ty) const; Index: lib/Target/Mips/MipsISelLowering.cpp =================================================================== --- lib/Target/Mips/MipsISelLowering.cpp +++ lib/Target/Mips/MipsISelLowering.cpp @@ -108,6 +108,11 @@ return true; } +void MipsTargetLowering::finalizeLowering(MachineFunction &MF) const { + MF.getFrameInfo().computeMaxCallFrameSize(MF); + TargetLoweringBase::finalizeLowering(MF); +} + // The MIPS MSA ABI passes vector arguments in the integer register set. // The number of integer registers used is dependant on the ABI used. MVT MipsTargetLowering::getRegisterTypeForCallingConv(MVT VT) const { Index: lib/Target/Mips/MipsRegisterInfo.cpp =================================================================== --- lib/Target/Mips/MipsRegisterInfo.cpp +++ lib/Target/Mips/MipsRegisterInfo.cpp @@ -74,7 +74,9 @@ case Mips::GPR64RegClassID: case Mips::DSPRRegClassID: { const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); - return 28 - TFI->hasFP(MF); + bool HasFP = MF.getFrameInfo().isMaxCallFrameSizeComputed() + ? TFI->hasFP(MF) : true; + return 28 - HasFP; } case Mips::FGR32RegClassID: return 32; Index: test/CodeGen/Mips/maxcallframesize.ll =================================================================== --- test/CodeGen/Mips/maxcallframesize.ll +++ test/CodeGen/Mips/maxcallframesize.ll @@ -0,0 +1,17 @@ +; RUN: llc < %s -mtriple=mips-unknown-linux -stop-before=prologepilog | FileCheck %s + +; Test that maxCallFrameSize is being computed early on. + +@glob = external global i32* + +declare void @bar(i32*, [20000 x i8]* byval) + +define void @foo([20000 x i8]* %addr) { + %tmp = alloca [4 x i32], align 32 + %tmp0 = getelementptr [4 x i32], [4 x i32]* %tmp, i32 0, i32 0 + call void @bar(i32* %tmp0, [20000 x i8]* byval %addr) + ret void +} + +; CHECK: adjustsStack: true +; CHECK: maxCallFrameSize: 20008