[PATCH] D62418: [MustExecute] Improve MustExecute to correctly handle loop nest

Xing Xue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 27 06:54:43 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL361762: [MustExecute] Improve MustExecute to correctly handle loop nest (authored by xingxue, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62418?vs=201406&id=201525#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62418/new/

https://reviews.llvm.org/D62418

Files:
  llvm/trunk/lib/Analysis/MustExecute.cpp
  llvm/trunk/test/Analysis/MustExecute/loop-header.ll


Index: llvm/trunk/test/Analysis/MustExecute/loop-header.ll
===================================================================
--- llvm/trunk/test/Analysis/MustExecute/loop-header.ll
+++ llvm/trunk/test/Analysis/MustExecute/loop-header.ll
@@ -83,17 +83,15 @@
   ret i1 false
 }
 
-; FIXME: everything in inner loop header should be must execute
-; for outer as well
 define i1 @nested_no_throw(i32* noalias %p, i32 %high) {
 ; CHECK-LABEL: @nested_no_throw
 ; CHECK-LABEL: loop:                                             ; preds = %next
 ; CHECK:         %iv = phi i32 [ 0, %entry ], [ %iv.next, %next ]	; (mustexec in: loop)
 ; CHECK:         br label %inner_loop	; (mustexec in: loop)
 ; CHECK-LABEL: inner_loop:
-; CHECK:         %v = load i32, i32* %p	; (mustexec in: inner_loop)
-; CHECK:         %inner.test = icmp eq i32 %v, 0	; (mustexec in: inner_loop)
-; CHECK:         br i1 %inner.test, label %inner_loop, label %next	; (mustexec in: inner_loop)
+; CHECK:         %v = load i32, i32* %p	; (mustexec in 2 loops: inner_loop, loop)
+; CHECK:         %inner.test = icmp eq i32 %v, 0	; (mustexec in 2 loops: inner_loop, loop)
+; CHECK:         br i1 %inner.test, label %inner_loop, label %next	; (mustexec in 2 loops: inner_loop, loop)
 ; CHECK-LABEL: next:
 ; CHECK:         %iv.next = add nuw nsw i32 %iv, 1 ; (mustexec in: loop)
 ; CHECK:         %exit.test = icmp slt i32 %iv, %high ; (mustexec in: loop)
Index: llvm/trunk/lib/Analysis/MustExecute.cpp
===================================================================
--- llvm/trunk/lib/Analysis/MustExecute.cpp
+++ llvm/trunk/lib/Analysis/MustExecute.cpp
@@ -193,7 +193,8 @@
   SmallPtrSet<const BasicBlock *, 4> Predecessors;
   collectTransitivePredecessors(CurLoop, BB, Predecessors);
 
-  // Make sure that all successors of all predecessors of BB are either:
+  // Make sure that all successors of, all predecessors of BB which are not
+  // dominated by BB, are either:
   // 1) BB,
   // 2) Also predecessors of BB,
   // 3) Exit blocks which are not taken on 1st iteration.
@@ -203,6 +204,12 @@
     // Predecessor block may throw, so it has a side exit.
     if (blockMayThrow(Pred))
       return false;
+
+    // BB dominates Pred, so if Pred runs, BB must run.
+    // This is true when Pred is a loop latch.
+    if (DT->dominates(BB, Pred))
+      continue;
+
     for (auto *Succ : successors(Pred))
       if (CheckedSuccessors.insert(Succ).second &&
           Succ != BB && !Predecessors.count(Succ))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62418.201525.patch
Type: text/x-patch
Size: 2485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190527/4432d17d/attachment.bin>


More information about the llvm-commits mailing list