Skip to content

Commit 63113cf

Browse files
authored
[RISCV] Remove what appears to be an unnecessary check for LMUL_8 in getSingleShuffleSrc. (#127250)
I think this dates to a time when we used to use a type twice as large as necessary for the input to the vnsrl. This was changed in #118509 when factor 4 and 8 were added. The existing test for this regresses because it uses a lot of undef elements and we previously figured out we could reduce its size and then try the vnsrl again. We now match it before we try to reduce the width so we miss this opportunity. I've added a second test that doesn't have any undef elements in the first half. Prior to this patch we used a vcompress lowering instead of vnsrl.
1 parent d7b89b0 commit 63113cf

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -4498,11 +4498,9 @@ static SDValue lowerScalarInsert(SDValue Scalar, SDValue VL, MVT VT,
44984498
}
44994499

45004500
// Can this shuffle be performed on exactly one (possibly larger) input?
4501-
static SDValue getSingleShuffleSrc(MVT VT, MVT ContainerVT, SDValue V1,
4502-
SDValue V2) {
4501+
static SDValue getSingleShuffleSrc(MVT VT, SDValue V1, SDValue V2) {
45034502

4504-
if (V2.isUndef() &&
4505-
RISCVTargetLowering::getLMUL(ContainerVT) != RISCVII::VLMUL::LMUL_8)
4503+
if (V2.isUndef())
45064504
return V1;
45074505

45084506
// Both input must be extracts.
@@ -5593,7 +5591,7 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG,
55935591
unsigned Index = 0;
55945592
if (ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, Factor, Index) &&
55955593
1 < count_if(Mask, [](int Idx) { return Idx != -1; })) {
5596-
if (SDValue Src = getSingleShuffleSrc(VT, ContainerVT, V1, V2))
5594+
if (SDValue Src = getSingleShuffleSrc(VT, V1, V2))
55975595
return getDeinterleaveShiftAndTrunc(DL, VT, Src, Factor, Index, DAG);
55985596
}
55995597
}

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shufflevector-vnsrl.ll

+36-3
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,15 @@ entry:
517517
ret void
518518
}
519519

520-
; Can't match the m8 result type as the source would have to be m16 which
521-
; isn't a legal type.
520+
; FIXME: We could use a smaller vl for the vnsrl since some elts are undefined.
522521
define void @vnsrl_0_i32_single_src_m8(ptr %in, ptr %out) {
523522
; V-LABEL: vnsrl_0_i32_single_src_m8:
524523
; V: # %bb.0: # %entry
525524
; V-NEXT: li a2, 64
526525
; V-NEXT: vsetvli zero, a2, e32, m8, ta, ma
527526
; V-NEXT: vle32.v v8, (a0)
528-
; V-NEXT: vsetivli zero, 16, e32, m2, ta, ma
527+
; V-NEXT: li a0, 32
528+
; V-NEXT: vsetvli zero, a0, e32, m4, ta, ma
529529
; V-NEXT: vnsrl.wi v16, v8, 0
530530
; V-NEXT: vsetvli zero, a2, e32, m8, ta, ma
531531
; V-NEXT: vse32.v v16, (a1)
@@ -551,3 +551,36 @@ entry:
551551
store <64 x i32> %shuffle.i5, ptr %out, align 4
552552
ret void
553553
}
554+
555+
define void @vnsrl_0_i32_single_src_m8_2(ptr %in, ptr %out) {
556+
; V-LABEL: vnsrl_0_i32_single_src_m8_2:
557+
; V: # %bb.0: # %entry
558+
; V-NEXT: li a2, 64
559+
; V-NEXT: vsetvli zero, a2, e32, m8, ta, ma
560+
; V-NEXT: vle32.v v8, (a0)
561+
; V-NEXT: li a0, 32
562+
; V-NEXT: vsetvli zero, a0, e32, m4, ta, ma
563+
; V-NEXT: vnsrl.wi v16, v8, 0
564+
; V-NEXT: vsetvli zero, a2, e32, m8, ta, ma
565+
; V-NEXT: vse32.v v16, (a1)
566+
; V-NEXT: ret
567+
;
568+
; ZVE32F-LABEL: vnsrl_0_i32_single_src_m8_2:
569+
; ZVE32F: # %bb.0: # %entry
570+
; ZVE32F-NEXT: li a2, 64
571+
; ZVE32F-NEXT: vsetvli zero, a2, e32, m8, ta, ma
572+
; ZVE32F-NEXT: vle32.v v8, (a0)
573+
; ZVE32F-NEXT: lui a0, 349525
574+
; ZVE32F-NEXT: addi a0, a0, 1365
575+
; ZVE32F-NEXT: vsetivli zero, 2, e32, m1, ta, ma
576+
; ZVE32F-NEXT: vmv.v.x v16, a0
577+
; ZVE32F-NEXT: vsetvli zero, a2, e32, m8, ta, ma
578+
; ZVE32F-NEXT: vcompress.vm v24, v8, v16
579+
; ZVE32F-NEXT: vse32.v v24, (a1)
580+
; ZVE32F-NEXT: ret
581+
entry:
582+
%0 = load <64 x i32>, ptr %in, align 4
583+
%shuffle.i5 = shufflevector <64 x i32> %0, <64 x i32> poison, <64 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18, i32 20, i32 22, i32 24, i32 26, i32 28, i32 30, i32 32, i32 34, i32 36, i32 38, i32 40, i32 42, i32 44, i32 46, i32 48, i32 50, i32 52, i32 54, i32 56, i32 58, i32 60, i32 62, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
584+
store <64 x i32> %shuffle.i5, ptr %out, align 4
585+
ret void
586+
}

0 commit comments

Comments
 (0)