Index: llvm/lib/Analysis/MustExecute.cpp =================================================================== --- llvm/lib/Analysis/MustExecute.cpp +++ llvm/lib/Analysis/MustExecute.cpp @@ -203,6 +203,11 @@ // 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. + if (DT->dominates(BB, Pred)) + continue; + for (auto *Succ : successors(Pred)) if (CheckedSuccessors.insert(Succ).second && Succ != BB && !Predecessors.count(Succ)) Index: llvm/test/Analysis/MustExecute/loop-header.ll =================================================================== --- llvm/test/Analysis/MustExecute/loop-header.ll +++ llvm/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)