[llvm] [VPlan] Move tail folding out of VPlanPredicator. NFC (PR #176143)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 29 01:41:00 PST 2026


lukel97 wrote:

> > Not only do you have to worry about where to insert logical-ands and deduplicating them, the big issue I found is that if you e.g. want to predicate everything past the exiting block here, you have to start dealing with control flow joins:
> 
> It seems with the the fold from #177887, the first part does not seem too bad: [d15e2db](https://github.com/llvm/llvm-project/commit/d15e2db3da528ad4bb0d8adf61fbebd4e74e2210)
> 

@fhahn sorry I missed this earlier, yeah I had also ended up with something similar. But my goal is to share this predication code for early exits in #172454, and I ran into the difficulties when I began applying the tail folding mask on top of the early exit mask.

> As for the second part, I need to think a bit more about it, but I think similarly with the explicit CFG we similarly need to make sure we insert phis to preserve SSA form?

This PR now inserts phis to preserve SSA form, and I think it simplifies things a lot (thanks @eas)

One benefit of this is that we can handle reduction phis so we don't need any special tail folding code in addReductionResultComputation: https://github.com/llvm/llvm-project/commit/2a8aaac1b08dc10bac52e21e4b4b50482002ca32
So the VPlan is "correct" after the VPlanTransforms::foldTailByMasking, and we don't need to worry about fixing it up later on.

Another benefit of is that if we eventually want to support early exit loops with reductions we won't need to do any special handling. Similarly for fault-first loads.

https://github.com/llvm/llvm-project/pull/176143


More information about the llvm-commits mailing list