Skip to content

Commit 820c8c7

Browse files
topperctstellar
authored andcommitted
[RISCV] Check isFixedLengthVector before calling getVectorNumElements in getSingleShuffleSrc. (#125455)
I have been unsuccessful at further reducing the test. The failure requires a shuffle with 2 scalable->fixed extracts with the same source. 0 is the only valid index for a scalable->fixed extract so the 2 sources must be the same extract. Shuffles with the same source are aggressively canonicalized to a unary shuffle. So it requires the extracts to become identical through other optimizations without the shuffle being canonicalized before it is lowered. Fixes #125306. (cherry picked from commit 7c5100d)
1 parent f7c7db9 commit 820c8c7

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4512,7 +4512,8 @@ static SDValue getSingleShuffleSrc(MVT VT, MVT ContainerVT, SDValue V1,
45124512

45134513
// Src needs to have twice the number of elements.
45144514
unsigned NumElts = VT.getVectorNumElements();
4515-
if (Src.getValueType().getVectorNumElements() != (NumElts * 2))
4515+
if (!Src.getValueType().isFixedLengthVector() ||
4516+
Src.getValueType().getVectorNumElements() != (NumElts * 2))
45164517
return SDValue();
45174518

45184519
// The extracts must extract the two halves of the source.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+v | FileCheck %s
3+
4+
; Test for an "Invalid size request on a scalable vector". Attempts to reduce
5+
; the test faurther were not successful. The failure requires a shuffle with 2
6+
; scalable->fixed extracts from the same vector. 0 is the only valid index for a
7+
; scalable->fixed extract so the 2 extract must be the same. Shuffles with the
8+
; same source are aggressively canonicalized to a unary shuffle so it requires
9+
; the extracts to become identical through other optimizations without the
10+
; shuffle being canonicalized before it is lowered.
11+
12+
define <2 x i32> @main(ptr %0) {
13+
; CHECK-LABEL: main:
14+
; CHECK: # %bb.0: # %entry
15+
; CHECK-NEXT: vsetivli zero, 16, e32, m4, ta, ma
16+
; CHECK-NEXT: vmv.v.i v8, 0
17+
; CHECK-NEXT: vse32.v v8, (zero)
18+
; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
19+
; CHECK-NEXT: vmv.v.i v8, 0
20+
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
21+
; CHECK-NEXT: vmv.v.i v10, 0
22+
; CHECK-NEXT: li a2, 64
23+
; CHECK-NEXT: sw zero, 80(zero)
24+
; CHECK-NEXT: lui a1, 7
25+
; CHECK-NEXT: lui a3, 1
26+
; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
27+
; CHECK-NEXT: vid.v v11
28+
; CHECK-NEXT: li a4, 16
29+
; CHECK-NEXT: lui a5, 2
30+
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
31+
; CHECK-NEXT: vse32.v v10, (a2)
32+
; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
33+
; CHECK-NEXT: vmv.v.i v10, 0
34+
; CHECK-NEXT: li a2, 24
35+
; CHECK-NEXT: sh zero, -392(a3)
36+
; CHECK-NEXT: sh zero, 534(a3)
37+
; CHECK-NEXT: sh zero, 1460(a3)
38+
; CHECK-NEXT: li a3, 32
39+
; CHECK-NEXT: vse32.v v10, (a2)
40+
; CHECK-NEXT: li a2, 40
41+
; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
42+
; CHECK-NEXT: vse32.v v8, (a0)
43+
; CHECK-NEXT: sh zero, -1710(a5)
44+
; CHECK-NEXT: sh zero, -784(a5)
45+
; CHECK-NEXT: sh zero, 142(a5)
46+
; CHECK-NEXT: lw a5, -304(a1)
47+
; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
48+
; CHECK-NEXT: vadd.vi v9, v11, -1
49+
; CHECK-NEXT: vse32.v v10, (a3)
50+
; CHECK-NEXT: sh zero, 0(a0)
51+
; CHECK-NEXT: lw a0, -188(a1)
52+
; CHECK-NEXT: vse32.v v10, (a2)
53+
; CHECK-NEXT: lw a2, -188(a1)
54+
; CHECK-NEXT: lw a3, 1244(a1)
55+
; CHECK-NEXT: vmv.v.x v8, a0
56+
; CHECK-NEXT: lw a0, 1244(a1)
57+
; CHECK-NEXT: lw a1, -304(a1)
58+
; CHECK-NEXT: vmv.v.x v10, a3
59+
; CHECK-NEXT: vmv.v.x v11, a5
60+
; CHECK-NEXT: vslide1down.vx v8, v8, zero
61+
; CHECK-NEXT: vslide1down.vx v10, v10, zero
62+
; CHECK-NEXT: vmin.vv v8, v10, v8
63+
; CHECK-NEXT: vmv.v.x v10, a0
64+
; CHECK-NEXT: vslide1down.vx v11, v11, zero
65+
; CHECK-NEXT: vmin.vx v10, v10, a2
66+
; CHECK-NEXT: vmin.vx v10, v10, a1
67+
; CHECK-NEXT: vmin.vv v11, v8, v11
68+
; CHECK-NEXT: vmv1r.v v8, v10
69+
; CHECK-NEXT: vand.vv v9, v11, v9
70+
; CHECK-NEXT: vslideup.vi v8, v10, 1
71+
; CHECK-NEXT: vse32.v v9, (a4)
72+
; CHECK-NEXT: sh zero, 0(zero)
73+
; CHECK-NEXT: ret
74+
entry:
75+
store <16 x i32> zeroinitializer, ptr null, align 4
76+
store <8 x i32> zeroinitializer, ptr %0, align 4
77+
store <4 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 64), align 4
78+
store i32 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 80), align 4
79+
%1 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
80+
%broadcast.splatinsert53 = insertelement <4 x i32> zeroinitializer, i32 %1, i64 0
81+
%2 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
82+
%broadcast.splatinsert55 = insertelement <4 x i32> zeroinitializer, i32 %2, i64 0
83+
%3 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert53, <4 x i32> %broadcast.splatinsert55)
84+
%4 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
85+
%broadcast.splatinsert57 = insertelement <4 x i32> zeroinitializer, i32 %4, i64 0
86+
%5 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %3, <4 x i32> %broadcast.splatinsert57)
87+
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 3704), align 2
88+
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 4630), align 2
89+
%6 = shufflevector <4 x i32> %5, <4 x i32> zeroinitializer, <2 x i32> <i32 0, i32 4>
90+
store <2 x i32> %6, ptr getelementptr inbounds nuw (i8, ptr null, i64 16), align 4
91+
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 5556), align 2
92+
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 6482), align 2
93+
store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 24), align 4
94+
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 7408), align 2
95+
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 8334), align 2
96+
store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 32), align 4
97+
store i16 0, ptr %0, align 2
98+
store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 4
99+
%7 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
100+
%broadcast.splatinsert165 = insertelement <4 x i32> poison, i32 %7, i64 0
101+
%8 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
102+
%broadcast.splatinsert167 = insertelement <4 x i32> poison, i32 %8, i64 0
103+
%9 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert165, <4 x i32> %broadcast.splatinsert167)
104+
%10 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
105+
%broadcast.splatinsert169 = insertelement <4 x i32> poison, i32 %10, i64 0
106+
%11 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %9, <4 x i32> %broadcast.splatinsert169)
107+
store i16 0, ptr null, align 2
108+
%12 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
109+
%broadcast.splatinsert179 = insertelement <4 x i32> poison, i32 %12, i64 0
110+
%13 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
111+
%broadcast.splatinsert181 = insertelement <4 x i32> poison, i32 %13, i64 0
112+
%14 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert179, <4 x i32> %broadcast.splatinsert181)
113+
%15 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
114+
%broadcast.splatinsert183 = insertelement <4 x i32> poison, i32 %15, i64 0
115+
%16 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %14, <4 x i32> %broadcast.splatinsert183)
116+
%17 = shufflevector <4 x i32> %11, <4 x i32> %16, <2 x i32> <i32 0, i32 4>
117+
ret <2 x i32> %17
118+
}

0 commit comments

Comments
 (0)