[llvm] [VPlan] Add VPInstruction to unpack vector values to scalars. (PR #155670)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 8 14:00:53 PDT 2025


================
@@ -3789,6 +3796,48 @@ void VPlanTransforms::materializeBuildVectors(VPlan &Plan) {
           });
     }
   }
+
+  // Create explicit VPInstructions to convert vectors to scalars.
+  for (VPBasicBlock *VPBB : VPBBsInsideLoopRegion) {
+    for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
+      if (isa<VPReplicateRecipe, VPInstruction, VPScalarIVStepsRecipe,
+              VPDerivedIVRecipe, VPCanonicalIVPHIRecipe>(&R))
+        continue;
+      for (VPValue *Def : R.definedValues()) {
+        // Skip recipes that are single-scalar or only have their first lane
+        // used.
+        // TODO: The Defs skipped here may or may not be vector values.
+        // Introduce Unpacks, and remove them later, if they are guaranteed to
+        // produce scalar values.
+        if (vputils::isSingleScalar(Def) || vputils::onlyFirstLaneUsed(Def))
+          continue;
+
+        // At the moment, we only create unpacks for scalar users outside
----------------
ayalz wrote:

```suggestion
        // At the moment, we create unpacks only for scalar users outside
```

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


More information about the llvm-commits mailing list