[llvm-commits] [llvm] r118875 - in /llvm/trunk: lib/Transforms/Scalar/DeadStoreElimination.cpp test/Transforms/DeadStoreElimination/free.ll
Dan Gohman
gohman at apple.com
Thu Nov 11 18:19:17 PST 2010
Author: djg
Date: Thu Nov 11 20:19:17 2010
New Revision: 118875
URL: http://llvm.org/viewvc/llvm-project?rev=118875&view=rev
Log:
Enhance DSE to handle the case where a free call makes more than
one store dead. This is especially noticeable in
SingleSource/Benchmarks/Shootout/objinst.
Modified:
llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/trunk/test/Transforms/DeadStoreElimination/free.ll
Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=118875&r1=118874&r2=118875&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Thu Nov 11 20:19:17 2010
@@ -59,6 +59,7 @@
bool runOnBasicBlock(BasicBlock &BB);
bool handleFreeWithNonTrivialDependency(const CallInst *F,
+ Instruction *Inst,
MemDepResult Dep);
bool handleEndBlock(BasicBlock &BB);
bool RemoveUndeadPointers(Value *Ptr, uint64_t killPointerSize,
@@ -212,7 +213,7 @@
// Handle frees whose dependencies are non-trivial.
if (const CallInst *F = isFreeCall(Inst)) {
- MadeChange |= handleFreeWithNonTrivialDependency(F, InstDep);
+ MadeChange |= handleFreeWithNonTrivialDependency(F, Inst, InstDep);
continue;
}
@@ -298,23 +299,34 @@
/// handleFreeWithNonTrivialDependency - Handle frees of entire structures whose
/// dependency is a store to a field of that structure.
bool DSE::handleFreeWithNonTrivialDependency(const CallInst *F,
+ Instruction *Inst,
MemDepResult Dep) {
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
+ MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
- Instruction *Dependency = Dep.getInst();
- if (!Dependency || !doesClobberMemory(Dependency) || !isElidable(Dependency))
- return false;
+ do {
+ Instruction *Dependency = Dep.getInst();
+ if (!Dependency || !doesClobberMemory(Dependency) || !isElidable(Dependency))
+ return false;
- Value *DepPointer = getPointerOperand(Dependency)->getUnderlyingObject();
+ Value *DepPointer = getPointerOperand(Dependency)->getUnderlyingObject();
- // Check for aliasing.
- if (AA.alias(F->getArgOperand(0), 1, DepPointer, 1) !=
- AliasAnalysis::MustAlias)
- return false;
+ // Check for aliasing.
+ if (AA.alias(F->getArgOperand(0), 1, DepPointer, 1) !=
+ AliasAnalysis::MustAlias)
+ return false;
- // DCE instructions only used to calculate that store
- DeleteDeadInstruction(Dependency);
- ++NumFastStores;
+ // DCE instructions only used to calculate that store
+ DeleteDeadInstruction(Dependency);
+ ++NumFastStores;
+
+ // Inst's old Dependency is now deleted. Compute the next dependency,
+ // which may also be dead, as in
+ // s[0] = 0;
+ // s[1] = 0; // This has just been deleted.
+ // free(s);
+ Dep = MD.getDependency(Inst);
+ } while (!Dep.isNonLocal());
return true;
}
Modified: llvm/trunk/test/Transforms/DeadStoreElimination/free.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/free.ll?rev=118875&r1=118874&r2=118875&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/DeadStoreElimination/free.ll (original)
+++ llvm/trunk/test/Transforms/DeadStoreElimination/free.ll Thu Nov 11 20:19:17 2010
@@ -24,3 +24,17 @@
ret void
}
+; CHECK: @test4
+; CHECK-NOT: store
+; CHECK: ret void
+define void @test4() {
+ %m = call i8* @malloc(i64 24)
+ store i8 0, i8* %m
+ %m1 = getelementptr i8* %m, i64 1
+ store i8 1, i8* %m1
+ call void @free(i8* %m)
+ ret void
+}
+
+declare void @free(i8*)
+declare i8* @malloc(i64)
More information about the llvm-commits
mailing list