SmallPtrSet<const BasicBlock *, 4> Predecessors;
collectTransitivePredecessors(CurLoop, BB, Predecessors);
+ // Bail out if a latch block is part of the predecessor set. In this case
+ // we may take the backedge to the header and not execute other latch
+ // successors.
+ for (const BasicBlock *Pred : predecessors(CurLoop->getHeader()))
+ // Predecessors only contains loop blocks, so we don't have to worry about
+ // preheader predecessors here.
+ if (Predecessors.contains(Pred))
+ return false;
+
// Make sure that all successors of, all predecessors of BB which are not
// dominated by BB, are either:
// 1) BB,
@c = global i16 0, align 2
-; FIXME: miscompile
; CHECK-LABEL: define void @latch_cycle_irreducible
-; CHECK: store i16 5, ptr @c, align 2 ; (mustexec in: loop)
+; CHECK: store i16 5, ptr @c, align 2{{$}}
define void @latch_cycle_irreducible() {
entry:
br label %loop
ret void
}
-; FIXME: miscompile
; CHECK-LABEL: define void @latch_cycle_reducible
-; CHECK: store i16 5, ptr @c, align 2 ; (mustexec in: loop)
+; CHECK: store i16 5, ptr @c, align 2{{$}}
define void @latch_cycle_reducible() {
entry:
br label %loop
define void @test() {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
-; CHECK-NEXT: store i16 5, ptr @c, align 2
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[V:%.*]] = phi i32 [ 10, [[ENTRY:%.*]] ], [ 0, [[LOOP_LATCH:%.*]] ]
; CHECK: loop.cont:
; CHECK-NEXT: br i1 false, label [[LOOP_IRREDUCIBLE:%.*]], label [[LOOP_LATCH]]
; CHECK: loop.irreducible:
+; CHECK-NEXT: store i16 5, ptr @c, align 2
; CHECK-NEXT: br label [[LOOP_LATCH]]
; CHECK: loop.latch:
; CHECK-NEXT: br i1 false, label [[LOOP_IRREDUCIBLE]], label [[LOOP]]