[IR] Drop BasicBlockEdge::isSingleEdge (#186767)
This was only called on CondBr instructions, where it is always faster to access the successors directly than to use successors(). Multi-edges don't dominate anything, so this rare case is often already handled by dominates(). There is also a very small (hardly measurable) performance improvement here (it did show up in profiles at 0.03% or so).
This commit is contained in:
parent
92e44b247f
commit
e8a4050263
@ -111,12 +111,7 @@ public:
|
||||
return Start;
|
||||
}
|
||||
|
||||
const BasicBlock *getEnd() const {
|
||||
return End;
|
||||
}
|
||||
|
||||
/// Check if this is the only edge between Start and End.
|
||||
LLVM_ABI bool isSingleEdge() const;
|
||||
const BasicBlock *getEnd() const { return End; }
|
||||
};
|
||||
|
||||
template <> struct DenseMapInfo<BasicBlockEdge> {
|
||||
|
||||
@ -6040,11 +6040,6 @@ static bool BrPHIToSelect(DominatorTree &DT, CondBrInst *BI, PHINode *Merge,
|
||||
BasicBlockEdge LeftEdge(BI->getParent(), BI->getSuccessor(0));
|
||||
BasicBlockEdge RightEdge(BI->getParent(), BI->getSuccessor(1));
|
||||
|
||||
if (!LeftEdge.isSingleEdge())
|
||||
return false;
|
||||
|
||||
assert(RightEdge.isSingleEdge() && "Follows from LeftEdge.isSingleEdge()");
|
||||
|
||||
Use &LeftUse = Merge->getOperandUse(0);
|
||||
Use &RightUse = Merge->getOperandUse(1);
|
||||
|
||||
@ -11878,27 +11873,20 @@ bool ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
|
||||
if (!PBB)
|
||||
continue;
|
||||
|
||||
CondBrInst *ContinuePredicate = dyn_cast<CondBrInst>(PBB->getTerminator());
|
||||
if (!ContinuePredicate)
|
||||
CondBrInst *ContBr = dyn_cast<CondBrInst>(PBB->getTerminator());
|
||||
if (!ContBr || ContBr->getSuccessor(0) == ContBr->getSuccessor(1))
|
||||
continue;
|
||||
|
||||
Value *Condition = ContinuePredicate->getCondition();
|
||||
|
||||
// If we have an edge `E` within the loop body that dominates the only
|
||||
// latch, the condition guarding `E` also guards the backedge. This
|
||||
// reasoning works only for loops with a single latch.
|
||||
|
||||
BasicBlockEdge DominatingEdge(PBB, BB);
|
||||
if (DominatingEdge.isSingleEdge()) {
|
||||
// We're constructively (and conservatively) enumerating edges within the
|
||||
// loop body that dominate the latch. The dominator tree better agree
|
||||
// with us on this:
|
||||
assert(DT.dominates(DominatingEdge, Latch) && "should be!");
|
||||
|
||||
if (isImpliedCond(Pred, LHS, RHS, Condition,
|
||||
BB != ContinuePredicate->getSuccessor(0)))
|
||||
return true;
|
||||
}
|
||||
// We're constructively (and conservatively) enumerating edges within the
|
||||
// loop body that dominate the latch. The dominator tree better agree
|
||||
// with us on this:
|
||||
assert(DT.dominates(BasicBlockEdge(PBB, BB), Latch) && "should be!");
|
||||
if (isImpliedCond(Pred, LHS, RHS, ContBr->getCondition(),
|
||||
BB != ContBr->getSuccessor(0)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@ -3005,7 +3005,7 @@ static bool isKnownNonNullFromDominatingCondition(const Value *V,
|
||||
BasicBlock *NonNullSuccessor =
|
||||
BI->getSuccessor(NonNullIfTrue ? 0 : 1);
|
||||
BasicBlockEdge Edge(BI->getParent(), NonNullSuccessor);
|
||||
if (Edge.isSingleEdge() && DT->dominates(Edge, CtxI->getParent()))
|
||||
if (DT->dominates(Edge, CtxI->getParent()))
|
||||
return true;
|
||||
} else if (NonNullIfTrue && isGuard(Curr) &&
|
||||
DT->dominates(cast<Instruction>(Curr), CtxI)) {
|
||||
@ -7529,8 +7529,6 @@ bool llvm::isOverflowIntrinsicNoWrap(const WithOverflowInst *WO,
|
||||
|
||||
auto AllUsesGuardedByBranch = [&](const CondBrInst *BI) {
|
||||
BasicBlockEdge NoWrapEdge(BI->getParent(), BI->getSuccessor(1));
|
||||
if (!NoWrapEdge.isSingleEdge())
|
||||
return false;
|
||||
|
||||
// Check if all users of the add are provably no-wrap.
|
||||
for (const auto *Result : Results) {
|
||||
|
||||
@ -49,18 +49,6 @@ static constexpr bool ExpensiveChecksEnabled = true;
|
||||
static constexpr bool ExpensiveChecksEnabled = false;
|
||||
#endif
|
||||
|
||||
bool BasicBlockEdge::isSingleEdge() const {
|
||||
unsigned NumEdgesToEnd = 0;
|
||||
for (const BasicBlock *Succ : successors(Start)) {
|
||||
if (Succ == End)
|
||||
++NumEdgesToEnd;
|
||||
if (NumEdgesToEnd >= 2)
|
||||
return false;
|
||||
}
|
||||
assert(NumEdgesToEnd == 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// DominatorTree Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@ -2238,15 +2238,10 @@ void WidenIV::calculatePostIncRange(Instruction *NarrowDef,
|
||||
auto *TrueSuccessor = BI->getSuccessor(0);
|
||||
auto *FalseSuccessor = BI->getSuccessor(1);
|
||||
|
||||
auto DominatesNarrowUser = [this, NarrowUser] (BasicBlockEdge BBE) {
|
||||
return BBE.isSingleEdge() &&
|
||||
DT->dominates(BBE, NarrowUser->getParent());
|
||||
};
|
||||
|
||||
if (DominatesNarrowUser(BasicBlockEdge(BB, TrueSuccessor)))
|
||||
if (DT->dominates(BasicBlockEdge(BB, TrueSuccessor), NarrowUserBB))
|
||||
UpdateRangeFromCondition(BI->getCondition(), /*TrueDest=*/true);
|
||||
|
||||
if (DominatesNarrowUser(BasicBlockEdge(BB, FalseSuccessor)))
|
||||
if (DT->dominates(BasicBlockEdge(BB, FalseSuccessor), NarrowUserBB))
|
||||
UpdateRangeFromCondition(BI->getCondition(), /*TrueDest=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user