Index: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVFrameLowering.cpp +++ llvm/lib/Target/RISCV/RISCVFrameLowering.cpp @@ -667,60 +667,38 @@ // If the stack was realigned, the frame pointer is set in order to allow // SP to be restored, so we need another base register to record the stack // after realignment. + // |--------------------------| -- <-- FP + // | callee-allocated save | | <----| + // | area for register varargs| | | + // |--------------------------| | | + // | callee-saved registers | | | + // |--------------------------| -- | + // | realignment (the size of | | | + // | this area is not counted | | | + // | in MFI.getStackSize()) | | | + // |--------------------------| -- | + // | Padding after RVV | | | + // | (not counted in | | | + // | MFI.getStackSize()) | | | + // |--------------------------| -- |-- MFI.getStackSize() + // | RVV objects | | | + // | (not counted in | | | + // | MFI.getStackSize()) | | | + // |--------------------------| -- | + // | Padding before RVV | | | + // | (not counted in | | | + // | MFI.getStackSize()) | | | + // |--------------------------| -- | + // | scalar local variables | | <----' + // |--------------------------| -- <-- BP (if present) + // | VarSize objects | | + // |--------------------------| -- <-- SP if (hasBP(MF)) { FrameReg = RISCVABI::getBPReg(); - // |--------------------------| -- <-- FP - // | callee-allocated save | | <----| - // | area for register varargs| | | - // |--------------------------| | | - // | callee-saved registers | | | - // |--------------------------| -- | - // | realignment (the size of | | | - // | this area is not counted | | | - // | in MFI.getStackSize()) | | | - // |--------------------------| -- | - // | Padding after RVV | | | - // | (not counted in | | | - // | MFI.getStackSize()) | | | - // |--------------------------| -- |-- MFI.getStackSize() - // | RVV objects | | | - // | (not counted in | | | - // | MFI.getStackSize()) | | | - // |--------------------------| -- | - // | Padding before RVV | | | - // | (not counted in | | | - // | MFI.getStackSize()) | | | - // |--------------------------| -- | - // | scalar local variables | | <----' - // |--------------------------| -- <-- BP - // | VarSize objects | | - // |--------------------------| -- <-- SP } else { + // VarSize objects must be empty in this case! + assert(!MFI.hasVarSizedObjects()); FrameReg = RISCV::X2; - // |--------------------------| -- <-- FP - // | callee-allocated save | | <----| - // | area for register varargs| | | - // |--------------------------| | | - // | callee-saved registers | | | - // |--------------------------| -- | - // | realignment (the size of | | | - // | this area is not counted | | | - // | in MFI.getStackSize()) | | | - // |--------------------------| -- | - // | Padding after RVV | | | - // | (not counted in | | | - // | MFI.getStackSize()) | | | - // |--------------------------| -- |-- MFI.getStackSize() - // | RVV objects | | | - // | (not counted in | | | - // | MFI.getStackSize()) | | | - // |--------------------------| -- | - // | Padding before RVV | | | - // | (not counted in | | | - // | MFI.getStackSize()) | | | - // |--------------------------| -- | - // | scalar local variables | | <----' - // |--------------------------| -- <-- SP } // The total amount of padding surrounding RVV objects is described by // RVV->getRVVPadding() and it can be zero. It allows us to align the RVV @@ -737,6 +715,7 @@ } else { FrameReg = RI->getFrameRegister(MF); if (hasFP(MF)) { + assert(FrameReg == RISCV::X8 && "Frame register not FP"); Offset += StackOffset::getFixed(RVFI->getVarArgsSaveSize()); if (FI >= 0) Offset -= StackOffset::getFixed(RVFI->getLibCallStackSize()); @@ -758,6 +737,7 @@ if (MFI.getStackID(FI) == TargetStackID::ScalableVector) Offset -= StackOffset::getFixed(MFI.getStackSize()); } else { + assert(FrameReg == RISCV::X2 && "Frame register not SP"); // When using SP to access frame objects, we need to add RVV stack size. // // |--------------------------| -- <-- FP