Index: lib/Target/Mips/MipsFastISel.cpp =================================================================== --- lib/Target/Mips/MipsFastISel.cpp +++ lib/Target/Mips/MipsFastISel.cpp @@ -186,6 +186,7 @@ UnsupportedFPMode = Subtarget->isFP64bit(); } + unsigned fastMaterializeAlloca(const AllocaInst *AI) override; unsigned fastMaterializeConstant(const Constant *C) override; bool fastSelectInstruction(const Instruction *I) override; @@ -252,6 +253,29 @@ return ResultReg; } +unsigned MipsFastISel::fastMaterializeAlloca(const AllocaInst *AI) { + assert(TLI.getValueType(AI->getType(), true) == MVT::i32 && + "Alloca should always return a pointer."); + + // Don't handle dynamic allocas. + if (!FuncInfo.StaticAllocaMap.count(AI)) + return 0; + + DenseMap::iterator SI = + FuncInfo.StaticAllocaMap.find(AI); + + if (SI != FuncInfo.StaticAllocaMap.end()) { + unsigned ResultReg = createResultReg(&Mips::GPR32RegClass); + BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Mips::LEA_ADDiu), + ResultReg) + .addFrameIndex(SI->second) + .addImm(0); + return ResultReg; + } + + return 0; +} + unsigned MipsFastISel::materializeInt(const Constant *C, MVT VT) { if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1) return 0; Index: test/CodeGen/Mips/Fast-ISel/fastalloca.ll =================================================================== --- /dev/null +++ test/CodeGen/Mips/Fast-ISel/fastalloca.ll @@ -0,0 +1,57 @@ +; RUN: llc -march=mipsel -relocation-model=pic -O0 -mips-fast-isel -fast-isel-abort=1 -mcpu=mips32r2 \ +; RUN: < %s | FileCheck %s + +; ModuleID = 'fooa.c' +target datalayout = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" +target triple = "mipsel--linux-gnu" + +%struct.x = type { i32 } + +@i = common global i32 0, align 4 + +; Function Attrs: nounwind +define i32 @foobar(i32 signext %x) #0 { +entry: +; CHECK-LABEL: foobar: + %retval = alloca i32, align 4 + %x.addr = alloca i32, align 4 + %a = alloca %struct.x, align 4 + %c = alloca %struct.x*, align 4 + store i32 %x, i32* %x.addr, align 4 + %x1 = getelementptr inbounds %struct.x, %struct.x* %a, i32 0, i32 0 + %0 = load i32, i32* %x.addr, align 4 + store i32 %0, i32* %x1, align 4 + store %struct.x* %a, %struct.x** %c, align 4 + %1 = load %struct.x*, %struct.x** %c, align 4 + %x2 = getelementptr inbounds %struct.x, %struct.x* %1, i32 0, i32 0 + %2 = load i32, i32* %x2, align 4 + store i32 %2, i32* @i, align 4 + %3 = load i32, i32* %retval +; CHECK-DAG: lw $[[I_ADDR:[0-9]+]], %got(i)($[[REG_GP:[0-9]+]]) +; CHECK-DAG: addiu $[[A_ADDR:[0-9]+]], $fp, 8 +; CHECK-DAG: sw $[[A_ADDR]], [[A_ADDR_FI:[0-9]+]]($fp) +; CHECK-DAG: lw $[[A_ADDR2:[0-9]+]], [[A_ADDR_FI]]($fp) +; CHECK-DAG: lw $[[A_X:[0-9]+]], 0($[[A_ADDR2]]) +; CHECK-DAG: sw $[[A_X]], 0($[[I_ADDR]]) + ret i32 %3 +} + +; Function Attrs: nounwind +define i32 @main() #0 { +entry: +; CHECK-LABEL: main: + %retval = alloca i32, align 4 + store i32 0, i32* %retval + %call = call i32 @foobar(i32 signext 99) + %0 = load i32, i32* @i, align 4 + %sub = sub nsw i32 99, %0 + ret i32 %sub +} + +attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"PIC Level", i32 2} +!1 = !{!"clang version 3.6.0 (gitosis@dmz-portal.mips.com:clang.git f96fd4c68e89695cc64686bcf0dc768aee4638e5) (gitosis@dmz-portal.mips.com:llvm.git 33df92e7a51bb034540e4de79d2d4cff83439d7b)"}