[llvm-commits] [llvm] r104911 - in /llvm/trunk: docs/LangRef.html lib/AsmParser/LLParser.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/VMCore/Instructions.cpp lib/VMCore/Verifier.cpp test/CodeGen/X86/alloca-align-rounding-32.ll test/CodeGen/X86/alloca-align-rounding.ll

Dan Gohman gohman at apple.com
Thu May 27 18:14:11 PDT 2010


Author: djg
Date: Thu May 27 20:14:11 2010
New Revision: 104911

URL: http://llvm.org/viewvc/llvm-project?rev=104911&view=rev
Log:
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.

Added:
    llvm/trunk/test/CodeGen/X86/alloca-align-rounding-32.ll
      - copied, changed from r104897, llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll
Modified:
    llvm/trunk/docs/LangRef.html
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/VMCore/Instructions.cpp
    llvm/trunk/lib/VMCore/Verifier.cpp
    llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll

Modified: llvm/trunk/docs/LangRef.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.html?rev=104911&r1=104910&r2=104911&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.html (original)
+++ llvm/trunk/docs/LangRef.html Thu May 27 20:14:11 2010
@@ -4239,7 +4239,7 @@
 
 <h5>Syntax:</h5>
 <pre>
-  <result> = alloca <type>[, i32 <NumElements>][, align <alignment>]     <i>; yields {type*}:result</i>
+  <result> = alloca <type>[, <ty> <NumElements>][, align <alignment>]     <i>; yields {type*}:result</i>
 </pre>
 
 <h5>Overview:</h5>

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=104911&r1=104910&r2=104911&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu May 27 20:14:11 2010
@@ -3791,8 +3791,8 @@
     }
   }
 
-  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 @@
 
   // 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);

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=104911&r1=104910&r2=104911&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Thu May 27 20:14:11 2010
@@ -2643,12 +2643,13 @@
 
   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

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=104911&r1=104910&r2=104911&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Thu May 27 20:14:11 2010
@@ -828,8 +828,8 @@
   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;
 }

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=104911&r1=104910&r2=104911&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Thu May 27 20:14:11 2010
@@ -1371,8 +1371,8 @@
           &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);
 }
 

Copied: llvm/trunk/test/CodeGen/X86/alloca-align-rounding-32.ll (from r104897, llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/alloca-align-rounding-32.ll?p2=llvm/trunk/test/CodeGen/X86/alloca-align-rounding-32.ll&p1=llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll&r1=104897&r2=104911&rev=104911&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll (original)
+++ llvm/trunk/test/CodeGen/X86/alloca-align-rounding-32.ll Thu May 27 20:14:11 2010
@@ -1,5 +1,4 @@
 ; 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)
 

Modified: llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll?rev=104911&r1=104910&r2=104911&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll (original)
+++ llvm/trunk/test/CodeGen/X86/alloca-align-rounding.ll Thu May 27 20:14:11 2010
@@ -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
 }





More information about the llvm-commits mailing list