forked from OSchip/llvm-project
[SCEV] Avoid unnecessary domination checks (NFC)
When determining the defining scope, avoid repeatedly querying dominationg against the function entry instruction. This ends up begin a very common case that we can handle more efficiently.
This commit is contained in:
parent
62d67d9e7c
commit
17c20a6dfb
|
@ -1921,9 +1921,10 @@ private:
|
||||||
SCEV::NoWrapFlags getNoWrapFlagsFromUB(const Value *V);
|
SCEV::NoWrapFlags getNoWrapFlagsFromUB(const Value *V);
|
||||||
|
|
||||||
/// Return a scope which provides an upper bound on the defining scope of
|
/// Return a scope which provides an upper bound on the defining scope of
|
||||||
/// 'S'. Specifically, return the first instruction in said bounding scope.
|
/// 'S'. Specifically, return the first instruction in said bounding scope.
|
||||||
|
/// Return nullptr if the scope is trivial (function entry).
|
||||||
/// (See scope definition rules associated with flag discussion above)
|
/// (See scope definition rules associated with flag discussion above)
|
||||||
const Instruction *getDefiningScopeBound(const SCEV *S);
|
const Instruction *getNonTrivialDefiningScopeBound(const SCEV *S);
|
||||||
|
|
||||||
/// Return a scope which provides an upper bound on the defining scope for
|
/// Return a scope which provides an upper bound on the defining scope for
|
||||||
/// a SCEV with the operands in Ops.
|
/// a SCEV with the operands in Ops.
|
||||||
|
|
|
@ -6585,25 +6585,24 @@ SCEV::NoWrapFlags ScalarEvolution::getNoWrapFlagsFromUB(const Value *V) {
|
||||||
return isSCEVExprNeverPoison(BinOp) ? Flags : SCEV::FlagAnyWrap;
|
return isSCEVExprNeverPoison(BinOp) ? Flags : SCEV::FlagAnyWrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Instruction *ScalarEvolution::getDefiningScopeBound(const SCEV *S) {
|
const Instruction *
|
||||||
|
ScalarEvolution::getNonTrivialDefiningScopeBound(const SCEV *S) {
|
||||||
if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(S))
|
if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(S))
|
||||||
return &*AddRec->getLoop()->getHeader()->begin();
|
return &*AddRec->getLoop()->getHeader()->begin();
|
||||||
if (auto *U = dyn_cast<SCEVUnknown>(S))
|
if (auto *U = dyn_cast<SCEVUnknown>(S))
|
||||||
if (auto *I = dyn_cast<Instruction>(U->getValue()))
|
if (auto *I = dyn_cast<Instruction>(U->getValue()))
|
||||||
return I;
|
return I;
|
||||||
// All SCEVs are bound by the entry to F
|
return nullptr;
|
||||||
return &*F.getEntryBlock().begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Instruction *
|
const Instruction *
|
||||||
ScalarEvolution::getDefiningScopeBound(ArrayRef<const SCEV *> Ops) {
|
ScalarEvolution::getDefiningScopeBound(ArrayRef<const SCEV *> Ops) {
|
||||||
const Instruction *Bound = &*F.getEntryBlock().begin();
|
const Instruction *Bound = nullptr;
|
||||||
for (auto *S : Ops) {
|
for (auto *S : Ops)
|
||||||
auto *DefI = getDefiningScopeBound(S);
|
if (auto *DefI = getNonTrivialDefiningScopeBound(S))
|
||||||
if (DT.dominates(Bound, DefI))
|
if (!Bound || DT.dominates(Bound, DefI))
|
||||||
Bound = DefI;
|
Bound = DefI;
|
||||||
}
|
return Bound ? Bound : &*F.getEntryBlock().begin();
|
||||||
return Bound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue