1; RUN: opt %s -S -riscv-gather-scatter-lowering -mtriple=riscv64 -mattr=+m,+experimental-v -riscv-v-vector-bits-min=256 | FileCheck %s
2; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+experimental-v -riscv-v-vector-bits-min=256 | FileCheck %s --check-prefix=CHECK-ASM
3
4%struct.foo = type { i32, i32, i32, i32 }
5
6; void gather(signed char * __restrict  A, signed char * __restrict B) {
7;   for (int i = 0; i != 1024; ++i)
8;       A[i] += B[i * 5];
9; }
10define void @gather(i8* noalias nocapture %A, i8* noalias nocapture readonly %B) {
11; CHECK-LABEL: @gather(
12; CHECK-NEXT:  entry:
13; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
14; CHECK:       vector.body:
15; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
16; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
17; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i8, i8* [[B:%.*]], i64 [[VEC_IND_SCALAR]]
18; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <32 x i8> @llvm.riscv.masked.strided.load.v32i8.p0i8.i64(<32 x i8> undef, i8* [[TMP0]], i64 5, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
19; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 [[INDEX]]
20; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
21; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, <32 x i8>* [[TMP2]], align 1
22; CHECK-NEXT:    [[TMP3:%.*]] = add <32 x i8> [[WIDE_LOAD]], [[WIDE_MASKED_GATHER]]
23; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
24; CHECK-NEXT:    store <32 x i8> [[TMP3]], <32 x i8>* [[TMP4]], align 1
25; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32
26; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 160
27; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
28; CHECK-NEXT:    br i1 [[TMP5]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
29; CHECK:       for.cond.cleanup:
30; CHECK-NEXT:    ret void
31;
32; CHECK-ASM-LABEL: gather:
33; CHECK-ASM:       # %bb.0: # %entry
34; CHECK-ASM-NEXT:    mv a2, zero
35; CHECK-ASM-NEXT:    addi a6, zero, 32
36; CHECK-ASM-NEXT:    addi a4, zero, 5
37; CHECK-ASM-NEXT:    addi a5, zero, 1024
38; CHECK-ASM-NEXT:  .LBB0_1: # %vector.body
39; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
40; CHECK-ASM-NEXT:    vsetvli zero, a6, e8, m1, ta, mu
41; CHECK-ASM-NEXT:    vlse8.v v8, (a1), a4
42; CHECK-ASM-NEXT:    add a3, a0, a2
43; CHECK-ASM-NEXT:    vle8.v v9, (a3)
44; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
45; CHECK-ASM-NEXT:    vse8.v v8, (a3)
46; CHECK-ASM-NEXT:    addi a2, a2, 32
47; CHECK-ASM-NEXT:    addi a1, a1, 160
48; CHECK-ASM-NEXT:    bne a2, a5, .LBB0_1
49; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
50; CHECK-ASM-NEXT:    ret
51entry:
52  br label %vector.body
53
54vector.body:                                      ; preds = %vector.body, %entry
55  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
56  %vec.ind = phi <32 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15, i64 16, i64 17, i64 18, i64 19, i64 20, i64 21, i64 22, i64 23, i64 24, i64 25, i64 26, i64 27, i64 28, i64 29, i64 30, i64 31>, %entry ], [ %vec.ind.next, %vector.body ]
57  %0 = mul nuw nsw <32 x i64> %vec.ind, <i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5>
58  %1 = getelementptr inbounds i8, i8* %B, <32 x i64> %0
59  %wide.masked.gather = call <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*> %1, i32 1, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <32 x i8> undef)
60  %2 = getelementptr inbounds i8, i8* %A, i64 %index
61  %3 = bitcast i8* %2 to <32 x i8>*
62  %wide.load = load <32 x i8>, <32 x i8>* %3, align 1
63  %4 = add <32 x i8> %wide.load, %wide.masked.gather
64  %5 = bitcast i8* %2 to <32 x i8>*
65  store <32 x i8> %4, <32 x i8>* %5, align 1
66  %index.next = add nuw i64 %index, 32
67  %vec.ind.next = add <32 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
68  %6 = icmp eq i64 %index.next, 1024
69  br i1 %6, label %for.cond.cleanup, label %vector.body
70
71for.cond.cleanup:                                 ; preds = %vector.body
72  ret void
73}
74
75define void @gather_masked(i8* noalias nocapture %A, i8* noalias nocapture readonly %B, <32 x i8> %maskedoff) {
76; CHECK-LABEL: @gather_masked(
77; CHECK-NEXT:  entry:
78; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
79; CHECK:       vector.body:
80; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
81; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
82; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i8, i8* [[B:%.*]], i64 [[VEC_IND_SCALAR]]
83; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <32 x i8> @llvm.riscv.masked.strided.load.v32i8.p0i8.i64(<32 x i8> [[MASKEDOFF:%.*]], i8* [[TMP0]], i64 5, <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>)
84; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 [[INDEX]]
85; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
86; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, <32 x i8>* [[TMP2]], align 1
87; CHECK-NEXT:    [[TMP3:%.*]] = add <32 x i8> [[WIDE_LOAD]], [[WIDE_MASKED_GATHER]]
88; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
89; CHECK-NEXT:    store <32 x i8> [[TMP3]], <32 x i8>* [[TMP4]], align 1
90; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32
91; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 160
92; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
93; CHECK-NEXT:    br i1 [[TMP5]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
94; CHECK:       for.cond.cleanup:
95; CHECK-NEXT:    ret void
96;
97; CHECK-ASM-LABEL: gather_masked:
98; CHECK-ASM:       # %bb.0: # %entry
99; CHECK-ASM-NEXT:    mv a2, zero
100; CHECK-ASM-NEXT:    lui a3, 983765
101; CHECK-ASM-NEXT:    addiw a3, a3, 873
102; CHECK-ASM-NEXT:    vsetivli zero, 1, e32, mf2, ta, mu
103; CHECK-ASM-NEXT:    vmv.s.x v0, a3
104; CHECK-ASM-NEXT:    addi a6, zero, 32
105; CHECK-ASM-NEXT:    addi a4, zero, 5
106; CHECK-ASM-NEXT:    addi a5, zero, 1024
107; CHECK-ASM-NEXT:  .LBB1_1: # %vector.body
108; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
109; CHECK-ASM-NEXT:    vsetvli zero, a6, e8, m1, ta, mu
110; CHECK-ASM-NEXT:    vmv1r.v v9, v8
111; CHECK-ASM-NEXT:    vlse8.v v9, (a1), a4, v0.t
112; CHECK-ASM-NEXT:    add a3, a0, a2
113; CHECK-ASM-NEXT:    vle8.v v10, (a3)
114; CHECK-ASM-NEXT:    vadd.vv v9, v10, v9
115; CHECK-ASM-NEXT:    vse8.v v9, (a3)
116; CHECK-ASM-NEXT:    addi a2, a2, 32
117; CHECK-ASM-NEXT:    addi a1, a1, 160
118; CHECK-ASM-NEXT:    bne a2, a5, .LBB1_1
119; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
120; CHECK-ASM-NEXT:    ret
121entry:
122  br label %vector.body
123
124vector.body:                                      ; preds = %vector.body, %entry
125  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
126  %vec.ind = phi <32 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15, i64 16, i64 17, i64 18, i64 19, i64 20, i64 21, i64 22, i64 23, i64 24, i64 25, i64 26, i64 27, i64 28, i64 29, i64 30, i64 31>, %entry ], [ %vec.ind.next, %vector.body ]
127  %0 = mul nuw nsw <32 x i64> %vec.ind, <i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5>
128  %1 = getelementptr inbounds i8, i8* %B, <32 x i64> %0
129  %wide.masked.gather = call <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*> %1, i32 1, <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>, <32 x i8> %maskedoff)
130  %2 = getelementptr inbounds i8, i8* %A, i64 %index
131  %3 = bitcast i8* %2 to <32 x i8>*
132  %wide.load = load <32 x i8>, <32 x i8>* %3, align 1
133  %4 = add <32 x i8> %wide.load, %wide.masked.gather
134  %5 = bitcast i8* %2 to <32 x i8>*
135  store <32 x i8> %4, <32 x i8>* %5, align 1
136  %index.next = add nuw i64 %index, 32
137  %vec.ind.next = add <32 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
138  %6 = icmp eq i64 %index.next, 1024
139  br i1 %6, label %for.cond.cleanup, label %vector.body
140
141for.cond.cleanup:                                 ; preds = %vector.body
142  ret void
143}
144
145define void @gather_negative_stride(i8* noalias nocapture %A, i8* noalias nocapture readonly %B) {
146; CHECK-LABEL: @gather_negative_stride(
147; CHECK-NEXT:  entry:
148; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
149; CHECK:       vector.body:
150; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
151; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 155, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
152; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i8, i8* [[B:%.*]], i64 [[VEC_IND_SCALAR]]
153; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <32 x i8> @llvm.riscv.masked.strided.load.v32i8.p0i8.i64(<32 x i8> undef, i8* [[TMP0]], i64 -5, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
154; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 [[INDEX]]
155; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
156; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, <32 x i8>* [[TMP2]], align 1
157; CHECK-NEXT:    [[TMP3:%.*]] = add <32 x i8> [[WIDE_LOAD]], [[WIDE_MASKED_GATHER]]
158; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
159; CHECK-NEXT:    store <32 x i8> [[TMP3]], <32 x i8>* [[TMP4]], align 1
160; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32
161; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 160
162; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
163; CHECK-NEXT:    br i1 [[TMP5]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
164; CHECK:       for.cond.cleanup:
165; CHECK-NEXT:    ret void
166;
167; CHECK-ASM-LABEL: gather_negative_stride:
168; CHECK-ASM:       # %bb.0: # %entry
169; CHECK-ASM-NEXT:    mv a2, zero
170; CHECK-ASM-NEXT:    addi a1, a1, 155
171; CHECK-ASM-NEXT:    addi a6, zero, 32
172; CHECK-ASM-NEXT:    addi a4, zero, -5
173; CHECK-ASM-NEXT:    addi a5, zero, 1024
174; CHECK-ASM-NEXT:  .LBB2_1: # %vector.body
175; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
176; CHECK-ASM-NEXT:    vsetvli zero, a6, e8, m1, ta, mu
177; CHECK-ASM-NEXT:    vlse8.v v8, (a1), a4
178; CHECK-ASM-NEXT:    add a3, a0, a2
179; CHECK-ASM-NEXT:    vle8.v v9, (a3)
180; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
181; CHECK-ASM-NEXT:    vse8.v v8, (a3)
182; CHECK-ASM-NEXT:    addi a2, a2, 32
183; CHECK-ASM-NEXT:    addi a1, a1, 160
184; CHECK-ASM-NEXT:    bne a2, a5, .LBB2_1
185; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
186; CHECK-ASM-NEXT:    ret
187entry:
188  br label %vector.body
189
190vector.body:                                      ; preds = %vector.body, %entry
191  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
192  %vec.ind = phi <32 x i64> [ <i64 31, i64 30, i64 29, i64 28, i64 27, i64 26, i64 25, i64 24, i64 23, i64 22, i64 21, i64 20, i64 19, i64 18, i64 17, i64 16, i64 15, i64 14, i64 13, i64 12, i64 11, i64 10, i64 9, i64 8, i64 7, i64 6, i64 5, i64 4, i64 3, i64 2, i64 1, i64 0>, %entry ], [ %vec.ind.next, %vector.body ]
193  %0 = mul nuw nsw <32 x i64> %vec.ind, <i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5>
194  %1 = getelementptr inbounds i8, i8* %B, <32 x i64> %0
195  %wide.masked.gather = call <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*> %1, i32 1, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <32 x i8> undef)
196  %2 = getelementptr inbounds i8, i8* %A, i64 %index
197  %3 = bitcast i8* %2 to <32 x i8>*
198  %wide.load = load <32 x i8>, <32 x i8>* %3, align 1
199  %4 = add <32 x i8> %wide.load, %wide.masked.gather
200  %5 = bitcast i8* %2 to <32 x i8>*
201  store <32 x i8> %4, <32 x i8>* %5, align 1
202  %index.next = add nuw i64 %index, 32
203  %vec.ind.next = add <32 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
204  %6 = icmp eq i64 %index.next, 1024
205  br i1 %6, label %for.cond.cleanup, label %vector.body
206
207for.cond.cleanup:                                 ; preds = %vector.body
208  ret void
209}
210
211define void @gather_zero_stride(i8* noalias nocapture %A, i8* noalias nocapture readonly %B) {
212; CHECK-LABEL: @gather_zero_stride(
213; CHECK-NEXT:  entry:
214; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
215; CHECK:       vector.body:
216; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
217; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
218; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i8, i8* [[B:%.*]], i64 [[VEC_IND_SCALAR]]
219; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <32 x i8> @llvm.riscv.masked.strided.load.v32i8.p0i8.i64(<32 x i8> undef, i8* [[TMP0]], i64 0, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
220; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 [[INDEX]]
221; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
222; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, <32 x i8>* [[TMP2]], align 1
223; CHECK-NEXT:    [[TMP3:%.*]] = add <32 x i8> [[WIDE_LOAD]], [[WIDE_MASKED_GATHER]]
224; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8* [[TMP1]] to <32 x i8>*
225; CHECK-NEXT:    store <32 x i8> [[TMP3]], <32 x i8>* [[TMP4]], align 1
226; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32
227; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 160
228; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
229; CHECK-NEXT:    br i1 [[TMP5]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
230; CHECK:       for.cond.cleanup:
231; CHECK-NEXT:    ret void
232;
233; CHECK-ASM-LABEL: gather_zero_stride:
234; CHECK-ASM:       # %bb.0: # %entry
235; CHECK-ASM-NEXT:    mv a2, zero
236; CHECK-ASM-NEXT:    addi a3, zero, 32
237; CHECK-ASM-NEXT:    addi a4, zero, 1024
238; CHECK-ASM-NEXT:  .LBB3_1: # %vector.body
239; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
240; CHECK-ASM-NEXT:    vsetvli zero, a3, e8, m1, ta, mu
241; CHECK-ASM-NEXT:    vlse8.v v8, (a1), zero
242; CHECK-ASM-NEXT:    add a5, a0, a2
243; CHECK-ASM-NEXT:    vle8.v v9, (a5)
244; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
245; CHECK-ASM-NEXT:    vse8.v v8, (a5)
246; CHECK-ASM-NEXT:    addi a2, a2, 32
247; CHECK-ASM-NEXT:    addi a1, a1, 160
248; CHECK-ASM-NEXT:    bne a2, a4, .LBB3_1
249; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
250; CHECK-ASM-NEXT:    ret
251entry:
252  br label %vector.body
253
254vector.body:                                      ; preds = %vector.body, %entry
255  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
256  %vec.ind = phi <32 x i64> [ zeroinitializer, %entry ], [ %vec.ind.next, %vector.body ]
257  %0 = mul nuw nsw <32 x i64> %vec.ind, <i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5>
258  %1 = getelementptr inbounds i8, i8* %B, <32 x i64> %0
259  %wide.masked.gather = call <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*> %1, i32 1, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <32 x i8> undef)
260  %2 = getelementptr inbounds i8, i8* %A, i64 %index
261  %3 = bitcast i8* %2 to <32 x i8>*
262  %wide.load = load <32 x i8>, <32 x i8>* %3, align 1
263  %4 = add <32 x i8> %wide.load, %wide.masked.gather
264  %5 = bitcast i8* %2 to <32 x i8>*
265  store <32 x i8> %4, <32 x i8>* %5, align 1
266  %index.next = add nuw i64 %index, 32
267  %vec.ind.next = add <32 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
268  %6 = icmp eq i64 %index.next, 1024
269  br i1 %6, label %for.cond.cleanup, label %vector.body
270
271for.cond.cleanup:                                 ; preds = %vector.body
272  ret void
273}
274
275;void scatter(signed char * __restrict  A, signed char * __restrict B) {
276;  for (int i = 0; i < 1024; ++i)
277;      A[i * 5] += B[i];
278;}
279define void @scatter(i8* noalias nocapture %A, i8* noalias nocapture readonly %B) {
280; CHECK-LABEL: @scatter(
281; CHECK-NEXT:  entry:
282; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
283; CHECK:       vector.body:
284; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
285; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
286; CHECK-NEXT:    [[VEC_IND_SCALAR1:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR2:%.*]], [[VECTOR_BODY]] ]
287; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i8, i8* [[B:%.*]], i64 [[INDEX]]
288; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <32 x i8>*
289; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, <32 x i8>* [[TMP1]], align 1
290; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i8, i8* [[A:%.*]], i64 [[VEC_IND_SCALAR]]
291; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i8, i8* [[A]], i64 [[VEC_IND_SCALAR1]]
292; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <32 x i8> @llvm.riscv.masked.strided.load.v32i8.p0i8.i64(<32 x i8> undef, i8* [[TMP2]], i64 5, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
293; CHECK-NEXT:    [[TMP4:%.*]] = add <32 x i8> [[WIDE_MASKED_GATHER]], [[WIDE_LOAD]]
294; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v32i8.p0i8.i64(<32 x i8> [[TMP4]], i8* [[TMP3]], i64 5, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
295; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32
296; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 160
297; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR2]] = add i64 [[VEC_IND_SCALAR1]], 160
298; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
299; CHECK-NEXT:    br i1 [[TMP5]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
300; CHECK:       for.cond.cleanup:
301; CHECK-NEXT:    ret void
302;
303; CHECK-ASM-LABEL: scatter:
304; CHECK-ASM:       # %bb.0: # %entry
305; CHECK-ASM-NEXT:    mv a2, zero
306; CHECK-ASM-NEXT:    addi a6, zero, 32
307; CHECK-ASM-NEXT:    addi a4, zero, 5
308; CHECK-ASM-NEXT:    addi a5, zero, 1024
309; CHECK-ASM-NEXT:  .LBB4_1: # %vector.body
310; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
311; CHECK-ASM-NEXT:    add a3, a1, a2
312; CHECK-ASM-NEXT:    vsetvli zero, a6, e8, m1, ta, mu
313; CHECK-ASM-NEXT:    vle8.v v8, (a3)
314; CHECK-ASM-NEXT:    vlse8.v v9, (a0), a4
315; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
316; CHECK-ASM-NEXT:    vsse8.v v8, (a0), a4
317; CHECK-ASM-NEXT:    addi a2, a2, 32
318; CHECK-ASM-NEXT:    addi a0, a0, 160
319; CHECK-ASM-NEXT:    bne a2, a5, .LBB4_1
320; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
321; CHECK-ASM-NEXT:    ret
322entry:
323  br label %vector.body
324
325vector.body:                                      ; preds = %vector.body, %entry
326  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
327  %vec.ind = phi <32 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15, i64 16, i64 17, i64 18, i64 19, i64 20, i64 21, i64 22, i64 23, i64 24, i64 25, i64 26, i64 27, i64 28, i64 29, i64 30, i64 31>, %entry ], [ %vec.ind.next, %vector.body ]
328  %0 = getelementptr inbounds i8, i8* %B, i64 %index
329  %1 = bitcast i8* %0 to <32 x i8>*
330  %wide.load = load <32 x i8>, <32 x i8>* %1, align 1
331  %2 = mul nuw nsw <32 x i64> %vec.ind, <i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5>
332  %3 = getelementptr inbounds i8, i8* %A, <32 x i64> %2
333  %wide.masked.gather = call <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*> %3, i32 1, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <32 x i8> undef)
334  %4 = add <32 x i8> %wide.masked.gather, %wide.load
335  call void @llvm.masked.scatter.v32i8.v32p0i8(<32 x i8> %4, <32 x i8*> %3, i32 1, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
336  %index.next = add nuw i64 %index, 32
337  %vec.ind.next = add <32 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
338  %5 = icmp eq i64 %index.next, 1024
339  br i1 %5, label %for.cond.cleanup, label %vector.body
340
341for.cond.cleanup:                                 ; preds = %vector.body
342  ret void
343}
344
345define void @scatter_masked(i8* noalias nocapture %A, i8* noalias nocapture readonly %B, <32 x i8> %maskedoff) {
346; CHECK-LABEL: @scatter_masked(
347; CHECK-NEXT:  entry:
348; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
349; CHECK:       vector.body:
350; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
351; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
352; CHECK-NEXT:    [[VEC_IND_SCALAR1:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR2:%.*]], [[VECTOR_BODY]] ]
353; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i8, i8* [[B:%.*]], i64 [[INDEX]]
354; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <32 x i8>*
355; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, <32 x i8>* [[TMP1]], align 1
356; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i8, i8* [[A:%.*]], i64 [[VEC_IND_SCALAR]]
357; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i8, i8* [[A]], i64 [[VEC_IND_SCALAR1]]
358; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <32 x i8> @llvm.riscv.masked.strided.load.v32i8.p0i8.i64(<32 x i8> [[MASKEDOFF:%.*]], i8* [[TMP2]], i64 5, <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>)
359; CHECK-NEXT:    [[TMP4:%.*]] = add <32 x i8> [[WIDE_MASKED_GATHER]], [[WIDE_LOAD]]
360; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v32i8.p0i8.i64(<32 x i8> [[TMP4]], i8* [[TMP3]], i64 5, <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>)
361; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32
362; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 160
363; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR2]] = add i64 [[VEC_IND_SCALAR1]], 160
364; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
365; CHECK-NEXT:    br i1 [[TMP5]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
366; CHECK:       for.cond.cleanup:
367; CHECK-NEXT:    ret void
368;
369; CHECK-ASM-LABEL: scatter_masked:
370; CHECK-ASM:       # %bb.0: # %entry
371; CHECK-ASM-NEXT:    mv a2, zero
372; CHECK-ASM-NEXT:    addi a6, zero, 32
373; CHECK-ASM-NEXT:    lui a4, 983765
374; CHECK-ASM-NEXT:    addiw a4, a4, 873
375; CHECK-ASM-NEXT:    vsetivli zero, 1, e32, mf2, ta, mu
376; CHECK-ASM-NEXT:    vmv.s.x v0, a4
377; CHECK-ASM-NEXT:    addi a4, zero, 5
378; CHECK-ASM-NEXT:    addi a5, zero, 1024
379; CHECK-ASM-NEXT:  .LBB5_1: # %vector.body
380; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
381; CHECK-ASM-NEXT:    add a3, a1, a2
382; CHECK-ASM-NEXT:    vsetvli zero, a6, e8, m1, ta, mu
383; CHECK-ASM-NEXT:    vle8.v v9, (a3)
384; CHECK-ASM-NEXT:    vmv1r.v v10, v8
385; CHECK-ASM-NEXT:    vlse8.v v10, (a0), a4, v0.t
386; CHECK-ASM-NEXT:    vadd.vv v9, v10, v9
387; CHECK-ASM-NEXT:    vsse8.v v9, (a0), a4, v0.t
388; CHECK-ASM-NEXT:    addi a2, a2, 32
389; CHECK-ASM-NEXT:    addi a0, a0, 160
390; CHECK-ASM-NEXT:    bne a2, a5, .LBB5_1
391; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
392; CHECK-ASM-NEXT:    ret
393entry:
394  br label %vector.body
395
396vector.body:                                      ; preds = %vector.body, %entry
397  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
398  %vec.ind = phi <32 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15, i64 16, i64 17, i64 18, i64 19, i64 20, i64 21, i64 22, i64 23, i64 24, i64 25, i64 26, i64 27, i64 28, i64 29, i64 30, i64 31>, %entry ], [ %vec.ind.next, %vector.body ]
399  %0 = getelementptr inbounds i8, i8* %B, i64 %index
400  %1 = bitcast i8* %0 to <32 x i8>*
401  %wide.load = load <32 x i8>, <32 x i8>* %1, align 1
402  %2 = mul nuw nsw <32 x i64> %vec.ind, <i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5, i64 5>
403  %3 = getelementptr inbounds i8, i8* %A, <32 x i64> %2
404  %wide.masked.gather = call <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*> %3, i32 1, <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>, <32 x i8> %maskedoff)
405  %4 = add <32 x i8> %wide.masked.gather, %wide.load
406  call void @llvm.masked.scatter.v32i8.v32p0i8(<32 x i8> %4, <32 x i8*> %3, i32 1, <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 true, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>)
407  %index.next = add nuw i64 %index, 32
408  %vec.ind.next = add <32 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
409  %5 = icmp eq i64 %index.next, 1024
410  br i1 %5, label %for.cond.cleanup, label %vector.body
411
412for.cond.cleanup:                                 ; preds = %vector.body
413  ret void
414}
415
416; void gather_pow2(signed char * __restrict  A, signed char * __restrict B) {
417;   for (int i = 0; i != 1024; ++i)
418;       A[i] += B[i * 4];
419; }
420define void @gather_pow2(i32* noalias nocapture %A, i32* noalias nocapture readonly %B) {
421; CHECK-LABEL: @gather_pow2(
422; CHECK-NEXT:  entry:
423; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
424; CHECK:       vector.body:
425; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
426; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
427; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i32, i32* [[B:%.*]], i64 [[VEC_IND_SCALAR]]
428; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to i8*
429; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP1]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
430; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
431; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <8 x i32>*
432; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i32>, <8 x i32>* [[TMP3]], align 1
433; CHECK-NEXT:    [[TMP4:%.*]] = add <8 x i32> [[WIDE_LOAD]], [[WIDE_MASKED_GATHER]]
434; CHECK-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP2]] to <8 x i32>*
435; CHECK-NEXT:    store <8 x i32> [[TMP4]], <8 x i32>* [[TMP5]], align 1
436; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
437; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 32
438; CHECK-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
439; CHECK-NEXT:    br i1 [[TMP6]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
440; CHECK:       for.cond.cleanup:
441; CHECK-NEXT:    ret void
442;
443; CHECK-ASM-LABEL: gather_pow2:
444; CHECK-ASM:       # %bb.0: # %entry
445; CHECK-ASM-NEXT:    addi a2, zero, 1024
446; CHECK-ASM-NEXT:    addi a3, zero, 16
447; CHECK-ASM-NEXT:    addi a4, zero, 32
448; CHECK-ASM-NEXT:  .LBB6_1: # %vector.body
449; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
450; CHECK-ASM-NEXT:    vsetivli zero, 8, e32, m1, ta, mu
451; CHECK-ASM-NEXT:    vlse32.v v8, (a1), a3
452; CHECK-ASM-NEXT:    vsetvli zero, a4, e8, m1, ta, mu
453; CHECK-ASM-NEXT:    vle8.v v9, (a0)
454; CHECK-ASM-NEXT:    vsetivli zero, 8, e32, m1, ta, mu
455; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
456; CHECK-ASM-NEXT:    vsetvli zero, a4, e8, m1, ta, mu
457; CHECK-ASM-NEXT:    vse8.v v8, (a0)
458; CHECK-ASM-NEXT:    addi a2, a2, -8
459; CHECK-ASM-NEXT:    addi a0, a0, 32
460; CHECK-ASM-NEXT:    addi a1, a1, 128
461; CHECK-ASM-NEXT:    bnez a2, .LBB6_1
462; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
463; CHECK-ASM-NEXT:    ret
464entry:
465  br label %vector.body
466
467vector.body:                                      ; preds = %vector.body, %entry
468  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
469  %vec.ind = phi <8 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7>, %entry ], [ %vec.ind.next, %vector.body ]
470  %0 = shl nsw <8 x i64> %vec.ind, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
471  %1 = getelementptr inbounds i32, i32* %B, <8 x i64> %0
472  %wide.masked.gather = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %1, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
473  %2 = getelementptr inbounds i32, i32* %A, i64 %index
474  %3 = bitcast i32* %2 to <8 x i32>*
475  %wide.load = load <8 x i32>, <8 x i32>* %3, align 1
476  %4 = add <8 x i32> %wide.load, %wide.masked.gather
477  %5 = bitcast i32* %2 to <8 x i32>*
478  store <8 x i32> %4, <8 x i32>* %5, align 1
479  %index.next = add nuw i64 %index, 8
480  %vec.ind.next = add <8 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8>
481  %6 = icmp eq i64 %index.next, 1024
482  br i1 %6, label %for.cond.cleanup, label %vector.body
483
484for.cond.cleanup:                                 ; preds = %vector.body
485  ret void
486}
487
488;void scatter_pow2(signed char * __restrict  A, signed char * __restrict B) {
489;  for (int i = 0; i < 1024; ++i)
490;      A[i * 4] += B[i];
491;}
492define void @scatter_pow2(i32* noalias nocapture %A, i32* noalias nocapture readonly %B) {
493; CHECK-LABEL: @scatter_pow2(
494; CHECK-NEXT:  entry:
495; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
496; CHECK:       vector.body:
497; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
498; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
499; CHECK-NEXT:    [[VEC_IND_SCALAR1:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR2:%.*]], [[VECTOR_BODY]] ]
500; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i32, i32* [[B:%.*]], i64 [[INDEX]]
501; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to <8 x i32>*
502; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i32>, <8 x i32>* [[TMP1]], align 1
503; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i32, i32* [[A:%.*]], i64 [[VEC_IND_SCALAR]]
504; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to i8*
505; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR1]]
506; CHECK-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to i8*
507; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP3]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
508; CHECK-NEXT:    [[TMP6:%.*]] = add <8 x i32> [[WIDE_MASKED_GATHER]], [[WIDE_LOAD]]
509; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v8i32.p0i8.i64(<8 x i32> [[TMP6]], i8* [[TMP5]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
510; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
511; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 32
512; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR2]] = add i64 [[VEC_IND_SCALAR1]], 32
513; CHECK-NEXT:    [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
514; CHECK-NEXT:    br i1 [[TMP7]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
515; CHECK:       for.cond.cleanup:
516; CHECK-NEXT:    ret void
517;
518; CHECK-ASM-LABEL: scatter_pow2:
519; CHECK-ASM:       # %bb.0: # %entry
520; CHECK-ASM-NEXT:    addi a2, zero, 1024
521; CHECK-ASM-NEXT:    addi a3, zero, 32
522; CHECK-ASM-NEXT:    addi a4, zero, 16
523; CHECK-ASM-NEXT:  .LBB7_1: # %vector.body
524; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
525; CHECK-ASM-NEXT:    vsetvli zero, a3, e8, m1, ta, mu
526; CHECK-ASM-NEXT:    vle8.v v8, (a1)
527; CHECK-ASM-NEXT:    vsetivli zero, 8, e32, m1, ta, mu
528; CHECK-ASM-NEXT:    vlse32.v v9, (a0), a4
529; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
530; CHECK-ASM-NEXT:    vsse32.v v8, (a0), a4
531; CHECK-ASM-NEXT:    addi a2, a2, -8
532; CHECK-ASM-NEXT:    addi a1, a1, 32
533; CHECK-ASM-NEXT:    addi a0, a0, 128
534; CHECK-ASM-NEXT:    bnez a2, .LBB7_1
535; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
536; CHECK-ASM-NEXT:    ret
537entry:
538  br label %vector.body
539
540vector.body:                                      ; preds = %vector.body, %entry
541  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
542  %vec.ind = phi <8 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7>, %entry ], [ %vec.ind.next, %vector.body ]
543  %0 = getelementptr inbounds i32, i32* %B, i64 %index
544  %1 = bitcast i32* %0 to <8 x i32>*
545  %wide.load = load <8 x i32>, <8 x i32>* %1, align 1
546  %2 = shl nuw nsw <8 x i64> %vec.ind, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
547  %3 = getelementptr inbounds i32, i32* %A, <8 x i64> %2
548  %wide.masked.gather = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %3, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
549  %4 = add <8 x i32> %wide.masked.gather, %wide.load
550  call void @llvm.masked.scatter.v8i32.v8p0i32(<8 x i32> %4, <8 x i32*> %3, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
551  %index.next = add nuw i64 %index, 8
552  %vec.ind.next = add <8 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8>
553  %5 = icmp eq i64 %index.next, 1024
554  br i1 %5, label %for.cond.cleanup, label %vector.body
555
556for.cond.cleanup:                                 ; preds = %vector.body
557  ret void
558}
559
560;struct foo {
561;  int a, b, c, d;
562;};
563;
564;void struct_gather(int * __restrict  A, struct foo * __restrict B) {
565;  for (int i = 0; i < 1024; ++i)
566;      A[i] += B[i].b;
567;}
568define void @struct_gather(i32* noalias nocapture %A, %struct.foo* noalias nocapture readonly %B) {
569; CHECK-LABEL: @struct_gather(
570; CHECK-NEXT:  entry:
571; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
572; CHECK:       vector.body:
573; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
574; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
575; CHECK-NEXT:    [[VEC_IND_SCALAR1:%.*]] = phi i64 [ 8, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR2:%.*]], [[VECTOR_BODY]] ]
576; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr [[STRUCT_FOO:%.*]], %struct.foo* [[B:%.*]], i64 [[VEC_IND_SCALAR]], i32 1
577; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to i8*
578; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr [[STRUCT_FOO]], %struct.foo* [[B]], i64 [[VEC_IND_SCALAR1]], i32 1
579; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to i8*
580; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP1]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
581; CHECK-NEXT:    [[WIDE_MASKED_GATHER9:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP3]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
582; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
583; CHECK-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <8 x i32>*
584; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i32>, <8 x i32>* [[TMP5]], align 4
585; CHECK-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i32, i32* [[TMP4]], i64 8
586; CHECK-NEXT:    [[TMP7:%.*]] = bitcast i32* [[TMP6]] to <8 x i32>*
587; CHECK-NEXT:    [[WIDE_LOAD10:%.*]] = load <8 x i32>, <8 x i32>* [[TMP7]], align 4
588; CHECK-NEXT:    [[TMP8:%.*]] = add nsw <8 x i32> [[WIDE_LOAD]], [[WIDE_MASKED_GATHER]]
589; CHECK-NEXT:    [[TMP9:%.*]] = add nsw <8 x i32> [[WIDE_LOAD10]], [[WIDE_MASKED_GATHER9]]
590; CHECK-NEXT:    [[TMP10:%.*]] = bitcast i32* [[TMP4]] to <8 x i32>*
591; CHECK-NEXT:    store <8 x i32> [[TMP8]], <8 x i32>* [[TMP10]], align 4
592; CHECK-NEXT:    [[TMP11:%.*]] = bitcast i32* [[TMP6]] to <8 x i32>*
593; CHECK-NEXT:    store <8 x i32> [[TMP9]], <8 x i32>* [[TMP11]], align 4
594; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
595; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 16
596; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR2]] = add i64 [[VEC_IND_SCALAR1]], 16
597; CHECK-NEXT:    [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
598; CHECK-NEXT:    br i1 [[TMP12]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
599; CHECK:       for.cond.cleanup:
600; CHECK-NEXT:    ret void
601;
602; CHECK-ASM-LABEL: struct_gather:
603; CHECK-ASM:       # %bb.0: # %entry
604; CHECK-ASM-NEXT:    addi a0, a0, 32
605; CHECK-ASM-NEXT:    addi a1, a1, 132
606; CHECK-ASM-NEXT:    addi a2, zero, 1024
607; CHECK-ASM-NEXT:    addi a3, zero, 16
608; CHECK-ASM-NEXT:  .LBB8_1: # %vector.body
609; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
610; CHECK-ASM-NEXT:    addi a4, a1, -128
611; CHECK-ASM-NEXT:    vsetivli zero, 8, e32, m1, ta, mu
612; CHECK-ASM-NEXT:    vlse32.v v8, (a4), a3
613; CHECK-ASM-NEXT:    vlse32.v v9, (a1), a3
614; CHECK-ASM-NEXT:    addi a4, a0, -32
615; CHECK-ASM-NEXT:    vle32.v v10, (a4)
616; CHECK-ASM-NEXT:    vle32.v v11, (a0)
617; CHECK-ASM-NEXT:    vadd.vv v8, v10, v8
618; CHECK-ASM-NEXT:    vadd.vv v9, v11, v9
619; CHECK-ASM-NEXT:    vse32.v v8, (a4)
620; CHECK-ASM-NEXT:    vse32.v v9, (a0)
621; CHECK-ASM-NEXT:    addi a2, a2, -16
622; CHECK-ASM-NEXT:    addi a0, a0, 64
623; CHECK-ASM-NEXT:    addi a1, a1, 256
624; CHECK-ASM-NEXT:    bnez a2, .LBB8_1
625; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
626; CHECK-ASM-NEXT:    ret
627entry:
628  br label %vector.body
629
630vector.body:                                      ; preds = %vector.body, %entry
631  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
632  %vec.ind = phi <8 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7>, %entry ], [ %vec.ind.next, %vector.body ]
633  %step.add = add <8 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8>
634  %0 = getelementptr inbounds %struct.foo, %struct.foo* %B, <8 x i64> %vec.ind, i32 1
635  %1 = getelementptr inbounds %struct.foo, %struct.foo* %B, <8 x i64> %step.add, i32 1
636  %wide.masked.gather = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %0, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
637  %wide.masked.gather9 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %1, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
638  %2 = getelementptr inbounds i32, i32* %A, i64 %index
639  %3 = bitcast i32* %2 to <8 x i32>*
640  %wide.load = load <8 x i32>, <8 x i32>* %3, align 4
641  %4 = getelementptr inbounds i32, i32* %2, i64 8
642  %5 = bitcast i32* %4 to <8 x i32>*
643  %wide.load10 = load <8 x i32>, <8 x i32>* %5, align 4
644  %6 = add nsw <8 x i32> %wide.load, %wide.masked.gather
645  %7 = add nsw <8 x i32> %wide.load10, %wide.masked.gather9
646  %8 = bitcast i32* %2 to <8 x i32>*
647  store <8 x i32> %6, <8 x i32>* %8, align 4
648  %9 = bitcast i32* %4 to <8 x i32>*
649  store <8 x i32> %7, <8 x i32>* %9, align 4
650  %index.next = add nuw i64 %index, 16
651  %vec.ind.next = add <8 x i64> %vec.ind, <i64 16, i64 16, i64 16, i64 16, i64 16, i64 16, i64 16, i64 16>
652  %10 = icmp eq i64 %index.next, 1024
653  br i1 %10, label %for.cond.cleanup, label %vector.body
654
655for.cond.cleanup:                                 ; preds = %vector.body
656  ret void
657}
658
659;void gather_unroll(int * __restrict  A, int * __restrict B) {
660;  for (int i = 0; i < 1024; i+= 4 ) {
661;    A[i] += B[i * 4];
662;    A[i+1] += B[(i+1) * 4];
663;    A[i+2] += B[(i+2) * 4];
664;    A[i+3] += B[(i+3) * 4];
665;  }
666;}
667define void @gather_unroll(i32* noalias nocapture %A, i32* noalias nocapture readonly %B) {
668; CHECK-LABEL: @gather_unroll(
669; CHECK-NEXT:  entry:
670; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
671; CHECK:       vector.body:
672; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
673; CHECK-NEXT:    [[VEC_IND_SCALAR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR:%.*]], [[VECTOR_BODY]] ]
674; CHECK-NEXT:    [[VEC_IND_SCALAR1:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR2:%.*]], [[VECTOR_BODY]] ]
675; CHECK-NEXT:    [[VEC_IND_SCALAR3:%.*]] = phi i64 [ 4, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR4:%.*]], [[VECTOR_BODY]] ]
676; CHECK-NEXT:    [[VEC_IND_SCALAR5:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR6:%.*]], [[VECTOR_BODY]] ]
677; CHECK-NEXT:    [[VEC_IND_SCALAR7:%.*]] = phi i64 [ 8, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR8:%.*]], [[VECTOR_BODY]] ]
678; CHECK-NEXT:    [[VEC_IND_SCALAR9:%.*]] = phi i64 [ 2, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR10:%.*]], [[VECTOR_BODY]] ]
679; CHECK-NEXT:    [[VEC_IND_SCALAR11:%.*]] = phi i64 [ 12, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR12:%.*]], [[VECTOR_BODY]] ]
680; CHECK-NEXT:    [[VEC_IND_SCALAR13:%.*]] = phi i64 [ 3, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR14:%.*]], [[VECTOR_BODY]] ]
681; CHECK-NEXT:    [[VEC_IND_SCALAR15:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR16:%.*]], [[VECTOR_BODY]] ]
682; CHECK-NEXT:    [[VEC_IND_SCALAR17:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR18:%.*]], [[VECTOR_BODY]] ]
683; CHECK-NEXT:    [[VEC_IND_SCALAR19:%.*]] = phi i64 [ 2, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR20:%.*]], [[VECTOR_BODY]] ]
684; CHECK-NEXT:    [[VEC_IND_SCALAR21:%.*]] = phi i64 [ 3, [[ENTRY]] ], [ [[VEC_IND_NEXT_SCALAR22:%.*]], [[VECTOR_BODY]] ]
685; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i32, i32* [[B:%.*]], i64 [[VEC_IND_SCALAR]]
686; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to i8*
687; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP1]], i64 64, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
688; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i32, i32* [[A:%.*]], i64 [[VEC_IND_SCALAR1]]
689; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to i8*
690; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR15]]
691; CHECK-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to i8*
692; CHECK-NEXT:    [[WIDE_MASKED_GATHER52:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP3]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
693; CHECK-NEXT:    [[TMP6:%.*]] = add nsw <8 x i32> [[WIDE_MASKED_GATHER52]], [[WIDE_MASKED_GATHER]]
694; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v8i32.p0i8.i64(<8 x i32> [[TMP6]], i8* [[TMP5]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
695; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr i32, i32* [[B]], i64 [[VEC_IND_SCALAR3]]
696; CHECK-NEXT:    [[TMP8:%.*]] = bitcast i32* [[TMP7]] to i8*
697; CHECK-NEXT:    [[WIDE_MASKED_GATHER53:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP8]], i64 64, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
698; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR5]]
699; CHECK-NEXT:    [[TMP10:%.*]] = bitcast i32* [[TMP9]] to i8*
700; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR17]]
701; CHECK-NEXT:    [[TMP12:%.*]] = bitcast i32* [[TMP11]] to i8*
702; CHECK-NEXT:    [[WIDE_MASKED_GATHER54:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP10]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
703; CHECK-NEXT:    [[TMP13:%.*]] = add nsw <8 x i32> [[WIDE_MASKED_GATHER54]], [[WIDE_MASKED_GATHER53]]
704; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v8i32.p0i8.i64(<8 x i32> [[TMP13]], i8* [[TMP12]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
705; CHECK-NEXT:    [[TMP14:%.*]] = getelementptr i32, i32* [[B]], i64 [[VEC_IND_SCALAR7]]
706; CHECK-NEXT:    [[TMP15:%.*]] = bitcast i32* [[TMP14]] to i8*
707; CHECK-NEXT:    [[WIDE_MASKED_GATHER55:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP15]], i64 64, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
708; CHECK-NEXT:    [[TMP16:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR9]]
709; CHECK-NEXT:    [[TMP17:%.*]] = bitcast i32* [[TMP16]] to i8*
710; CHECK-NEXT:    [[TMP18:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR19]]
711; CHECK-NEXT:    [[TMP19:%.*]] = bitcast i32* [[TMP18]] to i8*
712; CHECK-NEXT:    [[WIDE_MASKED_GATHER56:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP17]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
713; CHECK-NEXT:    [[TMP20:%.*]] = add nsw <8 x i32> [[WIDE_MASKED_GATHER56]], [[WIDE_MASKED_GATHER55]]
714; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v8i32.p0i8.i64(<8 x i32> [[TMP20]], i8* [[TMP19]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
715; CHECK-NEXT:    [[TMP21:%.*]] = getelementptr i32, i32* [[B]], i64 [[VEC_IND_SCALAR11]]
716; CHECK-NEXT:    [[TMP22:%.*]] = bitcast i32* [[TMP21]] to i8*
717; CHECK-NEXT:    [[WIDE_MASKED_GATHER57:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP22]], i64 64, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
718; CHECK-NEXT:    [[TMP23:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR13]]
719; CHECK-NEXT:    [[TMP24:%.*]] = bitcast i32* [[TMP23]] to i8*
720; CHECK-NEXT:    [[TMP25:%.*]] = getelementptr i32, i32* [[A]], i64 [[VEC_IND_SCALAR21]]
721; CHECK-NEXT:    [[TMP26:%.*]] = bitcast i32* [[TMP25]] to i8*
722; CHECK-NEXT:    [[WIDE_MASKED_GATHER58:%.*]] = call <8 x i32> @llvm.riscv.masked.strided.load.v8i32.p0i8.i64(<8 x i32> undef, i8* [[TMP24]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
723; CHECK-NEXT:    [[TMP27:%.*]] = add nsw <8 x i32> [[WIDE_MASKED_GATHER58]], [[WIDE_MASKED_GATHER57]]
724; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v8i32.p0i8.i64(<8 x i32> [[TMP27]], i8* [[TMP26]], i64 16, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
725; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
726; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR]] = add i64 [[VEC_IND_SCALAR]], 128
727; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR2]] = add i64 [[VEC_IND_SCALAR1]], 32
728; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR4]] = add i64 [[VEC_IND_SCALAR3]], 128
729; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR6]] = add i64 [[VEC_IND_SCALAR5]], 32
730; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR8]] = add i64 [[VEC_IND_SCALAR7]], 128
731; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR10]] = add i64 [[VEC_IND_SCALAR9]], 32
732; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR12]] = add i64 [[VEC_IND_SCALAR11]], 128
733; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR14]] = add i64 [[VEC_IND_SCALAR13]], 32
734; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR16]] = add i64 [[VEC_IND_SCALAR15]], 32
735; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR18]] = add i64 [[VEC_IND_SCALAR17]], 32
736; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR20]] = add i64 [[VEC_IND_SCALAR19]], 32
737; CHECK-NEXT:    [[VEC_IND_NEXT_SCALAR22]] = add i64 [[VEC_IND_SCALAR21]], 32
738; CHECK-NEXT:    [[TMP28:%.*]] = icmp eq i64 [[INDEX_NEXT]], 256
739; CHECK-NEXT:    br i1 [[TMP28]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
740; CHECK:       for.cond.cleanup:
741; CHECK-NEXT:    ret void
742;
743; CHECK-ASM-LABEL: gather_unroll:
744; CHECK-ASM:       # %bb.0: # %entry
745; CHECK-ASM-NEXT:    addi a2, zero, 256
746; CHECK-ASM-NEXT:    addi a3, zero, 64
747; CHECK-ASM-NEXT:    addi a4, zero, 16
748; CHECK-ASM-NEXT:  .LBB9_1: # %vector.body
749; CHECK-ASM-NEXT:    # =>This Inner Loop Header: Depth=1
750; CHECK-ASM-NEXT:    vsetivli zero, 8, e32, m1, ta, mu
751; CHECK-ASM-NEXT:    vlse32.v v8, (a1), a3
752; CHECK-ASM-NEXT:    vlse32.v v9, (a0), a4
753; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
754; CHECK-ASM-NEXT:    vsse32.v v8, (a0), a4
755; CHECK-ASM-NEXT:    addi a5, a1, 16
756; CHECK-ASM-NEXT:    vlse32.v v8, (a5), a3
757; CHECK-ASM-NEXT:    addi a5, a0, 4
758; CHECK-ASM-NEXT:    vlse32.v v9, (a5), a4
759; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
760; CHECK-ASM-NEXT:    vsse32.v v8, (a5), a4
761; CHECK-ASM-NEXT:    addi a5, a1, 32
762; CHECK-ASM-NEXT:    vlse32.v v8, (a5), a3
763; CHECK-ASM-NEXT:    addi a5, a0, 8
764; CHECK-ASM-NEXT:    vlse32.v v9, (a5), a4
765; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
766; CHECK-ASM-NEXT:    vsse32.v v8, (a5), a4
767; CHECK-ASM-NEXT:    addi a5, a1, 48
768; CHECK-ASM-NEXT:    vlse32.v v8, (a5), a3
769; CHECK-ASM-NEXT:    addi a5, a0, 12
770; CHECK-ASM-NEXT:    vlse32.v v9, (a5), a4
771; CHECK-ASM-NEXT:    vadd.vv v8, v9, v8
772; CHECK-ASM-NEXT:    vsse32.v v8, (a5), a4
773; CHECK-ASM-NEXT:    addi a2, a2, -8
774; CHECK-ASM-NEXT:    addi a1, a1, 512
775; CHECK-ASM-NEXT:    addi a0, a0, 128
776; CHECK-ASM-NEXT:    bnez a2, .LBB9_1
777; CHECK-ASM-NEXT:  # %bb.2: # %for.cond.cleanup
778; CHECK-ASM-NEXT:    ret
779entry:
780  br label %vector.body
781
782vector.body:                                      ; preds = %vector.body, %entry
783  %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
784  %vec.ind = phi <8 x i64> [ <i64 0, i64 4, i64 8, i64 12, i64 16, i64 20, i64 24, i64 28>, %entry ], [ %vec.ind.next, %vector.body ]
785  %0 = shl nuw nsw <8 x i64> %vec.ind, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
786  %1 = getelementptr inbounds i32, i32* %B, <8 x i64> %0
787  %wide.masked.gather = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %1, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
788  %2 = getelementptr inbounds i32, i32* %A, <8 x i64> %vec.ind
789  %wide.masked.gather52 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %2, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
790  %3 = add nsw <8 x i32> %wide.masked.gather52, %wide.masked.gather
791  call void @llvm.masked.scatter.v8i32.v8p0i32(<8 x i32> %3, <8 x i32*> %2, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
792  %4 = or <8 x i64> %vec.ind, <i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1>
793  %5 = shl nsw <8 x i64> %4, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
794  %6 = getelementptr inbounds i32, i32* %B, <8 x i64> %5
795  %wide.masked.gather53 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %6, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
796  %7 = getelementptr inbounds i32, i32* %A, <8 x i64> %4
797  %wide.masked.gather54 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %7, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
798  %8 = add nsw <8 x i32> %wide.masked.gather54, %wide.masked.gather53
799  call void @llvm.masked.scatter.v8i32.v8p0i32(<8 x i32> %8, <8 x i32*> %7, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
800  %9 = or <8 x i64> %vec.ind, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
801  %10 = shl nsw <8 x i64> %9, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
802  %11 = getelementptr inbounds i32, i32* %B, <8 x i64> %10
803  %wide.masked.gather55 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %11, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
804  %12 = getelementptr inbounds i32, i32* %A, <8 x i64> %9
805  %wide.masked.gather56 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %12, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
806  %13 = add nsw <8 x i32> %wide.masked.gather56, %wide.masked.gather55
807  call void @llvm.masked.scatter.v8i32.v8p0i32(<8 x i32> %13, <8 x i32*> %12, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
808  %14 = or <8 x i64> %vec.ind, <i64 3, i64 3, i64 3, i64 3, i64 3, i64 3, i64 3, i64 3>
809  %15 = shl nsw <8 x i64> %14, <i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2, i64 2>
810  %16 = getelementptr inbounds i32, i32* %B, <8 x i64> %15
811  %wide.masked.gather57 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %16, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
812  %17 = getelementptr inbounds i32, i32* %A, <8 x i64> %14
813  %wide.masked.gather58 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*> %17, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
814  %18 = add nsw <8 x i32> %wide.masked.gather58, %wide.masked.gather57
815  call void @llvm.masked.scatter.v8i32.v8p0i32(<8 x i32> %18, <8 x i32*> %17, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)
816  %index.next = add nuw i64 %index, 8
817  %vec.ind.next = add <8 x i64> %vec.ind, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
818  %19 = icmp eq i64 %index.next, 256
819  br i1 %19, label %for.cond.cleanup, label %vector.body
820
821for.cond.cleanup:                                 ; preds = %vector.body
822  ret void
823}
824
825declare <32 x i8> @llvm.masked.gather.v32i8.v32p0i8(<32 x i8*>, i32 immarg, <32 x i1>, <32 x i8>)
826declare <8 x i32> @llvm.masked.gather.v8i32.v8p0i32(<8 x i32*>, i32 immarg, <8 x i1>, <8 x i32>)
827declare void @llvm.masked.scatter.v32i8.v32p0i8(<32 x i8>, <32 x i8*>, i32 immarg, <32 x i1>)
828declare void @llvm.masked.scatter.v8i32.v8p0i32(<8 x i32>, <8 x i32*>, i32 immarg, <8 x i1>)
829
830; Make sure we don't crash in getTgtMemIntrinsic for a vector of pointers.
831define void @gather_of_pointers(i32** noalias nocapture %0, i32** noalias nocapture readonly %1) {
832; CHECK-LABEL: @gather_of_pointers(
833; CHECK-NEXT:    br label [[TMP3:%.*]]
834; CHECK:       3:
835; CHECK-NEXT:    [[TMP4:%.*]] = phi i64 [ 0, [[TMP2:%.*]] ], [ [[TMP15:%.*]], [[TMP3]] ]
836; CHECK-NEXT:    [[DOTSCALAR:%.*]] = phi i64 [ 0, [[TMP2]] ], [ [[DOTSCALAR1:%.*]], [[TMP3]] ]
837; CHECK-NEXT:    [[DOTSCALAR2:%.*]] = phi i64 [ 10, [[TMP2]] ], [ [[DOTSCALAR3:%.*]], [[TMP3]] ]
838; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr i32*, i32** [[TMP1:%.*]], i64 [[DOTSCALAR]]
839; CHECK-NEXT:    [[TMP6:%.*]] = bitcast i32** [[TMP5]] to i8*
840; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr i32*, i32** [[TMP1]], i64 [[DOTSCALAR2]]
841; CHECK-NEXT:    [[TMP8:%.*]] = bitcast i32** [[TMP7]] to i8*
842; CHECK-NEXT:    [[TMP9:%.*]] = call <2 x i32*> @llvm.riscv.masked.strided.load.v2p0i32.p0i8.i64(<2 x i32*> undef, i8* [[TMP6]], i64 40, <2 x i1> <i1 true, i1 true>)
843; CHECK-NEXT:    [[TMP10:%.*]] = call <2 x i32*> @llvm.riscv.masked.strided.load.v2p0i32.p0i8.i64(<2 x i32*> undef, i8* [[TMP8]], i64 40, <2 x i1> <i1 true, i1 true>)
844; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr inbounds i32*, i32** [[TMP0:%.*]], i64 [[TMP4]]
845; CHECK-NEXT:    [[TMP12:%.*]] = bitcast i32** [[TMP11]] to <2 x i32*>*
846; CHECK-NEXT:    store <2 x i32*> [[TMP9]], <2 x i32*>* [[TMP12]], align 8
847; CHECK-NEXT:    [[TMP13:%.*]] = getelementptr inbounds i32*, i32** [[TMP11]], i64 2
848; CHECK-NEXT:    [[TMP14:%.*]] = bitcast i32** [[TMP13]] to <2 x i32*>*
849; CHECK-NEXT:    store <2 x i32*> [[TMP10]], <2 x i32*>* [[TMP14]], align 8
850; CHECK-NEXT:    [[TMP15]] = add nuw i64 [[TMP4]], 4
851; CHECK-NEXT:    [[DOTSCALAR1]] = add i64 [[DOTSCALAR]], 20
852; CHECK-NEXT:    [[DOTSCALAR3]] = add i64 [[DOTSCALAR2]], 20
853; CHECK-NEXT:    [[TMP16:%.*]] = icmp eq i64 [[TMP15]], 1024
854; CHECK-NEXT:    br i1 [[TMP16]], label [[TMP17:%.*]], label [[TMP3]]
855; CHECK:       17:
856; CHECK-NEXT:    ret void
857;
858; CHECK-ASM-LABEL: gather_of_pointers:
859; CHECK-ASM:       # %bb.0:
860; CHECK-ASM-NEXT:    addi a0, a0, 16
861; CHECK-ASM-NEXT:    addi a2, zero, 1024
862; CHECK-ASM-NEXT:    addi a3, zero, 40
863; CHECK-ASM-NEXT:  .LBB10_1: # =>This Inner Loop Header: Depth=1
864; CHECK-ASM-NEXT:    addi a4, a1, 80
865; CHECK-ASM-NEXT:    vsetivli zero, 2, e64, m1, ta, mu
866; CHECK-ASM-NEXT:    vlse64.v v8, (a1), a3
867; CHECK-ASM-NEXT:    vlse64.v v9, (a4), a3
868; CHECK-ASM-NEXT:    addi a4, a0, -16
869; CHECK-ASM-NEXT:    vse64.v v8, (a4)
870; CHECK-ASM-NEXT:    vse64.v v9, (a0)
871; CHECK-ASM-NEXT:    addi a2, a2, -4
872; CHECK-ASM-NEXT:    addi a0, a0, 32
873; CHECK-ASM-NEXT:    addi a1, a1, 160
874; CHECK-ASM-NEXT:    bnez a2, .LBB10_1
875; CHECK-ASM-NEXT:  # %bb.2:
876; CHECK-ASM-NEXT:    ret
877  br label %3
878
8793:                                                ; preds = %3, %2
880  %4 = phi i64 [ 0, %2 ], [ %17, %3 ]
881  %5 = phi <2 x i64> [ <i64 0, i64 1>, %2 ], [ %18, %3 ]
882  %6 = mul nuw nsw <2 x i64> %5, <i64 5, i64 5>
883  %7 = mul <2 x i64> %5, <i64 5, i64 5>
884  %8 = add <2 x i64> %7, <i64 10, i64 10>
885  %9 = getelementptr inbounds i32*, i32** %1, <2 x i64> %6
886  %10 = getelementptr inbounds i32*, i32** %1, <2 x i64> %8
887  %11 = call <2 x i32*> @llvm.masked.gather.v2p0i32.v2p0p0i32(<2 x i32**> %9, i32 8, <2 x i1> <i1 true, i1 true>, <2 x i32*> undef)
888  %12 = call <2 x i32*> @llvm.masked.gather.v2p0i32.v2p0p0i32(<2 x i32**> %10, i32 8, <2 x i1> <i1 true, i1 true>, <2 x i32*> undef)
889  %13 = getelementptr inbounds i32*, i32** %0, i64 %4
890  %14 = bitcast i32** %13 to <2 x i32*>*
891  store <2 x i32*> %11, <2 x i32*>* %14, align 8
892  %15 = getelementptr inbounds i32*, i32** %13, i64 2
893  %16 = bitcast i32** %15 to <2 x i32*>*
894  store <2 x i32*> %12, <2 x i32*>* %16, align 8
895  %17 = add nuw i64 %4, 4
896  %18 = add <2 x i64> %5, <i64 4, i64 4>
897  %19 = icmp eq i64 %17, 1024
898  br i1 %19, label %20, label %3
899
90020:                                               ; preds = %3
901  ret void
902}
903
904declare <2 x i32*> @llvm.masked.gather.v2p0i32.v2p0p0i32(<2 x i32**>, i32 immarg, <2 x i1>, <2 x i32*>)
905
906; Make sure we don't crash in getTgtMemIntrinsic for a vector of pointers.
907define void @scatter_of_pointers(i32** noalias nocapture %0, i32** noalias nocapture readonly %1) {
908; CHECK-LABEL: @scatter_of_pointers(
909; CHECK-NEXT:    br label [[TMP3:%.*]]
910; CHECK:       3:
911; CHECK-NEXT:    [[TMP4:%.*]] = phi i64 [ 0, [[TMP2:%.*]] ], [ [[TMP15:%.*]], [[TMP3]] ]
912; CHECK-NEXT:    [[DOTSCALAR:%.*]] = phi i64 [ 0, [[TMP2]] ], [ [[DOTSCALAR1:%.*]], [[TMP3]] ]
913; CHECK-NEXT:    [[DOTSCALAR2:%.*]] = phi i64 [ 10, [[TMP2]] ], [ [[DOTSCALAR3:%.*]], [[TMP3]] ]
914; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i32*, i32** [[TMP1:%.*]], i64 [[TMP4]]
915; CHECK-NEXT:    [[TMP6:%.*]] = bitcast i32** [[TMP5]] to <2 x i32*>*
916; CHECK-NEXT:    [[TMP7:%.*]] = load <2 x i32*>, <2 x i32*>* [[TMP6]], align 8
917; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i32*, i32** [[TMP5]], i64 2
918; CHECK-NEXT:    [[TMP9:%.*]] = bitcast i32** [[TMP8]] to <2 x i32*>*
919; CHECK-NEXT:    [[TMP10:%.*]] = load <2 x i32*>, <2 x i32*>* [[TMP9]], align 8
920; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr i32*, i32** [[TMP0:%.*]], i64 [[DOTSCALAR]]
921; CHECK-NEXT:    [[TMP12:%.*]] = bitcast i32** [[TMP11]] to i8*
922; CHECK-NEXT:    [[TMP13:%.*]] = getelementptr i32*, i32** [[TMP0]], i64 [[DOTSCALAR2]]
923; CHECK-NEXT:    [[TMP14:%.*]] = bitcast i32** [[TMP13]] to i8*
924; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v2p0i32.p0i8.i64(<2 x i32*> [[TMP7]], i8* [[TMP12]], i64 40, <2 x i1> <i1 true, i1 true>)
925; CHECK-NEXT:    call void @llvm.riscv.masked.strided.store.v2p0i32.p0i8.i64(<2 x i32*> [[TMP10]], i8* [[TMP14]], i64 40, <2 x i1> <i1 true, i1 true>)
926; CHECK-NEXT:    [[TMP15]] = add nuw i64 [[TMP4]], 4
927; CHECK-NEXT:    [[DOTSCALAR1]] = add i64 [[DOTSCALAR]], 20
928; CHECK-NEXT:    [[DOTSCALAR3]] = add i64 [[DOTSCALAR2]], 20
929; CHECK-NEXT:    [[TMP16:%.*]] = icmp eq i64 [[TMP15]], 1024
930; CHECK-NEXT:    br i1 [[TMP16]], label [[TMP17:%.*]], label [[TMP3]]
931; CHECK:       17:
932; CHECK-NEXT:    ret void
933;
934; CHECK-ASM-LABEL: scatter_of_pointers:
935; CHECK-ASM:       # %bb.0:
936; CHECK-ASM-NEXT:    addi a1, a1, 16
937; CHECK-ASM-NEXT:    addi a2, zero, 1024
938; CHECK-ASM-NEXT:    addi a3, zero, 40
939; CHECK-ASM-NEXT:  .LBB11_1: # =>This Inner Loop Header: Depth=1
940; CHECK-ASM-NEXT:    addi a4, a1, -16
941; CHECK-ASM-NEXT:    vsetivli zero, 2, e64, m1, ta, mu
942; CHECK-ASM-NEXT:    vle64.v v8, (a4)
943; CHECK-ASM-NEXT:    vle64.v v9, (a1)
944; CHECK-ASM-NEXT:    addi a4, a0, 80
945; CHECK-ASM-NEXT:    vsse64.v v8, (a0), a3
946; CHECK-ASM-NEXT:    vsse64.v v9, (a4), a3
947; CHECK-ASM-NEXT:    addi a2, a2, -4
948; CHECK-ASM-NEXT:    addi a1, a1, 32
949; CHECK-ASM-NEXT:    addi a0, a0, 160
950; CHECK-ASM-NEXT:    bnez a2, .LBB11_1
951; CHECK-ASM-NEXT:  # %bb.2:
952; CHECK-ASM-NEXT:    ret
953  br label %3
954
9553:                                                ; preds = %3, %2
956  %4 = phi i64 [ 0, %2 ], [ %17, %3 ]
957  %5 = phi <2 x i64> [ <i64 0, i64 1>, %2 ], [ %18, %3 ]
958  %6 = getelementptr inbounds i32*, i32** %1, i64 %4
959  %7 = bitcast i32** %6 to <2 x i32*>*
960  %8 = load <2 x i32*>, <2 x i32*>* %7, align 8
961  %9 = getelementptr inbounds i32*, i32** %6, i64 2
962  %10 = bitcast i32** %9 to <2 x i32*>*
963  %11 = load <2 x i32*>, <2 x i32*>* %10, align 8
964  %12 = mul nuw nsw <2 x i64> %5, <i64 5, i64 5>
965  %13 = mul <2 x i64> %5, <i64 5, i64 5>
966  %14 = add <2 x i64> %13, <i64 10, i64 10>
967  %15 = getelementptr inbounds i32*, i32** %0, <2 x i64> %12
968  %16 = getelementptr inbounds i32*, i32** %0, <2 x i64> %14
969  call void @llvm.masked.scatter.v2p0i32.v2p0p0i32(<2 x i32*> %8, <2 x i32**> %15, i32 8, <2 x i1> <i1 true, i1 true>)
970  call void @llvm.masked.scatter.v2p0i32.v2p0p0i32(<2 x i32*> %11, <2 x i32**> %16, i32 8, <2 x i1> <i1 true, i1 true>)
971  %17 = add nuw i64 %4, 4
972  %18 = add <2 x i64> %5, <i64 4, i64 4>
973  %19 = icmp eq i64 %17, 1024
974  br i1 %19, label %20, label %3
975
97620:                                               ; preds = %3
977  ret void
978}
979
980declare void @llvm.masked.scatter.v2p0i32.v2p0p0i32(<2 x i32*>, <2 x i32**>, i32 immarg, <2 x i1>)
981