[llvm] [VPlan] Remove ExtractLastLane for plans with scalar VFs. (PR #171145)

via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 13 03:17:04 PST 2025


================
@@ -371,10 +371,9 @@ void UnrollState::unrollBlock(VPBlockBase *VPB) {
       continue;
     }
 
-    if (match(&R, m_ExtractLastLaneOfLastPart(m_VPValue(Op0))) ||
-        match(&R, m_ExtractPenultimateElement(m_VPValue(Op0)))) {
-      addUniformForAllParts(cast<VPSingleDefRecipe>(&R));
-      if (Plan.hasScalarVFOnly()) {
+    if (Plan.hasScalarVFOnly()) {
+      if (match(&R, m_ExtractLastPart(m_VPValue(Op0))) ||
+          match(&R, m_ExtractPenultimateElement(m_VPValue(Op0)))) {
----------------
ayalz wrote:

Right, but folding that difference seems to complicate two trivial cases, the first which should hold for any VF, scalar or not:
```
    if (match(&R, m_ExtractLastPart(m_VPValue(Op0)))) {
      cast<VPInstruction>(&R)->replaceAllUsesWith(getValueForPart(Op0, UF - 1));
      continue;
    }
```
and the second which deals with scalar VF only:
```
    if (Plan.hasScalarVFOnly() && match(&R, m_ExtractPenultimateElement(m_VPValue(Op0)))) {
      // For scalar VF, use the penultimate scalar part w/o extracting a lane.
      cast<VPInstruction>(&R)->replaceAllUsesWith(getValueForPart(Op0, UF - 2));
      continue;
    }
```
?

Are both missing `addUniformForAllParts(cast<VPSingleDefRecipe>(&R));`?



Can also hoist from below the `auto *SingleDef = dyn_cast<VPSingleDefRecipe>(&R)` to be used for the RAUW's here and `addUniformForAllParts()` elsewhere, instead of having to `cast<>(&R)` after various matches. Perhaps also handle the !SingleDef cases first, to freely access SingleDef afterwards.

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


More information about the llvm-commits mailing list