diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-05-03 21:19:58 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-05-03 21:19:58 +0000 |
commit | d2b71e7fa9ff1cfd889a16bbf583bdce200236f9 (patch) | |
tree | e29c3fc369f5d0cab4c735f7b9c7dbef39cd4390 /llvm/lib/Transforms/InstCombine | |
parent | 64e7ead1d817540a4ba4887da6c8a049788beee7 (diff) | |
download | bcm5719-llvm-d2b71e7fa9ff1cfd889a16bbf583bdce200236f9.tar.gz bcm5719-llvm-d2b71e7fa9ff1cfd889a16bbf583bdce200236f9.zip |
add support for calloc to objectsize lowering
llvm-svn: 156102
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 5be7997367f..4196ca6cf79 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/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 |