]> granicus.if.org Git - llvm/commitdiff
Merging r276510:
authorHans Wennborg <hans@hanshq.net>
Mon, 25 Jul 2016 20:53:27 +0000 (20:53 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 25 Jul 2016 20:53:27 +0000 (20:53 +0000)
------------------------------------------------------------------------
r276510 | majnemer | 2016-07-22 19:56:49 -0700 (Fri, 22 Jul 2016) | 9 lines

[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.
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@276688 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LoopUnrollAnalyzer.cpp

index f59257ab16b501706872e6b2526d08775e679dec..7bdf3408a5811624c57fba7c36de04091d85fd8f 100644 (file)
@@ -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.