summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2010-03-06 01:01:42 +0000
committerEvan Cheng <evan.cheng@apple.com>2010-03-06 01:01:42 +0000
commitafdc7d3aab1b50dca83bc6b6500459601be2603d (patch)
tree10e994e3c3738294864e1cf609087b86f0a58242 /llvm/lib
parentbeec5a080f57929bd3ebb29d8da25c43ee67aa6d (diff)
downloadbcm5719-llvm-afdc7d3aab1b50dca83bc6b6500459601be2603d.tar.gz
bcm5719-llvm-afdc7d3aab1b50dca83bc6b6500459601be2603d.zip
Transform @llvm.objectsize to integer if the argument is a result of malloc of known size.
llvm-svn: 97860
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index a241f169f28..85c3895b2a0 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -336,6 +336,16 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
}
return ReplaceInstUsesWith(CI, ConstantInt::get(ReturnTy, AllocaSize));
}
+ } else if (CallInst *MI = extractMallocCall(Op1)) {
+ const Type* MallocType = getMallocAllocatedType(MI);
+ // Get alloca size.
+ if (MallocType->isSized()) {
+ if (Value *NElems = getMallocArraySize(MI, TD, true)) {
+ if (ConstantInt *NElements = dyn_cast<ConstantInt>(NElems))
+ return ReplaceInstUsesWith(CI, ConstantInt::get(ReturnTy,
+ (NElements->getZExtValue() * TD->getTypeAllocSize(MallocType))));
+ }
+ }
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Op1)) {
// Only handle constant GEPs here.
if (CE->getOpcode() != Instruction::GetElementPtr) break;
OpenPOWER on IntegriCloud