Skip to content

Commit cbcffb1

Browse files
committed
Revert "[ADCE][Dominators] Teach ADCE to preserve dominators"
This reverts commit r311039. The patch caused the `test/Bindings/OCaml/Output/scalar_opts.ml` to fail. llvm-svn: 311049
1 parent bb1b2d0 commit cbcffb1

File tree

4 files changed

+8
-106
lines changed

4 files changed

+8
-106
lines changed

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,7 @@ struct SemiNCAInfo {
914914
if (!FromTN) return;
915915

916916
const TreeNodePtr ToTN = DT.getNode(To);
917-
if (!ToTN) {
918-
DEBUG(dbgs() << "\tTo (" << BlockNamePrinter(To)
919-
<< ") already unreachable -- there is no edge to delete\n");
920-
return;
921-
}
922-
917+
assert(ToTN && "To already unreachable -- there is no edge to delete");
923918
const NodePtr NCDBlock = DT.findNearestCommonDominator(From, To);
924919
const TreeNodePtr NCD = DT.getNode(NCDBlock);
925920

llvm/lib/Transforms/Scalar/ADCE.cpp

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "llvm/IR/BasicBlock.h"
2828
#include "llvm/IR/CFG.h"
2929
#include "llvm/IR/DebugInfoMetadata.h"
30-
#include "llvm/IR/Dominators.h"
3130
#include "llvm/IR/IRBuilder.h"
3231
#include "llvm/IR/InstIterator.h"
3332
#include "llvm/IR/Instructions.h"
@@ -90,10 +89,6 @@ struct BlockInfoType {
9089

9190
class AggressiveDeadCodeElimination {
9291
Function &F;
93-
94-
// ADCE does not use DominatorTree per se, but it updates it to preserve the
95-
// analysis.
96-
DominatorTree &DT;
9792
PostDominatorTree &PDT;
9893

9994
/// Mapping of blocks to associated information, an element in BlockInfoVec.
@@ -162,10 +157,9 @@ class AggressiveDeadCodeElimination {
162157
void makeUnconditional(BasicBlock *BB, BasicBlock *Target);
163158

164159
public:
165-
AggressiveDeadCodeElimination(Function &F, DominatorTree &DT,
166-
PostDominatorTree &PDT)
167-
: F(F), DT(DT), PDT(PDT) {}
168-
bool performDeadCodeElimination();
160+
AggressiveDeadCodeElimination(Function &F, PostDominatorTree &PDT)
161+
: F(F), PDT(PDT) {}
162+
bool performDeadCodeElimination();
169163
};
170164
}
171165

@@ -563,31 +557,14 @@ void AggressiveDeadCodeElimination::updateDeadRegions() {
563557
}
564558
assert((PreferredSucc && PreferredSucc->PostOrder > 0) &&
565559
"Failed to find safe successor for dead branch");
566-
567-
// Collect removed successors to update the (Post)DominatorTrees.
568-
SmallPtrSet<BasicBlock *, 4> RemovedSuccessors;
569560
bool First = true;
570561
for (auto *Succ : successors(BB)) {
571-
if (!First || Succ != PreferredSucc->BB) {
562+
if (!First || Succ != PreferredSucc->BB)
572563
Succ->removePredecessor(BB);
573-
RemovedSuccessors.insert(Succ);
574-
} else
564+
else
575565
First = false;
576566
}
577567
makeUnconditional(BB, PreferredSucc->BB);
578-
579-
// Inform the dominators about the deleted CFG edges.
580-
for (auto *Succ : RemovedSuccessors) {
581-
// It might have happened that the same successor appeared multiple times
582-
// and the CFG edge wasn't really removed.
583-
if (Succ != PreferredSucc->BB) {
584-
DEBUG(dbgs() << "ADCE: Removing (Post)DomTree edge " << BB->getName()
585-
<< " -> " << Succ->getName() << "\n");
586-
DT.deleteEdge(BB, Succ);
587-
PDT.deleteEdge(BB, Succ);
588-
}
589-
}
590-
591568
NumBranchesRemoved += 1;
592569
}
593570
}
@@ -632,9 +609,6 @@ void AggressiveDeadCodeElimination::makeUnconditional(BasicBlock *BB,
632609
InstInfo[NewTerm].Live = true;
633610
if (const DILocation *DL = PredTerm->getDebugLoc())
634611
NewTerm->setDebugLoc(DL);
635-
636-
InstInfo.erase(PredTerm);
637-
PredTerm->eraseFromParent();
638612
}
639613

640614
//===----------------------------------------------------------------------===//
@@ -643,16 +617,13 @@ void AggressiveDeadCodeElimination::makeUnconditional(BasicBlock *BB,
643617
//
644618
//===----------------------------------------------------------------------===//
645619
PreservedAnalyses ADCEPass::run(Function &F, FunctionAnalysisManager &FAM) {
646-
auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
647620
auto &PDT = FAM.getResult<PostDominatorTreeAnalysis>(F);
648-
if (!AggressiveDeadCodeElimination(F, DT, PDT).performDeadCodeElimination())
621+
if (!AggressiveDeadCodeElimination(F, PDT).performDeadCodeElimination())
649622
return PreservedAnalyses::all();
650623

651624
PreservedAnalyses PA;
652625
PA.preserveSet<CFGAnalyses>();
653626
PA.preserve<GlobalsAA>();
654-
PA.preserve<DominatorTreeAnalysis>();
655-
PA.preserve<PostDominatorTreeAnalysis>();
656627
return PA;
657628
}
658629

@@ -666,22 +637,15 @@ struct ADCELegacyPass : public FunctionPass {
666637
bool runOnFunction(Function &F) override {
667638
if (skipFunction(F))
668639
return false;
669-
670-
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
671640
auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
672-
return AggressiveDeadCodeElimination(F, DT, PDT)
673-
.performDeadCodeElimination();
641+
return AggressiveDeadCodeElimination(F, PDT).performDeadCodeElimination();
674642
}
675643

676644
void getAnalysisUsage(AnalysisUsage &AU) const override {
677-
// We require DominatorTree here only to update and thus preserve it.
678-
AU.addRequired<DominatorTreeWrapperPass>();
679645
AU.addRequired<PostDominatorTreeWrapperPass>();
680646
if (!RemoveControlFlowFlag)
681647
AU.setPreservesCFG();
682648
AU.addPreserved<GlobalsAAWrapperPass>();
683-
AU.addPreserved<DominatorTreeWrapperPass>();
684-
AU.addPreserved<PostDominatorTreeWrapperPass>();
685649
}
686650
};
687651
}

llvm/test/Transforms/ADCE/domtree-DoubleDeletion.ll

Lines changed: 0 additions & 39 deletions
This file was deleted.

llvm/test/Transforms/ADCE/unreachable.ll

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)