[llvm] [RISC-V] Only emit multiples of 16 as immediate for cm.push (PR #84935)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 28 00:57:47 PDT 2024


================
@@ -555,9 +555,9 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
       FirstFrameSetup->getOpcode() == RISCV::CM_PUSH) {
     // Use available stack adjustment in push instruction to allocate additional
     // stack space.
-    uint64_t Spimm = std::min(StackSize, (uint64_t)48);
+    uint64_t Spimm = alignTo(std::min(StackSize, (uint64_t)48), 16);
     FirstFrameSetup->getOperand(1).setImm(Spimm);
-    StackSize -= Spimm;
+    StackSize -= std::min(StackSize, Spimm);
----------------
jupiter-zzp wrote:

We can move the sp by more than StackSize here, and if it does, the stack pointer will be readjusted in the following if statement where `StackSize != 0`.

https://github.com/llvm/llvm-project/pull/84935


More information about the llvm-commits mailing list