[llvm-commits] [llvm] r67100 - in /llvm/branches/Apple/Dib: lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp test/CodeGen/X86/alloca-align-rounding.ll test/CodeGen/X86/x86-64-malloc.ll

Bill Wendling isanbard at gmail.com
Tue Mar 17 13:31:11 PDT 2009


Author: void
Date: Tue Mar 17 15:31:10 2009
New Revision: 67100

URL: http://llvm.org/viewvc/llvm-project?rev=67100&view=rev
Log:
--- Merging (from foreign repository) r67093 into '.':
A    test/CodeGen/X86/x86-64-malloc.ll
U    lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
U    test/CodeGen/X86/alloca-align-rounding.ll

Fix codegen to compute the size of an allocation by multiplying the
size by the array amount as an i32 value instead of promoting from
i32 to i64 then doing the multiply.  Not doing this broke wrap-around
assumptions that the optimizers (validly) made.  The ultimate real
fix for this is to introduce i64 version of alloca and remove mallocinst.

This fixes PR3829

Added:
    llvm/branches/Apple/Dib/test/CodeGen/X86/x86-64-malloc.ll
Modified:
    llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
    llvm/branches/Apple/Dib/test/CodeGen/X86/alloca-align-rounding.ll

Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=67100&r1=67099&r2=67100&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Tue Mar 17 15:31:10 2009
@@ -2763,6 +2763,13 @@
              I.getAlignment());
 
   SDValue AllocSize = getValue(I.getArraySize());
+  
+  AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), AllocSize.getValueType(),
+                          AllocSize,
+                          DAG.getConstant(TySize, AllocSize.getValueType()));
+  
+  
+  
   MVT IntPtr = TLI.getPointerTy();
   if (IntPtr.bitsLT(AllocSize.getValueType()))
     AllocSize = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), 
@@ -2771,9 +2778,6 @@
     AllocSize = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), 
                             IntPtr, AllocSize);
 
-  AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), IntPtr, AllocSize,
-                          DAG.getIntPtrConstant(TySize));
-
   // 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
   // the stack alignment, we note this in the DYNAMIC_STACKALLOC node.
@@ -5425,6 +5429,16 @@
 void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   SDValue Src = getValue(I.getOperand(0));
 
+  // Scale up by the type size in the original i32 type width.  Various
+  // mid-level optimizers may make assumptions about demanded bits etc from the
+  // i32-ness of the optimizer: we do not want to promote to i64 and then
+  // multiply on 64-bit targets.
+  // FIXME: Malloc inst should go away: PR715.
+  uint64_t ElementSize = TD->getTypePaddedSize(I.getType()->getElementType());
+  if (ElementSize != 1)
+    Src = DAG.getNode(ISD::MUL, getCurDebugLoc(), Src.getValueType(),
+                      Src, DAG.getConstant(ElementSize, Src.getValueType()));
+  
   MVT IntPtr = TLI.getPointerTy();
 
   if (IntPtr.bitsLT(Src.getValueType()))
@@ -5432,11 +5446,6 @@
   else if (IntPtr.bitsGT(Src.getValueType()))
     Src = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), IntPtr, Src);
 
-  // Scale the source by the type size.
-  uint64_t ElementSize = TD->getTypePaddedSize(I.getType()->getElementType());
-  Src = DAG.getNode(ISD::MUL, getCurDebugLoc(), Src.getValueType(),
-                    Src, DAG.getIntPtrConstant(ElementSize));
-
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
   Entry.Node = Src;

Modified: llvm/branches/Apple/Dib/test/CodeGen/X86/alloca-align-rounding.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/alloca-align-rounding.ll?rev=67100&r1=67099&r2=67100&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/test/CodeGen/X86/alloca-align-rounding.ll (original)
+++ llvm/branches/Apple/Dib/test/CodeGen/X86/alloca-align-rounding.ll Tue Mar 17 15:31:10 2009
@@ -1,6 +1,5 @@
 ; RUN: llvm-as < %s | llc -march=x86 -mtriple=i686-apple-darwin | grep and | count 1
 ; RUN: llvm-as < %s | llc -march=x86-64 -mtriple=i686-pc-linux | grep and | count 1
-; XFAIL: *
 
 declare void @bar(<2 x i64>* %n)
 

Added: llvm/branches/Apple/Dib/test/CodeGen/X86/x86-64-malloc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/x86-64-malloc.ll?rev=67100&view=auto

==============================================================================
--- llvm/branches/Apple/Dib/test/CodeGen/X86/x86-64-malloc.ll (added)
+++ llvm/branches/Apple/Dib/test/CodeGen/X86/x86-64-malloc.ll Tue Mar 17 15:31:10 2009
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | llc -march=x86-64 | grep {shll.*3, %edi}
+; PR3829
+; The generated code should multiply by 3 (sizeof i8*) as an i32,
+; not as an i64!
+
+define i8** @test(i32 %sz) {
+	%sub = add i32 %sz, 536870911		; <i32> [#uses=1]
+	%call = malloc i8*, i32 %sub		; <i8**> [#uses=1]
+	ret i8** %call
+}





More information about the llvm-commits mailing list