Skip to content

Commit 6af39d9

Browse files
authored
[RISCV][NFC] Simplify the sp-offset reduction by spimm of CM.PUSH/POP. (#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 5445359 commit 6af39d9

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
@@ -276,16 +276,6 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
276276
return MaxPushPopReg;
277277
}
278278

279-
static uint64_t adjSPInPushPop(MachineBasicBlock::iterator MBBI,
280-
unsigned RequiredStack, unsigned FreePushStack,
281-
bool IsPop) {
282-
if (FreePushStack > RequiredStack)
283-
RequiredStack = 0;
284-
unsigned Spimm = std::min(RequiredStack, 48u);
285-
MBBI->getOperand(1).setImm(Spimm);
286-
return alignTo(RequiredStack - Spimm, 16);
287-
}
288-
289279
// Return true if the specified function should have a dedicated frame
290280
// pointer register. This is true if frame pointer elimination is
291281
// disabled, if it needs dynamic stack realignment, if the function has
@@ -539,10 +529,9 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
539529
if (RVFI->isPushable(MF) && FirstFrameSetup->getOpcode() == RISCV::CM_PUSH) {
540530
// Use available stack adjustment in push instruction to allocate additional
541531
// stack space.
542-
unsigned PushStack = RVFI->getRVPushRegs() * (STI.getXLen() / 8);
543-
unsigned SpImmBase = RVFI->getRVPushStackSize();
544-
StackSize = adjSPInPushPop(FirstFrameSetup, StackSize,
545-
(SpImmBase - PushStack), true);
532+
uint64_t Spimm = std::min(StackSize, (uint64_t)48);
533+
FirstFrameSetup->getOperand(1).setImm(Spimm);
534+
StackSize -= Spimm;
546535
}
547536

548537
if (StackSize != 0) {
@@ -777,9 +766,9 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
777766
MBBI->getOpcode() == RISCV::CM_POP) {
778767
// Use available stack adjustment in pop instruction to deallocate stack
779768
// space.
780-
unsigned PushStack = RVFI->getRVPushRegs() * (STI.getXLen() / 8);
781-
unsigned SpImmBase = RVFI->getRVPushStackSize();
782-
StackSize = adjSPInPushPop(MBBI, StackSize, (SpImmBase - PushStack), true);
769+
uint64_t Spimm = std::min(StackSize, (uint64_t)48);
770+
MBBI->getOperand(1).setImm(Spimm);
771+
StackSize -= Spimm;
783772
}
784773

785774
// Deallocate stack

0 commit comments

Comments
 (0)