diff options
author | Evan Cheng <evan.cheng@apple.com> | 2010-03-08 22:54:36 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2010-03-08 22:54:36 +0000 |
commit | 687fed3530366b03a9a6433df0c032247ab17d5b (patch) | |
tree | a8ecdecd2b4058059c79a46d1b59386d8e42880d /lib/Transforms | |
parent | dd8187a3e9509c670162b6ae8b7115723a37f01c (diff) |
Re-commit 97860 with fix. getMallocAllocatedType may return null.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98000 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 e2b7d3d60d..0582210d40 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -337,6 +337,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 && 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; |