[PATCH] D133017: [LV] Use SCEV to check if the trip count <= VF * UF.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 1 12:50:06 PDT 2022


fhahn marked 2 inline comments as done.
fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/VPlan.cpp:608
+        SE.getConstant(TCS->getType(), State.VF.getKnownMinValue() * State.UF);
+    if (SE.isKnownViaNonRecursiveReasoning(CmpInst::ICMP_ULE, TCS, C)) {
       auto *BOC =
----------------
Ayal wrote:
> fhahn wrote:
> > reames wrote:
> > > Please don't change the SCEV interface for this.  Just use isKnownPredicate.  You don't care if the reasoning is recursive or not.  
> > The issue here is that we would need to limit the reasoning to methods that don’t try to look at the current IR, just at the SCEV expression, because the IR is in incomplete/partially modified state.
> > 
> > Using non-recursive reasoning is a proxy for that, but I’m not sure if it provides the required guarantees in all cases.
> > 
> > The alternative would be to compute the property before we start modifying the CFG, like we do for trip count expansion.
> Analyzing and optimizing VPlan should ideally take place as VPlan2VPlan and reflected in VPlan itself before starting/preparing to execute it - at which time the IR is in incomplete/partially modified state. This case of optimizing away the latch branch for single iteration loops depends on UF which VPlan is currently agnostic to and encounters only when executing. How about cloning VPlans (also) according to which UF*VF's result in a single iteration (upto reasonable UF values - computeMaxUF()?), updating the default "UF>=1" in VPlan names and extending getBestPlanFor() to pass both VF and UF? That may admittedly require splitting ranges currently serving multiple VF's.
I put up D135017 which is a step in between: perform the simplification as VP2VP transform that's VF & UF specific. This means we simplify before IR modifications and ScalarEvolution can be used without worrying about querying while the IR is in an incomplete state.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133017/new/

https://reviews.llvm.org/D133017



More information about the llvm-commits mailing list