[llvm-commits] [llvm] r67093 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp test/CodeGen/X86/x86-64-malloc.ll
Chris Lattner
clattner at apple.com
Tue Mar 17 13:23:56 PDT 2009
Thanks Bill, fixed.
On Mar 17, 2009, at 1:07 PM, Bill Wendling wrote:
> Chris,
>
> This is causing this test to XPASS. Should it be un-XFAILed?
>
> Running /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvm.src/test/
> CodeGen/X86/dg.exp
> ...
> XPASS: /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvm.src/test/
> CodeGen/X86/alloca-align-rounding.ll
>
>
> -bw
>
> On Tue, Mar 17, 2009 at 12:36 PM, Chris Lattner <sabre at nondot.org>
> wrote:
>> Author: lattner
>> Date: Tue Mar 17 14:36:00 2009
>> New Revision: 67093
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=67093&view=rev
>> Log:
>> 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/trunk/test/CodeGen/X86/x86-64-malloc.ll
>> Modified:
>> llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
>>
>> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=67093&r1=67092&r2=67093&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
>> (original)
>> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Tue
>> Mar 17 14:36:00 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;
>>
>> Added: llvm/trunk/test/CodeGen/X86/x86-64-malloc.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-64-malloc.ll?rev=67093&view=auto
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/test/CodeGen/X86/x86-64-malloc.ll (added)
>> +++ llvm/trunk/test/CodeGen/X86/x86-64-malloc.ll Tue Mar 17
>> 14:36:00 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
>> +}
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list