[llvm] 17c20a6 - [SCEV] Avoid unnecessary domination checks (NFC)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 6 14:06:47 PDT 2021
On 10/6/21 1:46 PM, Nikita Popov wrote:
> On Wed, Oct 6, 2021 at 10:32 PM Philip Reames
> <listmail at philipreames.com <mailto:listmail at philipreames.com>> wrote:
>
> Er, do you actually have evidence of this being a problem? I
> would be
> very surprised if calling DT was even *remotely* expensive here,
> and I
> would strongly prefer the simpler code.
>
> Philip
>
>
> Yes, this does recover the minor regression that calling dominates()
> here introduced.
Fair enough, thanks. And again, sorry for the sharpness of tone on the
original response. That was uncalled for on my part.
>
> Also, I consider this the simpler code. I didn't like how D111191
> couples implementation details, by having to hardcode the nodes
> supported by getDefiningScopeBound() in the caller as well. Now you
> can always call it and use a non-null result.
Hm, with D111191, I can see your point. Amusingly enough the helper
function is back to the signature I'd originally proposed, largely with
this in mind. I'm not a huge fan of the need for the double check, but
given it has a demonstrated benefit, it seems called for.
Anyways, thanks!
>
> Regards,
> Nikita
>
> On 10/6/21 1:14 PM, Nikita Popov via llvm-commits wrote:
> > Author: Nikita Popov
> > Date: 2021-10-06T22:14:04+02:00
> > New Revision: 17c20a6dfb7c89ac4eb13990308b731263345918
> >
> > URL:
> https://github.com/llvm/llvm-project/commit/17c20a6dfb7c89ac4eb13990308b731263345918
> <https://github.com/llvm/llvm-project/commit/17c20a6dfb7c89ac4eb13990308b731263345918>
> > DIFF:
> https://github.com/llvm/llvm-project/commit/17c20a6dfb7c89ac4eb13990308b731263345918.diff
> <https://github.com/llvm/llvm-project/commit/17c20a6dfb7c89ac4eb13990308b731263345918.diff>
> >
> > LOG: [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.
> >
> > Added:
> >
> >
> > Modified:
> > llvm/include/llvm/Analysis/ScalarEvolution.h
> > llvm/lib/Analysis/ScalarEvolution.cpp
> >
> > Removed:
> >
> >
> >
> >
> ################################################################################
> > diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h
> b/llvm/include/llvm/Analysis/ScalarEvolution.h
> > index df1b7c2ad157..a38b1a299163 100644
> > --- a/llvm/include/llvm/Analysis/ScalarEvolution.h
> > +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
> > @@ -1921,9 +1921,10 @@ class ScalarEvolution {
> > SCEV::NoWrapFlags getNoWrapFlagsFromUB(const Value *V);
> >
> > /// 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)
> > - 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
> > /// a SCEV with the operands in Ops.
> >
> > diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp
> b/llvm/lib/Analysis/ScalarEvolution.cpp
> > index b767adac6a59..14f5dd51c406 100644
> > --- a/llvm/lib/Analysis/ScalarEvolution.cpp
> > +++ b/llvm/lib/Analysis/ScalarEvolution.cpp
> > @@ -6585,25 +6585,24 @@ SCEV::NoWrapFlags
> ScalarEvolution::getNoWrapFlagsFromUB(const Value *V) {
> > 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))
> > return &*AddRec->getLoop()->getHeader()->begin();
> > if (auto *U = dyn_cast<SCEVUnknown>(S))
> > if (auto *I = dyn_cast<Instruction>(U->getValue()))
> > return I;
> > - // All SCEVs are bound by the entry to F
> > - return &*F.getEntryBlock().begin();
> > + return nullptr;
> > }
> >
> > const Instruction *
> > ScalarEvolution::getDefiningScopeBound(ArrayRef<const SCEV *>
> Ops) {
> > - const Instruction *Bound = &*F.getEntryBlock().begin();
> > - for (auto *S : Ops) {
> > - auto *DefI = getDefiningScopeBound(S);
> > - if (DT.dominates(Bound, DefI))
> > - Bound = DefI;
> > - }
> > - return Bound;
> > + const Instruction *Bound = nullptr;
> > + for (auto *S : Ops)
> > + if (auto *DefI = getNonTrivialDefiningScopeBound(S))
> > + if (!Bound || DT.dominates(Bound, DefI))
> > + Bound = DefI;
> > + return Bound ? Bound : &*F.getEntryBlock().begin();
> > }
> >
> >
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211006/bc468901/attachment.html>
More information about the llvm-commits
mailing list