From 32bcb5d7fb43a4c1c81632441ec5271d94d0caf2 Mon Sep 17 00:00:00 2001 From: Balaram Makam Date: Fri, 27 Oct 2017 00:35:18 +0000 Subject: Revert "[CGP] Merge empty case blocks if no extra moves are added." This reverts commit r316711. The domtree isn't getting updated correctly. llvm-svn: 316721 --- llvm/lib/CodeGen/CodeGenPrepare.cpp | 47 +++++++++---------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp') diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 9f9bde40164..1e5f15397bb 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -212,7 +212,6 @@ class TypePromotionTransaction; const TargetTransformInfo *TTI = nullptr; const TargetLibraryInfo *TLInfo; const LoopInfo *LI; - DominatorTree *DT; std::unique_ptr BFI; std::unique_ptr BPI; @@ -263,7 +262,6 @@ class TypePromotionTransaction; void getAnalysisUsage(AnalysisUsage &AU) const override { // FIXME: When we can selectively preserve passes, preserve the domtree. - AU.addRequired(); AU.addRequired(); AU.addRequired(); AU.addRequired(); @@ -345,8 +343,6 @@ bool CodeGenPrepare::runOnFunction(Function &F) { TLInfo = &getAnalysis().getTLI(); TTI = &getAnalysis().getTTI(F); LI = &getAnalysis().getLoopInfo(); - DT = &getAnalysis().getDomTree(); - OptSize = F.optForSize(); if (ProfileGuidedSectionPrefix) { @@ -759,11 +755,6 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB, return true; SmallPtrSet SameIncomingValueBBs; - SmallVector PNs; - - for (auto DestBBI = DestBB->begin(); - auto *DestPN = dyn_cast(&*DestBBI); ++DestBBI) - PNs.push_back(DestPN); // Find all other incoming blocks from which incoming values of all PHIs in // DestBB are the same as the ones from BB. @@ -773,10 +764,16 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB, if (DestBBPred == BB) continue; - if (llvm::all_of(PNs, [&](PHINode *PN) { - return (PN->getIncomingValueForBlock(BB) == - PN->getIncomingValueForBlock(DestBBPred)); - })) + bool HasAllSameValue = true; + BasicBlock::const_iterator DestBBI = DestBB->begin(); + while (const PHINode *DestPN = dyn_cast(DestBBI++)) { + if (DestPN->getIncomingValueForBlock(BB) != + DestPN->getIncomingValueForBlock(DestBBPred)) { + HasAllSameValue = false; + break; + } + } + if (HasAllSameValue) SameIncomingValueBBs.insert(DestBBPred); } @@ -786,14 +783,6 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB, if (SameIncomingValueBBs.count(Pred)) return true; - // Check to see if none of the phis have constant incoming values for BB and - // Pred dominates DestBB, in such case extra COPYs are likely not added, so - // there is no reason to skip merging. - if (DT->dominates(Pred, DestBB) && llvm::none_of(PNs, [BB](PHINode *PN) { - return isa(PN->getIncomingValueForBlock(BB)); - })) - return true; - if (!BFI) { Function &F = *BB->getParent(); LoopInfo LI{DominatorTree(F)}; @@ -896,7 +885,7 @@ void CodeGenPrepare::eliminateMostlyEmptyBlock(BasicBlock *BB) { // Remember if SinglePred was the entry block of the function. If so, we // will need to move BB back to the entry position. bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock(); - MergeBasicBlockIntoOnlyPred(DestBB, DT); + MergeBasicBlockIntoOnlyPred(DestBB, nullptr); if (isEntry && BB != &BB->getParent()->getEntryBlock()) BB->moveBefore(&BB->getParent()->getEntryBlock()); @@ -937,21 +926,7 @@ void CodeGenPrepare::eliminateMostlyEmptyBlock(BasicBlock *BB) { // The PHIs are now updated, change everything that refers to BB to use // DestBB and remove BB. - SmallVector Updates; - for (auto *PredBB : predecessors(BB)) { - if (PredBB == BB) - continue; - DominatorTree::UpdateType UT = {DominatorTree::Delete, PredBB, BB}; - if (!is_contained(Updates, UT)) { - Updates.push_back(UT); - if (PredBB != DestBB) - Updates.push_back({DominatorTree::Insert, PredBB, DestBB}); - } - } BB->replaceAllUsesWith(DestBB); - DT->applyUpdates(Updates); - BB->getTerminator()->eraseFromParent(); - DT->deleteEdge(BB, DestBB); BB->eraseFromParent(); ++NumBlocksElim; -- cgit v1.2.3