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

Vasileios Kalintiris Vasileios.Kalintiris at imgtec.com
Thu Apr 2 03:14:54 PDT 2015


Author: vkalintiris
Date: Thu Apr  2 05:14:54 2015
New Revision: 233904

URL: http://llvm.org/viewvc/llvm-project?rev=233904&view=rev
Log:
[mips] Make sure that we don't adjust the stack pointer by zero amount.

Reviewers: dsanders

Reviewed By: dsanders

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D8638

Added:
    llvm/trunk/test/CodeGen/Mips/adjust-callstack-sp.ll
Modified:
    llvm/trunk/lib/Target/Mips/Mips16InstrInfo.cpp
    llvm/trunk/lib/Target/Mips/MipsSEInstrInfo.cpp

Modified: llvm/trunk/lib/Target/Mips/Mips16InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Mips16InstrInfo.cpp?rev=233904&r1=233903&r2=233904&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/Mips16InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/Mips16InstrInfo.cpp Thu Apr  2 05:14:54 2015
@@ -293,6 +293,9 @@ void Mips16InstrInfo::adjustStackPtrBigU
 void Mips16InstrInfo::adjustStackPtr(unsigned SP, int64_t Amount,
                                      MachineBasicBlock &MBB,
                                      MachineBasicBlock::iterator I) const {
+  if (Amount == 0)
+    return;
+
   if (isInt<16>(Amount))  // need to change to addiu sp, ....and isInt<16>
     BuildAddiuSpImm(MBB, I, Amount);
   else

Modified: llvm/trunk/lib/Target/Mips/MipsSEInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsSEInstrInfo.cpp?rev=233904&r1=233903&r2=233904&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsSEInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsSEInstrInfo.cpp Thu Apr  2 05:14:54 2015
@@ -364,6 +364,9 @@ void MipsSEInstrInfo::adjustStackPtr(uns
   unsigned ADDu = STI.isABI_N64() ? Mips::DADDu : Mips::ADDu;
   unsigned ADDiu = STI.isABI_N64() ? Mips::DADDiu : Mips::ADDiu;
 
+  if (Amount == 0)
+    return;
+
   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.

Added: llvm/trunk/test/CodeGen/Mips/adjust-callstack-sp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/adjust-callstack-sp.ll?rev=233904&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/adjust-callstack-sp.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/adjust-callstack-sp.ll Thu Apr  2 05:14:54 2015
@@ -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
+}





More information about the llvm-commits mailing list