diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-07-23 02:56:49 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-07-23 02:56:49 +0000 |
commit | 796331c026a6cd33624c0f22e4e289fc89093b43 (patch) | |
tree | 306cc4979f731eecdccdcd3c0dd5cfa047b5712b /llvm/lib/Analysis/LoopUnrollAnalyzer.cpp | |
parent | cec363527e93e89d54daae937532350d41672050 (diff) | |
download | bcm5719-llvm-796331c026a6cd33624c0f22e4e289fc89093b43.tar.gz bcm5719-llvm-796331c026a6cd33624c0f22e4e289fc89093b43.zip |
[LoopUnrollAnalyzer] Handle out of bounds accesses in visitLoad
While we handed loads past the end of an array, we didn't handle loads
_before_ the array.
This fixes PR28062.
N.B. While the bug in the code is obvious, I am struggling to craft a
test case which is reasonable in size.
llvm-svn: 276510
Diffstat (limited to 'llvm/lib/Analysis/LoopUnrollAnalyzer.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopUnrollAnalyzer.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp b/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp index f59257ab16b..7bdf3408a58 100644 --- a/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp +++ b/llvm/lib/Analysis/LoopUnrollAnalyzer.cpp @@ -115,13 +115,19 @@ bool UnrolledInstAnalyzer::visitLoad(LoadInst &I) { // We might have a vector load from an array. FIXME: for now we just bail // out in this case, but we should be able to resolve and simplify such // loads. - if(CDS->getElementType() != I.getType()) + if (CDS->getElementType() != I.getType()) return false; - int ElemSize = CDS->getElementType()->getPrimitiveSizeInBits() / 8U; - if (SimplifiedAddrOp->getValue().getActiveBits() >= 64) + unsigned ElemSize = CDS->getElementType()->getPrimitiveSizeInBits() / 8U; + if (SimplifiedAddrOp->getValue().getActiveBits() > 64) return false; - int64_t Index = SimplifiedAddrOp->getSExtValue() / ElemSize; + int64_t SimplifiedAddrOpV = SimplifiedAddrOp->getSExtValue(); + if (SimplifiedAddrOpV < 0) { + // FIXME: For now we conservatively ignore out of bound accesses, but + // we're allowed to perform the optimization in this case. + return false; + } + uint64_t Index = static_cast<uint64_t>(SimplifiedAddrOpV) / ElemSize; if (Index >= CDS->getNumElements()) { // FIXME: For now we conservatively ignore out of bound accesses, but // we're allowed to perform the optimization in this case. |