<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152541>152541</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Split VPlanTransforms::addExplicitVectorLength into variable step transformation and header mask optimisation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:RISC-V,
vectorizers
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
lukel97
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lukel97
</td>
</tr>
</table>
<pre>
The transform that converts recipes into EVL recipes currently does two things:
1) It converts the vector loop region from having a fixed step of VF, to a variable step of EVL
2) It converts recipes which use the header mask to VP intrinsic based recipes
(1) changes the behaviour of the loop, whereas (2) is an optimisation to remove the need to compute a mask.
In theory we can just run (1) and still have a correct loop, because the header masks will make sure we don't execute trapping lanes etc, and we could move the (2) to VPlanTransforms::optimize.
Unfortunately we can't do this today because we somewhat conflate the two.
The main example that comes to mind is when we replace all uses of VF with EVL. When we replace it for `VPWidenIntOrFpInductionRecipe`/`VPWidenPointerInductionRecipe`/`VPScalarIVSteps`, this is for (1).
However, we also replace the VF operand in `VPVectorEndPointerRecipe`. This leaves the plan in an incorrect state until we convert `VPWidenLoadRecipe` to `VPWidenLoadEVLRecipe`, because the address is shifted in a way that requires the header mask to be removed.
A plan of action to untangle this could be:
- Adjust the `VPVectorEndPointerRecipe` VF operand alongside each load/store instead of globally
- Currently we transform all widened load/store/reduction recipes to EVL recipes. Change this to only transform them if they match the header mask
- Move the EVL recipe transformations into `VPTransforms::optimize`. Requires moving `transformRecipestoEVLRecipes` into `tryToBuildVPlanWithVPRecipes`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VU1v4zgM_TXKhWjgKM3XIYdOt8EW6GKLaTc90xYTaypLXomOm_n1C8kfTYqZBYoGkCXy8fHxEUPQR0u0FYtvQkrTvJPZrISUYvHHBBsund_2h5PcqfP2tSRgjzYcnK-AS2QonD2R5wCeCl1TAG3Zwc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