According to the API explanation, we should use exiting block instead of
latch block. llvm 3.6 place an assert on this.

v2:
  Use latch block if it is the exiting block, else use exiting block.

Signed-off-by: Ruiling Song <[email protected]>
---
 backend/src/llvm/llvm_unroll.cpp |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp
index f0ad4b4..5d3fad8 100644
--- a/backend/src/llvm/llvm_unroll.cpp
+++ b/backend/src/llvm/llvm_unroll.cpp
@@ -177,19 +177,25 @@ namespace gbe {
       bool handleParentLoops(Loop *L, LPPassManager &LPM) {
         Loop *currL = L;
         ScalarEvolution *SE = &getAnalysis<ScalarEvolution>();
-        BasicBlock *latchBlock = currL->getLoopLatch();
+        BasicBlock *ExitBlock = currL->getLoopLatch();
+        if (!ExitBlock || !L->isLoopExiting(ExitBlock))
+          ExitBlock = currL->getExitingBlock();
+
         unsigned currTripCount = 0;
         bool shouldUnroll = true;
-        if (latchBlock)
-          currTripCount = SE->getSmallConstantTripCount(L, latchBlock);
+        if (ExitBlock)
+          currTripCount = SE->getSmallConstantTripCount(L, ExitBlock);
 
         while(currL) {
           Loop *parentL = currL->getParentLoop();
           unsigned parentTripCount = 0;
           if (parentL) {
-            BasicBlock *parentLatchBlock = parentL->getLoopLatch();
-            if (parentLatchBlock)
-              parentTripCount = SE->getSmallConstantTripCount(parentL, 
parentLatchBlock);
+            BasicBlock *parentExitBlock = parentL->getLoopLatch();
+            if (!parentExitBlock || !parentL->isLoopExiting(parentExitBlock))
+              parentExitBlock = parentL->getExitingBlock();
+
+            if (parentExitBlock)
+              parentTripCount = SE->getSmallConstantTripCount(parentL, 
parentExitBlock);
           }
           if ((parentTripCount != 0 && currTripCount / parentTripCount > 16) ||
               (currTripCount > 32)) {
-- 
1.7.10.4

_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to