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 | 4f2fd2d2be6a14f164bc5f7fbd9cdb4c9d615e08 (patch) | |
| tree | d6849e8b42617b5a59a3f83a7d494b4f3fd0dfe0 /llvm/lib | |
| parent | ee20b5f2362aa45d5cf2446ee76c80a640ad5839 (diff) | |
| download | bcm5719-llvm-4f2fd2d2be6a14f164bc5f7fbd9cdb4c9d615e08.tar.gz bcm5719-llvm-4f2fd2d2be6a14f164bc5f7fbd9cdb4c9d615e08.zip | |
Re-commit 97860 with fix. getMallocAllocatedType may return null.
llvm-svn: 98000
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index e2b7d3d60db..0582210d407 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/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; |

