[llvm] [NFC][LV] Separate control-flow masking from tail-folding masking. (PR #169509)

Hassnaa Hamdi via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 29 15:08:18 PDT 2026


hassnaaHamdi wrote:

> Regarding the previous comment - "Wouldn't it be more correct to evaluate profitability after the tail-folding transformation has been applied, rather than before?" - this is indeed the approach behind VPlan in general: to check alternatives by first constructing their plans and then compare their relative costs. In the long run, Legal should be restricted to check obvious IfCanVectorize bailout cases only, migrating decisions HowToVectorize from recording information on immutable Instruction-based sets and maps to mutating VPlan in-place. Cost should be computed on VPlan rather than on LLVM-IR along with associated decision recordings. 
> 
> Conceptually, instructions executed conditionally, whether originally or under fold-tail, can always be vectorized - into a masked vector instruction, possibly unmasked with subsequent select, or under a replicating regions; i.e., this is a HowToVectorize decision (possibility cost-based VF-dependent) rather than an IfCanVectorize Legal one.
> 
> Currently, Legal's isMaskedOp is recording this decision for all VPlans, either all tail-folded or all not, and the patch equips Legal with another set to support both tail-folded plans and non-tail-folded plans. Further extending Legal this way sounds better than holding two Legals in the "short" term, but both sets should be migrated out of Legal eventually.
> 
> In VPlan, the decision how to mask a recipe is recorded by equipping it with a mask operand or by marking replicating recipes with isPredicated and forming replicating regions around them.
> In VPlan, whether tail is folded for a plan (or rather for a region within it) can be recorded by representing the loop region's header mask, as a RegionValue, similar to a region's CanonicalIV.
> 
> Currently, CM records this HowTo mask decision, using Legal, again considering all VPlans with tail-folded or all w/o it. Further complicating CM should arguably be avoided, to facilitate its future simplification, i.e., holding two separate CM's in the "short" term may be better.
> 
> 

Fine. Thanks so much for the detailed useful comment.

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


More information about the llvm-commits mailing list