Skip to content

Commit 6d52d26

Browse files
authored
Revert "[BasicBlockUtils] Fix dominator tree update for entry block in splitBlockBefore() (#178895)" (#179373)
This reverts commit ad8d534. LLVM Buildbot detected a failure, https://lab.llvm.org/buildbot/#/builders/210/builds/8229
1 parent 611f22d commit 6d52d26

2 files changed

Lines changed: 44 additions & 44 deletions

File tree

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,50 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
10541054
return SplitBlockImpl(Old, SplitPt, DTU, /*DT=*/nullptr, LI, MSSAU, BBName);
10551055
}
10561056

1057+
BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt,
1058+
DomTreeUpdater *DTU, LoopInfo *LI,
1059+
MemorySSAUpdater *MSSAU,
1060+
const Twine &BBName) {
1061+
1062+
BasicBlock::iterator SplitIt = SplitPt;
1063+
while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
1064+
++SplitIt;
1065+
std::string Name = BBName.str();
1066+
BasicBlock *New = Old->splitBasicBlockBefore(
1067+
SplitIt, Name.empty() ? Old->getName() + ".split" : Name);
1068+
1069+
// The new block lives in whichever loop the old one did. This preserves
1070+
// LCSSA as well, because we force the split point to be after any PHI nodes.
1071+
if (LI)
1072+
if (Loop *L = LI->getLoopFor(Old))
1073+
L->addBasicBlockToLoop(New, *LI);
1074+
1075+
if (DTU) {
1076+
SmallVector<DominatorTree::UpdateType, 8> DTUpdates;
1077+
// New dominates Old. The predecessor nodes of the Old node dominate
1078+
// New node.
1079+
SmallPtrSet<BasicBlock *, 8> UniquePredecessorsOfOld;
1080+
DTUpdates.push_back({DominatorTree::Insert, New, Old});
1081+
DTUpdates.reserve(DTUpdates.size() + 2 * pred_size(New));
1082+
for (BasicBlock *PredecessorOfOld : predecessors(New))
1083+
if (UniquePredecessorsOfOld.insert(PredecessorOfOld).second) {
1084+
DTUpdates.push_back({DominatorTree::Insert, PredecessorOfOld, New});
1085+
DTUpdates.push_back({DominatorTree::Delete, PredecessorOfOld, Old});
1086+
}
1087+
1088+
DTU->applyUpdates(DTUpdates);
1089+
1090+
// Move MemoryAccesses still tracked in Old, but part of New now.
1091+
// Update accesses in successor blocks accordingly.
1092+
if (MSSAU) {
1093+
MSSAU->applyUpdates(DTUpdates, DTU->getDomTree());
1094+
if (VerifyMemorySSA)
1095+
MSSAU->getMemorySSA()->verifyMemorySSA();
1096+
}
1097+
}
1098+
return New;
1099+
}
1100+
10571101
/// Update DominatorTree, LoopInfo, and LCCSA analysis information.
10581102
/// Invalidates DFS Numbering when DTU or DT is provided.
10591103
static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
@@ -1168,25 +1212,6 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
11681212
}
11691213
}
11701214

1171-
BasicBlock *llvm::splitBlockBefore(BasicBlock *Old,
1172-
BasicBlock::iterator SplitPt,
1173-
DomTreeUpdater *DTU, LoopInfo *LI,
1174-
MemorySSAUpdater *MSSAU,
1175-
const Twine &BBName) {
1176-
BasicBlock::iterator SplitIt = SplitPt;
1177-
while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
1178-
++SplitIt;
1179-
SmallVector<BasicBlock *, 4> Preds(predecessors(Old));
1180-
BasicBlock *New = Old->splitBasicBlockBefore(
1181-
SplitIt, BBName.isTriviallyEmpty() ? Old->getName() + ".split" : BBName);
1182-
1183-
bool HasLoopExit = false;
1184-
UpdateAnalysisInformation(Old, New, Preds, DTU, nullptr, LI, MSSAU, false,
1185-
HasLoopExit);
1186-
1187-
return New;
1188-
}
1189-
11901215
/// Update the PHI nodes in OrigBB to include the values coming from NewBB.
11911216
/// This also updates AliasAnalysis, if available.
11921217
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,

llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -378,31 +378,6 @@ define i32 @no_unreachable(i1 %cond) {
378378
EXPECT_TRUE(DT.verify());
379379
}
380380

381-
TEST(BasicBlockUtils, splitBlockBefore) {
382-
LLVMContext C;
383-
std::unique_ptr<Module> M = parseIR(C, R"IR(
384-
define i32 @basic_func(i1 %cond) {
385-
entry:
386-
br i1 %cond, label %bb0, label %bb1
387-
bb0:
388-
br label %bb1
389-
bb1:
390-
%phi = phi i32 [ 0, %entry ], [ 1, %bb0 ]
391-
ret i32 %phi
392-
}
393-
)IR");
394-
Function *F = M->getFunction("basic_func");
395-
DominatorTree DT(*F);
396-
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
397-
BasicBlock *EntryBB = &F->getEntryBlock();
398-
Instruction *TI = EntryBB->getTerminator();
399-
400-
// Make sure the dominator tree is properly updated if calling this on the
401-
// entry block.
402-
splitBlockBefore(EntryBB, TI, &DTU, nullptr, nullptr);
403-
EXPECT_TRUE(DTU.getDomTree().verify());
404-
}
405-
406381
TEST(BasicBlockUtils, SplitBlockPredecessors) {
407382
LLVMContext C;
408383
std::unique_ptr<Module> M = parseIR(C, R"IR(

0 commit comments

Comments
 (0)