summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-05-28 01:14:11 +0000
committerDan Gohman <gohman@apple.com>2010-05-28 01:14:11 +0000
commitf75a7d3fbf7fbb3071f45e248d3fb93312ec4fbd (patch)
tree8de936a75e71c78268a937ba4aecddde53052446
parent5ddb087f7fea1c4898d233a6cad6589d6f0a0b11 (diff)
downloadllvm-f75a7d3fbf7fbb3071f45e248d3fb93312ec4fbd.tar.gz
llvm-f75a7d3fbf7fbb3071f45e248d3fb93312ec4fbd.tar.bz2
llvm-f75a7d3fbf7fbb3071f45e248d3fb93312ec4fbd.tar.xz
Eliminate the restriction that the array size in an alloca must be i32.
This will help reduce the amount of casting required on 64-bit targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104911 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/LangRef.html2
-rw-r--r--lib/AsmParser/LLParser.cpp6
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp11
-rw-r--r--lib/VMCore/Instructions.cpp4
-rw-r--r--lib/VMCore/Verifier.cpp4
-rw-r--r--test/CodeGen/X86/alloca-align-rounding-32.ll15
-rw-r--r--test/CodeGen/X86/alloca-align-rounding.ll9
7 files changed, 34 insertions, 17 deletions
diff --git a/docs/LangRef.html b/docs/LangRef.html
index 4b1919adf0..bfb4256973 100644
--- a/docs/LangRef.html
+++ b/docs/LangRef.html
@@ -4239,7 +4239,7 @@ Instruction</a> </div>
<h5>Syntax:</h5>
<pre>
- &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
+ &lt;result&gt; = alloca &lt;type&gt;[, &lt;ty&gt; &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
</pre>
<h5>Overview:</h5>
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 226d8d3272..1cd66e536e 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -3791,8 +3791,8 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
}
}
- if (Size && !Size->getType()->isIntegerTy(32))
- return Error(SizeLoc, "element count must be i32");
+ if (Size && !Size->getType()->isIntegerTy())
+ return Error(SizeLoc, "element count must have integer type");
if (isAlloca) {
Inst = new AllocaInst(Ty, Size, Alignment);
@@ -3801,6 +3801,8 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
// Autoupgrade old malloc instruction to malloc call.
// FIXME: Remove in LLVM 3.0.
+ if (Size && !Size->getType()->isIntegerTy(32))
+ return Error(SizeLoc, "element count must be i32");
const Type *IntPtrTy = Type::getInt32Ty(Context);
Constant *AllocSize = ConstantExpr::getSizeOf(Ty);
AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, IntPtrTy);
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index fbe601f2db..90ad7f71f7 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2643,12 +2643,13 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
SDValue AllocSize = getValue(I.getArraySize());
- AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), AllocSize.getValueType(),
- AllocSize,
- DAG.getConstant(TySize, AllocSize.getValueType()));
-
EVT IntPtr = TLI.getPointerTy();
- AllocSize = DAG.getZExtOrTrunc(AllocSize, getCurDebugLoc(), IntPtr);
+ if (AllocSize.getValueType() != IntPtr)
+ AllocSize = DAG.getZExtOrTrunc(AllocSize, getCurDebugLoc(), IntPtr);
+
+ AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), IntPtr,
+ AllocSize,
+ DAG.getConstant(TySize, IntPtr));
// Handle alignment. If the requested alignment is less than or equal to
// the stack alignment, ignore it. If the size is greater than or equal to
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index f64b220c3f..3060a7601d 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -828,8 +828,8 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
else {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
- assert(Amt->getType()->isIntegerTy(32) &&
- "Allocation array size is not a 32-bit integer!");
+ assert(Amt->getType()->isIntegerTy() &&
+ "Allocation array size is not an integer!");
}
return Amt;
}
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 75988cca72..4ff03dbe9f 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -1371,8 +1371,8 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
&AI);
Assert1(PTy->getElementType()->isSized(), "Cannot allocate unsized type",
&AI);
- Assert1(AI.getArraySize()->getType()->isIntegerTy(32),
- "Alloca array size must be i32", &AI);
+ Assert1(AI.getArraySize()->getType()->isIntegerTy(),
+ "Alloca array size must have integer type", &AI);
visitInstruction(AI);
}
diff --git a/test/CodeGen/X86/alloca-align-rounding-32.ll b/test/CodeGen/X86/alloca-align-rounding-32.ll
new file mode 100644
index 0000000000..c0f1a18123
--- /dev/null
+++ b/test/CodeGen/X86/alloca-align-rounding-32.ll
@@ -0,0 +1,15 @@
+; RUN: llc < %s -march=x86 -mtriple=i686-apple-darwin | grep and | count 1
+
+declare void @bar(<2 x i64>* %n)
+
+define void @foo(i32 %h) {
+ %p = alloca <2 x i64>, i32 %h
+ call void @bar(<2 x i64>* %p)
+ ret void
+}
+
+define void @foo2(i32 %h) {
+ %p = alloca <2 x i64>, i32 %h, align 32
+ call void @bar(<2 x i64>* %p)
+ ret void
+}
diff --git a/test/CodeGen/X86/alloca-align-rounding.ll b/test/CodeGen/X86/alloca-align-rounding.ll
index f45e9b84b2..3c87dbf2bd 100644
--- a/test/CodeGen/X86/alloca-align-rounding.ll
+++ b/test/CodeGen/X86/alloca-align-rounding.ll
@@ -1,16 +1,15 @@
-; RUN: llc < %s -march=x86 -mtriple=i686-apple-darwin | grep and | count 1
; RUN: llc < %s -march=x86-64 -mtriple=i686-pc-linux | grep and | count 1
declare void @bar(<2 x i64>* %n)
-define void @foo(i32 %h) {
- %p = alloca <2 x i64>, i32 %h
+define void @foo(i64 %h) {
+ %p = alloca <2 x i64>, i64 %h
call void @bar(<2 x i64>* %p)
ret void
}
-define void @foo2(i32 %h) {
- %p = alloca <2 x i64>, i32 %h, align 32
+define void @foo2(i64 %h) {
+ %p = alloca <2 x i64>, i64 %h, align 32
call void @bar(<2 x i64>* %p)
ret void
}