Index: llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -207,12 +207,13 @@ // folding. Only handle blocks from current loop: branches in child loops // are skipped because if they can be folded, they should be folded during // the processing of child loops. - if (TheOnlySucc && LI.getLoopFor(BB) == &L) + bool TakeFoldCandidate = TheOnlySucc && LI.getLoopFor(BB) == &L; + if (TakeFoldCandidate) FoldCandidates.push_back(BB); // Handle successors. for (BasicBlock *Succ : successors(BB)) - if (!TheOnlySucc || TheOnlySucc == Succ) { + if (!TakeFoldCandidate || TheOnlySucc == Succ) { if (L.contains(Succ)) LiveLoopBlocks.insert(Succ); else Index: llvm/trunk/test/Transforms/LoopSimplifyCFG/live_block_marking.ll =================================================================== --- llvm/trunk/test/Transforms/LoopSimplifyCFG/live_block_marking.ll +++ llvm/trunk/test/Transforms/LoopSimplifyCFG/live_block_marking.ll @@ -1,4 +1,4 @@ -; XFAIL: * +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; REQUIRES: asserts ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -indvars -loop-simplifycfg -debug-only=loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa 2>&1 < %s | FileCheck %s ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require,loop(indvars,simplify-cfg)' -debug-only=loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa 2>&1 < %s | FileCheck %s @@ -7,8 +7,28 @@ ; This test demonstrates a bug in live blocks markup that is only catchable in ; inter-pass interaction. define void @test(i1 %c) { - ; CHECK-LABEL: @test( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[OUTER:%.*]] +; CHECK: outer: +; CHECK-NEXT: br i1 [[C:%.*]], label [[TO_FOLD:%.*]], label [[LATCH:%.*]] +; CHECK: to_fold: +; CHECK-NEXT: br i1 [[C]], label [[LATCH]], label [[INNER_PREHEADER:%.*]] +; CHECK: inner.preheader: +; CHECK-NEXT: br label [[INNER:%.*]] +; CHECK: inner: +; CHECK-NEXT: br i1 false, label [[INNER_LATCH:%.*]], label [[UNDEAD:%.*]] +; CHECK: inner_latch: +; CHECK-NEXT: br i1 true, label [[INNER]], label [[LATCH_LOOPEXIT:%.*]] +; CHECK: undead: +; CHECK-NEXT: br label [[LATCH]] +; CHECK: latch.loopexit: +; CHECK-NEXT: br label [[LATCH]] +; CHECK: latch: +; CHECK-NEXT: br i1 true, label [[OUTER]], label [[DEAD_EXIT:%.*]] +; CHECK: dead_exit: +; CHECK-NEXT: ret void +; entry: br label %outer