[llvm] [LV] Vectorize selecting last IV of min/max element. (PR #141431)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 09:26:53 PDT 2025


ayalz wrote:

> > #142322 is good and will definitely be useful in the future. However, I’m a bit confused about VPlanTransforms::legalizeUnclassifiedPhis. Do we have any plans to move legality checks into the VPlan transformation phase? What are the benefits of doing this?
> 
> We already do some legality checks in VPlan. The main one is for fixed-order recurrences, where we bail out if we fail to re-order the users of a recurrence. A number of VPlan transformations also check legality on VPlan before applying a transformation (including convertToSingleScalar). There are also some transforms that are required for legality, but work independently of LoopVectorizationLegality (e.g. dropPoisonGeneratingRecipes and the existing adjustRecipesForReductions, that converts recipes as needed for in-loop reductions).
> 
> I see the motivation similar to moving the cost model to be VPlan-based. Performing legality checks in VPlan allows combining checks directly with the transformations, which can be simpler/more direct due to not first requiring to collect the information separately in one place and then trying to translate it later to the already constructed VPlan based on IR references. It can also encourage more composable recipes. Many/most improvements over the last few years built on top of VPlan instead of the existing legacy code, and overall the approach has been very successful in my opinion.
> 
> In general, being able to perform legality checks directly on VPlan can also allow more flexibility, as we do not have to commit to a particular strategy (or check all possible strategies) early on (e.g. tail-folding vs. not folding the tail), and some legality issues can be resolved by other transforms that can be applied directly (e.g sinking/hoisting for fixed-order recurrences, peeling, distribution).
> 
> I think new capabilities serve as a great opportunity to improve and evolve the infrastructure to make sure the current VPlan representation is flexible and expressive enough to drive them
> 

Seconded.
Moving legality checks to be based on VPlan were conceived from the beginning, see last point on last slide of https://llvm.org/devmtg/2017-10/slides/Zaks-Vectorizing%20Loops%20with%20VPlan.pdf

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


More information about the llvm-commits mailing list