[LLVMdev] DeadStoreElimination: do better without TargetData
Hans Wennborg
hans at hanshq.net
Wed Nov 4 10:13:30 PST 2009
Sorry, I admit my e-mail was a bit unclear.
Here is an example:
declare void @foo()
define void @f(i32* noalias %p) {
store i32 1, i32* %p; <-- This is dead
call void @foo()
store i32 2, i32 *%p
ret void
}
When run through ./llvm-as test.ll -o - | ./opt -O3 -S
the dead store is not removed by the DSE pass.
(The call to @foo is there to prevent InstCombine from folding the store
instructions into one.)
This is because DSE relies on TargetData to find out about pointer
sizes. Apparently, there was some default value for this before, but
when running with top of the tree today, it turned out that TD=NULL in
the DSE code.
We discussed this in the IRC channel, and someone pointed out that the
more the pass can do without having info about the target, the better --
hence the patch.
With the patch, DSE will at least see if the data types are equal, even
though it doesn't have information about their sizes. This is enough for
handling the example above, and probably many others as well.
/ Hans
Chris Lattner wrote:
>
> On Nov 4, 2009, at 7:21 AM, Hans Wennborg wrote:
>
>> Re-posting with better-looking code.
>
> Thanks, do you have a testcase showing what this does?
>
> -Chris
>
>>
>> Hans Wennborg wrote:
>>> The attached patch makes DeadStoreElimination able to remove stores
>>> in store-store dependencies when the operand types are equal, even if
>>> there is no TargetData available.
>>> / Hans
>>> ------------------------------------------------------------------------
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>> Index: lib/Transforms/Scalar/DeadStoreElimination.cpp
>> ===================================================================
>> --- lib/Transforms/Scalar/DeadStoreElimination.cpp (revision 86023)
>> +++ lib/Transforms/Scalar/DeadStoreElimination.cpp (working copy)
>> @@ -117,10 +117,12 @@
>>
>> // If this is a store-store dependence, then the previous store is
>> dead so
>> // long as this store is at least as big as it.
>> - if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst()))
>> - if (TD &&
>> - TD->getTypeStoreSize(DepStore->getOperand(0)->getType()) <=
>> - TD->getTypeStoreSize(SI->getOperand(0)->getType())) {
>> + if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst())) {
>> + const Type *DepType = DepStore->getOperand(0)->getType();
>> + const Type *SIType = SI->getOperand(0)->getType();
>> + if (DepType == SIType ||
>> + (TD &&
>> + TD->getTypeStoreSize(DepType) <=
>> TD->getTypeStoreSize(SIType))) {
>> // Delete the store and now-dead instructions that feed it.
>> DeleteDeadInstruction(DepStore);
>> NumFastStores++;
>> @@ -133,6 +135,7 @@
>> --BBI;
>> continue;
>> }
>> + }
>>
>> // If we're storing the same value back to a pointer that we just
>> // loaded from, then the store can be removed.
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
More information about the llvm-dev
mailing list