[llvm] 03ceb26 - [RISCV] Fix incorrect slide offset when using vnsrl to de-interleave (#132123)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 20 09:06:28 PDT 2025
Author: Min-Yih Hsu
Date: 2025-03-20T09:06:24-07:00
New Revision: 03ceb26b55b855c64385c52020846eaa86dd278b
URL: https://github.com/llvm/llvm-project/commit/03ceb26b55b855c64385c52020846eaa86dd278b
DIFF: https://github.com/llvm/llvm-project/commit/03ceb26b55b855c64385c52020846eaa86dd278b.diff
LOG: [RISCV] Fix incorrect slide offset when using vnsrl to de-interleave (#132123)
Given this shuffle:
```
shufflevector <8 x i8> %0, <8 x i8> %1, <8 x i32> <i32 0, i32 4, i32 8, i32 12, i32 undef, i32 undef, i32 undef, i32 undef>
```
#127272 lowers it with a bunch of vnsrl. If we describe the result in
terms of the shuffle mask, we expect:
```
<0, 4, 8, 12, u, u, u, u>
```
but we actually got:
```
<0, 4, u, u, 8, 12, u, u>
```
for factor larger than 2. This is caused by `CONCAT_VECTORS` on
incorrect (sub) vector types. This patch fixes the said issue by
building an aggregate vector with the correct sub vector types.
Fix #132071
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-deinterleave.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 48d8fc23dc1bb..132faf5b85c1a 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -5545,12 +5545,25 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG,
})) {
// Narrow each source and concatenate them.
// FIXME: For small LMUL it is better to concatenate first.
- MVT HalfVT = VT.getHalfNumVectorElementsVT();
+ MVT EltVT = VT.getVectorElementType();
+ auto EltCnt = VT.getVectorElementCount();
+ MVT SubVT =
+ MVT::getVectorVT(EltVT, EltCnt.divideCoefficientBy(Factor));
+
SDValue Lo =
- getDeinterleaveShiftAndTrunc(DL, HalfVT, V1, Factor, Index, DAG);
+ getDeinterleaveShiftAndTrunc(DL, SubVT, V1, Factor, Index, DAG);
SDValue Hi =
- getDeinterleaveShiftAndTrunc(DL, HalfVT, V2, Factor, Index, DAG);
- return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, Lo, Hi);
+ getDeinterleaveShiftAndTrunc(DL, SubVT, V2, Factor, Index, DAG);
+
+ SDValue Concat =
+ DAG.getNode(ISD::CONCAT_VECTORS, DL,
+ SubVT.getDoubleNumVectorElementsVT(), Lo, Hi);
+ if (Factor == 2)
+ return Concat;
+
+ SDValue Vec = DAG.getUNDEF(VT);
+ return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, Vec, Concat,
+ DAG.getVectorIdxConstant(0, DL));
}
}
}
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-deinterleave.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-deinterleave.ll
index 5e6d7c1eedb76..0b4231cedcab5 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-deinterleave.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-deinterleave.ll
@@ -378,8 +378,9 @@ define void @deinterleave4_0_i8_two_source(ptr %in0, ptr %in1, ptr %out) {
; CHECK-NEXT: vsetvli zero, zero, e8, mf8, ta, ma
; CHECK-NEXT: vnsrl.wi v8, v8, 0
; CHECK-NEXT: vnsrl.wi v9, v9, 0
+; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
+; CHECK-NEXT: vslideup.vi v9, v8, 2
; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
-; CHECK-NEXT: vslideup.vi v9, v8, 4
; CHECK-NEXT: vse8.v v9, (a2)
; CHECK-NEXT: ret
entry:
@@ -402,8 +403,9 @@ define void @deinterleave4_8_i8_two_source(ptr %in0, ptr %in1, ptr %out) {
; CHECK-NEXT: vsetvli zero, zero, e8, mf8, ta, ma
; CHECK-NEXT: vnsrl.wi v8, v8, 0
; CHECK-NEXT: vnsrl.wi v9, v9, 0
+; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
+; CHECK-NEXT: vslideup.vi v9, v8, 2
; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
-; CHECK-NEXT: vslideup.vi v9, v8, 4
; CHECK-NEXT: vse8.v v9, (a2)
; CHECK-NEXT: ret
entry:
More information about the llvm-commits
mailing list