[V2] backend: refine load store optimization

Submitted by rander on July 3, 2017, 8:41 a.m.

Details

Message ID 1499071303-20283-1-git-send-email-rander.wang@intel.com
State New
Series "backend: refine load store optimization"
Headers show

Commit Message

rander July 3, 2017, 8:41 a.m.
this fix basic test in conformance tests failed for vec8 of char because
         of overflow. And it fix many test items failed in opencv because of
	 offset error

	(1)modify the size of searchInsnArray to 32, it is the max size for char
	   And add check for overflow if too many insn
	(2)Make sure the start insn is the first insn of searched array
           because if it is not the first, the offset maybe invalid. And
	   it is complex to modify offset without error

	V2:refine search index, using J not I

Signed-off-by: rander.wang <rander.wang@intel.com>
---
 backend/src/llvm/llvm_loadstore_optimization.cpp | 31 +++++++++++++++---------
 1 file changed, 19 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp
index c91c1a0..d0ce9e5 100644
--- a/backend/src/llvm/llvm_loadstore_optimization.cpp
+++ b/backend/src/llvm/llvm_loadstore_optimization.cpp
@@ -197,7 +197,6 @@  namespace gbe {
                             const BasicBlock::iterator &start,
                             unsigned maxVecSize,
                             bool isLoad) {
-
     if(!isSimpleLoadStore(&*start)) return false;
 
     unsigned targetAddrSpace = getAddressSpace(&*start);
@@ -212,23 +211,22 @@  namespace gbe {
     bool ready = false;
     int elementSize;
 
-    SmallVector<mergedInfo *, 16> searchInsnArray;
-    mergedInfo meInfoArray[16];
+    SmallVector<mergedInfo *, 32> searchInsnArray;
+    mergedInfo meInfoArray[32];
     int indx = 0;
     meInfoArray[indx++].init(&*start, 0);
-
     searchInsnArray.push_back(&meInfoArray[0]);
-    BasicBlock::iterator I = start;
-    ++I;
 
-    for(unsigned ss = 0; I!= E && ss <= maxLimit; ++ss, ++I) {
-      if((isLoad && isa<LoadInst>(*I)) || (!isLoad && isa<StoreInst>(*J))) {
+    for(unsigned ss = 0; J!= E && ss <= maxLimit; ++ss, ++J) {
+      if((isLoad && isa<LoadInst>(*J)) || (!isLoad && isa<StoreInst>(*J))) {
           int distance;
-          if(isLoadStoreCompatible(searchInsnArray[0]->mInsn, &*I, &distance, &elementSize, maxVecSize))
+          if(isLoadStoreCompatible(searchInsnArray[0]->mInsn, &*J, &distance, &elementSize, maxVecSize))
           {
-            meInfoArray[indx].init(&*I, distance);
+            meInfoArray[indx].init(&*J, distance);
             searchInsnArray.push_back(&meInfoArray[indx]);
             indx++;
+            if(indx >= 32)
+              break;
           }
       } else if((isLoad && isa<StoreInst>(*J))) {
         // simple stop to keep read/write order
@@ -237,6 +235,8 @@  namespace gbe {
         if (addrSpace != targetAddrSpace) {
           reordered = true;
         } else {
+          indx = 0;
+          searchInsnArray.clear();
           break;
         }
       } else if ((!isLoad && isa<LoadInst>(*J))) {
@@ -245,11 +245,11 @@  namespace gbe {
         if (addrSpace != targetAddrSpace) {
           reordered = true;
         } else {
+          indx = 0;
+          searchInsnArray.clear();
           break;
         }
       }
-
-      if(merged.size() >= maxVecSize) break;
     }
 
     if(indx > 1)
@@ -275,8 +275,15 @@  namespace gbe {
 
         if(j > 0 && ready)
         {
+          if (searchInsnArray[i]->mInsn != &*start)
+            break;
+
           for(unsigned k = 0; k < j+1; k++)
+          {
             merged.push_back(searchInsnArray[i+k]->mInsn);
+            if (k >= maxVecSize)
+              break;
+          }
 
           break;
         }