[llvm] Adding the support for vectorization of loops with load based tripcount (PR #209390)
Manish Srivastava via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 02:20:08 PDT 2026
================
@@ -7859,6 +7865,67 @@ static void connectEpilogueVectorLoop(VPlan &EpiPlan, Loop *L,
Phi.eraseFromParent();
}
+bool EnableLoadBoundVectorization(Loop *L, PredicatedScalarEvolution &PSE,
+ ScalarEvolution *SE, DominatorTree *DT,
+ AssumptionCache *AC) {
+ if (!L->isInnermost() || !L->isLoopSimplifyForm() ||
+ L->getNumBackEdges() != 1 || !L->getUniqueExitBlock()) {
+ return false;
+ }
+
+ if (!isa<SCEVCouldNotCompute>(SE->getBackedgeTakenCount(L))) {
+ return false;
+ }
+
+ SmallVector<Instruction *, 16> HoistedDeps;
+ SmallVector<LoadInst *, 4> BoundLoads;
+ if (!collectInvariantLoadsBoundChain(L, SE, DT, AC, HoistedDeps,
+ BoundLoads)) {
+ return false;
+ }
+
+ BasicBlock *Preheader = L->getLoopPreheader();
+ Instruction *InsertPt = Preheader->getTerminator();
+
+ DenseMap<Value *, Value *> CloneMap;
+ for (Instruction *I : HoistedDeps) {
+ Instruction *Clone = I->clone();
+ Clone->setName(I->getName() + ".bound.pre");
+ for (Use &U : Clone->operands()) {
+ if (auto *OpI = dyn_cast<Instruction>(U.get())) {
+ if (L->contains(OpI)) {
+ U.set(CloneMap[OpI]);
+ }
+ }
+ }
+ Clone->insertBefore(InsertPt->getIterator());
+ CloneMap[I] = Clone;
+ }
----------------
mk-srivastava wrote:
You are right, we can delete this hoisted clones if no vectorization happens.
But integrating this to VPlan construction can be tricky as the whole idea behind the changes as to make the loop countable from uncountable and this help the `LoopVectorizer`'s legality, LAA and other things even VPlan construction without making any major changes in it.
If the loop is uncountable then to support the vectorization we will have to make a lot of changes and at a lot of places before reaching the VPlan phase. Please correct me if I am missing anything major here.
https://github.com/llvm/llvm-project/pull/209390
More information about the llvm-commits
mailing list