diff options
author | Easwaran Raman <eraman@google.com> | 2016-06-27 22:31:53 +0000 |
---|---|---|
committer | Easwaran Raman <eraman@google.com> | 2016-06-27 22:31:53 +0000 |
commit | 22eb80a11419825e13dee2ea34d9e4bf90dfd220 (patch) | |
tree | 99d1ec336d95e3c109446bd9dd2459669b782977 /llvm/lib/Analysis/InlineCost.cpp | |
parent | 59ed2ffca38f01b326459d366d1b131ec45eb483 (diff) | |
download | llvm-22eb80a11419825e13dee2ea34d9e4bf90dfd220.zip llvm-22eb80a11419825e13dee2ea34d9e4bf90dfd220.tar.gz llvm-22eb80a11419825e13dee2ea34d9e4bf90dfd220.tar.bz2 |
Fix size computation of array allocation in inline cost analysis
Differential revision: http://reviews.llvm.org/D21690
llvm-svn: 273952
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 9382def..f6a9eda 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -339,9 +339,10 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) { if (I.isArrayAllocation()) { Constant *Size = SimplifiedValues.lookup(I.getArraySize()); if (auto *AllocSize = dyn_cast_or_null<ConstantInt>(Size)) { + const DataLayout &DL = F.getParent()->getDataLayout(); Type *Ty = I.getAllocatedType(); - // FIXME: This can't be right. AllocatedSize is in *bytes*. - AllocatedSize += Ty->getPrimitiveSizeInBits() * AllocSize->getZExtValue(); + AllocatedSize = SaturatingMultiplyAdd( + AllocSize->getLimitedValue(), DL.getTypeAllocSize(Ty), AllocatedSize); return Base::visitAlloca(I); } } @@ -350,7 +351,7 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) { if (I.isStaticAlloca()) { const DataLayout &DL = F.getParent()->getDataLayout(); Type *Ty = I.getAllocatedType(); - AllocatedSize += DL.getTypeAllocSize(Ty); + AllocatedSize = SaturatingAdd(DL.getTypeAllocSize(Ty), AllocatedSize); } // We will happily inline static alloca instructions. |