1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -hints-allow-reordering=false -passes=loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue < %s | FileCheck %s
4 target triple = "aarch64-unknown-linux-gnu"
7 define void @simple_memset(i32 %val, ptr %ptr, i64 %n) #0 {
8 ; CHECK-LABEL: @simple_memset(
10 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
11 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
13 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
14 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
15 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
16 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
17 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
18 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], [[TMP4]]
19 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
20 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
21 ; CHECK-NEXT: [[TMP13:%.*]] = call i64 @llvm.vscale.i64()
22 ; CHECK-NEXT: [[TMP14:%.*]] = mul i64 [[TMP13]], 4
23 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
24 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
25 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[UMAX]], [[TMP6]]
26 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[UMAX]], [[TMP6]]
27 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
28 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[UMAX]])
29 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[VAL:%.*]], i64 0
30 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
31 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
33 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
34 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
35 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
36 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, ptr [[PTR:%.*]], i64 [[TMP10]]
37 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i32, ptr [[TMP11]], i32 0
38 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[BROADCAST_SPLAT]], ptr [[TMP12]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
39 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], [[TMP14]]
40 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
41 ; CHECK-NEXT: [[TMP15:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
42 ; CHECK-NEXT: [[TMP16:%.*]] = extractelement <vscale x 4 x i1> [[TMP15]], i32 0
43 ; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
44 ; CHECK: middle.block:
45 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
47 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
48 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
50 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
51 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[PTR]], i64 [[INDEX]]
52 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP]], align 4
53 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
54 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
55 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP3:![0-9]+]]
56 ; CHECK: while.end.loopexit:
57 ; CHECK-NEXT: ret void
62 while.body: ; preds = %while.body, %entry
63 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
64 %gep = getelementptr i32, ptr %ptr, i64 %index
65 store i32 %val, ptr %gep
66 %index.next = add nsw i64 %index, 1
67 %cmp10 = icmp ult i64 %index.next, %n
68 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
70 while.end.loopexit: ; preds = %while.body
75 define void @simple_memset_v4i32(i32 %val, ptr %ptr, i64 %n) #0 {
76 ; CHECK-LABEL: @simple_memset_v4i32(
78 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
79 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
81 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], 3
82 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 4
83 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
84 ; CHECK-NEXT: [[TMP0:%.*]] = sub i64 [[UMAX]], 4
85 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i64 [[UMAX]], 4
86 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 [[TMP0]], i64 0
87 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 0, i64 [[UMAX]])
88 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[VAL:%.*]], i64 0
89 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
90 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
92 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
93 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
94 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX1]], 0
95 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i32, ptr [[PTR:%.*]], i64 [[TMP3]]
96 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i32, ptr [[TMP4]], i32 0
97 ; CHECK-NEXT: call void @llvm.masked.store.v4i32.p0(<4 x i32> [[BROADCAST_SPLAT]], ptr [[TMP5]], i32 4, <4 x i1> [[ACTIVE_LANE_MASK]])
98 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], 4
99 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 [[INDEX1]], i64 [[TMP2]])
100 ; CHECK-NEXT: [[TMP6:%.*]] = xor <4 x i1> [[ACTIVE_LANE_MASK_NEXT]], <i1 true, i1 true, i1 true, i1 true>
101 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i1> [[TMP6]], i32 0
102 ; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
103 ; CHECK: middle.block:
104 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
106 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
107 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
109 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
110 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[PTR]], i64 [[INDEX]]
111 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP]], align 4
112 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
113 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
114 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP5:![0-9]+]]
115 ; CHECK: while.end.loopexit:
116 ; CHECK-NEXT: ret void
121 while.body: ; preds = %while.body, %entry
122 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
123 %gep = getelementptr i32, ptr %ptr, i64 %index
124 store i32 %val, ptr %gep
125 %index.next = add nsw i64 %index, 1
126 %cmp10 = icmp ult i64 %index.next, %n
127 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !3
129 while.end.loopexit: ; preds = %while.body
134 define void @simple_memcpy(ptr noalias %dst, ptr noalias %src, i64 %n) #0 {
135 ; CHECK-LABEL: @simple_memcpy(
137 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
138 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
140 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
141 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
142 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
143 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
144 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
145 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], [[TMP4]]
146 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
147 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
148 ; CHECK-NEXT: [[TMP15:%.*]] = call i64 @llvm.vscale.i64()
149 ; CHECK-NEXT: [[TMP16:%.*]] = mul i64 [[TMP15]], 4
150 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
151 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
152 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[UMAX]], [[TMP6]]
153 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[UMAX]], [[TMP6]]
154 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
155 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[UMAX]])
156 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
157 ; CHECK: vector.body:
158 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
159 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
160 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
161 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, ptr [[SRC:%.*]], i64 [[TMP10]]
162 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i32, ptr [[TMP11]], i32 0
163 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP12]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
164 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr i32, ptr [[DST:%.*]], i64 [[TMP10]]
165 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr i32, ptr [[TMP13]], i32 0
166 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[WIDE_MASKED_LOAD]], ptr [[TMP14]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
167 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], [[TMP16]]
168 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
169 ; CHECK-NEXT: [[TMP17:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
170 ; CHECK-NEXT: [[TMP18:%.*]] = extractelement <vscale x 4 x i1> [[TMP17]], i32 0
171 ; CHECK-NEXT: br i1 [[TMP18]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
172 ; CHECK: middle.block:
173 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
175 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
176 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
178 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
179 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[SRC]], i64 [[INDEX]]
180 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[GEP1]], align 4
181 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[DST]], i64 [[INDEX]]
182 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP2]], align 4
183 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
184 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
185 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP7:![0-9]+]]
186 ; CHECK: while.end.loopexit:
187 ; CHECK-NEXT: ret void
192 while.body: ; preds = %while.body, %entry
193 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
194 %gep1 = getelementptr i32, ptr %src, i64 %index
195 %val = load i32, ptr %gep1
196 %gep2 = getelementptr i32, ptr %dst, i64 %index
197 store i32 %val, ptr %gep2
198 %index.next = add nsw i64 %index, 1
199 %cmp10 = icmp ult i64 %index.next, %n
200 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
202 while.end.loopexit: ; preds = %while.body
207 define void @copy_stride4(ptr noalias %dst, ptr noalias %src, i64 %n) #0 {
208 ; CHECK-LABEL: @copy_stride4(
210 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 4)
211 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[UMAX]], -1
212 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[TMP0]], 2
213 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
214 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
216 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.vscale.i64()
217 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], 4
218 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
219 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
220 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[TMP6]], 1
221 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[TMP2]], [[TMP7]]
222 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP4]]
223 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
224 ; CHECK-NEXT: [[IND_END:%.*]] = mul i64 [[N_VEC]], 4
225 ; CHECK-NEXT: [[TMP21:%.*]] = call i64 @llvm.vscale.i64()
226 ; CHECK-NEXT: [[TMP22:%.*]] = mul i64 [[TMP21]], 4
227 ; CHECK-NEXT: [[TMP8:%.*]] = call i64 @llvm.vscale.i64()
228 ; CHECK-NEXT: [[TMP9:%.*]] = mul i64 [[TMP8]], 4
229 ; CHECK-NEXT: [[TMP10:%.*]] = sub i64 [[TMP2]], [[TMP9]]
230 ; CHECK-NEXT: [[TMP11:%.*]] = icmp ugt i64 [[TMP2]], [[TMP9]]
231 ; CHECK-NEXT: [[TMP12:%.*]] = select i1 [[TMP11]], i64 [[TMP10]], i64 0
232 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[TMP2]])
233 ; CHECK-NEXT: [[TMP13:%.*]] = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
234 ; CHECK-NEXT: [[TMP14:%.*]] = add <vscale x 4 x i64> [[TMP13]], zeroinitializer
235 ; CHECK-NEXT: [[TMP15:%.*]] = mul <vscale x 4 x i64> [[TMP14]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 4, i64 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)
236 ; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 4 x i64> zeroinitializer, [[TMP15]]
237 ; CHECK-NEXT: [[TMP16:%.*]] = call i64 @llvm.vscale.i64()
238 ; CHECK-NEXT: [[TMP17:%.*]] = mul i64 [[TMP16]], 4
239 ; CHECK-NEXT: [[TMP18:%.*]] = mul i64 4, [[TMP17]]
240 ; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP18]], i64 0
241 ; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[DOTSPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
242 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
243 ; CHECK: vector.body:
244 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
245 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
246 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 4 x i64> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
247 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr i32, ptr [[SRC:%.*]], <vscale x 4 x i64> [[VEC_IND]]
248 ; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> [[TMP19]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
249 ; CHECK-NEXT: [[TMP20:%.*]] = getelementptr i32, ptr [[DST:%.*]], <vscale x 4 x i64> [[VEC_IND]]
250 ; CHECK-NEXT: call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[WIDE_MASKED_GATHER]], <vscale x 4 x ptr> [[TMP20]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
251 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], [[TMP22]]
252 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP12]])
253 ; CHECK-NEXT: [[TMP23:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
254 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 4 x i64> [[VEC_IND]], [[DOTSPLAT]]
255 ; CHECK-NEXT: [[TMP24:%.*]] = extractelement <vscale x 4 x i1> [[TMP23]], i32 0
256 ; CHECK-NEXT: br i1 [[TMP24]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
257 ; CHECK: middle.block:
258 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
260 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
261 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
263 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
264 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[SRC]], i64 [[INDEX]]
265 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[GEP1]], align 4
266 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[DST]], i64 [[INDEX]]
267 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP2]], align 4
268 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 4
269 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
270 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP9:![0-9]+]]
271 ; CHECK: while.end.loopexit:
272 ; CHECK-NEXT: ret void
277 while.body: ; preds = %while.body, %entry
278 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
279 %gep1 = getelementptr i32, ptr %src, i64 %index
280 %val = load i32, ptr %gep1
281 %gep2 = getelementptr i32, ptr %dst, i64 %index
282 store i32 %val, ptr %gep2
283 %index.next = add nsw i64 %index, 4
284 %cmp10 = icmp ult i64 %index.next, %n
285 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
287 while.end.loopexit: ; preds = %while.body
292 define void @simple_gather_scatter(ptr noalias %dst, ptr noalias %src, ptr noalias %ind, i64 %n) #0 {
293 ; CHECK-LABEL: @simple_gather_scatter(
295 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
296 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
298 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
299 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
300 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
301 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
302 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
303 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], [[TMP4]]
304 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
305 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
306 ; CHECK-NEXT: [[TMP15:%.*]] = call i64 @llvm.vscale.i64()
307 ; CHECK-NEXT: [[TMP16:%.*]] = mul i64 [[TMP15]], 4
308 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
309 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
310 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[UMAX]], [[TMP6]]
311 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[UMAX]], [[TMP6]]
312 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
313 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[UMAX]])
314 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
315 ; CHECK: vector.body:
316 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
317 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
318 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
319 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, ptr [[IND:%.*]], i64 [[TMP10]]
320 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i32, ptr [[TMP11]], i32 0
321 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP12]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
322 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr i32, ptr [[SRC:%.*]], <vscale x 4 x i32> [[WIDE_MASKED_LOAD]]
323 ; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> [[TMP13]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
324 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr i32, ptr [[DST:%.*]], <vscale x 4 x i32> [[WIDE_MASKED_LOAD]]
325 ; CHECK-NEXT: call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[WIDE_MASKED_GATHER]], <vscale x 4 x ptr> [[TMP14]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
326 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], [[TMP16]]
327 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
328 ; CHECK-NEXT: [[TMP17:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
329 ; CHECK-NEXT: [[TMP18:%.*]] = extractelement <vscale x 4 x i1> [[TMP17]], i32 0
330 ; CHECK-NEXT: br i1 [[TMP18]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
331 ; CHECK: middle.block:
332 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
334 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
335 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
337 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
338 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[IND]], i64 [[INDEX]]
339 ; CHECK-NEXT: [[IND_VAL:%.*]] = load i32, ptr [[GEP1]], align 4
340 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[SRC]], i32 [[IND_VAL]]
341 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[GEP2]], align 4
342 ; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i32, ptr [[DST]], i32 [[IND_VAL]]
343 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP3]], align 4
344 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
345 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
346 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP11:![0-9]+]]
347 ; CHECK: while.end.loopexit:
348 ; CHECK-NEXT: ret void
353 while.body: ; preds = %while.body, %entry
354 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
355 %gep1 = getelementptr i32, ptr %ind, i64 %index
356 %ind_val = load i32, ptr %gep1
357 %gep2 = getelementptr i32, ptr %src, i32 %ind_val
358 %val = load i32, ptr %gep2
359 %gep3 = getelementptr i32, ptr %dst, i32 %ind_val
360 store i32 %val, ptr %gep3
361 %index.next = add nsw i64 %index, 1
362 %cmp10 = icmp ult i64 %index.next, %n
363 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
365 while.end.loopexit: ; preds = %while.body
370 ; The original loop had an unconditional uniform load. Let's make sure
371 ; we don't artificially create new predicated blocks for the load.
372 define void @uniform_load(ptr noalias %dst, ptr noalias readonly %src, i64 %n) #0 {
373 ; CHECK-LABEL: @uniform_load(
375 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
377 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
378 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
379 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
380 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
381 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
382 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[N:%.*]], [[TMP4]]
383 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
384 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
385 ; CHECK-NEXT: [[TMP14:%.*]] = call i64 @llvm.vscale.i64()
386 ; CHECK-NEXT: [[TMP15:%.*]] = mul i64 [[TMP14]], 4
387 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
388 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
389 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[N]], [[TMP6]]
390 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[N]], [[TMP6]]
391 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
392 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[N]])
393 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
394 ; CHECK: vector.body:
395 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
396 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
397 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX]], 0
398 ; CHECK-NEXT: [[TMP11:%.*]] = load i32, ptr [[SRC:%.*]], align 4
399 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[TMP11]], i64 0
400 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
401 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[TMP10]]
402 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, ptr [[TMP12]], i32 0
403 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[BROADCAST_SPLAT]], ptr [[TMP13]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
404 ; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], [[TMP15]]
405 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX]], i64 [[TMP9]])
406 ; CHECK-NEXT: [[TMP16:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
407 ; CHECK-NEXT: [[TMP17:%.*]] = extractelement <vscale x 4 x i1> [[TMP16]], i32 0
408 ; CHECK-NEXT: br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
409 ; CHECK: middle.block:
410 ; CHECK-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
412 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
413 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
415 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
416 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[SRC]], align 4
417 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 [[INDVARS_IV]]
418 ; CHECK-NEXT: store i32 [[VAL]], ptr [[ARRAYIDX]], align 4
419 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
420 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
421 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
423 ; CHECK-NEXT: ret void
429 for.body: ; preds = %entry, %for.body
430 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
431 %val = load i32, ptr %src, align 4
432 %arrayidx = getelementptr inbounds i32, ptr %dst, i64 %indvars.iv
433 store i32 %val, ptr %arrayidx, align 4
434 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
435 %exitcond.not = icmp eq i64 %indvars.iv.next, %n
436 br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0
438 for.end: ; preds = %for.body, %entry
443 ; The original loop had a conditional uniform load. In this case we actually
444 ; do need to perform conditional loads and so we end up using a gather instead.
445 ; However, we at least ensure the mask is the overlap of the loop predicate
446 ; and the original condition.
447 define void @cond_uniform_load(ptr noalias %dst, ptr noalias readonly %src, ptr noalias readonly %cond, i64 %n) #0 {
448 ; CHECK-LABEL: @cond_uniform_load(
450 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
452 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
453 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
454 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
455 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
456 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
457 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[N:%.*]], [[TMP4]]
458 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
459 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
460 ; CHECK-NEXT: [[TMP20:%.*]] = call i64 @llvm.vscale.i64()
461 ; CHECK-NEXT: [[TMP21:%.*]] = mul i64 [[TMP20]], 4
462 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
463 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
464 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[N]], [[TMP6]]
465 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[N]], [[TMP6]]
466 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
467 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[N]])
468 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x ptr> poison, ptr [[SRC:%.*]], i64 0
469 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 4 x ptr> poison, <vscale x 4 x i32> zeroinitializer
470 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
471 ; CHECK: vector.body:
472 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
473 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
474 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
475 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds i32, ptr [[COND:%.*]], i64 [[TMP10]]
476 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds i32, ptr [[TMP11]], i32 0
477 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP12]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
478 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq <vscale x 4 x i32> [[WIDE_MASKED_LOAD]], zeroinitializer
479 ; CHECK-NEXT: [[TMP14:%.*]] = xor <vscale x 4 x i1> [[TMP13]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
480 ; CHECK-NEXT: [[TMP15:%.*]] = select <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i1> [[TMP14]], <vscale x 4 x i1> zeroinitializer
481 ; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> [[BROADCAST_SPLAT]], i32 4, <vscale x 4 x i1> [[TMP15]], <vscale x 4 x i32> poison)
482 ; CHECK-NEXT: [[TMP16:%.*]] = select <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i1> [[TMP13]], <vscale x 4 x i1> zeroinitializer
483 ; CHECK-NEXT: [[TMP18:%.*]] = or <vscale x 4 x i1> [[TMP15]], [[TMP16]]
484 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 4 x i1> [[TMP16]], <vscale x 4 x i32> zeroinitializer, <vscale x 4 x i32> [[WIDE_MASKED_GATHER]]
485 ; CHECK-NEXT: [[TMP17:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[TMP10]]
486 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr inbounds i32, ptr [[TMP17]], i32 0
487 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[PREDPHI]], ptr [[TMP19]], i32 4, <vscale x 4 x i1> [[TMP18]])
488 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], [[TMP21]]
489 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
490 ; CHECK-NEXT: [[TMP22:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
491 ; CHECK-NEXT: [[TMP23:%.*]] = extractelement <vscale x 4 x i1> [[TMP22]], i32 0
492 ; CHECK-NEXT: br i1 [[TMP23]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]
493 ; CHECK: middle.block:
494 ; CHECK-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
496 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
497 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
499 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[IF_END:%.*]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
500 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[COND]], i64 [[INDEX]]
501 ; CHECK-NEXT: [[TMP24:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
502 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[TMP24]], 0
503 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[IF_END]], label [[IF_THEN:%.*]]
505 ; CHECK-NEXT: [[TMP25:%.*]] = load i32, ptr [[SRC]], align 4
506 ; CHECK-NEXT: br label [[IF_END]]
508 ; CHECK-NEXT: [[VAL_0:%.*]] = phi i32 [ [[TMP25]], [[IF_THEN]] ], [ 0, [[FOR_BODY]] ]
509 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 [[INDEX]]
510 ; CHECK-NEXT: store i32 [[VAL_0]], ptr [[ARRAYIDX1]], align 4
511 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 1
512 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N]]
513 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
515 ; CHECK-NEXT: ret void
521 for.body: ; preds = %entry, %if.end
522 %index = phi i64 [ %index.next, %if.end ], [ 0, %entry ]
523 %arrayidx = getelementptr inbounds i32, ptr %cond, i64 %index
524 %0 = load i32, ptr %arrayidx, align 4
525 %tobool.not = icmp eq i32 %0, 0
526 br i1 %tobool.not, label %if.end, label %if.then
528 if.then: ; preds = %for.body
529 %1 = load i32, ptr %src, align 4
532 if.end: ; preds = %if.then, %for.body
533 %val.0 = phi i32 [ %1, %if.then ], [ 0, %for.body ]
534 %arrayidx1 = getelementptr inbounds i32, ptr %dst, i64 %index
535 store i32 %val.0, ptr %arrayidx1, align 4
536 %index.next = add nuw i64 %index, 1
537 %exitcond.not = icmp eq i64 %index.next, %n
538 br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0
540 for.end: ; preds = %for.inc, %entry
545 ; The original loop had an unconditional uniform store. Let's make sure
546 ; we don't artificially create new predicated blocks for the load.
547 define void @uniform_store(ptr noalias %dst, ptr noalias readonly %src, i64 %n) #0 {
548 ; CHECK-LABEL: @uniform_store(
550 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
552 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
553 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
554 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
555 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
556 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
557 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[N:%.*]], [[TMP4]]
558 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
559 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
560 ; CHECK-NEXT: [[TMP13:%.*]] = call i64 @llvm.vscale.i64()
561 ; CHECK-NEXT: [[TMP14:%.*]] = mul i64 [[TMP13]], 4
562 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
563 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
564 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[N]], [[TMP6]]
565 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[N]], [[TMP6]]
566 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
567 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[N]])
568 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x ptr> poison, ptr [[DST:%.*]], i64 0
569 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 4 x ptr> poison, <vscale x 4 x i32> zeroinitializer
570 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
571 ; CHECK: vector.body:
572 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
573 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
574 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX]], 0
575 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds i32, ptr [[SRC:%.*]], i64 [[TMP10]]
576 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds i32, ptr [[TMP11]], i32 0
577 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP12]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
578 ; CHECK-NEXT: call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[WIDE_MASKED_LOAD]], <vscale x 4 x ptr> [[BROADCAST_SPLAT]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
579 ; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], [[TMP14]]
580 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX]], i64 [[TMP9]])
581 ; CHECK-NEXT: [[TMP15:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
582 ; CHECK-NEXT: [[TMP16:%.*]] = extractelement <vscale x 4 x i1> [[TMP15]], i32 0
583 ; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]
584 ; CHECK: middle.block:
585 ; CHECK-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
587 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
588 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
590 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
591 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[SRC]], i64 [[INDVARS_IV]]
592 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
593 ; CHECK-NEXT: store i32 [[VAL]], ptr [[DST]], align 4
594 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
595 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
596 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
598 ; CHECK-NEXT: ret void
604 for.body: ; preds = %entry, %for.body
605 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
606 %arrayidx = getelementptr inbounds i32, ptr %src, i64 %indvars.iv
607 %val = load i32, ptr %arrayidx, align 4
608 store i32 %val, ptr %dst, align 4
609 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
610 %exitcond.not = icmp eq i64 %indvars.iv.next, %n
611 br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0
613 for.end: ; preds = %for.body, %entry
618 define void @simple_fdiv(ptr noalias %dst, ptr noalias %src, i64 %n) #0 {
619 ; CHECK-LABEL: @simple_fdiv(
621 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
622 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
624 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
625 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
626 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
627 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
628 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
629 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], [[TMP4]]
630 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
631 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
632 ; CHECK-NEXT: [[TMP16:%.*]] = call i64 @llvm.vscale.i64()
633 ; CHECK-NEXT: [[TMP17:%.*]] = mul i64 [[TMP16]], 4
634 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
635 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
636 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[UMAX]], [[TMP6]]
637 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[UMAX]], [[TMP6]]
638 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
639 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[UMAX]])
640 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
641 ; CHECK: vector.body:
642 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT3:%.*]], [[VECTOR_BODY]] ]
643 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
644 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
645 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr float, ptr [[SRC:%.*]], i64 [[TMP10]]
646 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr float, ptr [[DST:%.*]], i64 [[TMP10]]
647 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr float, ptr [[TMP11]], i32 0
648 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x float> @llvm.masked.load.nxv4f32.p0(ptr [[TMP13]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x float> poison)
649 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr float, ptr [[TMP12]], i32 0
650 ; CHECK-NEXT: [[WIDE_MASKED_LOAD2:%.*]] = call <vscale x 4 x float> @llvm.masked.load.nxv4f32.p0(ptr [[TMP14]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x float> poison)
651 ; CHECK-NEXT: [[TMP15:%.*]] = fdiv <vscale x 4 x float> [[WIDE_MASKED_LOAD]], [[WIDE_MASKED_LOAD2]]
652 ; CHECK-NEXT: call void @llvm.masked.store.nxv4f32.p0(<vscale x 4 x float> [[TMP15]], ptr [[TMP14]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
653 ; CHECK-NEXT: [[INDEX_NEXT3]] = add i64 [[INDEX1]], [[TMP17]]
654 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
655 ; CHECK-NEXT: [[TMP18:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
656 ; CHECK-NEXT: [[TMP19:%.*]] = extractelement <vscale x 4 x i1> [[TMP18]], i32 0
657 ; CHECK-NEXT: br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
658 ; CHECK: middle.block:
659 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
661 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
662 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
664 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
665 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr float, ptr [[SRC]], i64 [[INDEX]]
666 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr float, ptr [[DST]], i64 [[INDEX]]
667 ; CHECK-NEXT: [[VAL1:%.*]] = load float, ptr [[GEP1]], align 4
668 ; CHECK-NEXT: [[VAL2:%.*]] = load float, ptr [[GEP2]], align 4
669 ; CHECK-NEXT: [[RES:%.*]] = fdiv float [[VAL1]], [[VAL2]]
670 ; CHECK-NEXT: store float [[RES]], ptr [[GEP2]], align 4
671 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
672 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
673 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP19:![0-9]+]]
674 ; CHECK: while.end.loopexit:
675 ; CHECK-NEXT: ret void
680 while.body: ; preds = %while.body, %entry
681 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
682 %gep1 = getelementptr float, ptr %src, i64 %index
683 %gep2 = getelementptr float, ptr %dst, i64 %index
684 %val1 = load float, ptr %gep1
685 %val2 = load float, ptr %gep2
686 %res = fdiv float %val1, %val2
687 store float %res, ptr %gep2
688 %index.next = add nsw i64 %index, 1
689 %cmp10 = icmp ult i64 %index.next, %n
690 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
692 while.end.loopexit: ; preds = %while.body
696 ; Integer divides can throw exceptions; if we vectorize, we must ensure
697 ; that speculated lanes don't fault.
698 define void @simple_idiv(ptr noalias %dst, ptr noalias %src, i64 %n) #0 {
699 ; CHECK-LABEL: @simple_idiv(
701 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
702 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
704 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
705 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
706 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
707 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
708 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
709 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], [[TMP4]]
710 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
711 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
712 ; CHECK-NEXT: [[TMP17:%.*]] = call i64 @llvm.vscale.i64()
713 ; CHECK-NEXT: [[TMP18:%.*]] = mul i64 [[TMP17]], 4
714 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
715 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
716 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[UMAX]], [[TMP6]]
717 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[UMAX]], [[TMP6]]
718 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
719 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[UMAX]])
720 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
721 ; CHECK: vector.body:
722 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT3:%.*]], [[VECTOR_BODY]] ]
723 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
724 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
725 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, ptr [[SRC:%.*]], i64 [[TMP10]]
726 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i32, ptr [[DST:%.*]], i64 [[TMP10]]
727 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr i32, ptr [[TMP11]], i32 0
728 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP13]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
729 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr i32, ptr [[TMP12]], i32 0
730 ; CHECK-NEXT: [[WIDE_MASKED_LOAD2:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP14]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> poison)
731 ; CHECK-NEXT: [[TMP15:%.*]] = select <vscale x 4 x i1> [[ACTIVE_LANE_MASK]], <vscale x 4 x i32> [[WIDE_MASKED_LOAD2]], <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 1, i64 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
732 ; CHECK-NEXT: [[TMP16:%.*]] = udiv <vscale x 4 x i32> [[WIDE_MASKED_LOAD]], [[TMP15]]
733 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[TMP16]], ptr [[TMP14]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
734 ; CHECK-NEXT: [[INDEX_NEXT3]] = add i64 [[INDEX1]], [[TMP18]]
735 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
736 ; CHECK-NEXT: [[TMP19:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
737 ; CHECK-NEXT: [[TMP20:%.*]] = extractelement <vscale x 4 x i1> [[TMP19]], i32 0
738 ; CHECK-NEXT: br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP20:![0-9]+]]
739 ; CHECK: middle.block:
740 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
742 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
743 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
745 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
746 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[SRC]], i64 [[INDEX]]
747 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[DST]], i64 [[INDEX]]
748 ; CHECK-NEXT: [[VAL1:%.*]] = load i32, ptr [[GEP1]], align 4
749 ; CHECK-NEXT: [[VAL2:%.*]] = load i32, ptr [[GEP2]], align 4
750 ; CHECK-NEXT: [[RES:%.*]] = udiv i32 [[VAL1]], [[VAL2]]
751 ; CHECK-NEXT: store i32 [[RES]], ptr [[GEP2]], align 4
752 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
753 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
754 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP21:![0-9]+]]
755 ; CHECK: while.end.loopexit:
756 ; CHECK-NEXT: ret void
761 while.body: ; preds = %while.body, %entry
762 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
763 %gep1 = getelementptr i32, ptr %src, i64 %index
764 %gep2 = getelementptr i32, ptr %dst, i64 %index
765 %val1 = load i32, ptr %gep1
766 %val2 = load i32, ptr %gep2
767 %res = udiv i32 %val1, %val2
768 store i32 %res, ptr %gep2
769 %index.next = add nsw i64 %index, 1
770 %cmp10 = icmp ult i64 %index.next, %n
771 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
773 while.end.loopexit: ; preds = %while.body
777 define void @simple_memset_trip1024(i32 %val, ptr %ptr, i64 %n) #0 {
778 ; CHECK-LABEL: @simple_memset_trip1024(
780 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
781 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
782 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
783 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
785 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
786 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
787 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
788 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
789 ; CHECK-NEXT: [[TMP7:%.*]] = call i64 @llvm.vscale.i64()
790 ; CHECK-NEXT: [[TMP8:%.*]] = mul i64 [[TMP7]], 4
791 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[VAL:%.*]], i64 0
792 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
793 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
794 ; CHECK: vector.body:
795 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
796 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX1]], 0
797 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i32, ptr [[PTR:%.*]], i64 [[TMP4]]
798 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr i32, ptr [[TMP5]], i32 0
799 ; CHECK-NEXT: store <vscale x 4 x i32> [[BROADCAST_SPLAT]], ptr [[TMP6]], align 4
800 ; CHECK-NEXT: [[INDEX_NEXT2]] = add nuw i64 [[INDEX1]], [[TMP8]]
801 ; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT2]], [[N_VEC]]
802 ; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
803 ; CHECK: middle.block:
804 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
805 ; CHECK-NEXT: br i1 [[CMP_N]], label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
807 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
808 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
810 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
811 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[PTR]], i64 [[INDEX]]
812 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP]], align 4
813 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
814 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], 1024
815 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP23:![0-9]+]]
816 ; CHECK: while.end.loopexit:
817 ; CHECK-NEXT: ret void
822 while.body: ; preds = %while.body, %entry
823 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
824 %gep = getelementptr i32, ptr %ptr, i64 %index
825 store i32 %val, ptr %gep
826 %index.next = add nsw i64 %index, 1
827 %cmp10 = icmp ult i64 %index.next, 1024
828 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
830 while.end.loopexit: ; preds = %while.body
834 !0 = distinct !{!0, !1, !2}
835 !1 = !{!"llvm.loop.vectorize.width", i32 4}
836 !2 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
837 !3 = distinct !{!3, !4}
838 !4 = !{!"llvm.loop.vectorize.width", i32 4}
840 attributes #0 = { "target-features"="+sve" vscale_range(1,16) }