[llvm] [VPlan] Unroll VPReplicateRecipe by VF. (PR #142433)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 03:35:36 PDT 2025


================
@@ -608,6 +608,35 @@ Value *VPInstruction::generate(VPTransformState &State) {
     return Builder.CreateVectorSplat(
         State.VF, State.get(getOperand(0), /*IsScalar*/ true), "broadcast");
   }
+  case VPInstruction::BuildStructVector: {
+    // For struct types, we need to build a new 'wide' struct type, where each
+    // element is widened.
+    auto *StructTy =
+        cast<StructType>(State.TypeAnalysis.inferScalarType(getOperand(0)));
+    auto NumOfElements = ElementCount::getFixed(getNumOperands());
+    Value *Res = PoisonValue::get(toVectorizedTy(StructTy, NumOfElements));
+    assert(NumOfElements.getKnownMinValue() == StructTy->getNumElements() &&
+           "number of operands must match number of elements in StructTy");
+    for (const auto &[Idx, Op] : enumerate(operands())) {
+      for (unsigned I = 0; I != NumOfElements.getKnownMinValue(); I++) {
----------------
ayalz wrote:

Both loops seem to always have the same trip count, namely the number of operands (i.e., width of each resulting vector), but one (`I`) should be the number of fields in the struct (i.e., number of resulting vectors)?

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


More information about the llvm-commits mailing list