diff options
author | Evan Cheng <evan.cheng@apple.com> | 2010-03-06 01:01:42 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2010-03-06 01:01:42 +0000 |
commit | fc8ccfedbba651e324d827de6693aad1491314c7 (patch) | |
tree | d77634f669eb929c346ffffd918ce0bc83bb21ab /lib/Transforms | |
parent | e623050048e56a512e77c28b69925e7dc1efa6ad (diff) |
Transform @llvm.objectsize to integer if the argument is a result of malloc of known size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97860 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index a241f169f2..85c3895b2a 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/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; |