[llvm] [SelectionDAG] Legalize non-divisible scalable vector widening (PR #218777)

Harry Ramsey via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 06:52:50 PDT 2026


================
@@ -9259,6 +9242,30 @@ SDValue DAGTypeLegalizer::ModifyToType(SDValue InOp, EVT NVT,
   if (InEC.hasKnownScalarFactor(WidenEC))
     return DAG.getExtractSubvector(dl, NVT, InOp, 0);
 
+  if (NVT.isScalableVector() && InVT.isScalableVector()) {
+    // Split the input into the largest equal-sized scalable subvectors.
+    unsigned InNumElts = InVT.getVectorMinNumElements();
+    unsigned NewNumElts = NVT.getVectorMinNumElements();
+    unsigned CommonFactor = std::gcd(InNumElts, NewNumElts);
+    EVT PartVT = EVT::getVectorVT(*DAG.getContext(), NVT.getVectorElementType(),
+                                  ElementCount::getScalable(CommonFactor));
+
+    SmallVector<SDValue, 16> Ops;
+    unsigned NumCopiedParts = std::min(InNumElts, NewNumElts) / CommonFactor;
+    for (unsigned I = 0; I != NumCopiedParts; ++I)
+      Ops.push_back(
+          DAG.getExtractSubvector(dl, PartVT, InOp, I * CommonFactor));
+
+    SDValue FillVal =
+        FillWithZeroes ? DAG.getConstant(0, dl, PartVT) : DAG.getPOISON(PartVT);
----------------
Harry-Ramsey wrote:

Sorry, just didn't notice it could remain in the if statement. All fixed now.

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


More information about the llvm-commits mailing list