[PATCH] D21321: [mips] Optimize stack pointer adjustments.

Simon Dardis via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 05:21:48 PDT 2016

sdardis added inline comments.

Comment at: lib/Target/Mips/MipsSEInstrInfo.cpp:469-470
@@ -461,3 +468,4 @@
+    }
     unsigned Reg = loadImmediate(Amount, MBB, I, DL, nullptr);
-    BuildMI(MBB, I, DL, get(ADDu), SP).addReg(SP).addReg(Reg, RegState::Kill);
+    BuildMI(MBB, I, DL, get(Opc), SP).addReg(SP).addReg(Reg, RegState::Kill);
dsanders wrote:
> These suggestions are for another patch but just to mention them:
> * MIPS32R6/MIPS64R6 can add the immediate without materializing it first using AUI/DAUI/DATI/DAHI.
> * MIPS32R5/MIPS64R5 with MSA, and MIPS32R6/MIPS64R6 can improve on this using LSA/DLSA to add 17-20 bit immediates in two instructions instead of three as long as the amount is appropriately aligned (which is always true for 17-19 bit, and true on N32/N64 for 20-bit).
I hadn't thought about using (d)lsa to synthesize constants, but that's changes to MipsAnalyzeImmediate. This patch is to make a relatively tiny change to avoid some bad cases.

I'll look at R6ifying the return sequence after R6ifying constant synthesis.  

Comment at: test/CodeGen/Mips/cstmaterialization/stack.ll:29-31
@@ +28,5 @@
+; These are here to match other lui's used in offset computations and they're
+; also duplicated.
dsanders wrote:
> Can you clarify what needs fixing here? Is it just the duplication or is there something else?
For mips64 we repeatedly synthesize a large offset of the current stack pointer:

  lui   $5, 16
  daddu $5, $sp, $5
  sd    $ra, 24($5)             # 8-byte Folded Spill
  lui   $ra, 16
  daddu $ra, $sp, $ra
  sd    $gp, 16($ra)            # 8-byte Folded Spill

The second spill could have re-used $5 with the offset of 16. This also occurs when those values are reloaded. Turns out I missed one of them.


More information about the llvm-commits mailing list