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

Nemanja Ivanovic via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 03:33:29 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);
----------------
nemanjai wrote:

Well, if the amount of space in the offset for the `cm.push` is more than the additional stack space required, then yes we could. I don't follow why this is a problem though. Or maybe I am misunderstanding what the `StackSize` variable actually represents - the way I have interpreted it is "The amount of stack space required for parameters and local objects (not including the space to spill CSR's)". Of course, if my interpretation is correct, I'd certainly make the argument that the variable is poorly named, but hey.

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


More information about the llvm-commits mailing list