diff options
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 7068cb6669e..603a01075a5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -298,12 +298,16 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { } } } else if (CallInst *MI = extractMallocCall(Op1)) { - // Get alloca size. + // Get allocation size. const 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); + + // If there is no offset we can just return the size passed to malloc. + if (Offset == 0) + return ReplaceInstUsesWith(CI, MI->getArgOperand(0)); } // Do not return "I don't know" here. Later optimization passes could |