Skip to content

Commit aeec8de

Browse files
yetingkKaiYG
authored andcommitted
[RISCV][NFC] Simplify the sp-offset reduction by spimm of CM.PUSH/POP. (llvm#66667)
When inserting prolgue/epilogue, we use the spimm of CM.PUSH/POP to reduce the following offset for sp. Previously, we tried to use the free space of the push stack to minimize the following sp-offset. But it's useless, since the free space must be less than 16 and required stack should be aligned to 16 before/after the adjustment.
1 parent b0709d0 commit aeec8de

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,6 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
304304
return MaxPushPopReg;
305305
}
306306

307-
static uint64_t adjSPInPushPop(MachineBasicBlock::iterator MBBI,
308-
unsigned RequiredStack, unsigned FreePushStack,
309-
bool IsPop) {
310-
if (FreePushStack > RequiredStack)
311-
RequiredStack = 0;
312-
unsigned Spimm = std::min(RequiredStack, 48u);
313-
MBBI->getOperand(1).setImm(Spimm);
314-
return alignTo(RequiredStack - Spimm, 16);
315-
}
316-
317307
// Return true if the specified function should have a dedicated frame
318308
// pointer register. This is true if frame pointer elimination is
319309
// disabled, if it needs dynamic stack realignment, if the function has
@@ -617,10 +607,9 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
617607
FirstFrameSetup->getOpcode() == RISCV::CM_PUSH) {
618608
// Use available stack adjustment in push instruction to allocate additional
619609
// stack space.
620-
unsigned PushStack = RVFI->getRVPushRegs() * (STI.getXLen() / 8);
621-
unsigned SpImmBase = RVFI->getRVPushStackSize();
622-
StackSize = adjSPInPushPop(FirstFrameSetup, StackSize,
623-
(SpImmBase - PushStack), true);
610+
uint64_t Spimm = std::min(StackSize, (uint64_t)48);
611+
FirstFrameSetup->getOperand(1).setImm(Spimm);
612+
StackSize -= Spimm;
624613
}
625614

626615
if (StackSize != 0) {
@@ -847,9 +836,9 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
847836
MBBI->getOpcode() == RISCV::CM_POP) {
848837
// Use available stack adjustment in pop instruction to deallocate stack
849838
// space.
850-
unsigned PushStack = RVFI->getRVPushRegs() * (STI.getXLen() / 8);
851-
unsigned SpImmBase = RVFI->getRVPushStackSize();
852-
StackSize = adjSPInPushPop(MBBI, StackSize, (SpImmBase - PushStack), true);
839+
uint64_t Spimm = std::min(StackSize, (uint64_t)48);
840+
MBBI->getOperand(1).setImm(Spimm);
841+
StackSize -= Spimm;
853842
}
854843

855844
// Deallocate stack

0 commit comments

Comments
 (0)