[llvm-commits] [llvm] r132030 - in /llvm/trunk: lib/Target/Mips/MipsISelLowering.cpp test/CodeGen/Mips/alloca.ll
Akira Hatanaka
ahatanak at gmail.com
Tue May 24 19:20:00 PDT 2011
Author: ahatanak
Date: Tue May 24 21:20:00 2011
New Revision: 132030
URL: http://llvm.org/viewvc/llvm-project?rev=132030&view=rev
Log:
Fix lowering of DYNAMIC_STACKALLOC nodes.
Added:
llvm/trunk/test/CodeGen/Mips/alloca.ll
Modified:
llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
Modified: llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=132030&r1=132029&r2=132030&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp Tue May 24 21:20:00 2011
@@ -692,6 +692,13 @@
SDValue MipsTargetLowering::
LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
{
+ unsigned StackAlignment =
+ getTargetMachine().getFrameLowering()->getStackAlignment();
+ assert(StackAlignment >=
+ cast<ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue() &&
+ "Cannot lower if the alignment of the allocated space is larger than \
+ that of the stack.");
+
SDValue Chain = Op.getOperand(0);
SDValue Size = Op.getOperand(1);
DebugLoc dl = Op.getDebugLoc();
@@ -705,11 +712,22 @@
// The Sub result contains the new stack start address, so it
// must be placed in the stack pointer register.
- Chain = DAG.getCopyToReg(StackPointer.getValue(1), dl, Mips::SP, Sub);
+ Chain = DAG.getCopyToReg(StackPointer.getValue(1), dl, Mips::SP, Sub,
+ SDValue());
+ SDValue NewSP = DAG.getCopyFromReg(Chain, dl, Mips::SP, MVT::i32,
+ Chain.getValue(1));
+
+ // Align the allocated space.
+ MachineFunction &MF = DAG.getMachineFunction();
+ MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
+ unsigned SPOffset = (MipsFI->getMaxCallFrameSize() + StackAlignment - 1) /
+ StackAlignment * StackAlignment;
+ SDValue AllocPtr = DAG.getNode(ISD::ADD, dl, MVT::i32, NewSP,
+ DAG.getConstant(SPOffset, MVT::i32));
// This node always has two return values: a new stack pointer
// value and a chain
- SDValue Ops[2] = { Sub, Chain };
+ SDValue Ops[2] = { AllocPtr, NewSP.getValue(1) };
return DAG.getMergeValues(Ops, 2, dl);
}
Added: llvm/trunk/test/CodeGen/Mips/alloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/alloca.ll?rev=132030&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/alloca.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/alloca.ll Tue May 24 21:20:00 2011
@@ -0,0 +1,31 @@
+; RUN: llc -march=mipsel -mcpu=4ke < %s | FileCheck %s
+
+define i32 @twoalloca(i32 %size) nounwind {
+entry:
+; CHECK: subu $[[T0:[0-9]+]], $sp, $[[SZ:[0-9]+]]
+; CHECK: addu $sp, $zero, $[[T0]]
+; CHECK: addu $[[SP1:[0-9]+]], $zero, $sp
+; CHECK: subu $[[T1:[0-9]+]], $sp, $[[SZ]]
+; CHECK: addu $sp, $zero, $[[T1]]
+; CHECK: addu $[[SP2:[0-9]+]], $zero, $sp
+; CHECK: lw $25, %call16(foo)($gp)
+; CHECK: addiu $4, $[[SP1]], 24
+; CHECK: jalr $25
+; CHECK: lw $25, %call16(foo)($gp)
+; CHECK: addiu $4, $[[SP2]], 24
+; CHECK: jalr $25
+ %tmp1 = alloca i8, i32 %size, align 4
+ %add.ptr = getelementptr inbounds i8* %tmp1, i32 5
+ store i8 97, i8* %add.ptr, align 1
+ %tmp4 = alloca i8, i32 %size, align 4
+ call void @foo2(double 1.000000e+00, double 2.000000e+00, i32 3) nounwind
+ %call = call i32 @foo(i8* %tmp1) nounwind
+ %call7 = call i32 @foo(i8* %tmp4) nounwind
+ %add = add nsw i32 %call7, %call
+ ret i32 %add
+}
+
+declare void @foo2(double, double, i32)
+
+declare i32 @foo(i8*)
+
More information about the llvm-commits
mailing list