[PATCH] D143422: [LV] Update logic for calculating register usage due to invariants

Sushant Gokhale via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 03:02:09 PST 2023


sushgokh added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:6122
+      }
     }
 
----------------
sdesmalen wrote:
> sdesmalen wrote:
> > I think you can write the algorithm above a bit shorter using a lambda:
> > 
> >   bool IsScalar = all_of(cast<Instruction>(Inst)->users(), [&](User *U) {
> >     auto *I = dyn_cast<Instruction>(U);
> >     return !I || TheLoop != LI->getLoopFor(I->getParent()) ||
> >            isScalarAfterVectorization(I, VFs[i]);
> >   });      
> >   
> >   ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[i];
> >   unsigned  ClassID = TTI.getRegisterClassForType(VF.isVector(), Inst->getType());
> >   Invariant[ClassID] += GetRegusage(Inst->getType(), VF);;
> > 
> > I think you can write the algorithm above a bit shorter using a lambda:
> > 
> >   bool IsScalar = all_of(cast<Instruction>(Inst)->users(), [&](User *U) {
> >     auto *I = dyn_cast<Instruction>(U);
> >     return !I || TheLoop != LI->getLoopFor(I->getParent()) ||
> >            isScalarAfterVectorization(I, VFs[i]);
> >   });      
> >   
> >   ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[i];
> >   unsigned  ClassID = TTI.getRegisterClassForType(VF.isVector(), Inst->getType());
> >   Invariant[ClassID] += GetRegusage(Inst->getType(), VF);;
> > 
> @sushgokh did you try the above suggestion?
> 
> When I try it locally, all the tests in your patch still pass.
@sdesmalen Yes, I tried your suggestion and all the tests passed. But,my only intention was not to assume anything(as I have stated in the comment). But if you advise, will go with your suggestion


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

https://reviews.llvm.org/D143422



More information about the llvm-commits mailing list