Index: llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -352,14 +352,9 @@ // Construct split preheader and the dummy switch to thread edges from it to // dead exits. BasicBlock *Preheader = L.getLoopPreheader(); - BasicBlock *NewPreheader = Preheader->splitBasicBlock( - Preheader->getTerminator(), - Twine(Preheader->getName()).concat("-split")); - if (MSSAU) - MSSAU->removeEdge(Preheader, L.getHeader()); - DTUpdates.push_back({DominatorTree::Delete, Preheader, L.getHeader()}); - DTUpdates.push_back({DominatorTree::Insert, NewPreheader, L.getHeader()}); - DTUpdates.push_back({DominatorTree::Insert, Preheader, NewPreheader}); + BasicBlock *NewPreheader = llvm::SplitBlock( + Preheader, Preheader->getTerminator(), &DT, &LI, MSSAU); + IRBuilder<> Builder(Preheader->getTerminator()); SwitchInst *DummySwitch = Builder.CreateSwitch(Builder.getInt32(0), NewPreheader); @@ -384,8 +379,6 @@ assert(L.getLoopPreheader() == NewPreheader && "Malformed CFG?"); if (Loop *OuterLoop = LI.getLoopFor(Preheader)) { - OuterLoop->addBasicBlockToLoop(NewPreheader, LI); - // When we break dead edges, the outer loop may become unreachable from // the current loop. We need to fix loop info accordingly. For this, we // find the most nested loop that still contains L and remove L from all @@ -414,10 +407,21 @@ assert(FixLCSSALoop && "Should be a loop!"); // We need all DT updates to be done before forming LCSSA. DTU.applyUpdates(DTUpdates); + if (MSSAU) + MSSAU->applyUpdates(DTUpdates, DT); DTUpdates.clear(); formLCSSARecursively(*FixLCSSALoop, DT, &LI, &SE); } } + + if (MSSAU) { + // Clear all updates now. Facilitates deletes that follow. + DTU.applyUpdates(DTUpdates); + MSSAU->applyUpdates(DTUpdates, DT); + DTUpdates.clear(); + if (VerifyMemorySSA) + MSSAU->getMemorySSA()->verifyMemorySSA(); + } } /// Delete loop blocks that have become unreachable after folding. Make all @@ -589,6 +593,9 @@ DTUpdates.clear(); } + if (MSSAU && VerifyMemorySSA) + MSSAU->getMemorySSA()->verifyMemorySSA(); + #ifndef NDEBUG // Make sure that we have preserved all data structures after the transform. assert(DT.verify() && "DT broken after transform!"); Index: llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll =================================================================== --- llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll +++ llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll @@ -1,8 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; REQUIRES: asserts -; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -debug-only=loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s -; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require,loop(simplify-cfg)' -debug-only=loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s -; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -debug-only=loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s +; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s +; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require,loop(simplify-cfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s +; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1" @@ -239,7 +239,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[DEAD:%.*]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -288,7 +288,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[DEAD:%.*]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -554,7 +554,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[EXIT:%.*]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -594,7 +594,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[EXIT:%.*]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -1197,7 +1197,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[OUTER_BACKEDGE]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -1258,7 +1258,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[OUTER_BACKEDGE]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -1320,7 +1320,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[OUTER_BACKEDGE]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -1380,7 +1380,7 @@ ; CHECK-NEXT: switch i32 0, label [[PREHEADER_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[OUTER_BACKEDGE]] ; CHECK-NEXT: ] -; CHECK: preheader-split: +; CHECK: preheader.split: ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER_SPLIT]] ], [ [[I_INC:%.*]], [[HEADER]] ] @@ -1443,7 +1443,7 @@ ; CHECK-NEXT: switch i32 0, label [[LOOP_2_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[LOOP_2_BACKEDGE]] ; CHECK-NEXT: ] -; CHECK: loop_2-split: +; CHECK: loop_2.split: ; CHECK-NEXT: br label [[LOOP_3:%.*]] ; CHECK: loop_3: ; CHECK-NEXT: [[K:%.*]] = phi i32 [ 0, [[LOOP_2_SPLIT]] ], [ [[K_NEXT:%.*]], [[LOOP_3_BACKEDGE:%.*]] ] @@ -1512,7 +1512,7 @@ ; CHECK-NEXT: switch i32 0, label [[LOOP_2_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[LOOP_2_BACKEDGE]] ; CHECK-NEXT: ] -; CHECK: loop_2-split: +; CHECK: loop_2.split: ; CHECK-NEXT: br label [[LOOP_3:%.*]] ; CHECK: loop_3: ; CHECK-NEXT: [[K:%.*]] = phi i32 [ 0, [[LOOP_2_SPLIT]] ], [ [[K_NEXT:%.*]], [[LOOP_3_BACKEDGE:%.*]] ] @@ -2590,7 +2590,7 @@ ; CHECK-NEXT: switch i32 0, label [[BB2_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[BB19:%.*]] ; CHECK-NEXT: ] -; CHECK: bb2-split: +; CHECK: bb2.split: ; CHECK-NEXT: br label [[BB3:%.*]] ; CHECK: bb3: ; CHECK-NEXT: switch i32 undef, label [[BB16:%.*]] [ Index: llvm/trunk/test/Transforms/LoopSimplifyCFG/lcssa.ll =================================================================== --- llvm/trunk/test/Transforms/LoopSimplifyCFG/lcssa.ll +++ llvm/trunk/test/Transforms/LoopSimplifyCFG/lcssa.ll @@ -62,7 +62,7 @@ ; CHECK-NEXT: switch i32 0, label [[FOR_COND_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[FOR_COND_LOOPEXIT]] ; CHECK-NEXT: ] -; CHECK: for.cond-split: +; CHECK: for.cond.split: ; CHECK-NEXT: [[INC41_LCSSA3_LCSSA:%.*]] = phi i16 [ [[INC41_LCSSA3]], [[FOR_COND]] ] ; CHECK-NEXT: br label [[WHILE_COND:%.*]] ; CHECK: while.cond: @@ -96,7 +96,7 @@ ; CHECK-NEXT: switch i32 0, label [[BB_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[BB10:%.*]] ; CHECK-NEXT: ] -; CHECK: bb-split: +; CHECK: bb.split: ; CHECK-NEXT: br label [[BB1:%.*]] ; CHECK: bb1: ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ [[TMP7:%.*]], [[BB6:%.*]] ], [ undef, [[BB_SPLIT]] ] @@ -161,7 +161,7 @@ ; CHECK-NEXT: switch i32 0, label [[ENTRY_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[DEFAULT_BB:%.*]] ; CHECK-NEXT: ] -; CHECK: entry-split: +; CHECK: entry.split: ; CHECK-NEXT: br label [[FOR_BODY:%.*]] ; CHECK: for.body: ; CHECK-NEXT: call void @foo() 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,8 +1,8 @@ ; 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 -; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -indvars -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -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 -indvars -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)' -verify-loop-info -verify-dom-info -verify-loop-lcssa 2>&1 < %s | FileCheck %s +; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -indvars -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa 2>&1 < %s | FileCheck %s define void @test(i1 %c) { ; CHECK-LABEL: @test( @@ -10,7 +10,7 @@ ; CHECK-NEXT: switch i32 0, label [[ENTRY_SPLIT:%.*]] [ ; CHECK-NEXT: i32 1, label [[DEAD_EXIT:%.*]] ; CHECK-NEXT: ] -; CHECK: entry-split: +; CHECK: entry.split: ; CHECK-NEXT: br label [[OUTER:%.*]] ; CHECK: outer: ; CHECK-NEXT: br i1 [[C:%.*]], label [[TO_FOLD:%.*]], label [[LATCH:%.*]] Index: llvm/trunk/test/Transforms/LoopSimplifyCFG/mssa_update.ll =================================================================== --- llvm/trunk/test/Transforms/LoopSimplifyCFG/mssa_update.ll +++ llvm/trunk/test/Transforms/LoopSimplifyCFG/mssa_update.ll @@ -1,6 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; REQUIRES: asserts -; XFAIL: * ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require,loop(simplify-cfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s Index: llvm/trunk/test/Transforms/LoopSimplifyCFG/update_parents.ll =================================================================== --- llvm/trunk/test/Transforms/LoopSimplifyCFG/update_parents.ll +++ llvm/trunk/test/Transforms/LoopSimplifyCFG/update_parents.ll @@ -1,8 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; REQUIRES: asserts -; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -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(simplify-cfg)' -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 -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -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 -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(simplify-cfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa 2>&1 < %s | FileCheck %s +; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa 2>&1 < %s | FileCheck %s target triple = "x86_64-unknown-linux-gnu" @@ -20,7 +20,7 @@ ; CHECK-NEXT: i32 1, label [[BB1_LOOPEXIT:%.*]] ; CHECK-NEXT: i32 2, label [[BB2_LOOPEXIT:%.*]] ; CHECK-NEXT: ] -; CHECK: bb2-split: +; CHECK: bb2.split: ; CHECK-NEXT: br label [[BB3:%.*]] ; CHECK: bb3: ; CHECK-NEXT: br label [[BB3]] @@ -61,7 +61,7 @@ ; CHECK-NEXT: i32 1, label [[BB1_LOOPEXIT:%.*]] ; CHECK-NEXT: i32 2, label [[BB2_LOOPEXIT:%.*]] ; CHECK-NEXT: ] -; CHECK: bb2-split: +; CHECK: bb2.split: ; CHECK-NEXT: br label [[BB3:%.*]] ; CHECK: bb3: ; CHECK-NEXT: br label [[BB3]]