[llvm] 6ebc12b - [SDAG] Add scalable vector support to WidenVecOp_CONCAT_VECTORS (#219146)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 05:51:05 PDT 2026
Author: Serval MARTINOT-LAGARDE
Date: 2026-09-16T13:50:58+01:00
New Revision: 6ebc12bb7d5764c08765caeb82c559e9b209ba7d
URL: https://github.com/llvm/llvm-project/commit/6ebc12bb7d5764c08765caeb82c559e9b209ba7d
DIFF: https://github.com/llvm/llvm-project/commit/6ebc12bb7d5764c08765caeb82c559e9b209ba7d.diff
LOG: [SDAG] Add scalable vector support to WidenVecOp_CONCAT_VECTORS (#219146)
This fixes a crash when lowering:
```
; llc -mattr=+sve crash.ll
define <vscale x 2 x float> @interleave2_nxv2f32(<vscale x 1 x float> %vec0, <vscale x 1 x float> %vec1) {
%retval = call <vscale x 2 x float> @llvm.vector.interleave2.nxv2f32(<vscale x 1 x float> %vec0, <vscale x 1 x float> %vec1)
ret <vscale x 2 x float> %retval
}
```
---------
Co-authored-by: Benjamin Maxwell <macdue at dueutil.tech>
Added:
llvm/test/CodeGen/AArch64/sve-interleave-of-splat.ll
Modified:
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index 35ea443edbab6..dc3b589087421 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -8072,6 +8072,18 @@ SDValue DAGTypeLegalizer::WidenVecOp_CONCAT_VECTORS(SDNode *N) {
return GetWidenedVector(N->getOperand(0));
}
+ if (VT.isScalableVector()) {
+ SDValue Result = DAG.getPOISON(VT);
+ unsigned NumInElts = InVT.getVectorMinNumElements();
+ for (unsigned i = 0; i < NumOperands; ++i) {
+ SDValue InOp = GetWidenedVector(N->getOperand(i));
+ if (InOp.getValueType() != InVT)
+ InOp = DAG.getExtractSubvector(dl, InVT, InOp, 0);
+ Result = DAG.getInsertSubvector(dl, Result, InOp, i * NumInElts);
+ }
+ return Result;
+ }
+
// Otherwise, fall back to a nasty build vector.
unsigned NumElts = VT.getVectorNumElements();
SmallVector<SDValue, 16> Ops(NumElts);
diff --git a/llvm/test/CodeGen/AArch64/sve-interleave-of-splat.ll b/llvm/test/CodeGen/AArch64/sve-interleave-of-splat.ll
new file mode 100644
index 0000000000000..b2137f0fd8587
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sve-interleave-of-splat.ll
@@ -0,0 +1,80 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc < %s | FileCheck %s
+
+target triple = "aarch64"
+
+define <vscale x 2 x float> @interleave2_nxv2f32(float %a, float %b) #0 {
+; CHECK-LABEL: interleave2_nxv2f32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT: addvl sp, sp, #-2
+; CHECK-NEXT: .cfi_escape 0x0f, 0x08, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x40, 0x1e, 0x22 // sp + 16 + 16 * VG
+; CHECK-NEXT: .cfi_offset w29, -16
+; CHECK-NEXT: // kill: def $s1 killed $s1 def $z1
+; CHECK-NEXT: // kill: def $s0 killed $s0 def $z0
+; CHECK-NEXT: rdvl x8, #1
+; CHECK-NEXT: ptrue p0.d
+; CHECK-NEXT: cntw x9
+; CHECK-NEXT: mov z0.s, s0
+; CHECK-NEXT: mov z1.s, s1
+; CHECK-NEXT: lsr x8, x8, #4
+; CHECK-NEXT: whilelo p1.d, xzr, x8
+; CHECK-NEXT: addvl x8, sp, #1
+; CHECK-NEXT: zip1 z2.d, z0.d, z1.d
+; CHECK-NEXT: trn1 z0.s, z0.s, z1.s
+; CHECK-NEXT: add x8, x8, x9
+; CHECK-NEXT: st1w { z2.d }, p0, [sp, #1, mul vl]
+; CHECK-NEXT: str z0, [sp, #1, mul vl]
+; CHECK-NEXT: ld1w { z0.d }, p1/z, [x8]
+; CHECK-NEXT: addpl x8, sp, #4
+; CHECK-NEXT: add x8, x8, x9
+; CHECK-NEXT: st1w { z0.d }, p1, [x8]
+; CHECK-NEXT: ld1w { z0.d }, p0/z, [sp, #1, mul vl]
+; CHECK-NEXT: addvl sp, sp, #2
+; CHECK-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT: ret
+ %a.insert = insertelement <vscale x 1 x float> poison, float %a, i64 0
+ %a.splat = shufflevector <vscale x 1 x float> %a.insert, <vscale x 1 x float> poison, <vscale x 1 x i32> zeroinitializer
+ %b.insert = insertelement <vscale x 1 x float> poison, float %b, i64 0
+ %b.splat = shufflevector <vscale x 1 x float> %b.insert, <vscale x 1 x float> poison, <vscale x 1 x i32> zeroinitializer
+ %res = call <vscale x 2 x float> @llvm.vector.interleave2.nxv2f32(<vscale x 1 x float> %a.splat, <vscale x 1 x float> %b.splat)
+ ret <vscale x 2 x float> %res
+}
+
+define <vscale x 4 x float> @interleave2_nxv4f32(float %a, float %b) #0 {
+; CHECK-LABEL: interleave2_nxv4f32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: // kill: def $s1 killed $s1 def $z1
+; CHECK-NEXT: // kill: def $s0 killed $s0 def $z0
+; CHECK-NEXT: mov z0.s, s0
+; CHECK-NEXT: mov z1.s, s1
+; CHECK-NEXT: trn1 z0.s, z0.s, z1.s
+; CHECK-NEXT: ret
+ %a.insert = insertelement <vscale x 2 x float> poison, float %a, i64 0
+ %a.splat = shufflevector <vscale x 2 x float> %a.insert, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer
+ %b.insert = insertelement <vscale x 2 x float> poison, float %b, i64 0
+ %b.splat = shufflevector <vscale x 2 x float> %b.insert, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer
+ %res = call <vscale x 4 x float> @llvm.vector.interleave2.nxv4f32(<vscale x 2 x float> %a.splat, <vscale x 2 x float> %b.splat)
+ ret <vscale x 4 x float> %res
+}
+
+define <vscale x 8 x float> @interleave2_nxv8f32(float %a, float %b) #0 {
+; CHECK-LABEL: interleave2_nxv8f32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: // kill: def $s1 killed $s1 def $z1
+; CHECK-NEXT: // kill: def $s0 killed $s0 def $z0
+; CHECK-NEXT: mov z2.s, s0
+; CHECK-NEXT: mov z1.s, s1
+; CHECK-NEXT: zip1 z0.s, z2.s, z1.s
+; CHECK-NEXT: zip2 z1.s, z2.s, z1.s
+; CHECK-NEXT: ret
+ %a.insert = insertelement <vscale x 4 x float> poison, float %a, i64 0
+ %a.splat = shufflevector <vscale x 4 x float> %a.insert, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
+ %b.insert = insertelement <vscale x 4 x float> poison, float %b, i64 0
+ %b.splat = shufflevector <vscale x 4 x float> %b.insert, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
+ %res = call <vscale x 8 x float> @llvm.vector.interleave2.nxv8f32(<vscale x 4 x float> %a.splat, <vscale x 4 x float> %b.splat)
+ ret <vscale x 8 x float> %res
+}
+
+
+attributes #0 = { vscale_range(1,16) "target-features"="+sve" }
More information about the llvm-commits
mailing list