1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=loop-vectorize -scalable-vectorization=on -mtriple riscv64-linux-gnu -mattr=+v,+f -S 2>%t | FileCheck %s
3 ; RUN: opt < %s -passes=loop-vectorize -scalable-vectorization=off -riscv-v-vector-bits-min=-1 -mtriple riscv64-linux-gnu -mattr=+v,+f -S 2>%t | FileCheck --check-prefix=FIXED %s
5 ; Tests specific to div/rem handling - both predicated and not
7 target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
8 target triple = "riscv64"
10 define void @vector_udiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
11 ; CHECK-LABEL: @vector_udiv(
13 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
14 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
15 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
16 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
18 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
19 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
20 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
21 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
22 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
23 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
24 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
25 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
26 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
28 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
29 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
30 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
31 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
32 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
33 ; CHECK-NEXT: [[TMP9:%.*]] = udiv <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
34 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
35 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
36 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
37 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
38 ; CHECK: middle.block:
39 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
40 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
42 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
43 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
45 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
46 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
47 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
48 ; CHECK-NEXT: [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
49 ; CHECK-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
50 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
51 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
52 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
54 ; CHECK-NEXT: ret void
56 ; FIXED-LABEL: @vector_udiv(
58 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
60 ; FIXED-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
61 ; FIXED-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
62 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
64 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
65 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
66 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
67 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
68 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
69 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
70 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
71 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
72 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
73 ; FIXED-NEXT: [[TMP6:%.*]] = udiv <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
74 ; FIXED-NEXT: [[TMP7:%.*]] = udiv <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
75 ; FIXED-NEXT: store <4 x i64> [[TMP6]], ptr [[TMP4]], align 8
76 ; FIXED-NEXT: store <4 x i64> [[TMP7]], ptr [[TMP5]], align 8
77 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
78 ; FIXED-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
79 ; FIXED-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
80 ; FIXED: middle.block:
81 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
83 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
84 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
86 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
87 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
88 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
89 ; FIXED-NEXT: [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
90 ; FIXED-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
91 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
92 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
93 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
95 ; FIXED-NEXT: ret void
101 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
102 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
103 %elem = load i64, ptr %arrayidx
104 %divrem = udiv i64 %elem, %v
105 store i64 %divrem, ptr %arrayidx
106 %iv.next = add nuw nsw i64 %iv, 1
107 %exitcond.not = icmp eq i64 %iv.next, 1024
108 br i1 %exitcond.not, label %for.end, label %for.body
114 define void @vector_sdiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
115 ; CHECK-LABEL: @vector_sdiv(
117 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
118 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
119 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
120 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
122 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
123 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
124 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
125 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
126 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
127 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
128 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
129 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
130 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
131 ; CHECK: vector.body:
132 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
133 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
134 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
135 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
136 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
137 ; CHECK-NEXT: [[TMP9:%.*]] = sdiv <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
138 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
139 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
140 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
141 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
142 ; CHECK: middle.block:
143 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
144 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
146 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
147 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
149 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
150 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
151 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
152 ; CHECK-NEXT: [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
153 ; CHECK-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
154 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
155 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
156 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
158 ; CHECK-NEXT: ret void
160 ; FIXED-LABEL: @vector_sdiv(
162 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
164 ; FIXED-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
165 ; FIXED-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
166 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
167 ; FIXED: vector.body:
168 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
169 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
170 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
171 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
172 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
173 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
174 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
175 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
176 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
177 ; FIXED-NEXT: [[TMP6:%.*]] = sdiv <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
178 ; FIXED-NEXT: [[TMP7:%.*]] = sdiv <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
179 ; FIXED-NEXT: store <4 x i64> [[TMP6]], ptr [[TMP4]], align 8
180 ; FIXED-NEXT: store <4 x i64> [[TMP7]], ptr [[TMP5]], align 8
181 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
182 ; FIXED-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
183 ; FIXED-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
184 ; FIXED: middle.block:
185 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
187 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
188 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
190 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
191 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
192 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
193 ; FIXED-NEXT: [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
194 ; FIXED-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
195 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
196 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
197 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
199 ; FIXED-NEXT: ret void
205 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
206 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
207 %elem = load i64, ptr %arrayidx
208 %divrem = sdiv i64 %elem, %v
209 store i64 %divrem, ptr %arrayidx
210 %iv.next = add nuw nsw i64 %iv, 1
211 %exitcond.not = icmp eq i64 %iv.next, 1024
212 br i1 %exitcond.not, label %for.end, label %for.body
218 define void @vector_urem(ptr noalias nocapture %a, i64 %v, i64 %n) {
219 ; CHECK-LABEL: @vector_urem(
221 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
222 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
223 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
224 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
226 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
227 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
228 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
229 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
230 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
231 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
232 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
233 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
234 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
235 ; CHECK: vector.body:
236 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
237 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
238 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
239 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
240 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
241 ; CHECK-NEXT: [[TMP9:%.*]] = urem <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
242 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
243 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
244 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
245 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
246 ; CHECK: middle.block:
247 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
248 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
250 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
251 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
253 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
254 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
255 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
256 ; CHECK-NEXT: [[DIVREM:%.*]] = urem i64 [[ELEM]], [[V]]
257 ; CHECK-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
258 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
259 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
260 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
262 ; CHECK-NEXT: ret void
264 ; FIXED-LABEL: @vector_urem(
266 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
268 ; FIXED-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
269 ; FIXED-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
270 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
271 ; FIXED: vector.body:
272 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
273 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
274 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
275 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
276 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
277 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
278 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
279 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
280 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
281 ; FIXED-NEXT: [[TMP6:%.*]] = urem <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
282 ; FIXED-NEXT: [[TMP7:%.*]] = urem <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
283 ; FIXED-NEXT: store <4 x i64> [[TMP6]], ptr [[TMP4]], align 8
284 ; FIXED-NEXT: store <4 x i64> [[TMP7]], ptr [[TMP5]], align 8
285 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
286 ; FIXED-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
287 ; FIXED-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
288 ; FIXED: middle.block:
289 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
291 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
292 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
294 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
295 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
296 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
297 ; FIXED-NEXT: [[DIVREM:%.*]] = urem i64 [[ELEM]], [[V]]
298 ; FIXED-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
299 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
300 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
301 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
303 ; FIXED-NEXT: ret void
309 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
310 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
311 %elem = load i64, ptr %arrayidx
312 %divrem = urem i64 %elem, %v
313 store i64 %divrem, ptr %arrayidx
314 %iv.next = add nuw nsw i64 %iv, 1
315 %exitcond.not = icmp eq i64 %iv.next, 1024
316 br i1 %exitcond.not, label %for.end, label %for.body
322 define void @vector_srem(ptr noalias nocapture %a, i64 %v, i64 %n) {
323 ; CHECK-LABEL: @vector_srem(
325 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
326 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
327 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
328 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
330 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
331 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
332 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
333 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
334 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
335 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
336 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
337 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
338 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
339 ; CHECK: vector.body:
340 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
341 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
342 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
343 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
344 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
345 ; CHECK-NEXT: [[TMP9:%.*]] = srem <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
346 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
347 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
348 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
349 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
350 ; CHECK: middle.block:
351 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
352 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
354 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
355 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
357 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
358 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
359 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
360 ; CHECK-NEXT: [[DIVREM:%.*]] = srem i64 [[ELEM]], [[V]]
361 ; CHECK-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
362 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
363 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
364 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
366 ; CHECK-NEXT: ret void
368 ; FIXED-LABEL: @vector_srem(
370 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
372 ; FIXED-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
373 ; FIXED-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
374 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
375 ; FIXED: vector.body:
376 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
377 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
378 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
379 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
380 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
381 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
382 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
383 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
384 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
385 ; FIXED-NEXT: [[TMP6:%.*]] = srem <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
386 ; FIXED-NEXT: [[TMP7:%.*]] = srem <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
387 ; FIXED-NEXT: store <4 x i64> [[TMP6]], ptr [[TMP4]], align 8
388 ; FIXED-NEXT: store <4 x i64> [[TMP7]], ptr [[TMP5]], align 8
389 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
390 ; FIXED-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
391 ; FIXED-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
392 ; FIXED: middle.block:
393 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
395 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
396 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
398 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
399 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
400 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
401 ; FIXED-NEXT: [[DIVREM:%.*]] = srem i64 [[ELEM]], [[V]]
402 ; FIXED-NEXT: store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
403 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
404 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
405 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
407 ; FIXED-NEXT: ret void
413 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
414 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
415 %elem = load i64, ptr %arrayidx
416 %divrem = srem i64 %elem, %v
417 store i64 %divrem, ptr %arrayidx
418 %iv.next = add nuw nsw i64 %iv, 1
419 %exitcond.not = icmp eq i64 %iv.next, 1024
420 br i1 %exitcond.not, label %for.end, label %for.body
426 define void @predicated_udiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
427 ; CHECK-LABEL: @predicated_udiv(
429 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
430 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
431 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
432 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
434 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
435 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
436 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
437 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
438 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
439 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
440 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
441 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
442 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
443 ; CHECK: vector.body:
444 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
445 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
446 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
447 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
448 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
449 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ne <vscale x 2 x i64> [[BROADCAST_SPLAT]], zeroinitializer
450 ; CHECK-NEXT: [[TMP10:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[BROADCAST_SPLAT]], <vscale x 2 x i64> shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
451 ; CHECK-NEXT: [[TMP11:%.*]] = udiv <vscale x 2 x i64> [[WIDE_LOAD]], [[TMP10]]
452 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[TMP11]], <vscale x 2 x i64> [[WIDE_LOAD]]
453 ; CHECK-NEXT: store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP8]], align 8
454 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
455 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
456 ; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
457 ; CHECK: middle.block:
458 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
459 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
461 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
462 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
464 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
465 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
466 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
467 ; CHECK-NEXT: [[C:%.*]] = icmp ne i64 [[V]], 0
468 ; CHECK-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
470 ; CHECK-NEXT: [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
471 ; CHECK-NEXT: br label [[LATCH]]
473 ; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
474 ; CHECK-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
475 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
476 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
477 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
479 ; CHECK-NEXT: ret void
481 ; FIXED-LABEL: @predicated_udiv(
483 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
485 ; FIXED-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
486 ; FIXED-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
487 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
488 ; FIXED: vector.body:
489 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
490 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
491 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
492 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
493 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
494 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
495 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
496 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
497 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
498 ; FIXED-NEXT: [[TMP6:%.*]] = icmp ne <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer
499 ; FIXED-NEXT: [[TMP7:%.*]] = icmp ne <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer
500 ; FIXED-NEXT: [[TMP8:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[BROADCAST_SPLAT]], <4 x i64> <i64 1, i64 1, i64 1, i64 1>
501 ; FIXED-NEXT: [[TMP9:%.*]] = select <4 x i1> [[TMP7]], <4 x i64> [[BROADCAST_SPLAT]], <4 x i64> <i64 1, i64 1, i64 1, i64 1>
502 ; FIXED-NEXT: [[TMP10:%.*]] = udiv <4 x i64> [[WIDE_LOAD]], [[TMP8]]
503 ; FIXED-NEXT: [[TMP11:%.*]] = udiv <4 x i64> [[WIDE_LOAD1]], [[TMP9]]
504 ; FIXED-NEXT: [[PREDPHI:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[TMP10]], <4 x i64> [[WIDE_LOAD]]
505 ; FIXED-NEXT: [[PREDPHI2:%.*]] = select <4 x i1> [[TMP7]], <4 x i64> [[TMP11]], <4 x i64> [[WIDE_LOAD1]]
506 ; FIXED-NEXT: store <4 x i64> [[PREDPHI]], ptr [[TMP4]], align 8
507 ; FIXED-NEXT: store <4 x i64> [[PREDPHI2]], ptr [[TMP5]], align 8
508 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
509 ; FIXED-NEXT: [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
510 ; FIXED-NEXT: br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
511 ; FIXED: middle.block:
512 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
514 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
515 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
517 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
518 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
519 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
520 ; FIXED-NEXT: [[C:%.*]] = icmp ne i64 [[V]], 0
521 ; FIXED-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
523 ; FIXED-NEXT: [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
524 ; FIXED-NEXT: br label [[LATCH]]
526 ; FIXED-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
527 ; FIXED-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
528 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
529 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
530 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
532 ; FIXED-NEXT: ret void
538 %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
539 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
540 %elem = load i64, ptr %arrayidx
541 %c = icmp ne i64 %v, 0
542 br i1 %c, label %do_op, label %latch
544 %divrem = udiv i64 %elem, %v
547 %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
548 store i64 %phi, ptr %arrayidx
549 %iv.next = add nuw nsw i64 %iv, 1
550 %exitcond.not = icmp eq i64 %iv.next, 1024
551 br i1 %exitcond.not, label %for.end, label %for.body
557 define void @predicated_sdiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
558 ; CHECK-LABEL: @predicated_sdiv(
560 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
561 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
562 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
563 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
565 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
566 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
567 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
568 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
569 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
570 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
571 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
572 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
573 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
574 ; CHECK: vector.body:
575 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
576 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
577 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
578 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
579 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
580 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ne <vscale x 2 x i64> [[BROADCAST_SPLAT]], zeroinitializer
581 ; CHECK-NEXT: [[TMP10:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[BROADCAST_SPLAT]], <vscale x 2 x i64> shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
582 ; CHECK-NEXT: [[TMP11:%.*]] = sdiv <vscale x 2 x i64> [[WIDE_LOAD]], [[TMP10]]
583 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[TMP11]], <vscale x 2 x i64> [[WIDE_LOAD]]
584 ; CHECK-NEXT: store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP8]], align 8
585 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
586 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
587 ; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
588 ; CHECK: middle.block:
589 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
590 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
592 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
593 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
595 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
596 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
597 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
598 ; CHECK-NEXT: [[C:%.*]] = icmp ne i64 [[V]], 0
599 ; CHECK-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
601 ; CHECK-NEXT: [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
602 ; CHECK-NEXT: br label [[LATCH]]
604 ; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
605 ; CHECK-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
606 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
607 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
608 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
610 ; CHECK-NEXT: ret void
612 ; FIXED-LABEL: @predicated_sdiv(
614 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
616 ; FIXED-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
617 ; FIXED-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
618 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
619 ; FIXED: vector.body:
620 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
621 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
622 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
623 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
624 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
625 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
626 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
627 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
628 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
629 ; FIXED-NEXT: [[TMP6:%.*]] = icmp ne <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer
630 ; FIXED-NEXT: [[TMP7:%.*]] = icmp ne <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer
631 ; FIXED-NEXT: [[TMP8:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[BROADCAST_SPLAT]], <4 x i64> <i64 1, i64 1, i64 1, i64 1>
632 ; FIXED-NEXT: [[TMP9:%.*]] = select <4 x i1> [[TMP7]], <4 x i64> [[BROADCAST_SPLAT]], <4 x i64> <i64 1, i64 1, i64 1, i64 1>
633 ; FIXED-NEXT: [[TMP10:%.*]] = sdiv <4 x i64> [[WIDE_LOAD]], [[TMP8]]
634 ; FIXED-NEXT: [[TMP11:%.*]] = sdiv <4 x i64> [[WIDE_LOAD1]], [[TMP9]]
635 ; FIXED-NEXT: [[PREDPHI:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[TMP10]], <4 x i64> [[WIDE_LOAD]]
636 ; FIXED-NEXT: [[PREDPHI2:%.*]] = select <4 x i1> [[TMP7]], <4 x i64> [[TMP11]], <4 x i64> [[WIDE_LOAD1]]
637 ; FIXED-NEXT: store <4 x i64> [[PREDPHI]], ptr [[TMP4]], align 8
638 ; FIXED-NEXT: store <4 x i64> [[PREDPHI2]], ptr [[TMP5]], align 8
639 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
640 ; FIXED-NEXT: [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
641 ; FIXED-NEXT: br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
642 ; FIXED: middle.block:
643 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
645 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
646 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
648 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
649 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
650 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
651 ; FIXED-NEXT: [[C:%.*]] = icmp ne i64 [[V]], 0
652 ; FIXED-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
654 ; FIXED-NEXT: [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
655 ; FIXED-NEXT: br label [[LATCH]]
657 ; FIXED-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
658 ; FIXED-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
659 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
660 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
661 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
663 ; FIXED-NEXT: ret void
669 %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
670 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
671 %elem = load i64, ptr %arrayidx
672 %c = icmp ne i64 %v, 0
673 br i1 %c, label %do_op, label %latch
675 %divrem = sdiv i64 %elem, %v
678 %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
679 store i64 %phi, ptr %arrayidx
680 %iv.next = add nuw nsw i64 %iv, 1
681 %exitcond.not = icmp eq i64 %iv.next, 1024
682 br i1 %exitcond.not, label %for.end, label %for.body
688 define void @predicated_udiv_by_constant(ptr noalias nocapture %a, i64 %n) {
689 ; CHECK-LABEL: @predicated_udiv_by_constant(
691 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
692 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
693 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
694 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
696 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
697 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
698 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
699 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
700 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
701 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
702 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
703 ; CHECK: vector.body:
704 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
705 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
706 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
707 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
708 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
709 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ne <vscale x 2 x i64> [[WIDE_LOAD]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 42, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
710 ; CHECK-NEXT: [[TMP10:%.*]] = udiv <vscale x 2 x i64> [[WIDE_LOAD]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 27, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
711 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[TMP10]], <vscale x 2 x i64> [[WIDE_LOAD]]
712 ; CHECK-NEXT: store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP8]], align 8
713 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
714 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
715 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]
716 ; CHECK: middle.block:
717 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
718 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
720 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
721 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
723 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
724 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
725 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
726 ; CHECK-NEXT: [[C:%.*]] = icmp ne i64 [[ELEM]], 42
727 ; CHECK-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
729 ; CHECK-NEXT: [[DIVREM:%.*]] = udiv i64 [[ELEM]], 27
730 ; CHECK-NEXT: br label [[LATCH]]
732 ; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
733 ; CHECK-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
734 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
735 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
736 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
738 ; CHECK-NEXT: ret void
740 ; FIXED-LABEL: @predicated_udiv_by_constant(
742 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
744 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
745 ; FIXED: vector.body:
746 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
747 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
748 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
749 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
750 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
751 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
752 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
753 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
754 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
755 ; FIXED-NEXT: [[TMP6:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD]], <i64 42, i64 42, i64 42, i64 42>
756 ; FIXED-NEXT: [[TMP7:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD1]], <i64 42, i64 42, i64 42, i64 42>
757 ; FIXED-NEXT: [[TMP8:%.*]] = udiv <4 x i64> [[WIDE_LOAD]], <i64 27, i64 27, i64 27, i64 27>
758 ; FIXED-NEXT: [[TMP9:%.*]] = udiv <4 x i64> [[WIDE_LOAD1]], <i64 27, i64 27, i64 27, i64 27>
759 ; FIXED-NEXT: [[PREDPHI:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[TMP8]], <4 x i64> [[WIDE_LOAD]]
760 ; FIXED-NEXT: [[PREDPHI2:%.*]] = select <4 x i1> [[TMP7]], <4 x i64> [[TMP9]], <4 x i64> [[WIDE_LOAD1]]
761 ; FIXED-NEXT: store <4 x i64> [[PREDPHI]], ptr [[TMP4]], align 8
762 ; FIXED-NEXT: store <4 x i64> [[PREDPHI2]], ptr [[TMP5]], align 8
763 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
764 ; FIXED-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
765 ; FIXED-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]
766 ; FIXED: middle.block:
767 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
769 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
770 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
772 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
773 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
774 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
775 ; FIXED-NEXT: [[C:%.*]] = icmp ne i64 [[ELEM]], 42
776 ; FIXED-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
778 ; FIXED-NEXT: [[DIVREM:%.*]] = udiv i64 [[ELEM]], 27
779 ; FIXED-NEXT: br label [[LATCH]]
781 ; FIXED-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
782 ; FIXED-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
783 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
784 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
785 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
787 ; FIXED-NEXT: ret void
793 %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
794 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
795 %elem = load i64, ptr %arrayidx
796 %c = icmp ne i64 %elem, 42
797 br i1 %c, label %do_op, label %latch
799 %divrem = udiv i64 %elem, 27
802 %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
803 store i64 %phi, ptr %arrayidx
804 %iv.next = add nuw nsw i64 %iv, 1
805 %exitcond.not = icmp eq i64 %iv.next, 1024
806 br i1 %exitcond.not, label %for.end, label %for.body
812 define void @predicated_sdiv_by_constant(ptr noalias nocapture %a, i64 %n) {
813 ; CHECK-LABEL: @predicated_sdiv_by_constant(
815 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
816 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
817 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
818 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
820 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
821 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
822 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
823 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
824 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
825 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 2
826 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
827 ; CHECK: vector.body:
828 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
829 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
830 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
831 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
832 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
833 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ne <vscale x 2 x i64> [[WIDE_LOAD]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 42, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
834 ; CHECK-NEXT: [[TMP10:%.*]] = sdiv <vscale x 2 x i64> [[WIDE_LOAD]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 27, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
835 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[TMP10]], <vscale x 2 x i64> [[WIDE_LOAD]]
836 ; CHECK-NEXT: store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP8]], align 8
837 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
838 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
839 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]
840 ; CHECK: middle.block:
841 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
842 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
844 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
845 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
847 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
848 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
849 ; CHECK-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
850 ; CHECK-NEXT: [[C:%.*]] = icmp ne i64 [[ELEM]], 42
851 ; CHECK-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
853 ; CHECK-NEXT: [[DIVREM:%.*]] = sdiv i64 [[ELEM]], 27
854 ; CHECK-NEXT: br label [[LATCH]]
856 ; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
857 ; CHECK-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
858 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
859 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
860 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
862 ; CHECK-NEXT: ret void
864 ; FIXED-LABEL: @predicated_sdiv_by_constant(
866 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
868 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
869 ; FIXED: vector.body:
870 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
871 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
872 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
873 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
874 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP1]]
875 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
876 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
877 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
878 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP5]], align 8
879 ; FIXED-NEXT: [[TMP6:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD]], <i64 42, i64 42, i64 42, i64 42>
880 ; FIXED-NEXT: [[TMP7:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD1]], <i64 42, i64 42, i64 42, i64 42>
881 ; FIXED-NEXT: [[TMP8:%.*]] = sdiv <4 x i64> [[WIDE_LOAD]], <i64 27, i64 27, i64 27, i64 27>
882 ; FIXED-NEXT: [[TMP9:%.*]] = sdiv <4 x i64> [[WIDE_LOAD1]], <i64 27, i64 27, i64 27, i64 27>
883 ; FIXED-NEXT: [[PREDPHI:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[TMP8]], <4 x i64> [[WIDE_LOAD]]
884 ; FIXED-NEXT: [[PREDPHI2:%.*]] = select <4 x i1> [[TMP7]], <4 x i64> [[TMP9]], <4 x i64> [[WIDE_LOAD1]]
885 ; FIXED-NEXT: store <4 x i64> [[PREDPHI]], ptr [[TMP4]], align 8
886 ; FIXED-NEXT: store <4 x i64> [[PREDPHI2]], ptr [[TMP5]], align 8
887 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
888 ; FIXED-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
889 ; FIXED-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]
890 ; FIXED: middle.block:
891 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
893 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
894 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
896 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
897 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
898 ; FIXED-NEXT: [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
899 ; FIXED-NEXT: [[C:%.*]] = icmp ne i64 [[ELEM]], 42
900 ; FIXED-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
902 ; FIXED-NEXT: [[DIVREM:%.*]] = sdiv i64 [[ELEM]], 27
903 ; FIXED-NEXT: br label [[LATCH]]
905 ; FIXED-NEXT: [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
906 ; FIXED-NEXT: store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
907 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
908 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
909 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
911 ; FIXED-NEXT: ret void
917 %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
918 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
919 %elem = load i64, ptr %arrayidx
920 %c = icmp ne i64 %elem, 42
921 br i1 %c, label %do_op, label %latch
923 %divrem = sdiv i64 %elem, 27
926 %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
927 store i64 %phi, ptr %arrayidx
928 %iv.next = add nuw nsw i64 %iv, 1
929 %exitcond.not = icmp eq i64 %iv.next, 1024
930 br i1 %exitcond.not, label %for.end, label %for.body
936 define void @predicated_sdiv_by_minus_one(ptr noalias nocapture %a, i64 %n) {
937 ; CHECK-LABEL: @predicated_sdiv_by_minus_one(
939 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
940 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 16
941 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
942 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
944 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
945 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 16
946 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
947 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
948 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
949 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 16
950 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
951 ; CHECK: vector.body:
952 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
953 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
954 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 [[TMP6]]
955 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i8, ptr [[TMP7]], i32 0
956 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 16 x i8>, ptr [[TMP8]], align 1
957 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ne <vscale x 16 x i8> [[WIDE_LOAD]], shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> poison, i8 -128, i64 0), <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer)
958 ; CHECK-NEXT: [[TMP10:%.*]] = select <vscale x 16 x i1> [[TMP9]], <vscale x 16 x i8> shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> poison, i8 -1, i64 0), <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer), <vscale x 16 x i8> shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> poison, i8 1, i64 0), <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer)
959 ; CHECK-NEXT: [[TMP11:%.*]] = sdiv <vscale x 16 x i8> [[WIDE_LOAD]], [[TMP10]]
960 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <vscale x 16 x i1> [[TMP9]], <vscale x 16 x i8> [[TMP11]], <vscale x 16 x i8> [[WIDE_LOAD]]
961 ; CHECK-NEXT: store <vscale x 16 x i8> [[PREDPHI]], ptr [[TMP8]], align 1
962 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
963 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
964 ; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
965 ; CHECK: middle.block:
966 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
967 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
969 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
970 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
972 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
973 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[IV]]
974 ; CHECK-NEXT: [[ELEM:%.*]] = load i8, ptr [[ARRAYIDX]], align 1
975 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[ELEM]], -128
976 ; CHECK-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
978 ; CHECK-NEXT: [[DIVREM:%.*]] = sdiv i8 [[ELEM]], -1
979 ; CHECK-NEXT: br label [[LATCH]]
981 ; CHECK-NEXT: [[PHI:%.*]] = phi i8 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
982 ; CHECK-NEXT: store i8 [[PHI]], ptr [[ARRAYIDX]], align 1
983 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
984 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
985 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]
987 ; CHECK-NEXT: ret void
989 ; FIXED-LABEL: @predicated_sdiv_by_minus_one(
991 ; FIXED-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
993 ; FIXED-NEXT: br label [[VECTOR_BODY:%.*]]
994 ; FIXED: vector.body:
995 ; FIXED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
996 ; FIXED-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
997 ; FIXED-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 32
998 ; FIXED-NEXT: [[TMP2:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 [[TMP0]]
999 ; FIXED-NEXT: [[TMP3:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[TMP1]]
1000 ; FIXED-NEXT: [[TMP4:%.*]] = getelementptr inbounds i8, ptr [[TMP2]], i32 0
1001 ; FIXED-NEXT: [[TMP5:%.*]] = getelementptr inbounds i8, ptr [[TMP2]], i32 32
1002 ; FIXED-NEXT: [[WIDE_LOAD:%.*]] = load <32 x i8>, ptr [[TMP4]], align 1
1003 ; FIXED-NEXT: [[WIDE_LOAD1:%.*]] = load <32 x i8>, ptr [[TMP5]], align 1
1004 ; FIXED-NEXT: [[TMP6:%.*]] = icmp ne <32 x i8> [[WIDE_LOAD]], <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
1005 ; FIXED-NEXT: [[TMP7:%.*]] = icmp ne <32 x i8> [[WIDE_LOAD1]], <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
1006 ; FIXED-NEXT: [[TMP8:%.*]] = select <32 x i1> [[TMP6]], <32 x i8> <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, <32 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
1007 ; FIXED-NEXT: [[TMP9:%.*]] = select <32 x i1> [[TMP7]], <32 x i8> <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, <32 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
1008 ; FIXED-NEXT: [[TMP10:%.*]] = sdiv <32 x i8> [[WIDE_LOAD]], [[TMP8]]
1009 ; FIXED-NEXT: [[TMP11:%.*]] = sdiv <32 x i8> [[WIDE_LOAD1]], [[TMP9]]
1010 ; FIXED-NEXT: [[PREDPHI:%.*]] = select <32 x i1> [[TMP6]], <32 x i8> [[TMP10]], <32 x i8> [[WIDE_LOAD]]
1011 ; FIXED-NEXT: [[PREDPHI2:%.*]] = select <32 x i1> [[TMP7]], <32 x i8> [[TMP11]], <32 x i8> [[WIDE_LOAD1]]
1012 ; FIXED-NEXT: store <32 x i8> [[PREDPHI]], ptr [[TMP4]], align 1
1013 ; FIXED-NEXT: store <32 x i8> [[PREDPHI2]], ptr [[TMP5]], align 1
1014 ; FIXED-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 64
1015 ; FIXED-NEXT: [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
1016 ; FIXED-NEXT: br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
1017 ; FIXED: middle.block:
1018 ; FIXED-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
1020 ; FIXED-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1021 ; FIXED-NEXT: br label [[FOR_BODY:%.*]]
1023 ; FIXED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
1024 ; FIXED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[IV]]
1025 ; FIXED-NEXT: [[ELEM:%.*]] = load i8, ptr [[ARRAYIDX]], align 1
1026 ; FIXED-NEXT: [[C:%.*]] = icmp ne i8 [[ELEM]], -128
1027 ; FIXED-NEXT: br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
1029 ; FIXED-NEXT: [[DIVREM:%.*]] = sdiv i8 [[ELEM]], -1
1030 ; FIXED-NEXT: br label [[LATCH]]
1032 ; FIXED-NEXT: [[PHI:%.*]] = phi i8 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
1033 ; FIXED-NEXT: store i8 [[PHI]], ptr [[ARRAYIDX]], align 1
1034 ; FIXED-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
1035 ; FIXED-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
1036 ; FIXED-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]
1038 ; FIXED-NEXT: ret void
1044 %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
1045 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %iv
1046 %elem = load i8, ptr %arrayidx
1047 %c = icmp ne i8 %elem, 128
1048 br i1 %c, label %do_op, label %latch
1050 %divrem = sdiv i8 %elem, -1 ;; UB if %elem = INT_MIN
1053 %phi = phi i8 [%elem, %for.body], [%divrem, %do_op]
1054 store i8 %phi, ptr %arrayidx
1055 %iv.next = add nuw nsw i64 %iv, 1
1056 %exitcond.not = icmp eq i64 %iv.next, 1024
1057 br i1 %exitcond.not, label %for.end, label %for.body