[llvm] [VPlan] Introduce vputils::getSingleScalarClone (PR #161667)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 21 06:52:00 PDT 2025


================
@@ -250,3 +250,24 @@ vputils::getRecipesForUncountableExit(VPlan &Plan,
 
   return UncountableCondition;
 }
+
+VPSingleDefRecipe *vputils::getSingleScalarClone(VPSingleDefRecipe *R) {
+  return TypeSwitch<VPSingleDefRecipe *, VPSingleDefRecipe *>(R)
+      .Case<VPInstruction, VPWidenRecipe, VPWidenSelectRecipe,
+            VPWidenCallRecipe, VPReplicateRecipe>([](auto *I) {
+        return new VPReplicateRecipe(I->getUnderlyingInstr(), I->operands(),
+                                     /*IsSingleScalar*/ true,
+                                     /*Mask*/ nullptr,
+                                     /*Metadata*/ *I);
+      })
+      .Case<VPWidenGEPRecipe>([](auto *I) {
+        // WidenGEP does not have metadata.
+        return new VPReplicateRecipe(I->getUnderlyingInstr(), I->operands(),
+                                     /*IsSingleScalar*/ true, /*Mask*/ nullptr);
+      })
+      .Case<VPScalarIVStepsRecipe>([](auto *I) { return I->clone(); })
+      .Default([](auto *I) {
+        llvm_unreachable("Recipe not convertible to single-scalar");
----------------
david-arm wrote:

Perhaps better to say something like "Don't know how to convert to single-scalar"? It's possible we've missed something and it's actually convertible, but not implemented here yet.

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


More information about the llvm-commits mailing list