[Beignet] [PATCH] fix opencv_test_imgproc subcase OCL_ImgProc/Accumulate.Mask regression.

xionghu.luo at intel.com xionghu.luo at intel.com
Mon Aug 25 14:36:21 PDT 2014


From: Luo Xionghu <xionghu.luo at intel.com>

This regression is caused by structural analysis when check the if-then
node, acturally there are four types of if-then node according to the
topology and fallthrough information. fallthrough check is added in this
patch.

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 backend/src/backend/gen_insn_selection.cpp |    4 +++-
 backend/src/ir/function.hpp                |    5 +++++
 backend/src/ir/structural_analysis.cpp     |    9 ++++++++-
 backend/src/ir/structural_analysis.hpp     |   16 +++++++++++++++-
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp
index b7a39af..9a552b1 100644
--- a/backend/src/backend/gen_insn_selection.cpp
+++ b/backend/src/backend/gen_insn_selection.cpp
@@ -4018,7 +4018,9 @@ namespace gbe
           sel.curr.physicalFlag = 0;
           sel.curr.flagIndex = (uint64_t)pred;
           sel.curr.externFlag = 1;
-          sel.curr.inversePredicate = 1;
+          if(insn.getParent()->need_reverse ){
+            sel.curr.inversePredicate = 1;
+          }
           sel.curr.predicate = GEN_PREDICATE_NORMAL;
           sel.IF(GenRegister::immd(0), jip, uip);
           sel.curr.inversePredicate = 0;
diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
index c5582b4..b877bce 100644
--- a/backend/src/ir/function.hpp
+++ b/backend/src/ir/function.hpp
@@ -87,6 +87,11 @@ namespace ir {
     set <Register> definedPhiRegs;
   /* these three are used by structure transforming */
   public:
+    /*if need_reverse is true,  need to reverse prediction.
+     *if condition is TRUE, IF instruction will execute the following block,
+     * different from BRA instruction, so all the IF instruction need_reverse
+     * except two special case(fallthrough is the same with succs.). */
+    bool need_reverse;
     /* if needEndif is true, it means that this bb is the exit of an
      * outermost structure, so this block needs another endif to match
      * the if inserted at the entry of this structure, otherwise this
diff --git a/backend/src/ir/structural_analysis.cpp b/backend/src/ir/structural_analysis.cpp
index dfc2118..c106fa7 100644
--- a/backend/src/ir/structural_analysis.cpp
+++ b/backend/src/ir/structural_analysis.cpp
@@ -120,6 +120,7 @@ namespace analysis
     /* since this node is an if node, so we remove the BRA instruction at the bottom of the exit BB of 'node',
      * and insert IF instead
      */
+    pbb->need_reverse = node->need_reverse;
     pbb->erase(it);
     ir::Instruction insn = ir::IF(matchingElseLabel, reg);
     ir::Instruction* p_new_insn = pbb->getParent().newInstruction(insn);
@@ -724,7 +725,7 @@ namespace analysis
       n = *(++(node->succs().begin()));
 
       /* check for if node then n */
-      if(n->succs().size() == 1 &&
+      if( n->succs().size() == 1 &&
          n->preds().size() == 1 &&
          *(n->succs().begin()) == m &&
          !n->hasBarrier() && !node->hasBarrier())
@@ -734,6 +735,9 @@ namespace analysis
         nset.insert(n);
 
         Node* p = new IfThenNode(node, n);
+        if(node->fallthrough() == m){
+          node->need_reverse = false;
+        }
 
         if(node->canBeHandled == false || n->canBeHandled == false)
           p->canBeHandled = false;
@@ -752,6 +756,9 @@ namespace analysis
         nset.insert(m);
 
         Node* p = new IfThenNode(node, m);
+        if(node->fallthrough() == n){
+          node->need_reverse = false;
+        }
 
         if(node->canBeHandled == false || m->canBeHandled == false)
           p->canBeHandled = false;
diff --git a/backend/src/ir/structural_analysis.hpp b/backend/src/ir/structural_analysis.hpp
index 06c2f5f..f7a34d1 100644
--- a/backend/src/ir/structural_analysis.hpp
+++ b/backend/src/ir/structural_analysis.hpp
@@ -87,7 +87,7 @@ namespace analysis
   class Node
   {
   public:
-    Node(RegionType rtype, const NodeList& children): has_barrier(false), mark(false), canBeHandled(true)
+    Node(RegionType rtype, const NodeList& children): has_barrier(false), mark(false), canBeHandled(true), need_reverse(true)
     {
       this->rtype = rtype;
       this->children = children;
@@ -118,6 +118,20 @@ namespace analysis
     bool canBeHandled;
     //label is for debug
     int label;
+    /* need_reverse should be false under two circumstance,
+     * fallthrough is the same with succs:
+     * (1) n->succs == m && node->fallthrough == m
+     * node
+     * | \
+     * |  \
+     * m<--n
+     * (2) m->succs == n && node->fallthrough == n
+     * node
+     * | \
+     * |  \
+     * m-->n
+     * */
+    bool need_reverse;
   };
 
   /* represents basic block */
-- 
1.7.9.5



More information about the Beignet mailing list