summaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineCalls.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-05-03 21:19:58 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-05-03 21:19:58 +0000
commit252ef566e8734b6bcf46434d0a7954c9eda0bd96 (patch)
treeb71231a8b801496ddd368cc3b642544a33bad547 /lib/Transforms/InstCombine/InstCombineCalls.cpp
parent1d61f283fad2e49d3e50a3585aac4cc9183a0d28 (diff)
downloadllvm-252ef566e8734b6bcf46434d0a7954c9eda0bd96.tar.gz
llvm-252ef566e8734b6bcf46434d0a7954c9eda0bd96.tar.bz2
llvm-252ef566e8734b6bcf46434d0a7954c9eda0bd96.tar.xz
add support for calloc to objectsize lowering
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156102 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCalls.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 5be7997367..4196ca6cf7 100644
--- a/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -300,11 +300,23 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
}
} else if (CallInst *MI = extractMallocCall(Op1)) {
// Get allocation size.
- Type* MallocType = getMallocAllocatedType(MI);
- if (MallocType && MallocType->isSized())
- if (Value *NElems = getMallocArraySize(MI, TD, true))
- if (ConstantInt *NElements = dyn_cast<ConstantInt>(NElems))
- Size = NElements->getZExtValue() * TD->getTypeAllocSize(MallocType);
+ Value *Arg = MI->getArgOperand(0);
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(Arg))
+ Size = CI->getZExtValue();
+
+ } else if (CallInst *MI = extractCallocCall(Op1)) {
+ // Get allocation size.
+ Value *Arg1 = MI->getArgOperand(0);
+ Value *Arg2 = MI->getArgOperand(1);
+ if (ConstantInt *CI1 = dyn_cast<ConstantInt>(Arg1))
+ if (ConstantInt *CI2 = dyn_cast<ConstantInt>(Arg2)) {
+ bool overflow;
+ APInt SizeAP = CI1->getValue().umul_ov(CI2->getValue(), overflow);
+ if (!overflow)
+ Size = SizeAP.getZExtValue();
+ else
+ return ReplaceInstUsesWith(CI, ConstantInt::get(ReturnTy, DontKnow));
+ }
}
// Do not return "I don't know" here. Later optimization passes could