[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:52 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.
----------------
ayalz wrote:

Should this be placed above - next to "Create explicit...", to also capture skipping VPInstructions?

```suggestion
  // Current implementation is conservative - it may miss some cases that may
  // or may not be vector values. TODO: introduce Unpacks speculatively - remove
  // them later if they are known to operate on scalar values.
```

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


More information about the llvm-commits mailing list