[llvm] [SDAG] Handle widened operands for scalable PromoteIntRes_CONCAT_VECTORS (PR #224274)
Mattéo Rizza Murgier via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 04:46:49 PDT 2026
https://github.com/matteo-rm created https://github.com/llvm/llvm-project/pull/224274
This PR implements legalization of `CONCAT_VECTORS` on scalable int vectors for the case where the result needs promoting while the operands require widening. Similar fix to D109509.
Fixes the following crash:
```llvm
; llc -mtriple=aarch64 -mattr=+sve crash.ll
define <vscale x 2 x i16> @interleave2_nxv1i16(<vscale x 1 x i16> %vec0, <vscale x 1 x i16> %vec1) {
%retval = call <vscale x 2 x i16> @llvm.vector.interleave2.nxv2i16(<vscale x 1 x i16> %vec0, <vscale x 1 x i16> %vec1)
ret <vscale x 2 x i16> %retval
}
```
>From 561aed6ed34fd83009822fe44c4087bb0341d63e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?=
<matteo.rizza-murgier at sipearl.com>
Date: Thu, 17 Sep 2026 10:48:58 +0200
Subject: [PATCH] [SDAG] Handle widened operands for scalable
PromoteIntRes_CONCAT_VECTORS
---
.../SelectionDAG/LegalizeIntegerTypes.cpp | 10 +
.../CodeGen/AArch64/sve-vector-interleave.ll | 204 +++++++++++++++++-
2 files changed, 213 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 7d61c3445ab9f..822a0f7261910 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -6322,6 +6322,16 @@ SDValue DAGTypeLegalizer::PromoteIntRes_CONCAT_VECTORS(SDNode *N) {
unsigned NumOutElem = NOutVT.getVectorMinNumElements();
EVT OutElemTy = NOutVT.getVectorElementType();
if (OutVT.isScalableVector()) {
+ // Try and concatenate from a widened type.
+ EVT InVT = N->getOperand(0).getValueType();
+ if (getTypeAction(InVT) == TargetLowering::TypeWidenVector) {
+ EVT ExtVT = InVT.changeVectorElementType(*DAG.getContext(), OutElemTy);
+ SmallVector<SDValue, 8> Ops;
+ for (SDValue Op : N->op_values())
+ Ops.push_back(DAG.getNode(ISD::ANY_EXTEND, dl, ExtVT, Op));
+ return DAG.getNode(ISD::CONCAT_VECTORS, dl, NOutVT, Ops);
+ }
+
// Find the largest promoted element type for each of the operands.
SDUse *MaxSizedValue = std::max_element(
N->op_begin(), N->op_end(), [](const SDValue &A, const SDValue &B) {
diff --git a/llvm/test/CodeGen/AArch64/sve-vector-interleave.ll b/llvm/test/CodeGen/AArch64/sve-vector-interleave.ll
index 32689d88c09ea..26670a761cf5d 100644
--- a/llvm/test/CodeGen/AArch64/sve-vector-interleave.ll
+++ b/llvm/test/CodeGen/AArch64/sve-vector-interleave.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -mattr=+sve -enable-subreg-liveness=true | FileCheck %s -check-prefixes=CHECK,SVE
+; RUN: llc < %s -mattr=+sve -sve-use-scalar-inc-vl=true -enable-subreg-liveness=true | FileCheck %s -check-prefixes=CHECK,SVE
; RUN: llc < %s -mattr=+sve,+sme2 -enable-subreg-liveness=true | FileCheck %s -check-prefixes=CHECK,SVE
; RUN: llc < %s -mattr=+sme2 -force-streaming -enable-subreg-liveness=true | FileCheck %s -check-prefixes=CHECK,SME2,SME-ALL
; RUN: llc < %s -mattr=+sme2 -force-streaming -aarch64-sve-vector-bits-min=256 -enable-subreg-liveness=true | FileCheck %s -check-prefixes=CHECK,SME2,SME2-256
@@ -868,6 +868,208 @@ define <vscale x 4 x i32> @interleave2_nxv2i32(<vscale x 2 x i32> %vec0, <vscale
ret <vscale x 4 x i32> %retval
}
+define <vscale x 2 x i8> @interleave2_nxv1i8(<vscale x 1 x i8> %vec0, <vscale x 1 x i8> %vec1) {
+; SVE-LABEL: interleave2_nxv1i8:
+; SVE: // %bb.0:
+; SVE-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; SVE-NEXT: addvl sp, sp, #-3
+; SVE-NEXT: .cfi_escape 0x0f, 0x08, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x48, 0x1e, 0x22 // sp + 16 + 24 * VG
+; SVE-NEXT: .cfi_offset w29, -16
+; SVE-NEXT: zip1 z2.b, z0.b, z1.b
+; SVE-NEXT: rdvl x8, #1
+; SVE-NEXT: zip2 z0.b, z0.b, z1.b
+; SVE-NEXT: lsr x8, x8, #4
+; SVE-NEXT: addvl x9, sp, #1
+; SVE-NEXT: uunpklo z3.h, z2.b
+; SVE-NEXT: whilelo p0.b, xzr, x8
+; SVE-NEXT: str z0, [sp, #2, mul vl]
+; SVE-NEXT: str z2, [sp, #1, mul vl]
+; SVE-NEXT: uunpklo z3.s, z3.h
+; SVE-NEXT: uunpklo z1.d, z3.s
+; SVE-NEXT: str z1, [sp]
+; SVE-NEXT: ld1b { z0.b }, p0/z, [x9, x8]
+; SVE-NEXT: mov x9, sp
+; SVE-NEXT: whilelo p0.d, xzr, x8
+; SVE-NEXT: inch x9
+; SVE-NEXT: uunpklo z0.h, z0.b
+; SVE-NEXT: uunpklo z0.s, z0.h
+; SVE-NEXT: uunpklo z0.d, z0.s
+; SVE-NEXT: st1d { z0.d }, p0, [x9]
+; SVE-NEXT: ldr z0, [sp]
+; SVE-NEXT: addvl sp, sp, #3
+; SVE-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; SVE-NEXT: ret
+;
+; SME2-LABEL: interleave2_nxv1i8:
+; SME2: // %bb.0:
+; SME2-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; SME2-NEXT: addvl sp, sp, #-1
+; SME2-NEXT: str p8, [sp, #7, mul vl] // 2-byte Spill
+; SME2-NEXT: addvl sp, sp, #-3
+; SME2-NEXT: .cfi_escape 0x0f, 0x09, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x11, 0x20, 0x1e, 0x22 // sp + 16 + 32 * VG
+; SME2-NEXT: .cfi_offset w29, -16
+; SME2-NEXT: zip { z0.b, z1.b }, z0.b, z1.b
+; SME2-NEXT: rdvl x8, #1
+; SME2-NEXT: ptrue pn8.b
+; SME2-NEXT: uunpklo z2.h, z0.b
+; SME2-NEXT: lsr x8, x8, #4
+; SME2-NEXT: addvl x9, sp, #1
+; SME2-NEXT: st1b { z0.b, z1.b }, pn8, [x9]
+; SME2-NEXT: addvl x9, sp, #1
+; SME2-NEXT: whilelo p0.b, xzr, x8
+; SME2-NEXT: uunpklo z2.s, z2.h
+; SME2-NEXT: uunpklo z2.d, z2.s
+; SME2-NEXT: str z2, [sp]
+; SME2-NEXT: ld1b { z0.b }, p0/z, [x9, x8]
+; SME2-NEXT: mov x9, sp
+; SME2-NEXT: whilelo p0.d, xzr, x8
+; SME2-NEXT: inch x9
+; SME2-NEXT: uunpklo z0.h, z0.b
+; SME2-NEXT: uunpklo z0.s, z0.h
+; SME2-NEXT: uunpklo z0.d, z0.s
+; SME2-NEXT: st1d { z0.d }, p0, [x9]
+; SME2-NEXT: ldr z0, [sp]
+; SME2-NEXT: addvl sp, sp, #3
+; SME2-NEXT: ldr p8, [sp, #7, mul vl] // 2-byte Reload
+; SME2-NEXT: addvl sp, sp, #1
+; SME2-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; SME2-NEXT: ret
+ %retval = call <vscale x 2 x i8> @llvm.vector.interleave2.nxv2i8(<vscale x 1 x i8> %vec0, <vscale x 1 x i8> %vec1)
+ ret <vscale x 2 x i8> %retval
+}
+
+define <vscale x 2 x i16> @interleave2_nxv1i16(<vscale x 1 x i16> %vec0, <vscale x 1 x i16> %vec1) {
+; SVE-LABEL: interleave2_nxv1i16:
+; SVE: // %bb.0:
+; SVE-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; SVE-NEXT: addvl sp, sp, #-3
+; SVE-NEXT: .cfi_escape 0x0f, 0x08, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x48, 0x1e, 0x22 // sp + 16 + 24 * VG
+; SVE-NEXT: .cfi_offset w29, -16
+; SVE-NEXT: zip1 z2.h, z0.h, z1.h
+; SVE-NEXT: rdvl x8, #1
+; SVE-NEXT: zip2 z0.h, z0.h, z1.h
+; SVE-NEXT: lsr x8, x8, #4
+; SVE-NEXT: addvl x9, sp, #1
+; SVE-NEXT: incd x9
+; SVE-NEXT: uunpklo z3.s, z2.h
+; SVE-NEXT: whilelo p0.h, xzr, x8
+; SVE-NEXT: str z0, [sp, #2, mul vl]
+; SVE-NEXT: str z2, [sp, #1, mul vl]
+; SVE-NEXT: uunpklo z1.d, z3.s
+; SVE-NEXT: str z1, [sp]
+; SVE-NEXT: ld1h { z0.h }, p0/z, [x9]
+; SVE-NEXT: mov x9, sp
+; SVE-NEXT: whilelo p0.d, xzr, x8
+; SVE-NEXT: inch x9
+; SVE-NEXT: uunpklo z0.s, z0.h
+; SVE-NEXT: uunpklo z0.d, z0.s
+; SVE-NEXT: st1d { z0.d }, p0, [x9]
+; SVE-NEXT: ldr z0, [sp]
+; SVE-NEXT: addvl sp, sp, #3
+; SVE-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; SVE-NEXT: ret
+;
+; SME2-LABEL: interleave2_nxv1i16:
+; SME2: // %bb.0:
+; SME2-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; SME2-NEXT: addvl sp, sp, #-1
+; SME2-NEXT: str p8, [sp, #7, mul vl] // 2-byte Spill
+; SME2-NEXT: addvl sp, sp, #-3
+; SME2-NEXT: .cfi_escape 0x0f, 0x09, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x11, 0x20, 0x1e, 0x22 // sp + 16 + 32 * VG
+; SME2-NEXT: .cfi_offset w29, -16
+; SME2-NEXT: zip { z0.h, z1.h }, z0.h, z1.h
+; SME2-NEXT: rdvl x8, #1
+; SME2-NEXT: addvl x9, sp, #1
+; SME2-NEXT: uunpklo z2.s, z0.h
+; SME2-NEXT: lsr x8, x8, #4
+; SME2-NEXT: incd x9
+; SME2-NEXT: ptrue pn8.h
+; SME2-NEXT: addvl x10, sp, #1
+; SME2-NEXT: whilelo p0.h, xzr, x8
+; SME2-NEXT: st1h { z0.h, z1.h }, pn8, [x10]
+; SME2-NEXT: uunpklo z2.d, z2.s
+; SME2-NEXT: str z2, [sp]
+; SME2-NEXT: ld1h { z0.h }, p0/z, [x9]
+; SME2-NEXT: mov x9, sp
+; SME2-NEXT: whilelo p0.d, xzr, x8
+; SME2-NEXT: inch x9
+; SME2-NEXT: uunpklo z0.s, z0.h
+; SME2-NEXT: uunpklo z0.d, z0.s
+; SME2-NEXT: st1d { z0.d }, p0, [x9]
+; SME2-NEXT: ldr z0, [sp]
+; SME2-NEXT: addvl sp, sp, #3
+; SME2-NEXT: ldr p8, [sp, #7, mul vl] // 2-byte Reload
+; SME2-NEXT: addvl sp, sp, #1
+; SME2-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; SME2-NEXT: ret
+ %retval = call <vscale x 2 x i16> @llvm.vector.interleave2.nxv2i16(<vscale x 1 x i16> %vec0, <vscale x 1 x i16> %vec1)
+ ret <vscale x 2 x i16> %retval
+}
+
+define <vscale x 2 x i32> @interleave2_nxv1i32(<vscale x 1 x i32> %vec0, <vscale x 1 x i32> %vec1) {
+; SVE-LABEL: interleave2_nxv1i32:
+; SVE: // %bb.0:
+; SVE-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; SVE-NEXT: addvl sp, sp, #-3
+; SVE-NEXT: .cfi_escape 0x0f, 0x08, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x48, 0x1e, 0x22 // sp + 16 + 24 * VG
+; SVE-NEXT: .cfi_offset w29, -16
+; SVE-NEXT: zip1 z2.s, z0.s, z1.s
+; SVE-NEXT: rdvl x8, #1
+; SVE-NEXT: zip2 z0.s, z0.s, z1.s
+; SVE-NEXT: lsr x8, x8, #4
+; SVE-NEXT: addvl x9, sp, #1
+; SVE-NEXT: incw x9
+; SVE-NEXT: uunpklo z1.d, z2.s
+; SVE-NEXT: whilelo p0.s, xzr, x8
+; SVE-NEXT: str z0, [sp, #2, mul vl]
+; SVE-NEXT: str z2, [sp, #1, mul vl]
+; SVE-NEXT: str z1, [sp]
+; SVE-NEXT: ld1w { z0.s }, p0/z, [x9]
+; SVE-NEXT: mov x9, sp
+; SVE-NEXT: whilelo p0.d, xzr, x8
+; SVE-NEXT: inch x9
+; SVE-NEXT: uunpklo z0.d, z0.s
+; SVE-NEXT: st1d { z0.d }, p0, [x9]
+; SVE-NEXT: ldr z0, [sp]
+; SVE-NEXT: addvl sp, sp, #3
+; SVE-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; SVE-NEXT: ret
+;
+; SME2-LABEL: interleave2_nxv1i32:
+; SME2: // %bb.0:
+; SME2-NEXT: str x29, [sp, #-16]! // 8-byte Folded Spill
+; SME2-NEXT: addvl sp, sp, #-1
+; SME2-NEXT: str p8, [sp, #7, mul vl] // 2-byte Spill
+; SME2-NEXT: addvl sp, sp, #-3
+; SME2-NEXT: .cfi_escape 0x0f, 0x09, 0x8f, 0x10, 0x92, 0x2e, 0x00, 0x11, 0x20, 0x1e, 0x22 // sp + 16 + 32 * VG
+; SME2-NEXT: .cfi_offset w29, -16
+; SME2-NEXT: zip { z0.s, z1.s }, z0.s, z1.s
+; SME2-NEXT: rdvl x8, #1
+; SME2-NEXT: addvl x9, sp, #1
+; SME2-NEXT: uunpklo z2.d, z0.s
+; SME2-NEXT: lsr x8, x8, #4
+; SME2-NEXT: incw x9
+; SME2-NEXT: ptrue pn8.s
+; SME2-NEXT: addvl x10, sp, #1
+; SME2-NEXT: whilelo p0.s, xzr, x8
+; SME2-NEXT: st1w { z0.s, z1.s }, pn8, [x10]
+; SME2-NEXT: str z2, [sp]
+; SME2-NEXT: ld1w { z0.s }, p0/z, [x9]
+; SME2-NEXT: mov x9, sp
+; SME2-NEXT: whilelo p0.d, xzr, x8
+; SME2-NEXT: inch x9
+; SME2-NEXT: uunpklo z0.d, z0.s
+; SME2-NEXT: st1d { z0.d }, p0, [x9]
+; SME2-NEXT: ldr z0, [sp]
+; SME2-NEXT: addvl sp, sp, #3
+; SME2-NEXT: ldr p8, [sp, #7, mul vl] // 2-byte Reload
+; SME2-NEXT: addvl sp, sp, #1
+; SME2-NEXT: ldr x29, [sp], #16 // 8-byte Folded Reload
+; SME2-NEXT: ret
+ %retval = call <vscale x 2 x i32> @llvm.vector.interleave2.nxv2i32(<vscale x 1 x i32> %vec0, <vscale x 1 x i32> %vec1)
+ ret <vscale x 2 x i32> %retval
+}
+
define <vscale x 4 x i16> @interleave2_same_const_splat_nxv4i16() {
; CHECK-LABEL: interleave2_same_const_splat_nxv4i16:
; CHECK: // %bb.0:
More information about the llvm-commits
mailing list