[llvm] [TableGen][AArch64] Relax EnforceVectorSubVectorTypeIs for mixing fixed and scalable vectors. (PR #228552)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 15:10:00 PDT 2026


https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/228552

>From 527c807db6ce05838458970064251bde48c11d24 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Fri, 2 Oct 2026 11:37:33 -0700
Subject: [PATCH 1/2] [TableGen][AArch64] Relax EnforceVectorSubVectorTypeIs
 for mixing fixed and scalable vectors.

The minimum elements of a fixed subvector may be greater than or
equal to the minimum elements of the scalable vector when vscale
is greater than 1. Since we don't know vscale, we can't rule it out.

With that fixed, migrate AArch64 to use extract_subvector/insert_subvector
instead of vector_extract_subvec/vector_insert_subvec.
---
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td | 20 +++++++++----------
 .../TableGen/Common/CodeGenDAGPatterns.cpp    |  5 ++++-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
index 7d50afe3cbaa967..cdb7dd1e1f9ffbf 100644
--- a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
@@ -1319,13 +1319,13 @@ let Predicates = [HasSVE_or_SME] in {
   defm LD1RQ_D      : sve_mem_ldqr_ss<0b11, "ld1rqd", Z_d, ZPR64, GPR64NoXZRshifted64>;
 
   multiclass sve_ld1rq_duplane_pat<ValueType vt1, ValueType vt2, SDPatternOperator op, Instruction load_instr_imm, Instruction ptrue, Instruction load_instr_scalar, ComplexPattern AddrCP> {
-    def : Pat<(vt1 (op (vt1 (vector_insert_subvec (vt1 undef), (vt2 (load GPR64sp:$Xn)), (i64 0))), (i64 0))),
+    def : Pat<(vt1 (op (vt1 (insert_subvector (vt1 undef), (vt2 (load GPR64sp:$Xn)), (i64 0))), (i64 0))),
           (load_instr_imm (ptrue 31), GPR64sp:$Xn, 0)>;
     let AddedComplexity = 2 in {
-      def : Pat<(vt1 (op (vt1 (vector_insert_subvec (vt1 undef), (vt2 (load (add GPR64sp:$Xn, simm4s16:$imm))), (i64 0))), (i64 0))),
+      def : Pat<(vt1 (op (vt1 (insert_subvector (vt1 undef), (vt2 (load (add GPR64sp:$Xn, simm4s16:$imm))), (i64 0))), (i64 0))),
             (load_instr_imm (ptrue 31), GPR64sp:$Xn, simm4s16:$imm)>;
     }
-    def : Pat<(vt1 (op (vt1 (vector_insert_subvec (vt1 undef), (vt2 (load (AddrCP GPR64sp:$Xn, GPR64sp:$idx))), (i64 0))), (i64 0))),
+    def : Pat<(vt1 (op (vt1 (insert_subvector (vt1 undef), (vt2 (load (AddrCP GPR64sp:$Xn, GPR64sp:$idx))), (i64 0))), (i64 0))),
           (load_instr_scalar (ptrue 31), GPR64sp:$Xn, $idx)>;
   }
   defm : sve_ld1rq_duplane_pat<nxv16i8, v16i8, AArch64duplane128, LD1RQ_B_IMM, PTRUE_B, LD1RQ_B, am_sve_regreg_lsl0>;
@@ -2269,32 +2269,32 @@ let Predicates = [HasSVE_or_SME] in {
   // Insert subvectors into FP SVE vectors.
   foreach VT = [nxv4f16, nxv4f32, nxv4bf16] in
     foreach idx = [0, 2] in
-      def : Pat<(VT (vector_insert_subvec undef, SVEType<VT>.HalfLength:$src, (i64 idx))),
+      def : Pat<(VT (insert_subvector undef, SVEType<VT>.HalfLength:$src, (i64 idx))),
                 (UZP1_ZZZ_S $src, $src)>;
 
   foreach VT = [nxv8f16, nxv8bf16] in {
     foreach  idx = [0, 4] in
-      def : Pat<(VT (vector_insert_subvec undef, SVEType<VT>.HalfLength:$src, (i64 idx))),
+      def : Pat<(VT (insert_subvector undef, SVEType<VT>.HalfLength:$src, (i64 idx))),
                 (UZP1_ZZZ_H $src, $src)>;
 
     foreach idx = [0, 2, 4, 6] in
-      def : Pat<(VT (vector_insert_subvec undef, SVEType<VT>.QuarterLength:$src, (i64 idx))),
+      def : Pat<(VT (insert_subvector undef, SVEType<VT>.QuarterLength:$src, (i64 idx))),
                 (UZP1_ZZZ_H (UZP1_ZZZ_H $src, $src), (UZP1_ZZZ_H $src, $src))>;
   }
 
   // extract/insert 64-bit fixed length vector from/into a scalable vector
   foreach VT = [v8i8, v4i16, v2i32, v1i64, v4f16, v2f32, v1f64, v4bf16] in {
-    def : Pat<(VT (vector_extract_subvec NEONType<VT>.SVEContainer:$Zs, (i64 0))),
+    def : Pat<(VT (extract_subvector NEONType<VT>.SVEContainer:$Zs, (i64 0))),
               (EXTRACT_SUBREG ZPR:$Zs, dsub)>;
-    def : Pat<(NEONType<VT>.SVEContainer (vector_insert_subvec undef, (VT V64:$src), (i64 0))),
+    def : Pat<(NEONType<VT>.SVEContainer (insert_subvector undef, (VT V64:$src), (i64 0))),
               (INSERT_SUBREG (IMPLICIT_DEF), $src, dsub)>;
   }
 
   // extract/insert 128-bit fixed length vector from/into a scalable vector
   foreach VT = [v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64, v8bf16] in {
-    def : Pat<(VT (vector_extract_subvec NEONType<VT>.SVEContainer:$Zs, (i64 0))),
+    def : Pat<(VT (extract_subvector NEONType<VT>.SVEContainer:$Zs, (i64 0))),
               (EXTRACT_SUBREG ZPR:$Zs, zsub)>;
-    def : Pat<(NEONType<VT>.SVEContainer (vector_insert_subvec undef, (VT V128:$src), (i64 0))),
+    def : Pat<(NEONType<VT>.SVEContainer (insert_subvector undef, (VT V128:$src), (i64 0))),
               (INSERT_SUBREG (IMPLICIT_DEF), $src, zsub)>;
   }
 
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index dbfc7f18c08d312..e0b69b7e6e1edd0 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -657,7 +657,10 @@ bool TypeInfer::EnforceVectorSubVectorTypeIs(TypeSetByHwMode &Vec,
       return false;
     if (B.getVectorElementType() != P.getVectorElementType())
       return false;
-    return B.getVectorMinNumElements() < P.getVectorMinNumElements();
+    // We can't tell if a fixed vector is bigger than a scalable vector without
+    // knowing vscale.
+    return B.isScalableVector() != P.isScalableVector() ||
+           B.getVectorMinNumElements() < P.getVectorMinNumElements();
   };
 
   /// Return true if S has no element (vector type) that T is a sub-vector of,

>From b94b65dfc579cb6e5e2e9dc0064bba53ac04ba88 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Fri, 2 Oct 2026 14:09:48 -0700
Subject: [PATCH 2/2] fixup! Address review comment.

---
 llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index e0b69b7e6e1edd0..7fae7811d048b6e 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -657,10 +657,16 @@ bool TypeInfer::EnforceVectorSubVectorTypeIs(TypeSetByHwMode &Vec,
       return false;
     if (B.getVectorElementType() != P.getVectorElementType())
       return false;
-    // We can't tell if a fixed vector is bigger than a scalable vector without
-    // knowing vscale.
-    return B.isScalableVector() != P.isScalableVector() ||
-           B.getVectorMinNumElements() < P.getVectorMinNumElements();
+    // If the subvector and vector are both fixed or both scalable, require
+    // the minimum element count to be smaller.
+    if (B.isScalableVector() == P.isScalableVector())
+      return B.getVectorMinNumElements() < P.getVectorMinNumElements();
+
+    // If the subvector is fixed and the vector is scalable, allow the
+    // minimum number of elements to be less than or equal. Note, if vscale is
+    // known to be greater than 1, the subvector could have more than the
+    // minimum number of elements, but that would probably require custom isel.
+    return B.getVectorMinNumElements() <= P.getVectorMinNumElements();
   };
 
   /// Return true if S has no element (vector type) that T is a sub-vector of,



More information about the llvm-commits mailing list