xref: /llvm-project/llvm/test/Transforms/LoopVectorize/RISCV/divrem.ll (revision f0d5104c944b329c479802788571ed6df41e0e86)
1190cdf51SPhilip Reames; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2be51fa45SRoman Lebedev; RUN: opt < %s -passes=loop-vectorize -scalable-vectorization=on -mtriple riscv64-linux-gnu -mattr=+v,+f -S 2>%t | FileCheck %s
3be51fa45SRoman Lebedev; 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
4190cdf51SPhilip Reames
5190cdf51SPhilip Reames; Tests specific to div/rem handling - both predicated and not
6190cdf51SPhilip Reames
7190cdf51SPhilip Reamestarget datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
8190cdf51SPhilip Reamestarget triple = "riscv64"
9190cdf51SPhilip Reames
10190cdf51SPhilip Reamesdefine void @vector_udiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
11190cdf51SPhilip Reames; CHECK-LABEL: @vector_udiv(
12190cdf51SPhilip Reames; CHECK-NEXT:  entry:
13190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
148d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
158d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
16190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
17190cdf51SPhilip Reames; CHECK:       vector.ph:
188d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
198d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
208d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
21190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
225ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
235ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
24a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
25a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
26190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
27190cdf51SPhilip Reames; CHECK:       vector.body:
28190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
295ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
305ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
315ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
325ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
335ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP9:%.*]] = udiv <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
345ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
355ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
368d16c680SLuke Lau; CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
378d16c680SLuke Lau; CHECK-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
38190cdf51SPhilip Reames; CHECK:       middle.block:
39190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
40190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
41190cdf51SPhilip Reames; CHECK:       scalar.ph:
42190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
43190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
44190cdf51SPhilip Reames; CHECK:       for.body:
45190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
46190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
47190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
48190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
49190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
50190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
51190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
525a115452SSander de Smalen; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
53190cdf51SPhilip Reames; CHECK:       for.end:
54190cdf51SPhilip Reames; CHECK-NEXT:    ret void
55190cdf51SPhilip Reames;
56190cdf51SPhilip Reames; FIXED-LABEL: @vector_udiv(
57190cdf51SPhilip Reames; FIXED-NEXT:  entry:
58190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
59190cdf51SPhilip Reames; FIXED:       vector.ph:
608d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
618d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
62190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
63190cdf51SPhilip Reames; FIXED:       vector.body:
64190cdf51SPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
65190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
6653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
6753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
6853266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 4
6953266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP2]], align 8
7053266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
7153266f73SFlorian Hahn; FIXED-NEXT:    [[TMP4:%.*]] = udiv <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
7253266f73SFlorian Hahn; FIXED-NEXT:    [[TMP5:%.*]] = udiv <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
7353266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP4]], ptr [[TMP2]], align 8
7453266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP5]], ptr [[TMP3]], align 8
758d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
7653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
7753266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
78190cdf51SPhilip Reames; FIXED:       middle.block:
7996e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
80190cdf51SPhilip Reames; FIXED:       scalar.ph:
81190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
82190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
83190cdf51SPhilip Reames; FIXED:       for.body:
84190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
85190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
86190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
87190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
88190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
89190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
90190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
915a115452SSander de Smalen; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
92190cdf51SPhilip Reames; FIXED:       for.end:
93190cdf51SPhilip Reames; FIXED-NEXT:    ret void
94190cdf51SPhilip Reames;
95190cdf51SPhilip Reamesentry:
96190cdf51SPhilip Reames  br label %for.body
97190cdf51SPhilip Reames
98190cdf51SPhilip Reamesfor.body:
99190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
100190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
101190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
102190cdf51SPhilip Reames  %divrem = udiv i64 %elem, %v
103190cdf51SPhilip Reames  store i64 %divrem, ptr %arrayidx
104190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
105190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
106190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
107190cdf51SPhilip Reames
108190cdf51SPhilip Reamesfor.end:
109190cdf51SPhilip Reames  ret void
110190cdf51SPhilip Reames}
111190cdf51SPhilip Reames
112190cdf51SPhilip Reamesdefine void @vector_sdiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
113190cdf51SPhilip Reames; CHECK-LABEL: @vector_sdiv(
114190cdf51SPhilip Reames; CHECK-NEXT:  entry:
115190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
1168d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
1178d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
118190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
119190cdf51SPhilip Reames; CHECK:       vector.ph:
1208d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
1218d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
1228d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
123190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
1245ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
1255ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
126a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
127a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
128190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
129190cdf51SPhilip Reames; CHECK:       vector.body:
130190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1315ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
1325ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
1335ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
1345ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
1355ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP9:%.*]] = sdiv <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
1365ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
1375ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
1388d16c680SLuke Lau; CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1398d16c680SLuke Lau; CHECK-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
140190cdf51SPhilip Reames; CHECK:       middle.block:
141190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
142190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
143190cdf51SPhilip Reames; CHECK:       scalar.ph:
144190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
145190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
146190cdf51SPhilip Reames; CHECK:       for.body:
147190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
148190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
149190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
150190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
151190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
152190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
153190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
154190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
155190cdf51SPhilip Reames; CHECK:       for.end:
156190cdf51SPhilip Reames; CHECK-NEXT:    ret void
157190cdf51SPhilip Reames;
158190cdf51SPhilip Reames; FIXED-LABEL: @vector_sdiv(
159190cdf51SPhilip Reames; FIXED-NEXT:  entry:
160190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
161190cdf51SPhilip Reames; FIXED:       vector.ph:
1628d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
1638d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
164190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
165190cdf51SPhilip Reames; FIXED:       vector.body:
166190cdf51SPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
167190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
16853266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
16953266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
17053266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 4
17153266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP2]], align 8
17253266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
17353266f73SFlorian Hahn; FIXED-NEXT:    [[TMP4:%.*]] = sdiv <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
17453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP5:%.*]] = sdiv <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
17553266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP4]], ptr [[TMP2]], align 8
17653266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP5]], ptr [[TMP3]], align 8
1778d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
17853266f73SFlorian Hahn; FIXED-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
17953266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
180190cdf51SPhilip Reames; FIXED:       middle.block:
18196e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
182190cdf51SPhilip Reames; FIXED:       scalar.ph:
183190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
184190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
185190cdf51SPhilip Reames; FIXED:       for.body:
186190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
187190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
188190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
189190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
190190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
191190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
192190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
193190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
194190cdf51SPhilip Reames; FIXED:       for.end:
195190cdf51SPhilip Reames; FIXED-NEXT:    ret void
196190cdf51SPhilip Reames;
197190cdf51SPhilip Reamesentry:
198190cdf51SPhilip Reames  br label %for.body
199190cdf51SPhilip Reames
200190cdf51SPhilip Reamesfor.body:
201190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
202190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
203190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
204190cdf51SPhilip Reames  %divrem = sdiv i64 %elem, %v
205190cdf51SPhilip Reames  store i64 %divrem, ptr %arrayidx
206190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
207190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
208190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
209190cdf51SPhilip Reames
210190cdf51SPhilip Reamesfor.end:
211190cdf51SPhilip Reames  ret void
212190cdf51SPhilip Reames}
213190cdf51SPhilip Reames
214190cdf51SPhilip Reamesdefine void @vector_urem(ptr noalias nocapture %a, i64 %v, i64 %n) {
215190cdf51SPhilip Reames; CHECK-LABEL: @vector_urem(
216190cdf51SPhilip Reames; CHECK-NEXT:  entry:
217190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
2188d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
2198d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
220190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
221190cdf51SPhilip Reames; CHECK:       vector.ph:
2228d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
2238d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
2248d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
225190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
2265ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
2275ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
228a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
229a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
230190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
231190cdf51SPhilip Reames; CHECK:       vector.body:
232190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
2335ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
2345ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
2355ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
2365ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
2375ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP9:%.*]] = urem <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
2385ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
2395ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
2408d16c680SLuke Lau; CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
2418d16c680SLuke Lau; CHECK-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
242190cdf51SPhilip Reames; CHECK:       middle.block:
243190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
244190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
245190cdf51SPhilip Reames; CHECK:       scalar.ph:
246190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
247190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
248190cdf51SPhilip Reames; CHECK:       for.body:
249190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
250190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
251190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
252190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = urem i64 [[ELEM]], [[V]]
253190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
254190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
255190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
256190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
257190cdf51SPhilip Reames; CHECK:       for.end:
258190cdf51SPhilip Reames; CHECK-NEXT:    ret void
259190cdf51SPhilip Reames;
260190cdf51SPhilip Reames; FIXED-LABEL: @vector_urem(
261190cdf51SPhilip Reames; FIXED-NEXT:  entry:
262190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
263190cdf51SPhilip Reames; FIXED:       vector.ph:
2648d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
2658d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
266190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
267190cdf51SPhilip Reames; FIXED:       vector.body:
268190cdf51SPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
269190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
27053266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
27153266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
27253266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 4
27353266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP2]], align 8
27453266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
27553266f73SFlorian Hahn; FIXED-NEXT:    [[TMP4:%.*]] = urem <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
27653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP5:%.*]] = urem <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
27753266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP4]], ptr [[TMP2]], align 8
27853266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP5]], ptr [[TMP3]], align 8
2798d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
28053266f73SFlorian Hahn; FIXED-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
28153266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
282190cdf51SPhilip Reames; FIXED:       middle.block:
28396e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
284190cdf51SPhilip Reames; FIXED:       scalar.ph:
285190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
286190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
287190cdf51SPhilip Reames; FIXED:       for.body:
288190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
289190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
290190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
291190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = urem i64 [[ELEM]], [[V]]
292190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
293190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
294190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
295190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
296190cdf51SPhilip Reames; FIXED:       for.end:
297190cdf51SPhilip Reames; FIXED-NEXT:    ret void
298190cdf51SPhilip Reames;
299190cdf51SPhilip Reamesentry:
300190cdf51SPhilip Reames  br label %for.body
301190cdf51SPhilip Reames
302190cdf51SPhilip Reamesfor.body:
303190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
304190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
305190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
306190cdf51SPhilip Reames  %divrem = urem i64 %elem, %v
307190cdf51SPhilip Reames  store i64 %divrem, ptr %arrayidx
308190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
309190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
310190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
311190cdf51SPhilip Reames
312190cdf51SPhilip Reamesfor.end:
313190cdf51SPhilip Reames  ret void
314190cdf51SPhilip Reames}
315190cdf51SPhilip Reames
316190cdf51SPhilip Reamesdefine void @vector_srem(ptr noalias nocapture %a, i64 %v, i64 %n) {
317190cdf51SPhilip Reames; CHECK-LABEL: @vector_srem(
318190cdf51SPhilip Reames; CHECK-NEXT:  entry:
319190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
3208d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
3218d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
322190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
323190cdf51SPhilip Reames; CHECK:       vector.ph:
3248d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
3258d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
3268d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
327190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
3285ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
3295ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
330a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
331a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
332190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
333190cdf51SPhilip Reames; CHECK:       vector.body:
334190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3355ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
3365ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
3375ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
3385ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
3395ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP9:%.*]] = srem <vscale x 2 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
3405ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[TMP9]], ptr [[TMP8]], align 8
3415ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
3428d16c680SLuke Lau; CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
3438d16c680SLuke Lau; CHECK-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
344190cdf51SPhilip Reames; CHECK:       middle.block:
345190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
346190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
347190cdf51SPhilip Reames; CHECK:       scalar.ph:
348190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
349190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
350190cdf51SPhilip Reames; CHECK:       for.body:
351190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
352190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
353190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
354190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = srem i64 [[ELEM]], [[V]]
355190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
356190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
357190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
358190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
359190cdf51SPhilip Reames; CHECK:       for.end:
360190cdf51SPhilip Reames; CHECK-NEXT:    ret void
361190cdf51SPhilip Reames;
362190cdf51SPhilip Reames; FIXED-LABEL: @vector_srem(
363190cdf51SPhilip Reames; FIXED-NEXT:  entry:
364190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
365190cdf51SPhilip Reames; FIXED:       vector.ph:
3668d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
3678d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
368190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
369190cdf51SPhilip Reames; FIXED:       vector.body:
370190cdf51SPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
371190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
37253266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
37353266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
37453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 4
37553266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP2]], align 8
37653266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
37753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP4:%.*]] = srem <4 x i64> [[WIDE_LOAD]], [[BROADCAST_SPLAT]]
37853266f73SFlorian Hahn; FIXED-NEXT:    [[TMP5:%.*]] = srem <4 x i64> [[WIDE_LOAD1]], [[BROADCAST_SPLAT]]
37953266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP4]], ptr [[TMP2]], align 8
38053266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[TMP5]], ptr [[TMP3]], align 8
3818d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
38253266f73SFlorian Hahn; FIXED-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
38353266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
384190cdf51SPhilip Reames; FIXED:       middle.block:
38596e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
386190cdf51SPhilip Reames; FIXED:       scalar.ph:
387190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
388190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
389190cdf51SPhilip Reames; FIXED:       for.body:
390190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
391190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
392190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
393190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = srem i64 [[ELEM]], [[V]]
394190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[DIVREM]], ptr [[ARRAYIDX]], align 8
395190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
396190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
397190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
398190cdf51SPhilip Reames; FIXED:       for.end:
399190cdf51SPhilip Reames; FIXED-NEXT:    ret void
400190cdf51SPhilip Reames;
401190cdf51SPhilip Reamesentry:
402190cdf51SPhilip Reames  br label %for.body
403190cdf51SPhilip Reames
404190cdf51SPhilip Reamesfor.body:
405190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
406190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
407190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
408190cdf51SPhilip Reames  %divrem = srem i64 %elem, %v
409190cdf51SPhilip Reames  store i64 %divrem, ptr %arrayidx
410190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
411190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
412190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
413190cdf51SPhilip Reames
414190cdf51SPhilip Reamesfor.end:
415190cdf51SPhilip Reames  ret void
416190cdf51SPhilip Reames}
417190cdf51SPhilip Reames
418190cdf51SPhilip Reamesdefine void @predicated_udiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
419190cdf51SPhilip Reames; CHECK-LABEL: @predicated_udiv(
420190cdf51SPhilip Reames; CHECK-NEXT:  entry:
421190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
4228d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
4238d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
424190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
425190cdf51SPhilip Reames; CHECK:       vector.ph:
4268d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
4278d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
4288d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
429190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
4305ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
4315ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
432a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
433a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
43453266f73SFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = icmp ne <vscale x 2 x i64> [[BROADCAST_SPLAT]], zeroinitializer
435*f0d5104cSLuke Lau; CHECK-NEXT:    [[TMP10:%.*]] = select <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> [[BROADCAST_SPLAT]], <vscale x 2 x i64> splat (i64 1)
436190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
437190cdf51SPhilip Reames; CHECK:       vector.body:
438190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
43953266f73SFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = add i64 [[INDEX]], 0
44053266f73SFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP7]]
44153266f73SFlorian Hahn; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i64, ptr [[TMP8]], i32 0
44253266f73SFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP9]], align 8
4435ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP11:%.*]] = udiv <vscale x 2 x i64> [[WIDE_LOAD]], [[TMP10]]
44453266f73SFlorian Hahn; CHECK-NEXT:    [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> [[TMP11]], <vscale x 2 x i64> [[WIDE_LOAD]]
44553266f73SFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP9]], align 8
4465ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
44753266f73SFlorian Hahn; CHECK-NEXT:    [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
44853266f73SFlorian Hahn; CHECK-NEXT:    br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
449190cdf51SPhilip Reames; CHECK:       middle.block:
450190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
451190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
452190cdf51SPhilip Reames; CHECK:       scalar.ph:
453190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
454190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
455190cdf51SPhilip Reames; CHECK:       for.body:
456190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
457190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
458190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
459190cdf51SPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ne i64 [[V]], 0
460190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
461190cdf51SPhilip Reames; CHECK:       do_op:
462190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
463190cdf51SPhilip Reames; CHECK-NEXT:    br label [[LATCH]]
464190cdf51SPhilip Reames; CHECK:       latch:
465190cdf51SPhilip Reames; CHECK-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
466190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
467190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
468190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
469190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
470190cdf51SPhilip Reames; CHECK:       for.end:
471190cdf51SPhilip Reames; CHECK-NEXT:    ret void
472190cdf51SPhilip Reames;
473190cdf51SPhilip Reames; FIXED-LABEL: @predicated_udiv(
474190cdf51SPhilip Reames; FIXED-NEXT:  entry:
475190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
476190cdf51SPhilip Reames; FIXED:       vector.ph:
4778d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
4788d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
47953266f73SFlorian Hahn; FIXED-NEXT:    [[TMP0:%.*]] = icmp ne <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer
480*f0d5104cSLuke Lau; FIXED-NEXT:    [[TMP5:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[BROADCAST_SPLAT]], <4 x i64> splat (i64 1)
481190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
482190cdf51SPhilip Reames; FIXED:       vector.body:
4834c4c0d2cSPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
48453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 0
48553266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP1]]
48653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
48753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
48853266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
48953266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
49053266f73SFlorian Hahn; FIXED-NEXT:    [[TMP7:%.*]] = udiv <4 x i64> [[WIDE_LOAD]], [[TMP5]]
491*f0d5104cSLuke Lau; FIXED-NEXT:    [[TMP8:%.*]] = udiv <4 x i64> [[WIDE_LOAD1]], [[TMP5]]
49253266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[TMP7]], <4 x i64> [[WIDE_LOAD]]
49353266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI2:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[TMP8]], <4 x i64> [[WIDE_LOAD1]]
49453266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI]], ptr [[TMP3]], align 8
49553266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI2]], ptr [[TMP4]], align 8
4968d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
49753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
49853266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
499190cdf51SPhilip Reames; FIXED:       middle.block:
50096e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
501190cdf51SPhilip Reames; FIXED:       scalar.ph:
502190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
503190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
504190cdf51SPhilip Reames; FIXED:       for.body:
505190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
506190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
507190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
508190cdf51SPhilip Reames; FIXED-NEXT:    [[C:%.*]] = icmp ne i64 [[V]], 0
509190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
510190cdf51SPhilip Reames; FIXED:       do_op:
511190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = udiv i64 [[ELEM]], [[V]]
512190cdf51SPhilip Reames; FIXED-NEXT:    br label [[LATCH]]
513190cdf51SPhilip Reames; FIXED:       latch:
514190cdf51SPhilip Reames; FIXED-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
515190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
516190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
517190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
518190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
519190cdf51SPhilip Reames; FIXED:       for.end:
520190cdf51SPhilip Reames; FIXED-NEXT:    ret void
521190cdf51SPhilip Reames;
522190cdf51SPhilip Reamesentry:
523190cdf51SPhilip Reames  br label %for.body
524190cdf51SPhilip Reames
525190cdf51SPhilip Reamesfor.body:
526190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
527190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
528190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
529190cdf51SPhilip Reames  %c = icmp ne i64 %v, 0
530190cdf51SPhilip Reames  br i1 %c, label %do_op, label %latch
531190cdf51SPhilip Reamesdo_op:
532190cdf51SPhilip Reames  %divrem = udiv i64 %elem, %v
533190cdf51SPhilip Reames  br label %latch
534190cdf51SPhilip Reameslatch:
535190cdf51SPhilip Reames  %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
536190cdf51SPhilip Reames  store i64 %phi, ptr %arrayidx
537190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
538190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
539190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
540190cdf51SPhilip Reames
541190cdf51SPhilip Reamesfor.end:
542190cdf51SPhilip Reames  ret void
543190cdf51SPhilip Reames}
544190cdf51SPhilip Reames
545190cdf51SPhilip Reamesdefine void @predicated_sdiv(ptr noalias nocapture %a, i64 %v, i64 %n) {
546190cdf51SPhilip Reames; CHECK-LABEL: @predicated_sdiv(
547190cdf51SPhilip Reames; CHECK-NEXT:  entry:
548190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
5498d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
5508d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
551190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
552190cdf51SPhilip Reames; CHECK:       vector.ph:
5538d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
5548d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
5558d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
556190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
5575ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
5585ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
559a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[V:%.*]], i64 0
560a5891fa4SFlorian Hahn; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
56153266f73SFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = icmp ne <vscale x 2 x i64> [[BROADCAST_SPLAT]], zeroinitializer
562*f0d5104cSLuke Lau; CHECK-NEXT:    [[TMP10:%.*]] = select <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> [[BROADCAST_SPLAT]], <vscale x 2 x i64> splat (i64 1)
563190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
564190cdf51SPhilip Reames; CHECK:       vector.body:
565190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
56653266f73SFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = add i64 [[INDEX]], 0
56753266f73SFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP7]]
56853266f73SFlorian Hahn; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i64, ptr [[TMP8]], i32 0
56953266f73SFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP9]], align 8
5705ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP11:%.*]] = sdiv <vscale x 2 x i64> [[WIDE_LOAD]], [[TMP10]]
57153266f73SFlorian Hahn; CHECK-NEXT:    [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> [[TMP11]], <vscale x 2 x i64> [[WIDE_LOAD]]
57253266f73SFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP9]], align 8
5735ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
57453266f73SFlorian Hahn; CHECK-NEXT:    [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
57553266f73SFlorian Hahn; CHECK-NEXT:    br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
576190cdf51SPhilip Reames; CHECK:       middle.block:
577190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
578190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
579190cdf51SPhilip Reames; CHECK:       scalar.ph:
580190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
581190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
582190cdf51SPhilip Reames; CHECK:       for.body:
583190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
584190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
585190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
586190cdf51SPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ne i64 [[V]], 0
587190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
588190cdf51SPhilip Reames; CHECK:       do_op:
589190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
590190cdf51SPhilip Reames; CHECK-NEXT:    br label [[LATCH]]
591190cdf51SPhilip Reames; CHECK:       latch:
592190cdf51SPhilip Reames; CHECK-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
593190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
594190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
595190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
596190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
597190cdf51SPhilip Reames; CHECK:       for.end:
598190cdf51SPhilip Reames; CHECK-NEXT:    ret void
599190cdf51SPhilip Reames;
600190cdf51SPhilip Reames; FIXED-LABEL: @predicated_sdiv(
601190cdf51SPhilip Reames; FIXED-NEXT:  entry:
602190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
603190cdf51SPhilip Reames; FIXED:       vector.ph:
6048d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[V:%.*]], i64 0
6058d16c680SLuke Lau; FIXED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
60653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP0:%.*]] = icmp ne <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer
607*f0d5104cSLuke Lau; FIXED-NEXT:    [[TMP5:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[BROADCAST_SPLAT]], <4 x i64> splat (i64 1)
608190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
609190cdf51SPhilip Reames; FIXED:       vector.body:
6104c4c0d2cSPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
61153266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 0
61253266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP1]]
61353266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
61453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 4
61553266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
61653266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP4]], align 8
61753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP7:%.*]] = sdiv <4 x i64> [[WIDE_LOAD]], [[TMP5]]
618*f0d5104cSLuke Lau; FIXED-NEXT:    [[TMP8:%.*]] = sdiv <4 x i64> [[WIDE_LOAD1]], [[TMP5]]
61953266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[TMP7]], <4 x i64> [[WIDE_LOAD]]
62053266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI2:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[TMP8]], <4 x i64> [[WIDE_LOAD1]]
62153266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI]], ptr [[TMP3]], align 8
62253266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI2]], ptr [[TMP4]], align 8
6238d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
62453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
62553266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
626190cdf51SPhilip Reames; FIXED:       middle.block:
62796e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
628190cdf51SPhilip Reames; FIXED:       scalar.ph:
629190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
630190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
631190cdf51SPhilip Reames; FIXED:       for.body:
632190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
633190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
634190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
635190cdf51SPhilip Reames; FIXED-NEXT:    [[C:%.*]] = icmp ne i64 [[V]], 0
636190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
637190cdf51SPhilip Reames; FIXED:       do_op:
638190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = sdiv i64 [[ELEM]], [[V]]
639190cdf51SPhilip Reames; FIXED-NEXT:    br label [[LATCH]]
640190cdf51SPhilip Reames; FIXED:       latch:
641190cdf51SPhilip Reames; FIXED-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
642190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
643190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
644190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
645190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
646190cdf51SPhilip Reames; FIXED:       for.end:
647190cdf51SPhilip Reames; FIXED-NEXT:    ret void
648190cdf51SPhilip Reames;
649190cdf51SPhilip Reamesentry:
650190cdf51SPhilip Reames  br label %for.body
651190cdf51SPhilip Reames
652190cdf51SPhilip Reamesfor.body:
653190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
654190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
655190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
656190cdf51SPhilip Reames  %c = icmp ne i64 %v, 0
657190cdf51SPhilip Reames  br i1 %c, label %do_op, label %latch
658190cdf51SPhilip Reamesdo_op:
659190cdf51SPhilip Reames  %divrem = sdiv i64 %elem, %v
660190cdf51SPhilip Reames  br label %latch
661190cdf51SPhilip Reameslatch:
662190cdf51SPhilip Reames  %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
663190cdf51SPhilip Reames  store i64 %phi, ptr %arrayidx
664190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
665190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
666190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
667190cdf51SPhilip Reames
668190cdf51SPhilip Reamesfor.end:
669190cdf51SPhilip Reames  ret void
670190cdf51SPhilip Reames}
671190cdf51SPhilip Reames
672190cdf51SPhilip Reamesdefine void @predicated_udiv_by_constant(ptr noalias nocapture %a, i64 %n) {
673190cdf51SPhilip Reames; CHECK-LABEL: @predicated_udiv_by_constant(
674190cdf51SPhilip Reames; CHECK-NEXT:  entry:
675190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
6768d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
6778d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
678190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
679190cdf51SPhilip Reames; CHECK:       vector.ph:
6808d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
6818d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
6828d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
683190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
6845ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
6855ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
686190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
687190cdf51SPhilip Reames; CHECK:       vector.body:
688190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6895ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
6905ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
6915ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
6925ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
69356c091eaSPaul Walker; CHECK-NEXT:    [[TMP9:%.*]] = icmp ne <vscale x 2 x i64> [[WIDE_LOAD]], splat (i64 42)
69456c091eaSPaul Walker; CHECK-NEXT:    [[TMP10:%.*]] = udiv <vscale x 2 x i64> [[WIDE_LOAD]], splat (i64 27)
6955ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[TMP10]], <vscale x 2 x i64> [[WIDE_LOAD]]
6965ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP8]], align 8
6975ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
69853266f73SFlorian Hahn; CHECK-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
69953266f73SFlorian Hahn; CHECK-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]
700190cdf51SPhilip Reames; CHECK:       middle.block:
701190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
702190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
703190cdf51SPhilip Reames; CHECK:       scalar.ph:
704190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
705190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
706190cdf51SPhilip Reames; CHECK:       for.body:
707190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
708190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
709190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
710190cdf51SPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ne i64 [[ELEM]], 42
711190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
712190cdf51SPhilip Reames; CHECK:       do_op:
713190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = udiv i64 [[ELEM]], 27
714190cdf51SPhilip Reames; CHECK-NEXT:    br label [[LATCH]]
715190cdf51SPhilip Reames; CHECK:       latch:
716190cdf51SPhilip Reames; CHECK-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
717190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
718190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
719190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
720190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
721190cdf51SPhilip Reames; CHECK:       for.end:
722190cdf51SPhilip Reames; CHECK-NEXT:    ret void
723190cdf51SPhilip Reames;
724190cdf51SPhilip Reames; FIXED-LABEL: @predicated_udiv_by_constant(
725190cdf51SPhilip Reames; FIXED-NEXT:  entry:
726190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
727190cdf51SPhilip Reames; FIXED:       vector.ph:
728190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
729190cdf51SPhilip Reames; FIXED:       vector.body:
730190cdf51SPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
731190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
73253266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
73353266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
73453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 4
73553266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP2]], align 8
73653266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
73738fffa63SPaul Walker; FIXED-NEXT:    [[TMP4:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD]], splat (i64 42)
73838fffa63SPaul Walker; FIXED-NEXT:    [[TMP5:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD1]], splat (i64 42)
73938fffa63SPaul Walker; FIXED-NEXT:    [[TMP6:%.*]] = udiv <4 x i64> [[WIDE_LOAD]], splat (i64 27)
74038fffa63SPaul Walker; FIXED-NEXT:    [[TMP7:%.*]] = udiv <4 x i64> [[WIDE_LOAD1]], splat (i64 27)
74153266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP4]], <4 x i64> [[TMP6]], <4 x i64> [[WIDE_LOAD]]
74253266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI2:%.*]] = select <4 x i1> [[TMP5]], <4 x i64> [[TMP7]], <4 x i64> [[WIDE_LOAD1]]
74353266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI]], ptr [[TMP2]], align 8
74453266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI2]], ptr [[TMP3]], align 8
7458d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
74653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
74753266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]
748190cdf51SPhilip Reames; FIXED:       middle.block:
74996e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
750190cdf51SPhilip Reames; FIXED:       scalar.ph:
751190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
752190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
753190cdf51SPhilip Reames; FIXED:       for.body:
754190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
755190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
756190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
757190cdf51SPhilip Reames; FIXED-NEXT:    [[C:%.*]] = icmp ne i64 [[ELEM]], 42
758190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
759190cdf51SPhilip Reames; FIXED:       do_op:
760190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = udiv i64 [[ELEM]], 27
761190cdf51SPhilip Reames; FIXED-NEXT:    br label [[LATCH]]
762190cdf51SPhilip Reames; FIXED:       latch:
763190cdf51SPhilip Reames; FIXED-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
764190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
765190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
766190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
767190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
768190cdf51SPhilip Reames; FIXED:       for.end:
769190cdf51SPhilip Reames; FIXED-NEXT:    ret void
770190cdf51SPhilip Reames;
771190cdf51SPhilip Reamesentry:
772190cdf51SPhilip Reames  br label %for.body
773190cdf51SPhilip Reames
774190cdf51SPhilip Reamesfor.body:
775190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
776190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
777190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
778190cdf51SPhilip Reames  %c = icmp ne i64 %elem, 42
779190cdf51SPhilip Reames  br i1 %c, label %do_op, label %latch
780190cdf51SPhilip Reamesdo_op:
781190cdf51SPhilip Reames  %divrem = udiv i64 %elem, 27
782190cdf51SPhilip Reames  br label %latch
783190cdf51SPhilip Reameslatch:
784190cdf51SPhilip Reames  %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
785190cdf51SPhilip Reames  store i64 %phi, ptr %arrayidx
786190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
787190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
788190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
789190cdf51SPhilip Reames
790190cdf51SPhilip Reamesfor.end:
791190cdf51SPhilip Reames  ret void
792190cdf51SPhilip Reames}
793190cdf51SPhilip Reames
794190cdf51SPhilip Reamesdefine void @predicated_sdiv_by_constant(ptr noalias nocapture %a, i64 %n) {
795190cdf51SPhilip Reames; CHECK-LABEL: @predicated_sdiv_by_constant(
796190cdf51SPhilip Reames; CHECK-NEXT:  entry:
797190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
7988d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 2
7998d16c680SLuke Lau; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
800190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
801190cdf51SPhilip Reames; CHECK:       vector.ph:
8028d16c680SLuke Lau; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
8038d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 2
8048d16c680SLuke Lau; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
805190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
8065ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
8075ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 2
808190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
809190cdf51SPhilip Reames; CHECK:       vector.body:
810190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
8115ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
8125ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP6]]
8135ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[TMP7]], i32 0
8145ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP8]], align 8
81556c091eaSPaul Walker; CHECK-NEXT:    [[TMP9:%.*]] = icmp ne <vscale x 2 x i64> [[WIDE_LOAD]], splat (i64 42)
81656c091eaSPaul Walker; CHECK-NEXT:    [[TMP10:%.*]] = sdiv <vscale x 2 x i64> [[WIDE_LOAD]], splat (i64 27)
8175ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[PREDPHI:%.*]] = select <vscale x 2 x i1> [[TMP9]], <vscale x 2 x i64> [[TMP10]], <vscale x 2 x i64> [[WIDE_LOAD]]
8185ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 2 x i64> [[PREDPHI]], ptr [[TMP8]], align 8
8195ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
82053266f73SFlorian Hahn; CHECK-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
82153266f73SFlorian Hahn; CHECK-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]
822190cdf51SPhilip Reames; CHECK:       middle.block:
823190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
824190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
825190cdf51SPhilip Reames; CHECK:       scalar.ph:
826190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
827190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
828190cdf51SPhilip Reames; CHECK:       for.body:
829190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
830190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
831190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
832190cdf51SPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ne i64 [[ELEM]], 42
833190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
834190cdf51SPhilip Reames; CHECK:       do_op:
835190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = sdiv i64 [[ELEM]], 27
836190cdf51SPhilip Reames; CHECK-NEXT:    br label [[LATCH]]
837190cdf51SPhilip Reames; CHECK:       latch:
838190cdf51SPhilip Reames; CHECK-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
839190cdf51SPhilip Reames; CHECK-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
840190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
841190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
842190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
843190cdf51SPhilip Reames; CHECK:       for.end:
844190cdf51SPhilip Reames; CHECK-NEXT:    ret void
845190cdf51SPhilip Reames;
846190cdf51SPhilip Reames; FIXED-LABEL: @predicated_sdiv_by_constant(
847190cdf51SPhilip Reames; FIXED-NEXT:  entry:
848190cdf51SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
849190cdf51SPhilip Reames; FIXED:       vector.ph:
850190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
851190cdf51SPhilip Reames; FIXED:       vector.body:
852190cdf51SPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
853190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
85453266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i64 [[TMP0]]
85553266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
85653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 4
85753266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP2]], align 8
85853266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <4 x i64>, ptr [[TMP3]], align 8
85938fffa63SPaul Walker; FIXED-NEXT:    [[TMP4:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD]], splat (i64 42)
86038fffa63SPaul Walker; FIXED-NEXT:    [[TMP5:%.*]] = icmp ne <4 x i64> [[WIDE_LOAD1]], splat (i64 42)
86138fffa63SPaul Walker; FIXED-NEXT:    [[TMP6:%.*]] = sdiv <4 x i64> [[WIDE_LOAD]], splat (i64 27)
86238fffa63SPaul Walker; FIXED-NEXT:    [[TMP7:%.*]] = sdiv <4 x i64> [[WIDE_LOAD1]], splat (i64 27)
86353266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP4]], <4 x i64> [[TMP6]], <4 x i64> [[WIDE_LOAD]]
86453266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI2:%.*]] = select <4 x i1> [[TMP5]], <4 x i64> [[TMP7]], <4 x i64> [[WIDE_LOAD1]]
86553266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI]], ptr [[TMP2]], align 8
86653266f73SFlorian Hahn; FIXED-NEXT:    store <4 x i64> [[PREDPHI2]], ptr [[TMP3]], align 8
8678d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
86853266f73SFlorian Hahn; FIXED-NEXT:    [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
86953266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]
870190cdf51SPhilip Reames; FIXED:       middle.block:
87196e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
872190cdf51SPhilip Reames; FIXED:       scalar.ph:
873190cdf51SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
874190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
875190cdf51SPhilip Reames; FIXED:       for.body:
876190cdf51SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
877190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
878190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
879190cdf51SPhilip Reames; FIXED-NEXT:    [[C:%.*]] = icmp ne i64 [[ELEM]], 42
880190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
881190cdf51SPhilip Reames; FIXED:       do_op:
882190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = sdiv i64 [[ELEM]], 27
883190cdf51SPhilip Reames; FIXED-NEXT:    br label [[LATCH]]
884190cdf51SPhilip Reames; FIXED:       latch:
885190cdf51SPhilip Reames; FIXED-NEXT:    [[PHI:%.*]] = phi i64 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
886190cdf51SPhilip Reames; FIXED-NEXT:    store i64 [[PHI]], ptr [[ARRAYIDX]], align 8
887190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
888190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
889190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
890190cdf51SPhilip Reames; FIXED:       for.end:
891190cdf51SPhilip Reames; FIXED-NEXT:    ret void
892190cdf51SPhilip Reames;
893190cdf51SPhilip Reamesentry:
894190cdf51SPhilip Reames  br label %for.body
895190cdf51SPhilip Reames
896190cdf51SPhilip Reamesfor.body:
897190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
898190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
899190cdf51SPhilip Reames  %elem = load i64, ptr %arrayidx
900190cdf51SPhilip Reames  %c = icmp ne i64 %elem, 42
901190cdf51SPhilip Reames  br i1 %c, label %do_op, label %latch
902190cdf51SPhilip Reamesdo_op:
903190cdf51SPhilip Reames  %divrem = sdiv i64 %elem, 27
904190cdf51SPhilip Reames  br label %latch
905190cdf51SPhilip Reameslatch:
906190cdf51SPhilip Reames  %phi = phi i64 [%elem, %for.body], [%divrem, %do_op]
907190cdf51SPhilip Reames  store i64 %phi, ptr %arrayidx
908190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
909190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
910190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
911190cdf51SPhilip Reames
912190cdf51SPhilip Reamesfor.end:
913190cdf51SPhilip Reames  ret void
914190cdf51SPhilip Reames}
915190cdf51SPhilip Reames
916190cdf51SPhilip Reamesdefine void @predicated_sdiv_by_minus_one(ptr noalias nocapture %a, i64 %n) {
917190cdf51SPhilip Reames; CHECK-LABEL: @predicated_sdiv_by_minus_one(
918190cdf51SPhilip Reames; CHECK-NEXT:  entry:
919190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
9208d16c680SLuke Lau; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 16
921190cdf51SPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
922190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
923190cdf51SPhilip Reames; CHECK:       vector.ph:
924190cdf51SPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
9258d16c680SLuke Lau; CHECK-NEXT:    [[TMP3:%.*]] = mul i64 [[TMP2]], 16
926190cdf51SPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
927190cdf51SPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
9285ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
9295ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP5:%.*]] = mul i64 [[TMP4]], 16
930190cdf51SPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
931190cdf51SPhilip Reames; CHECK:       vector.body:
932190cdf51SPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
9335ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 0
9345ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 [[TMP6]]
9355ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i8, ptr [[TMP7]], i32 0
9365ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 16 x i8>, ptr [[TMP8]], align 1
93756c091eaSPaul Walker; CHECK-NEXT:    [[TMP9:%.*]] = icmp ne <vscale x 16 x i8> [[WIDE_LOAD]], splat (i8 -128)
93856c091eaSPaul Walker; CHECK-NEXT:    [[TMP10:%.*]] = select <vscale x 16 x i1> [[TMP9]], <vscale x 16 x i8> splat (i8 -1), <vscale x 16 x i8> splat (i8 1)
9395ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[TMP11:%.*]] = sdiv <vscale x 16 x i8> [[WIDE_LOAD]], [[TMP10]]
9405ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[PREDPHI:%.*]] = select <vscale x 16 x i1> [[TMP9]], <vscale x 16 x i8> [[TMP11]], <vscale x 16 x i8> [[WIDE_LOAD]]
9415ea6a3fcSFlorian Hahn; CHECK-NEXT:    store <vscale x 16 x i8> [[PREDPHI]], ptr [[TMP8]], align 1
9425ea6a3fcSFlorian Hahn; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
94353266f73SFlorian Hahn; CHECK-NEXT:    [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
94453266f73SFlorian Hahn; CHECK-NEXT:    br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
945190cdf51SPhilip Reames; CHECK:       middle.block:
946190cdf51SPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
947190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
948190cdf51SPhilip Reames; CHECK:       scalar.ph:
949190cdf51SPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
950190cdf51SPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
951190cdf51SPhilip Reames; CHECK:       for.body:
952190cdf51SPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
953190cdf51SPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[IV]]
954190cdf51SPhilip Reames; CHECK-NEXT:    [[ELEM:%.*]] = load i8, ptr [[ARRAYIDX]], align 1
955190cdf51SPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ne i8 [[ELEM]], -128
956190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
957190cdf51SPhilip Reames; CHECK:       do_op:
958190cdf51SPhilip Reames; CHECK-NEXT:    [[DIVREM:%.*]] = sdiv i8 [[ELEM]], -1
959190cdf51SPhilip Reames; CHECK-NEXT:    br label [[LATCH]]
960190cdf51SPhilip Reames; CHECK:       latch:
961190cdf51SPhilip Reames; CHECK-NEXT:    [[PHI:%.*]] = phi i8 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
962190cdf51SPhilip Reames; CHECK-NEXT:    store i8 [[PHI]], ptr [[ARRAYIDX]], align 1
963190cdf51SPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
964190cdf51SPhilip Reames; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
965190cdf51SPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]
966190cdf51SPhilip Reames; CHECK:       for.end:
967190cdf51SPhilip Reames; CHECK-NEXT:    ret void
968190cdf51SPhilip Reames;
969190cdf51SPhilip Reames; FIXED-LABEL: @predicated_sdiv_by_minus_one(
970269bc684SPhilip Reames; FIXED-NEXT:  entry:
971269bc684SPhilip Reames; FIXED-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
972190cdf51SPhilip Reames; FIXED:       vector.ph:
973190cdf51SPhilip Reames; FIXED-NEXT:    br label [[VECTOR_BODY:%.*]]
974190cdf51SPhilip Reames; FIXED:       vector.body:
9754c4c0d2cSPhilip Reames; FIXED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
976190cdf51SPhilip Reames; FIXED-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
97753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 [[TMP0]]
97853266f73SFlorian Hahn; FIXED-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i8, ptr [[TMP1]], i32 0
97953266f73SFlorian Hahn; FIXED-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i8, ptr [[TMP1]], i32 32
98053266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD:%.*]] = load <32 x i8>, ptr [[TMP2]], align 1
98153266f73SFlorian Hahn; FIXED-NEXT:    [[WIDE_LOAD1:%.*]] = load <32 x i8>, ptr [[TMP3]], align 1
98238fffa63SPaul Walker; FIXED-NEXT:    [[TMP4:%.*]] = icmp ne <32 x i8> [[WIDE_LOAD]], splat (i8 -128)
98338fffa63SPaul Walker; FIXED-NEXT:    [[TMP5:%.*]] = icmp ne <32 x i8> [[WIDE_LOAD1]], splat (i8 -128)
98438fffa63SPaul Walker; FIXED-NEXT:    [[TMP6:%.*]] = select <32 x i1> [[TMP4]], <32 x i8> splat (i8 -1), <32 x i8> splat (i8 1)
98538fffa63SPaul Walker; FIXED-NEXT:    [[TMP7:%.*]] = select <32 x i1> [[TMP5]], <32 x i8> splat (i8 -1), <32 x i8> splat (i8 1)
98653266f73SFlorian Hahn; FIXED-NEXT:    [[TMP8:%.*]] = sdiv <32 x i8> [[WIDE_LOAD]], [[TMP6]]
98753266f73SFlorian Hahn; FIXED-NEXT:    [[TMP9:%.*]] = sdiv <32 x i8> [[WIDE_LOAD1]], [[TMP7]]
98853266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI:%.*]] = select <32 x i1> [[TMP4]], <32 x i8> [[TMP8]], <32 x i8> [[WIDE_LOAD]]
98953266f73SFlorian Hahn; FIXED-NEXT:    [[PREDPHI2:%.*]] = select <32 x i1> [[TMP5]], <32 x i8> [[TMP9]], <32 x i8> [[WIDE_LOAD1]]
99053266f73SFlorian Hahn; FIXED-NEXT:    store <32 x i8> [[PREDPHI]], ptr [[TMP2]], align 1
99153266f73SFlorian Hahn; FIXED-NEXT:    store <32 x i8> [[PREDPHI2]], ptr [[TMP3]], align 1
9928d16c680SLuke Lau; FIXED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 64
99353266f73SFlorian Hahn; FIXED-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
99453266f73SFlorian Hahn; FIXED-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
995190cdf51SPhilip Reames; FIXED:       middle.block:
99696e83d37SFlorian Hahn; FIXED-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
997269bc684SPhilip Reames; FIXED:       scalar.ph:
998269bc684SPhilip Reames; FIXED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
999190cdf51SPhilip Reames; FIXED-NEXT:    br label [[FOR_BODY:%.*]]
1000190cdf51SPhilip Reames; FIXED:       for.body:
1001269bc684SPhilip Reames; FIXED-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LATCH:%.*]] ]
1002190cdf51SPhilip Reames; FIXED-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[IV]]
1003190cdf51SPhilip Reames; FIXED-NEXT:    [[ELEM:%.*]] = load i8, ptr [[ARRAYIDX]], align 1
1004190cdf51SPhilip Reames; FIXED-NEXT:    [[C:%.*]] = icmp ne i8 [[ELEM]], -128
1005190cdf51SPhilip Reames; FIXED-NEXT:    br i1 [[C]], label [[DO_OP:%.*]], label [[LATCH]]
1006190cdf51SPhilip Reames; FIXED:       do_op:
1007190cdf51SPhilip Reames; FIXED-NEXT:    [[DIVREM:%.*]] = sdiv i8 [[ELEM]], -1
1008190cdf51SPhilip Reames; FIXED-NEXT:    br label [[LATCH]]
1009190cdf51SPhilip Reames; FIXED:       latch:
1010190cdf51SPhilip Reames; FIXED-NEXT:    [[PHI:%.*]] = phi i8 [ [[ELEM]], [[FOR_BODY]] ], [ [[DIVREM]], [[DO_OP]] ]
1011190cdf51SPhilip Reames; FIXED-NEXT:    store i8 [[PHI]], ptr [[ARRAYIDX]], align 1
1012190cdf51SPhilip Reames; FIXED-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
1013190cdf51SPhilip Reames; FIXED-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
1014269bc684SPhilip Reames; FIXED-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]
1015190cdf51SPhilip Reames; FIXED:       for.end:
1016190cdf51SPhilip Reames; FIXED-NEXT:    ret void
1017190cdf51SPhilip Reames;
1018190cdf51SPhilip Reamesentry:
1019190cdf51SPhilip Reames  br label %for.body
1020190cdf51SPhilip Reames
1021190cdf51SPhilip Reamesfor.body:
1022190cdf51SPhilip Reames  %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
1023190cdf51SPhilip Reames  %arrayidx = getelementptr inbounds i8, ptr %a, i64 %iv
1024190cdf51SPhilip Reames  %elem = load i8, ptr %arrayidx
1025190cdf51SPhilip Reames  %c = icmp ne i8 %elem, 128
1026190cdf51SPhilip Reames  br i1 %c, label %do_op, label %latch
1027190cdf51SPhilip Reamesdo_op:
1028190cdf51SPhilip Reames  %divrem = sdiv i8 %elem, -1 ;; UB if %elem = INT_MIN
1029190cdf51SPhilip Reames  br label %latch
1030190cdf51SPhilip Reameslatch:
1031190cdf51SPhilip Reames  %phi = phi i8 [%elem, %for.body], [%divrem, %do_op]
1032190cdf51SPhilip Reames  store i8 %phi, ptr %arrayidx
1033190cdf51SPhilip Reames  %iv.next = add nuw nsw i64 %iv, 1
1034190cdf51SPhilip Reames  %exitcond.not = icmp eq i64 %iv.next, 1024
1035190cdf51SPhilip Reames  br i1 %exitcond.not, label %for.end, label %for.body
1036190cdf51SPhilip Reames
1037190cdf51SPhilip Reamesfor.end:
1038190cdf51SPhilip Reames  ret void
1039190cdf51SPhilip Reames}
1040