[llvm] [VPlan] Add vputils::reconstructSSA (PR #212209)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 02:44:04 PDT 2026
lukel97 wrote:
> Since this patch currently lacks landed real-world use cases, could we re-implement this block in `VPlanTransforms::foldTailByMasking`:
> ``` c++
> // Insert phis for values coming past the end of the tail.
> Builder.setInsertPoint(Latch, Latch->begin());
> for (const auto &[V, Users] : NeedsPhi) {
> if (isa<VPIRValue>(V))
> continue;
> VPValue *TailVal = Plan.getPoison(V->getScalarType());
> VPIRFlags Flags;
> assert(llvm::count_if(Users, IsaPred<VPReductionPHIRecipe>) <= 1 &&
> "Value used by more than two reduction phis?");
> auto *RedIt = find_if(Users, IsaPred<VPReductionPHIRecipe>);
> auto *RdxPhi =
> RedIt != Users.end() ? cast<VPReductionPHIRecipe>(*RedIt) : nullptr;
> if (RdxPhi && !RdxPhi->isInLoop()) {
> TailVal = RdxPhi;
> Flags = *RdxPhi;
> }
>
> VPInstruction *Phi = Builder.createScalarPhi({V, TailVal}, {}, "", Flags);
> for (VPUser *U : Users)
> U->replaceUsesOfWith(V, Phi);
> }
> ```
> by `reconstructSSA({{OrigLatch, V}, {Header, TailVal}}, Latch)`?
This was discussed earlier in https://github.com/llvm/llvm-project/pull/201784#discussion_r3378409300
We could, but I decided against it because we only never need to insert one phi there. reconstructSSA doesn't replace any of the uses so it doesn't shorten the code
https://github.com/llvm/llvm-project/pull/212209
More information about the llvm-commits
mailing list