[PATCH] [mips] Make sure that we don't adjust the stack pointer by zero amount.

Vasileios Kalintiris Vasileios.Kalintiris at imgtec.com
Thu Mar 26 10:09:36 PDT 2015


Hi dsanders,

http://reviews.llvm.org/D8638

Files:
  lib/Target/Mips/Mips16FrameLowering.cpp
  lib/Target/Mips/MipsSEFrameLowering.cpp
  lib/Target/Mips/MipsSEInstrInfo.cpp
  test/CodeGen/Mips/adjust-callstack-sp.ll

Index: lib/Target/Mips/Mips16FrameLowering.cpp
===================================================================
--- lib/Target/Mips/Mips16FrameLowering.cpp
+++ lib/Target/Mips/Mips16FrameLowering.cpp
@@ -147,16 +147,17 @@
 void Mips16FrameLowering::
 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
                               MachineBasicBlock::iterator I) const {
+  const Mips16InstrInfo &TII =
+    *static_cast<const Mips16InstrInfo *>(STI.getInstrInfo());
+
   if (!hasReservedCallFrame(MF)) {
     int64_t Amount = I->getOperand(0).getImm();
+    if (Amount) {
+      if (I->getOpcode() == Mips::ADJCALLSTACKDOWN)
+        Amount = -Amount;
 
-    if (I->getOpcode() == Mips::ADJCALLSTACKDOWN)
-      Amount = -Amount;
-
-    const Mips16InstrInfo &TII =
-        *static_cast<const Mips16InstrInfo *>(STI.getInstrInfo());
-
-    TII.adjustStackPtr(Mips::SP, Amount, MBB, I);
+      TII.adjustStackPtr(Mips::SP, Amount, MBB, I);
+    }
   }
 
   MBB.erase(I);
Index: lib/Target/Mips/MipsSEFrameLowering.cpp
===================================================================
--- lib/Target/Mips/MipsSEFrameLowering.cpp
+++ lib/Target/Mips/MipsSEFrameLowering.cpp
@@ -616,12 +616,13 @@
 
   if (!hasReservedCallFrame(MF)) {
     int64_t Amount = I->getOperand(0).getImm();
+    if (Amount) {
+      if (I->getOpcode() == Mips::ADJCALLSTACKDOWN)
+        Amount = -Amount;
 
-    if (I->getOpcode() == Mips::ADJCALLSTACKDOWN)
-      Amount = -Amount;
-
-    unsigned SP = STI.isABI_N64() ? Mips::SP_64 : Mips::SP;
-    TII.adjustStackPtr(SP, Amount, MBB, I);
+      unsigned SP = STI.isABI_N64() ? Mips::SP_64 : Mips::SP;
+      TII.adjustStackPtr(SP, Amount, MBB, I);
+    }
   }
 
   MBB.erase(I);
Index: lib/Target/Mips/MipsSEInstrInfo.cpp
===================================================================
--- lib/Target/Mips/MipsSEInstrInfo.cpp
+++ lib/Target/Mips/MipsSEInstrInfo.cpp
@@ -364,6 +364,8 @@
   unsigned ADDu = STI.isABI_N64() ? Mips::DADDu : Mips::ADDu;
   unsigned ADDiu = STI.isABI_N64() ? Mips::DADDiu : Mips::ADDiu;
 
+  assert(Amount && "Request to adjust stack pointer by zero amount.");
+
   if (isInt<16>(Amount))// addi sp, sp, amount
     BuildMI(MBB, I, DL, get(ADDiu), SP).addReg(SP).addImm(Amount);
   else { // Expand immediate that doesn't fit in 16-bit.
Index: test/CodeGen/Mips/adjust-callstack-sp.ll
===================================================================
--- /dev/null
+++ test/CodeGen/Mips/adjust-callstack-sp.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s -march=mips -mcpu=mips16 | FileCheck %s -check-prefix=M16
+; RUN: llc < %s -march=mips -mcpu=mips2 | FileCheck %s -check-prefix=GP32
+; RUN: llc < %s -march=mips -mcpu=mips32 | FileCheck %s -check-prefix=GP32
+; RUN: llc < %s -march=mips -mcpu=mips32r6 | FileCheck %s -check-prefix=GP32
+; RUN: llc < %s -march=mips -mcpu=mips3 | FileCheck %s -check-prefix=GP64
+; RUN: llc < %s -march=mips -mcpu=mips64 | FileCheck %s -check-prefix=GP64
+; RUN: llc < %s -march=mips -mcpu=mips64r6 | FileCheck %s -check-prefix=GP64
+
+declare void @bar(i32*)
+
+define void @foo(i32 %sz) {
+  ; ALL-LABEL: foo:
+
+    ; M16-NOT:        addiu     $sp, 0 # 16 bit inst
+    ; GP32-NOT:       addiu     $sp, $sp, 0
+    ; GP64-NOT:       daddiu    $sp, $sp, 0
+  %a = alloca i32, i32 %sz
+  call void @bar(i32* %a)
+  ret void
+}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8638.22733.patch
Type: text/x-patch
Size: 3348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150326/fefd45a0/attachment.bin>


More information about the llvm-commits mailing list