summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-07-06 23:09:25 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-07-06 23:09:25 +0000
commitfa0dffcceedb408c42716a3877c4357371a0fb55 (patch)
tree3b7e47b6ef22fcf58b8dd071f6c5582819e65870 /llvm/lib
parent9877f689f282b19ca697aa8c6fecd752a84dbddd (diff)
downloadbcm5719-llvm-fa0dffcceedb408c42716a3877c4357371a0fb55.tar.gz
bcm5719-llvm-fa0dffcceedb408c42716a3877c4357371a0fb55.zip
teach instcombine to remove allocated buffers even if there are stores, memcpy/memmove/memset, and objectsize users.
This means we can do cheap DSE for heap memory. Nothing is done if the pointer excapes or has a load. The churn in the tests is mostly due to objectsize, since we want to make sure we don't delete the malloc call before evaluating the objectsize (otherwise it becomes -1/0) llvm-svn: 159876
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index c5124bf7b28..bcf69183bba 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1137,12 +1137,29 @@ static bool IsOnlyNullComparedAndFreed(Value *V, SmallVectorImpl<WeakVH> &Users,
}
}
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U)) {
- if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
- II->getIntrinsicID() == Intrinsic::lifetime_end) {
+ switch (II->getIntrinsicID()) {
+ default: return false;
+ case Intrinsic::memmove:
+ case Intrinsic::memcpy:
+ case Intrinsic::memset: {
+ MemIntrinsic *MI = cast<MemIntrinsic>(II);
+ if (MI->isVolatile() || MI->getRawDest() != V)
+ return false;
+ }
+ // fall through
+ case Intrinsic::objectsize:
+ case Intrinsic::lifetime_start:
+ case Intrinsic::lifetime_end:
Users.push_back(II);
continue;
}
}
+ if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
+ if (SI->isVolatile() || SI->getPointerOperand() != V)
+ return false;
+ Users.push_back(SI);
+ continue;
+ }
return false;
}
return true;
@@ -1164,6 +1181,12 @@ Instruction *InstCombiner::visitMalloc(Instruction &MI) {
C->isFalseWhenEqual()));
} else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) {
ReplaceInstUsesWith(*I, UndefValue::get(I->getType()));
+ } else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
+ if (II->getIntrinsicID() == Intrinsic::objectsize) {
+ ConstantInt *CI = cast<ConstantInt>(II->getArgOperand(1));
+ uint64_t DontKnow = CI->isZero() ? -1ULL : 0;
+ ReplaceInstUsesWith(*I, ConstantInt::get(I->getType(), DontKnow));
+ }
}
EraseInstFromFunction(*I);
}
OpenPOWER on IntegriCloud