1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.8.0"
7 @c = common global [2048 x i32] zeroinitializer, align 16
8 @b = common global [2048 x i32] zeroinitializer, align 16
9 @d = common global [2048 x i32] zeroinitializer, align 16
10 @a = common global [2048 x i32] zeroinitializer, align 16
12 ; The program below gathers and scatters data. We better not vectorize it.
13 define void @cost_model_1() nounwind uwtable noinline ssp {
14 ; CHECK-LABEL: @cost_model_1(
16 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
18 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
19 ; CHECK-NEXT: [[TMP0:%.*]] = shl nsw i64 [[INDVARS_IV]], 1
20 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2048 x i32], ptr @c, i64 0, i64 [[TMP0]]
21 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX]], align 8
22 ; CHECK-NEXT: [[IDXPROM1:%.*]] = sext i32 [[TMP1]] to i64
23 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2048 x i32], ptr @b, i64 0, i64 [[IDXPROM1]]
24 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
25 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [2048 x i32], ptr @d, i64 0, i64 [[INDVARS_IV]]
26 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX4]], align 4
27 ; CHECK-NEXT: [[IDXPROM5:%.*]] = sext i32 [[TMP3]] to i64
28 ; CHECK-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds [2048 x i32], ptr @a, i64 0, i64 [[IDXPROM5]]
29 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[ARRAYIDX6]], align 4
30 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
31 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
32 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], 256
33 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
35 ; CHECK-NEXT: ret void
40 for.body: ; preds = %for.body, %entry
41 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
42 %0 = shl nsw i64 %indvars.iv, 1
43 %arrayidx = getelementptr inbounds [2048 x i32], ptr @c, i64 0, i64 %0
44 %1 = load i32, ptr %arrayidx, align 8
45 %idxprom1 = sext i32 %1 to i64
46 %arrayidx2 = getelementptr inbounds [2048 x i32], ptr @b, i64 0, i64 %idxprom1
47 %2 = load i32, ptr %arrayidx2, align 4
48 %arrayidx4 = getelementptr inbounds [2048 x i32], ptr @d, i64 0, i64 %indvars.iv
49 %3 = load i32, ptr %arrayidx4, align 4
50 %idxprom5 = sext i32 %3 to i64
51 %arrayidx6 = getelementptr inbounds [2048 x i32], ptr @a, i64 0, i64 %idxprom5
52 store i32 %2, ptr %arrayidx6, align 4
53 %indvars.iv.next = add i64 %indvars.iv, 1
54 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
55 %exitcond = icmp eq i32 %lftr.wideiv, 256
56 br i1 %exitcond, label %for.end, label %for.body
58 for.end: ; preds = %for.body
62 ; This function uses a stride that is generally too big to benefit from vectorization without
63 ; really good support for a gather load. But if we don't vectorize the pointer induction,
64 ; then we don't need to extract the pointers out of vector of pointers,
65 ; and the vectorization becomes profitable.
67 define float @PR27826(ptr nocapture readonly %a, ptr nocapture readonly %b, i32 %n) {
68 ; CHECK-LABEL: @PR27826(
70 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[N:%.*]], 0
71 ; CHECK-NEXT: br i1 [[CMP]], label [[ITER_CHECK:%.*]], label [[FOR_END:%.*]]
73 ; CHECK-NEXT: [[T0:%.*]] = sext i32 [[N]] to i64
74 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i64 [[T0]], -1
75 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[TMP0]], 5
76 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
77 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 4
78 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH:%.*]], label [[VECTOR_MAIN_LOOP_ITER_CHECK:%.*]]
79 ; CHECK: vector.main.loop.iter.check:
80 ; CHECK-NEXT: [[MIN_ITERS_CHECK1:%.*]] = icmp ult i64 [[TMP2]], 16
81 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK1]], label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH:%.*]]
83 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 16
84 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
85 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
87 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
88 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP119:%.*]], [[VECTOR_BODY]] ]
89 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <4 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP120:%.*]], [[VECTOR_BODY]] ]
90 ; CHECK-NEXT: [[VEC_PHI3:%.*]] = phi <4 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP121:%.*]], [[VECTOR_BODY]] ]
91 ; CHECK-NEXT: [[VEC_PHI4:%.*]] = phi <4 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP122:%.*]], [[VECTOR_BODY]] ]
92 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], 32
93 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[OFFSET_IDX]], 0
94 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[OFFSET_IDX]], 32
95 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[OFFSET_IDX]], 64
96 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[OFFSET_IDX]], 96
97 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[OFFSET_IDX]], 128
98 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[OFFSET_IDX]], 160
99 ; CHECK-NEXT: [[TMP9:%.*]] = add i64 [[OFFSET_IDX]], 192
100 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[OFFSET_IDX]], 224
101 ; CHECK-NEXT: [[TMP11:%.*]] = add i64 [[OFFSET_IDX]], 256
102 ; CHECK-NEXT: [[TMP12:%.*]] = add i64 [[OFFSET_IDX]], 288
103 ; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[OFFSET_IDX]], 320
104 ; CHECK-NEXT: [[TMP14:%.*]] = add i64 [[OFFSET_IDX]], 352
105 ; CHECK-NEXT: [[TMP15:%.*]] = add i64 [[OFFSET_IDX]], 384
106 ; CHECK-NEXT: [[TMP16:%.*]] = add i64 [[OFFSET_IDX]], 416
107 ; CHECK-NEXT: [[TMP17:%.*]] = add i64 [[OFFSET_IDX]], 448
108 ; CHECK-NEXT: [[TMP18:%.*]] = add i64 [[OFFSET_IDX]], 480
109 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr inbounds float, ptr [[A:%.*]], i64 [[TMP3]]
110 ; CHECK-NEXT: [[TMP20:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP4]]
111 ; CHECK-NEXT: [[TMP21:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP5]]
112 ; CHECK-NEXT: [[TMP22:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP6]]
113 ; CHECK-NEXT: [[TMP23:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP7]]
114 ; CHECK-NEXT: [[TMP24:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP8]]
115 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP9]]
116 ; CHECK-NEXT: [[TMP26:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP10]]
117 ; CHECK-NEXT: [[TMP27:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP11]]
118 ; CHECK-NEXT: [[TMP28:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP12]]
119 ; CHECK-NEXT: [[TMP29:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP13]]
120 ; CHECK-NEXT: [[TMP30:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP14]]
121 ; CHECK-NEXT: [[TMP31:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP15]]
122 ; CHECK-NEXT: [[TMP32:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP16]]
123 ; CHECK-NEXT: [[TMP33:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP17]]
124 ; CHECK-NEXT: [[TMP34:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP18]]
125 ; CHECK-NEXT: [[TMP35:%.*]] = load float, ptr [[TMP19]], align 4
126 ; CHECK-NEXT: [[TMP36:%.*]] = load float, ptr [[TMP20]], align 4
127 ; CHECK-NEXT: [[TMP37:%.*]] = load float, ptr [[TMP21]], align 4
128 ; CHECK-NEXT: [[TMP38:%.*]] = load float, ptr [[TMP22]], align 4
129 ; CHECK-NEXT: [[TMP39:%.*]] = insertelement <4 x float> poison, float [[TMP35]], i32 0
130 ; CHECK-NEXT: [[TMP40:%.*]] = insertelement <4 x float> [[TMP39]], float [[TMP36]], i32 1
131 ; CHECK-NEXT: [[TMP41:%.*]] = insertelement <4 x float> [[TMP40]], float [[TMP37]], i32 2
132 ; CHECK-NEXT: [[TMP42:%.*]] = insertelement <4 x float> [[TMP41]], float [[TMP38]], i32 3
133 ; CHECK-NEXT: [[TMP43:%.*]] = load float, ptr [[TMP23]], align 4
134 ; CHECK-NEXT: [[TMP44:%.*]] = load float, ptr [[TMP24]], align 4
135 ; CHECK-NEXT: [[TMP45:%.*]] = load float, ptr [[TMP25]], align 4
136 ; CHECK-NEXT: [[TMP46:%.*]] = load float, ptr [[TMP26]], align 4
137 ; CHECK-NEXT: [[TMP47:%.*]] = insertelement <4 x float> poison, float [[TMP43]], i32 0
138 ; CHECK-NEXT: [[TMP48:%.*]] = insertelement <4 x float> [[TMP47]], float [[TMP44]], i32 1
139 ; CHECK-NEXT: [[TMP49:%.*]] = insertelement <4 x float> [[TMP48]], float [[TMP45]], i32 2
140 ; CHECK-NEXT: [[TMP50:%.*]] = insertelement <4 x float> [[TMP49]], float [[TMP46]], i32 3
141 ; CHECK-NEXT: [[TMP51:%.*]] = load float, ptr [[TMP27]], align 4
142 ; CHECK-NEXT: [[TMP52:%.*]] = load float, ptr [[TMP28]], align 4
143 ; CHECK-NEXT: [[TMP53:%.*]] = load float, ptr [[TMP29]], align 4
144 ; CHECK-NEXT: [[TMP54:%.*]] = load float, ptr [[TMP30]], align 4
145 ; CHECK-NEXT: [[TMP55:%.*]] = insertelement <4 x float> poison, float [[TMP51]], i32 0
146 ; CHECK-NEXT: [[TMP56:%.*]] = insertelement <4 x float> [[TMP55]], float [[TMP52]], i32 1
147 ; CHECK-NEXT: [[TMP57:%.*]] = insertelement <4 x float> [[TMP56]], float [[TMP53]], i32 2
148 ; CHECK-NEXT: [[TMP58:%.*]] = insertelement <4 x float> [[TMP57]], float [[TMP54]], i32 3
149 ; CHECK-NEXT: [[TMP59:%.*]] = load float, ptr [[TMP31]], align 4
150 ; CHECK-NEXT: [[TMP60:%.*]] = load float, ptr [[TMP32]], align 4
151 ; CHECK-NEXT: [[TMP61:%.*]] = load float, ptr [[TMP33]], align 4
152 ; CHECK-NEXT: [[TMP62:%.*]] = load float, ptr [[TMP34]], align 4
153 ; CHECK-NEXT: [[TMP63:%.*]] = insertelement <4 x float> poison, float [[TMP59]], i32 0
154 ; CHECK-NEXT: [[TMP64:%.*]] = insertelement <4 x float> [[TMP63]], float [[TMP60]], i32 1
155 ; CHECK-NEXT: [[TMP65:%.*]] = insertelement <4 x float> [[TMP64]], float [[TMP61]], i32 2
156 ; CHECK-NEXT: [[TMP66:%.*]] = insertelement <4 x float> [[TMP65]], float [[TMP62]], i32 3
157 ; CHECK-NEXT: [[TMP67:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i64 [[TMP3]]
158 ; CHECK-NEXT: [[TMP68:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP4]]
159 ; CHECK-NEXT: [[TMP69:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP5]]
160 ; CHECK-NEXT: [[TMP70:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP6]]
161 ; CHECK-NEXT: [[TMP71:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP7]]
162 ; CHECK-NEXT: [[TMP72:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP8]]
163 ; CHECK-NEXT: [[TMP73:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP9]]
164 ; CHECK-NEXT: [[TMP74:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP10]]
165 ; CHECK-NEXT: [[TMP75:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP11]]
166 ; CHECK-NEXT: [[TMP76:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP12]]
167 ; CHECK-NEXT: [[TMP77:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP13]]
168 ; CHECK-NEXT: [[TMP78:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP14]]
169 ; CHECK-NEXT: [[TMP79:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP15]]
170 ; CHECK-NEXT: [[TMP80:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP16]]
171 ; CHECK-NEXT: [[TMP81:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP17]]
172 ; CHECK-NEXT: [[TMP82:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP18]]
173 ; CHECK-NEXT: [[TMP83:%.*]] = load float, ptr [[TMP67]], align 4
174 ; CHECK-NEXT: [[TMP84:%.*]] = load float, ptr [[TMP68]], align 4
175 ; CHECK-NEXT: [[TMP85:%.*]] = load float, ptr [[TMP69]], align 4
176 ; CHECK-NEXT: [[TMP86:%.*]] = load float, ptr [[TMP70]], align 4
177 ; CHECK-NEXT: [[TMP87:%.*]] = insertelement <4 x float> poison, float [[TMP83]], i32 0
178 ; CHECK-NEXT: [[TMP88:%.*]] = insertelement <4 x float> [[TMP87]], float [[TMP84]], i32 1
179 ; CHECK-NEXT: [[TMP89:%.*]] = insertelement <4 x float> [[TMP88]], float [[TMP85]], i32 2
180 ; CHECK-NEXT: [[TMP90:%.*]] = insertelement <4 x float> [[TMP89]], float [[TMP86]], i32 3
181 ; CHECK-NEXT: [[TMP91:%.*]] = load float, ptr [[TMP71]], align 4
182 ; CHECK-NEXT: [[TMP92:%.*]] = load float, ptr [[TMP72]], align 4
183 ; CHECK-NEXT: [[TMP93:%.*]] = load float, ptr [[TMP73]], align 4
184 ; CHECK-NEXT: [[TMP94:%.*]] = load float, ptr [[TMP74]], align 4
185 ; CHECK-NEXT: [[TMP95:%.*]] = insertelement <4 x float> poison, float [[TMP91]], i32 0
186 ; CHECK-NEXT: [[TMP96:%.*]] = insertelement <4 x float> [[TMP95]], float [[TMP92]], i32 1
187 ; CHECK-NEXT: [[TMP97:%.*]] = insertelement <4 x float> [[TMP96]], float [[TMP93]], i32 2
188 ; CHECK-NEXT: [[TMP98:%.*]] = insertelement <4 x float> [[TMP97]], float [[TMP94]], i32 3
189 ; CHECK-NEXT: [[TMP99:%.*]] = load float, ptr [[TMP75]], align 4
190 ; CHECK-NEXT: [[TMP100:%.*]] = load float, ptr [[TMP76]], align 4
191 ; CHECK-NEXT: [[TMP101:%.*]] = load float, ptr [[TMP77]], align 4
192 ; CHECK-NEXT: [[TMP102:%.*]] = load float, ptr [[TMP78]], align 4
193 ; CHECK-NEXT: [[TMP103:%.*]] = insertelement <4 x float> poison, float [[TMP99]], i32 0
194 ; CHECK-NEXT: [[TMP104:%.*]] = insertelement <4 x float> [[TMP103]], float [[TMP100]], i32 1
195 ; CHECK-NEXT: [[TMP105:%.*]] = insertelement <4 x float> [[TMP104]], float [[TMP101]], i32 2
196 ; CHECK-NEXT: [[TMP106:%.*]] = insertelement <4 x float> [[TMP105]], float [[TMP102]], i32 3
197 ; CHECK-NEXT: [[TMP107:%.*]] = load float, ptr [[TMP79]], align 4
198 ; CHECK-NEXT: [[TMP108:%.*]] = load float, ptr [[TMP80]], align 4
199 ; CHECK-NEXT: [[TMP109:%.*]] = load float, ptr [[TMP81]], align 4
200 ; CHECK-NEXT: [[TMP110:%.*]] = load float, ptr [[TMP82]], align 4
201 ; CHECK-NEXT: [[TMP111:%.*]] = insertelement <4 x float> poison, float [[TMP107]], i32 0
202 ; CHECK-NEXT: [[TMP112:%.*]] = insertelement <4 x float> [[TMP111]], float [[TMP108]], i32 1
203 ; CHECK-NEXT: [[TMP113:%.*]] = insertelement <4 x float> [[TMP112]], float [[TMP109]], i32 2
204 ; CHECK-NEXT: [[TMP114:%.*]] = insertelement <4 x float> [[TMP113]], float [[TMP110]], i32 3
205 ; CHECK-NEXT: [[TMP115:%.*]] = fadd fast <4 x float> [[TMP42]], [[VEC_PHI]]
206 ; CHECK-NEXT: [[TMP116:%.*]] = fadd fast <4 x float> [[TMP50]], [[VEC_PHI2]]
207 ; CHECK-NEXT: [[TMP117:%.*]] = fadd fast <4 x float> [[TMP58]], [[VEC_PHI3]]
208 ; CHECK-NEXT: [[TMP118:%.*]] = fadd fast <4 x float> [[TMP66]], [[VEC_PHI4]]
209 ; CHECK-NEXT: [[TMP119]] = fadd fast <4 x float> [[TMP115]], [[TMP90]]
210 ; CHECK-NEXT: [[TMP120]] = fadd fast <4 x float> [[TMP116]], [[TMP98]]
211 ; CHECK-NEXT: [[TMP121]] = fadd fast <4 x float> [[TMP117]], [[TMP106]]
212 ; CHECK-NEXT: [[TMP122]] = fadd fast <4 x float> [[TMP118]], [[TMP114]]
213 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
214 ; CHECK-NEXT: [[TMP123:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
215 ; CHECK-NEXT: br i1 [[TMP123]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
216 ; CHECK: middle.block:
217 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd fast <4 x float> [[TMP120]], [[TMP119]]
218 ; CHECK-NEXT: [[BIN_RDX5:%.*]] = fadd fast <4 x float> [[TMP121]], [[BIN_RDX]]
219 ; CHECK-NEXT: [[BIN_RDX6:%.*]] = fadd fast <4 x float> [[TMP122]], [[BIN_RDX5]]
220 ; CHECK-NEXT: [[TMP124:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[BIN_RDX6]])
221 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
222 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[VEC_EPILOG_ITER_CHECK:%.*]]
223 ; CHECK: vec.epilog.iter.check:
224 ; CHECK-NEXT: [[IND_END9:%.*]] = mul i64 [[N_VEC]], 32
225 ; CHECK-NEXT: [[N_VEC_REMAINING:%.*]] = sub i64 [[TMP2]], [[N_VEC]]
226 ; CHECK-NEXT: [[MIN_EPILOG_ITERS_CHECK:%.*]] = icmp ult i64 [[N_VEC_REMAINING]], 4
227 ; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH]], label [[VEC_EPILOG_PH]]
228 ; CHECK: vec.epilog.ph:
229 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi float [ [[TMP124]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0.000000e+00, [[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
230 ; CHECK-NEXT: [[VEC_EPILOG_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
231 ; CHECK-NEXT: [[N_MOD_VF7:%.*]] = urem i64 [[TMP2]], 4
232 ; CHECK-NEXT: [[N_VEC8:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF7]]
233 ; CHECK-NEXT: [[IND_END:%.*]] = mul i64 [[N_VEC8]], 32
234 ; CHECK-NEXT: [[TMP125:%.*]] = insertelement <4 x float> zeroinitializer, float [[BC_MERGE_RDX]], i32 0
235 ; CHECK-NEXT: br label [[VEC_EPILOG_VECTOR_BODY:%.*]]
236 ; CHECK: vec.epilog.vector.body:
237 ; CHECK-NEXT: [[INDEX10:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL]], [[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT13:%.*]], [[VEC_EPILOG_VECTOR_BODY]] ]
238 ; CHECK-NEXT: [[VEC_PHI11:%.*]] = phi <4 x float> [ [[TMP125]], [[VEC_EPILOG_PH]] ], [ [[TMP155:%.*]], [[VEC_EPILOG_VECTOR_BODY]] ]
239 ; CHECK-NEXT: [[OFFSET_IDX12:%.*]] = mul i64 [[INDEX10]], 32
240 ; CHECK-NEXT: [[TMP126:%.*]] = add i64 [[OFFSET_IDX12]], 0
241 ; CHECK-NEXT: [[TMP127:%.*]] = add i64 [[OFFSET_IDX12]], 32
242 ; CHECK-NEXT: [[TMP128:%.*]] = add i64 [[OFFSET_IDX12]], 64
243 ; CHECK-NEXT: [[TMP129:%.*]] = add i64 [[OFFSET_IDX12]], 96
244 ; CHECK-NEXT: [[TMP130:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP126]]
245 ; CHECK-NEXT: [[TMP131:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP127]]
246 ; CHECK-NEXT: [[TMP132:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP128]]
247 ; CHECK-NEXT: [[TMP133:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[TMP129]]
248 ; CHECK-NEXT: [[TMP134:%.*]] = load float, ptr [[TMP130]], align 4
249 ; CHECK-NEXT: [[TMP135:%.*]] = load float, ptr [[TMP131]], align 4
250 ; CHECK-NEXT: [[TMP136:%.*]] = load float, ptr [[TMP132]], align 4
251 ; CHECK-NEXT: [[TMP137:%.*]] = load float, ptr [[TMP133]], align 4
252 ; CHECK-NEXT: [[TMP138:%.*]] = insertelement <4 x float> poison, float [[TMP134]], i32 0
253 ; CHECK-NEXT: [[TMP139:%.*]] = insertelement <4 x float> [[TMP138]], float [[TMP135]], i32 1
254 ; CHECK-NEXT: [[TMP140:%.*]] = insertelement <4 x float> [[TMP139]], float [[TMP136]], i32 2
255 ; CHECK-NEXT: [[TMP141:%.*]] = insertelement <4 x float> [[TMP140]], float [[TMP137]], i32 3
256 ; CHECK-NEXT: [[TMP142:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP126]]
257 ; CHECK-NEXT: [[TMP143:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP127]]
258 ; CHECK-NEXT: [[TMP144:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP128]]
259 ; CHECK-NEXT: [[TMP145:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[TMP129]]
260 ; CHECK-NEXT: [[TMP146:%.*]] = load float, ptr [[TMP142]], align 4
261 ; CHECK-NEXT: [[TMP147:%.*]] = load float, ptr [[TMP143]], align 4
262 ; CHECK-NEXT: [[TMP148:%.*]] = load float, ptr [[TMP144]], align 4
263 ; CHECK-NEXT: [[TMP149:%.*]] = load float, ptr [[TMP145]], align 4
264 ; CHECK-NEXT: [[TMP150:%.*]] = insertelement <4 x float> poison, float [[TMP146]], i32 0
265 ; CHECK-NEXT: [[TMP151:%.*]] = insertelement <4 x float> [[TMP150]], float [[TMP147]], i32 1
266 ; CHECK-NEXT: [[TMP152:%.*]] = insertelement <4 x float> [[TMP151]], float [[TMP148]], i32 2
267 ; CHECK-NEXT: [[TMP153:%.*]] = insertelement <4 x float> [[TMP152]], float [[TMP149]], i32 3
268 ; CHECK-NEXT: [[TMP154:%.*]] = fadd fast <4 x float> [[TMP141]], [[VEC_PHI11]]
269 ; CHECK-NEXT: [[TMP155]] = fadd fast <4 x float> [[TMP154]], [[TMP153]]
270 ; CHECK-NEXT: [[INDEX_NEXT13]] = add nuw i64 [[INDEX10]], 4
271 ; CHECK-NEXT: [[TMP156:%.*]] = icmp eq i64 [[INDEX_NEXT13]], [[N_VEC8]]
272 ; CHECK-NEXT: br i1 [[TMP156]], label [[VEC_EPILOG_MIDDLE_BLOCK:%.*]], label [[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
273 ; CHECK: vec.epilog.middle.block:
274 ; CHECK-NEXT: [[TMP157:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[TMP155]])
275 ; CHECK-NEXT: [[CMP_N14:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC8]]
276 ; CHECK-NEXT: br i1 [[CMP_N14]], label [[LOOPEXIT]], label [[VEC_EPILOG_SCALAR_PH]]
277 ; CHECK: vec.epilog.scalar.ph:
278 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[VEC_EPILOG_MIDDLE_BLOCK]] ], [ [[IND_END9]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[ITER_CHECK]] ]
279 ; CHECK-NEXT: [[BC_MERGE_RDX15:%.*]] = phi float [ [[TMP157]], [[VEC_EPILOG_MIDDLE_BLOCK]] ], [ 0.000000e+00, [[ITER_CHECK]] ], [ [[TMP124]], [[VEC_EPILOG_ITER_CHECK]] ]
280 ; CHECK-NEXT: br label [[FOR:%.*]]
282 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[VEC_EPILOG_SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR]] ]
283 ; CHECK-NEXT: [[S_02:%.*]] = phi float [ [[BC_MERGE_RDX15]], [[VEC_EPILOG_SCALAR_PH]] ], [ [[ADD4:%.*]], [[FOR]] ]
284 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[INDVARS_IV]]
285 ; CHECK-NEXT: [[T1:%.*]] = load float, ptr [[ARRAYIDX]], align 4
286 ; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[INDVARS_IV]]
287 ; CHECK-NEXT: [[T2:%.*]] = load float, ptr [[ARRAYIDX3]], align 4
288 ; CHECK-NEXT: [[ADD:%.*]] = fadd fast float [[T1]], [[S_02]]
289 ; CHECK-NEXT: [[ADD4]] = fadd fast float [[ADD]], [[T2]]
290 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 32
291 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[INDVARS_IV_NEXT]], [[T0]]
292 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR]], label [[LOOPEXIT]], !llvm.loop [[LOOP4:![0-9]+]]
294 ; CHECK-NEXT: [[ADD4_LCSSA:%.*]] = phi float [ [[ADD4]], [[FOR]] ], [ [[TMP124]], [[MIDDLE_BLOCK]] ], [ [[TMP157]], [[VEC_EPILOG_MIDDLE_BLOCK]] ]
295 ; CHECK-NEXT: br label [[FOR_END]]
297 ; CHECK-NEXT: [[S_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD4_LCSSA]], [[LOOPEXIT]] ]
298 ; CHECK-NEXT: ret float [[S_0_LCSSA]]
301 %cmp = icmp sgt i32 %n, 0
302 br i1 %cmp, label %preheader, label %for.end
305 %t0 = sext i32 %n to i64
309 %indvars.iv = phi i64 [ 0, %preheader ], [ %indvars.iv.next, %for ]
310 %s.02 = phi float [ 0.0, %preheader ], [ %add4, %for ]
311 %arrayidx = getelementptr inbounds float, ptr %a, i64 %indvars.iv
312 %t1 = load float, ptr %arrayidx, align 4
313 %arrayidx3 = getelementptr inbounds float, ptr %b, i64 %indvars.iv
314 %t2 = load float, ptr %arrayidx3, align 4
315 %add = fadd fast float %t1, %s.02
316 %add4 = fadd fast float %add, %t2
317 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 32
318 %cmp1 = icmp slt i64 %indvars.iv.next, %t0
319 br i1 %cmp1, label %for, label %loopexit
322 %add4.lcssa = phi float [ %add4, %for ]
326 %s.0.lcssa = phi float [ 0.0, %entry ], [ %add4.lcssa, %loopexit ]
330 define void @multi_exit(ptr %dst, ptr %src.1, ptr %src.2, i64 %A, i64 %B) #0 {
331 ; CHECK-LABEL: @multi_exit(
333 ; CHECK-NEXT: [[UMAX6:%.*]] = call i64 @llvm.umax.i64(i64 [[B:%.*]], i64 1)
334 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[UMAX6]], -1
335 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i64 [[TMP0]]
336 ; CHECK-NEXT: [[UMIN7:%.*]] = call i64 @llvm.umin.i64(i64 [[TMP1]], i64 [[A:%.*]])
337 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw i64 [[UMIN7]], 1
338 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 [[TMP2]], 30
339 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
340 ; CHECK: vector.scevcheck:
341 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[B]], i64 1)
342 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[UMAX]], -1
343 ; CHECK-NEXT: [[TMP4:%.*]] = freeze i64 [[TMP3]]
344 ; CHECK-NEXT: [[UMIN:%.*]] = call i64 @llvm.umin.i64(i64 [[TMP4]], i64 [[A]])
345 ; CHECK-NEXT: [[TMP5:%.*]] = icmp ugt i64 [[UMIN]], 4294967295
346 ; CHECK-NEXT: [[TMP6:%.*]] = trunc i64 [[UMIN]] to i32
347 ; CHECK-NEXT: [[TMP7:%.*]] = add i32 1, [[TMP6]]
348 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ult i32 [[TMP7]], 1
349 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ugt i64 [[UMIN]], 4294967295
350 ; CHECK-NEXT: [[TMP10:%.*]] = or i1 [[TMP8]], [[TMP9]]
351 ; CHECK-NEXT: br i1 [[TMP10]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]]
352 ; CHECK: vector.memcheck:
353 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[DST:%.*]], i64 1
354 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[SRC_1:%.*]], i64 8
355 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[SRC_2:%.*]], i64 8
356 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[DST]], [[SCEVGEP1]]
357 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[SRC_1]], [[SCEVGEP]]
358 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
359 ; CHECK-NEXT: [[BOUND03:%.*]] = icmp ult ptr [[DST]], [[SCEVGEP2]]
360 ; CHECK-NEXT: [[BOUND14:%.*]] = icmp ult ptr [[SRC_2]], [[SCEVGEP]]
361 ; CHECK-NEXT: [[FOUND_CONFLICT5:%.*]] = and i1 [[BOUND03]], [[BOUND14]]
362 ; CHECK-NEXT: [[CONFLICT_RDX:%.*]] = or i1 [[FOUND_CONFLICT]], [[FOUND_CONFLICT5]]
363 ; CHECK-NEXT: br i1 [[CONFLICT_RDX]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
365 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 4
366 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
367 ; CHECK-NEXT: [[TMP12:%.*]] = select i1 [[TMP11]], i64 4, i64 [[N_MOD_VF]]
368 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[TMP12]]
369 ; CHECK-NEXT: [[IND_END:%.*]] = trunc i64 [[N_VEC]] to i32
370 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
371 ; CHECK: vector.body:
372 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
373 ; CHECK-NEXT: [[TMP13:%.*]] = load i64, ptr [[SRC_1]], align 8, !alias.scope [[META5:![0-9]+]]
374 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[TMP13]], i64 0
375 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
376 ; CHECK-NEXT: [[TMP14:%.*]] = load i64, ptr [[SRC_2]], align 8, !alias.scope [[META8:![0-9]+]]
377 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT9:%.*]] = insertelement <2 x i64> poison, i64 [[TMP14]], i64 0
378 ; CHECK-NEXT: [[BROADCAST_SPLAT10:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT9]], <2 x i64> poison, <2 x i32> zeroinitializer
379 ; CHECK-NEXT: [[TMP15:%.*]] = icmp eq <2 x i64> [[BROADCAST_SPLAT]], zeroinitializer
380 ; CHECK-NEXT: [[TMP16:%.*]] = icmp ne <2 x i64> [[BROADCAST_SPLAT10]], zeroinitializer
381 ; CHECK-NEXT: [[TMP17:%.*]] = and <2 x i1> [[TMP16]], [[TMP15]]
382 ; CHECK-NEXT: [[TMP18:%.*]] = zext <2 x i1> [[TMP17]] to <2 x i8>
383 ; CHECK-NEXT: [[TMP19:%.*]] = extractelement <2 x i8> [[TMP18]], i32 1
384 ; CHECK-NEXT: store i8 [[TMP19]], ptr [[DST]], align 1, !alias.scope [[META10:![0-9]+]], !noalias [[META12:![0-9]+]]
385 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
386 ; CHECK-NEXT: [[TMP20:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
387 ; CHECK-NEXT: br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
388 ; CHECK: middle.block:
389 ; CHECK-NEXT: br label [[SCALAR_PH]]
391 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[VECTOR_MEMCHECK]] ]
392 ; CHECK-NEXT: [[BC_RESUME_VAL8:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ], [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[VECTOR_MEMCHECK]] ]
393 ; CHECK-NEXT: br label [[LOOP:%.*]]
395 ; CHECK-NEXT: [[IV_1_WIDE:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_1_NEXT_WIDE:%.*]], [[LOOP_LATCH:%.*]] ]
396 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ [[BC_RESUME_VAL8]], [[SCALAR_PH]] ], [ [[IV_1_NEXT:%.*]], [[LOOP_LATCH]] ]
397 ; CHECK-NEXT: [[EC_1:%.*]] = icmp ult i64 [[IV_1_WIDE]], [[A]]
398 ; CHECK-NEXT: br i1 [[EC_1]], label [[LOOP_LATCH]], label [[EXIT:%.*]]
400 ; CHECK-NEXT: [[L_1:%.*]] = load i64, ptr [[SRC_1]], align 8
401 ; CHECK-NEXT: [[L_2:%.*]] = load i64, ptr [[SRC_2]], align 8
402 ; CHECK-NEXT: [[CMP55_US:%.*]] = icmp eq i64 [[L_1]], 0
403 ; CHECK-NEXT: [[CMP_I_US:%.*]] = icmp ne i64 [[L_2]], 0
404 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP_I_US]], [[CMP55_US]]
405 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[AND]] to i8
406 ; CHECK-NEXT: store i8 [[EXT]], ptr [[DST]], align 1
407 ; CHECK-NEXT: [[IV_1_NEXT]] = add i32 [[IV_1]], 1
408 ; CHECK-NEXT: [[IV_1_NEXT_WIDE]] = zext i32 [[IV_1_NEXT]] to i64
409 ; CHECK-NEXT: [[EC_2:%.*]] = icmp ult i64 [[IV_1_NEXT_WIDE]], [[B]]
410 ; CHECK-NEXT: br i1 [[EC_2]], label [[LOOP]], label [[EXIT]], !llvm.loop [[LOOP14:![0-9]+]]
412 ; CHECK-NEXT: ret void
418 %iv.1.wide = phi i64 [ 0, %entry ], [ %iv.1.next.wide, %loop.latch ]
419 %iv.1 = phi i32 [ 0, %entry ], [ %iv.1.next, %loop.latch ]
420 %ec.1 = icmp ult i64 %iv.1.wide, %A
421 br i1 %ec.1, label %loop.latch, label %exit
424 %l.1 = load i64, ptr %src.1, align 8
425 %l.2 = load i64, ptr %src.2, align 8
426 %cmp55.us = icmp eq i64 %l.1, 0
427 %cmp.i.us = icmp ne i64 %l.2, 0
428 %and = and i1 %cmp.i.us, %cmp55.us
429 %ext = zext i1 %and to i8
430 store i8 %ext, ptr %dst, align 1
431 %iv.1.next = add i32 %iv.1, 1
432 %iv.1.next.wide = zext i32 %iv.1.next to i64
433 %ec.2 = icmp ult i64 %iv.1.next.wide, %B
434 br i1 %ec.2, label %loop, label %exit
440 define i1 @any_of_cost(ptr %start, ptr %end) #0 {
441 ; CHECK-LABEL: @any_of_cost(
443 ; CHECK-NEXT: [[START2:%.*]] = ptrtoint ptr [[START:%.*]] to i64
444 ; CHECK-NEXT: [[END1:%.*]] = ptrtoint ptr [[END:%.*]] to i64
445 ; CHECK-NEXT: [[TMP0:%.*]] = sub i64 [[END1]], [[START2]]
446 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[TMP0]], 40
447 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
448 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 [[TMP2]], 4
449 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
451 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 4
452 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
453 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i64 4, i64 [[N_MOD_VF]]
454 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[TMP4]]
455 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[N_VEC]], 40
456 ; CHECK-NEXT: [[IND_END:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP5]]
457 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
458 ; CHECK: vector.body:
459 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
460 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <2 x i1> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP26:%.*]], [[VECTOR_BODY]] ]
461 ; CHECK-NEXT: [[VEC_PHI3:%.*]] = phi <2 x i1> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP27:%.*]], [[VECTOR_BODY]] ]
462 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], 40
463 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[OFFSET_IDX]], 0
464 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[OFFSET_IDX]], 40
465 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[OFFSET_IDX]], 80
466 ; CHECK-NEXT: [[TMP9:%.*]] = add i64 [[OFFSET_IDX]], 120
467 ; CHECK-NEXT: [[NEXT_GEP:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP6]]
468 ; CHECK-NEXT: [[NEXT_GEP4:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP7]]
469 ; CHECK-NEXT: [[NEXT_GEP5:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP8]]
470 ; CHECK-NEXT: [[NEXT_GEP6:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP9]]
471 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr i8, ptr [[NEXT_GEP]], i64 8
472 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i8, ptr [[NEXT_GEP4]], i64 8
473 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i8, ptr [[NEXT_GEP5]], i64 8
474 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr i8, ptr [[NEXT_GEP6]], i64 8
475 ; CHECK-NEXT: [[TMP14:%.*]] = load ptr, ptr [[TMP10]], align 8
476 ; CHECK-NEXT: [[TMP15:%.*]] = load ptr, ptr [[TMP11]], align 8
477 ; CHECK-NEXT: [[TMP16:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP14]], i32 0
478 ; CHECK-NEXT: [[TMP17:%.*]] = insertelement <2 x ptr> [[TMP16]], ptr [[TMP15]], i32 1
479 ; CHECK-NEXT: [[TMP18:%.*]] = load ptr, ptr [[TMP12]], align 8
480 ; CHECK-NEXT: [[TMP19:%.*]] = load ptr, ptr [[TMP13]], align 8
481 ; CHECK-NEXT: [[TMP20:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP18]], i32 0
482 ; CHECK-NEXT: [[TMP21:%.*]] = insertelement <2 x ptr> [[TMP20]], ptr [[TMP19]], i32 1
483 ; CHECK-NEXT: [[TMP22:%.*]] = icmp eq <2 x ptr> [[TMP17]], zeroinitializer
484 ; CHECK-NEXT: [[TMP23:%.*]] = icmp eq <2 x ptr> [[TMP21]], zeroinitializer
485 ; CHECK-NEXT: [[TMP24:%.*]] = xor <2 x i1> [[TMP22]], splat (i1 true)
486 ; CHECK-NEXT: [[TMP25:%.*]] = xor <2 x i1> [[TMP23]], splat (i1 true)
487 ; CHECK-NEXT: [[TMP26]] = or <2 x i1> [[VEC_PHI]], [[TMP24]]
488 ; CHECK-NEXT: [[TMP27]] = or <2 x i1> [[VEC_PHI3]], [[TMP25]]
489 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
490 ; CHECK-NEXT: [[TMP28:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
491 ; CHECK-NEXT: br i1 [[TMP28]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
492 ; CHECK: middle.block:
493 ; CHECK-NEXT: [[BIN_RDX:%.*]] = or <2 x i1> [[TMP27]], [[TMP26]]
494 ; CHECK-NEXT: [[TMP29:%.*]] = call i1 @llvm.vector.reduce.or.v2i1(<2 x i1> [[BIN_RDX]])
495 ; CHECK-NEXT: [[TMP30:%.*]] = freeze i1 [[TMP29]]
496 ; CHECK-NEXT: [[RDX_SELECT:%.*]] = select i1 [[TMP30]], i1 false, i1 false
497 ; CHECK-NEXT: br label [[SCALAR_PH]]
499 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi ptr [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[START]], [[ENTRY:%.*]] ]
500 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i1 [ [[RDX_SELECT]], [[MIDDLE_BLOCK]] ], [ false, [[ENTRY]] ]
501 ; CHECK-NEXT: br label [[LOOP:%.*]]
503 ; CHECK-NEXT: [[ANY_OF:%.*]] = phi i1 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[ANY_OF_NEXT:%.*]], [[LOOP]] ]
504 ; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[PTR_IV_NEXT:%.*]], [[LOOP]] ]
505 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[PTR_IV]], i64 8
506 ; CHECK-NEXT: [[L:%.*]] = load ptr, ptr [[GEP]], align 8
507 ; CHECK-NEXT: [[CMP13_NOT_NOT:%.*]] = icmp eq ptr [[L]], null
508 ; CHECK-NEXT: [[ANY_OF_NEXT]] = select i1 [[CMP13_NOT_NOT]], i1 [[ANY_OF]], i1 false
509 ; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr inbounds i8, ptr [[PTR_IV]], i64 40
510 ; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq ptr [[PTR_IV]], [[END]]
511 ; CHECK-NEXT: br i1 [[CMP_NOT]], label [[EXIT:%.*]], label [[LOOP]], !llvm.loop [[LOOP16:![0-9]+]]
513 ; CHECK-NEXT: [[ANY_OF_NEXT_LCSSA:%.*]] = phi i1 [ [[ANY_OF_NEXT]], [[LOOP]] ]
514 ; CHECK-NEXT: ret i1 [[ANY_OF_NEXT_LCSSA]]
520 %any.of = phi i1 [ false, %entry ], [ %any.of.next, %loop ]
521 %ptr.iv = phi ptr [ %start, %entry ], [ %ptr.iv.next, %loop ]
522 %gep = getelementptr i8, ptr %ptr.iv, i64 8
523 %l = load ptr, ptr %gep, align 8
524 %cmp13.not.not = icmp eq ptr %l, null
525 %any.of.next = select i1 %cmp13.not.not, i1 %any.of, i1 false
526 %ptr.iv.next = getelementptr inbounds i8, ptr %ptr.iv, i64 40
527 %cmp.not = icmp eq ptr %ptr.iv, %end
528 br i1 %cmp.not, label %exit, label %loop
534 define i64 @avx512_cond_load_cost(ptr %src, i32 %a, i64 %b, i32 %c, i32 %d) #1 {
535 ; CHECK-LABEL: @avx512_cond_load_cost(
537 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
538 ; CHECK: loop.header:
539 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
540 ; CHECK-NEXT: [[C_1:%.*]] = icmp slt i32 [[IV]], 0
541 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[LOOP_LATCH]]
543 ; CHECK-NEXT: [[TMP0:%.*]] = urem i32 [[A:%.*]], [[C:%.*]]
544 ; CHECK-NEXT: [[MUL:%.*]] = sub i32 0, [[TMP0]]
545 ; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[C]], [[D:%.*]]
546 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[DIV]], [[MUL]]
547 ; CHECK-NEXT: [[EXT:%.*]] = sext i32 [[OR]] to i64
548 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr { i64, i64, i64 }, ptr [[SRC:%.*]], i64 [[EXT]], i32 2
549 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 8
550 ; CHECK-NEXT: [[OR_2:%.*]] = or i64 [[L]], [[B:%.*]]
551 ; CHECK-NEXT: br label [[LOOP_LATCH]]
553 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ 0, [[LOOP_HEADER]] ], [ [[OR_2]], [[IF_THEN]] ]
554 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
555 ; CHECK-NEXT: [[EC:%.*]] = icmp ult i32 [[IV]], [[C]]
556 ; CHECK-NEXT: br i1 [[EC]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
558 ; CHECK-NEXT: [[RES_LCSSA:%.*]] = phi i64 [ [[RES]], [[LOOP_LATCH]] ]
559 ; CHECK-NEXT: ret i64 [[RES_LCSSA]]
562 br label %loop.header
565 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
566 %c.1 = icmp slt i32 %iv, 0
567 br i1 %c.1, label %if.then, label %loop.latch
572 %div = udiv i32 %c, %d
573 %or = or i32 %div, %mul
574 %ext = sext i32 %or to i64
575 %gep = getelementptr { i64, i64, i64 }, ptr %src, i64 %ext, i32 2
576 %l = load i64, ptr %gep, align 8
577 %or.2 = or i64 %l, %b
581 %res = phi i64 [ 0, %loop.header ], [ %or.2, %if.then ]
582 %iv.next = add i32 %iv, 1
583 %ec = icmp ult i32 %iv, %c
584 br i1 %ec, label %loop.header, label %exit
590 define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 {
591 ; CHECK-LABEL: @cost_duplicate_recipe_for_sinking(
592 ; CHECK-NEXT: iter.check:
593 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N:%.*]], 1
594 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 [[TMP0]], 4
595 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH:%.*]], label [[VECTOR_MAIN_LOOP_ITER_CHECK:%.*]]
596 ; CHECK: vector.main.loop.iter.check:
597 ; CHECK-NEXT: [[MIN_ITERS_CHECK1:%.*]] = icmp ule i64 [[TMP0]], 16
598 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK1]], label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH:%.*]]
600 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP0]], 16
601 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
602 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 16, i64 [[N_MOD_VF]]
603 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP0]], [[TMP2]]
604 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
605 ; CHECK: vector.body:
606 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE37:%.*]] ]
607 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 0
608 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 4
609 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[INDEX]], 8
610 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 12
611 ; CHECK-NEXT: [[TMP7:%.*]] = shl nsw i64 [[TMP3]], 2
612 ; CHECK-NEXT: [[TMP8:%.*]] = shl nsw i64 [[TMP4]], 2
613 ; CHECK-NEXT: [[TMP9:%.*]] = shl nsw i64 [[TMP5]], 2
614 ; CHECK-NEXT: [[TMP10:%.*]] = shl nsw i64 [[TMP6]], 2
615 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP7]]
616 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP8]]
617 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP9]]
618 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP10]]
619 ; CHECK-NEXT: [[WIDE_VEC:%.*]] = load <16 x double>, ptr [[TMP11]], align 8
620 ; CHECK-NEXT: [[STRIDED_VEC:%.*]] = shufflevector <16 x double> [[WIDE_VEC]], <16 x double> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
621 ; CHECK-NEXT: [[WIDE_VEC1:%.*]] = load <16 x double>, ptr [[TMP12]], align 8
622 ; CHECK-NEXT: [[STRIDED_VEC4:%.*]] = shufflevector <16 x double> [[WIDE_VEC1]], <16 x double> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
623 ; CHECK-NEXT: [[WIDE_VEC2:%.*]] = load <16 x double>, ptr [[TMP13]], align 8
624 ; CHECK-NEXT: [[STRIDED_VEC5:%.*]] = shufflevector <16 x double> [[WIDE_VEC2]], <16 x double> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
625 ; CHECK-NEXT: [[WIDE_VEC3:%.*]] = load <16 x double>, ptr [[TMP14]], align 8
626 ; CHECK-NEXT: [[STRIDED_VEC6:%.*]] = shufflevector <16 x double> [[WIDE_VEC3]], <16 x double> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
627 ; CHECK-NEXT: [[TMP19:%.*]] = fcmp oeq <4 x double> [[STRIDED_VEC]], zeroinitializer
628 ; CHECK-NEXT: [[TMP20:%.*]] = fcmp oeq <4 x double> [[STRIDED_VEC4]], zeroinitializer
629 ; CHECK-NEXT: [[TMP21:%.*]] = fcmp oeq <4 x double> [[STRIDED_VEC5]], zeroinitializer
630 ; CHECK-NEXT: [[TMP22:%.*]] = fcmp oeq <4 x double> [[STRIDED_VEC6]], zeroinitializer
631 ; CHECK-NEXT: [[TMP23:%.*]] = extractelement <4 x i1> [[TMP19]], i32 0
632 ; CHECK-NEXT: br i1 [[TMP23]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
633 ; CHECK: pred.store.if:
634 ; CHECK-NEXT: [[TMP24:%.*]] = shl nsw i64 [[TMP3]], 2
635 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP24]]
636 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP25]], align 8
637 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]]
638 ; CHECK: pred.store.continue:
639 ; CHECK-NEXT: [[TMP26:%.*]] = extractelement <4 x i1> [[TMP19]], i32 1
640 ; CHECK-NEXT: br i1 [[TMP26]], label [[PRED_STORE_IF8:%.*]], label [[PRED_STORE_CONTINUE9:%.*]]
641 ; CHECK: pred.store.if8:
642 ; CHECK-NEXT: [[TMP27:%.*]] = add i64 [[INDEX]], 1
643 ; CHECK-NEXT: [[TMP28:%.*]] = shl nsw i64 [[TMP27]], 2
644 ; CHECK-NEXT: [[TMP29:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP28]]
645 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP29]], align 8
646 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE9]]
647 ; CHECK: pred.store.continue9:
648 ; CHECK-NEXT: [[TMP30:%.*]] = extractelement <4 x i1> [[TMP19]], i32 2
649 ; CHECK-NEXT: br i1 [[TMP30]], label [[PRED_STORE_IF10:%.*]], label [[PRED_STORE_CONTINUE11:%.*]]
650 ; CHECK: pred.store.if10:
651 ; CHECK-NEXT: [[TMP31:%.*]] = add i64 [[INDEX]], 2
652 ; CHECK-NEXT: [[TMP32:%.*]] = shl nsw i64 [[TMP31]], 2
653 ; CHECK-NEXT: [[TMP33:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP32]]
654 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP33]], align 8
655 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE11]]
656 ; CHECK: pred.store.continue11:
657 ; CHECK-NEXT: [[TMP34:%.*]] = extractelement <4 x i1> [[TMP19]], i32 3
658 ; CHECK-NEXT: br i1 [[TMP34]], label [[PRED_STORE_IF12:%.*]], label [[PRED_STORE_CONTINUE13:%.*]]
659 ; CHECK: pred.store.if12:
660 ; CHECK-NEXT: [[TMP35:%.*]] = add i64 [[INDEX]], 3
661 ; CHECK-NEXT: [[TMP36:%.*]] = shl nsw i64 [[TMP35]], 2
662 ; CHECK-NEXT: [[TMP37:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP36]]
663 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP37]], align 8
664 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE13]]
665 ; CHECK: pred.store.continue13:
666 ; CHECK-NEXT: [[TMP38:%.*]] = extractelement <4 x i1> [[TMP20]], i32 0
667 ; CHECK-NEXT: br i1 [[TMP38]], label [[PRED_STORE_IF14:%.*]], label [[PRED_STORE_CONTINUE15:%.*]]
668 ; CHECK: pred.store.if14:
669 ; CHECK-NEXT: [[TMP39:%.*]] = shl nsw i64 [[TMP4]], 2
670 ; CHECK-NEXT: [[TMP40:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP39]]
671 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP40]], align 8
672 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE15]]
673 ; CHECK: pred.store.continue15:
674 ; CHECK-NEXT: [[TMP41:%.*]] = extractelement <4 x i1> [[TMP20]], i32 1
675 ; CHECK-NEXT: br i1 [[TMP41]], label [[PRED_STORE_IF16:%.*]], label [[PRED_STORE_CONTINUE17:%.*]]
676 ; CHECK: pred.store.if16:
677 ; CHECK-NEXT: [[TMP42:%.*]] = add i64 [[INDEX]], 5
678 ; CHECK-NEXT: [[TMP43:%.*]] = shl nsw i64 [[TMP42]], 2
679 ; CHECK-NEXT: [[TMP44:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP43]]
680 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP44]], align 8
681 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE17]]
682 ; CHECK: pred.store.continue17:
683 ; CHECK-NEXT: [[TMP45:%.*]] = extractelement <4 x i1> [[TMP20]], i32 2
684 ; CHECK-NEXT: br i1 [[TMP45]], label [[PRED_STORE_IF18:%.*]], label [[PRED_STORE_CONTINUE19:%.*]]
685 ; CHECK: pred.store.if18:
686 ; CHECK-NEXT: [[TMP46:%.*]] = add i64 [[INDEX]], 6
687 ; CHECK-NEXT: [[TMP47:%.*]] = shl nsw i64 [[TMP46]], 2
688 ; CHECK-NEXT: [[TMP48:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP47]]
689 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP48]], align 8
690 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE19]]
691 ; CHECK: pred.store.continue19:
692 ; CHECK-NEXT: [[TMP49:%.*]] = extractelement <4 x i1> [[TMP20]], i32 3
693 ; CHECK-NEXT: br i1 [[TMP49]], label [[PRED_STORE_IF20:%.*]], label [[PRED_STORE_CONTINUE21:%.*]]
694 ; CHECK: pred.store.if20:
695 ; CHECK-NEXT: [[TMP50:%.*]] = add i64 [[INDEX]], 7
696 ; CHECK-NEXT: [[TMP51:%.*]] = shl nsw i64 [[TMP50]], 2
697 ; CHECK-NEXT: [[TMP52:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP51]]
698 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP52]], align 8
699 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE21]]
700 ; CHECK: pred.store.continue21:
701 ; CHECK-NEXT: [[TMP53:%.*]] = extractelement <4 x i1> [[TMP21]], i32 0
702 ; CHECK-NEXT: br i1 [[TMP53]], label [[PRED_STORE_IF22:%.*]], label [[PRED_STORE_CONTINUE23:%.*]]
703 ; CHECK: pred.store.if22:
704 ; CHECK-NEXT: [[TMP54:%.*]] = shl nsw i64 [[TMP5]], 2
705 ; CHECK-NEXT: [[TMP55:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP54]]
706 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP55]], align 8
707 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE23]]
708 ; CHECK: pred.store.continue23:
709 ; CHECK-NEXT: [[TMP56:%.*]] = extractelement <4 x i1> [[TMP21]], i32 1
710 ; CHECK-NEXT: br i1 [[TMP56]], label [[PRED_STORE_IF24:%.*]], label [[PRED_STORE_CONTINUE25:%.*]]
711 ; CHECK: pred.store.if24:
712 ; CHECK-NEXT: [[TMP57:%.*]] = add i64 [[INDEX]], 9
713 ; CHECK-NEXT: [[TMP58:%.*]] = shl nsw i64 [[TMP57]], 2
714 ; CHECK-NEXT: [[TMP59:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP58]]
715 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP59]], align 8
716 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE25]]
717 ; CHECK: pred.store.continue25:
718 ; CHECK-NEXT: [[TMP60:%.*]] = extractelement <4 x i1> [[TMP21]], i32 2
719 ; CHECK-NEXT: br i1 [[TMP60]], label [[PRED_STORE_IF26:%.*]], label [[PRED_STORE_CONTINUE27:%.*]]
720 ; CHECK: pred.store.if26:
721 ; CHECK-NEXT: [[TMP61:%.*]] = add i64 [[INDEX]], 10
722 ; CHECK-NEXT: [[TMP62:%.*]] = shl nsw i64 [[TMP61]], 2
723 ; CHECK-NEXT: [[TMP63:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP62]]
724 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP63]], align 8
725 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE27]]
726 ; CHECK: pred.store.continue27:
727 ; CHECK-NEXT: [[TMP64:%.*]] = extractelement <4 x i1> [[TMP21]], i32 3
728 ; CHECK-NEXT: br i1 [[TMP64]], label [[PRED_STORE_IF28:%.*]], label [[PRED_STORE_CONTINUE29:%.*]]
729 ; CHECK: pred.store.if28:
730 ; CHECK-NEXT: [[TMP65:%.*]] = add i64 [[INDEX]], 11
731 ; CHECK-NEXT: [[TMP66:%.*]] = shl nsw i64 [[TMP65]], 2
732 ; CHECK-NEXT: [[TMP67:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP66]]
733 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP67]], align 8
734 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE29]]
735 ; CHECK: pred.store.continue29:
736 ; CHECK-NEXT: [[TMP68:%.*]] = extractelement <4 x i1> [[TMP22]], i32 0
737 ; CHECK-NEXT: br i1 [[TMP68]], label [[PRED_STORE_IF30:%.*]], label [[PRED_STORE_CONTINUE31:%.*]]
738 ; CHECK: pred.store.if30:
739 ; CHECK-NEXT: [[TMP69:%.*]] = shl nsw i64 [[TMP6]], 2
740 ; CHECK-NEXT: [[TMP70:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP69]]
741 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP70]], align 8
742 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE31]]
743 ; CHECK: pred.store.continue31:
744 ; CHECK-NEXT: [[TMP71:%.*]] = extractelement <4 x i1> [[TMP22]], i32 1
745 ; CHECK-NEXT: br i1 [[TMP71]], label [[PRED_STORE_IF32:%.*]], label [[PRED_STORE_CONTINUE33:%.*]]
746 ; CHECK: pred.store.if32:
747 ; CHECK-NEXT: [[TMP72:%.*]] = add i64 [[INDEX]], 13
748 ; CHECK-NEXT: [[TMP73:%.*]] = shl nsw i64 [[TMP72]], 2
749 ; CHECK-NEXT: [[TMP74:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP73]]
750 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP74]], align 8
751 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE33]]
752 ; CHECK: pred.store.continue33:
753 ; CHECK-NEXT: [[TMP75:%.*]] = extractelement <4 x i1> [[TMP22]], i32 2
754 ; CHECK-NEXT: br i1 [[TMP75]], label [[PRED_STORE_IF34:%.*]], label [[PRED_STORE_CONTINUE35:%.*]]
755 ; CHECK: pred.store.if34:
756 ; CHECK-NEXT: [[TMP76:%.*]] = add i64 [[INDEX]], 14
757 ; CHECK-NEXT: [[TMP77:%.*]] = shl nsw i64 [[TMP76]], 2
758 ; CHECK-NEXT: [[TMP78:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP77]]
759 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP78]], align 8
760 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE35]]
761 ; CHECK: pred.store.continue35:
762 ; CHECK-NEXT: [[TMP79:%.*]] = extractelement <4 x i1> [[TMP22]], i32 3
763 ; CHECK-NEXT: br i1 [[TMP79]], label [[PRED_STORE_IF36:%.*]], label [[PRED_STORE_CONTINUE37]]
764 ; CHECK: pred.store.if36:
765 ; CHECK-NEXT: [[TMP80:%.*]] = add i64 [[INDEX]], 15
766 ; CHECK-NEXT: [[TMP81:%.*]] = shl nsw i64 [[TMP80]], 2
767 ; CHECK-NEXT: [[TMP82:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP81]]
768 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP82]], align 8
769 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE37]]
770 ; CHECK: pred.store.continue37:
771 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
772 ; CHECK-NEXT: [[TMP83:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
773 ; CHECK-NEXT: br i1 [[TMP83]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
774 ; CHECK: middle.block:
775 ; CHECK-NEXT: br label [[VEC_EPILOG_ITER_CHECK:%.*]]
776 ; CHECK: vec.epilog.iter.check:
777 ; CHECK-NEXT: [[N_VEC_REMAINING:%.*]] = sub i64 [[TMP0]], [[N_VEC]]
778 ; CHECK-NEXT: [[MIN_EPILOG_ITERS_CHECK:%.*]] = icmp ule i64 [[N_VEC_REMAINING]], 4
779 ; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH]], label [[VEC_EPILOG_PH]]
780 ; CHECK: vec.epilog.ph:
781 ; CHECK-NEXT: [[VEC_EPILOG_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
782 ; CHECK-NEXT: [[N_MOD_VF38:%.*]] = urem i64 [[TMP0]], 4
783 ; CHECK-NEXT: [[TMP84:%.*]] = icmp eq i64 [[N_MOD_VF38]], 0
784 ; CHECK-NEXT: [[TMP85:%.*]] = select i1 [[TMP84]], i64 4, i64 [[N_MOD_VF38]]
785 ; CHECK-NEXT: [[N_VEC39:%.*]] = sub i64 [[TMP0]], [[TMP85]]
786 ; CHECK-NEXT: br label [[VEC_EPILOG_VECTOR_BODY:%.*]]
787 ; CHECK: vec.epilog.vector.body:
788 ; CHECK-NEXT: [[INDEX40:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL]], [[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT51:%.*]], [[PRED_STORE_CONTINUE50:%.*]] ]
789 ; CHECK-NEXT: [[TMP86:%.*]] = add i64 [[INDEX40]], 0
790 ; CHECK-NEXT: [[TMP87:%.*]] = shl nsw i64 [[TMP86]], 2
791 ; CHECK-NEXT: [[TMP89:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP87]]
792 ; CHECK-NEXT: [[WIDE_VEC41:%.*]] = load <16 x double>, ptr [[TMP89]], align 8
793 ; CHECK-NEXT: [[STRIDED_VEC42:%.*]] = shufflevector <16 x double> [[WIDE_VEC41]], <16 x double> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
794 ; CHECK-NEXT: [[TMP90:%.*]] = fcmp oeq <4 x double> [[STRIDED_VEC42]], zeroinitializer
795 ; CHECK-NEXT: [[TMP91:%.*]] = extractelement <4 x i1> [[TMP90]], i32 0
796 ; CHECK-NEXT: br i1 [[TMP91]], label [[PRED_STORE_IF43:%.*]], label [[PRED_STORE_CONTINUE44:%.*]]
797 ; CHECK: pred.store.if43:
798 ; CHECK-NEXT: [[TMP92:%.*]] = shl nsw i64 [[TMP86]], 2
799 ; CHECK-NEXT: [[TMP93:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP92]]
800 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP93]], align 8
801 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE44]]
802 ; CHECK: pred.store.continue44:
803 ; CHECK-NEXT: [[TMP94:%.*]] = extractelement <4 x i1> [[TMP90]], i32 1
804 ; CHECK-NEXT: br i1 [[TMP94]], label [[PRED_STORE_IF45:%.*]], label [[PRED_STORE_CONTINUE46:%.*]]
805 ; CHECK: pred.store.if45:
806 ; CHECK-NEXT: [[TMP95:%.*]] = add i64 [[INDEX40]], 1
807 ; CHECK-NEXT: [[TMP96:%.*]] = shl nsw i64 [[TMP95]], 2
808 ; CHECK-NEXT: [[TMP97:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP96]]
809 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP97]], align 8
810 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE46]]
811 ; CHECK: pred.store.continue46:
812 ; CHECK-NEXT: [[TMP98:%.*]] = extractelement <4 x i1> [[TMP90]], i32 2
813 ; CHECK-NEXT: br i1 [[TMP98]], label [[PRED_STORE_IF47:%.*]], label [[PRED_STORE_CONTINUE48:%.*]]
814 ; CHECK: pred.store.if47:
815 ; CHECK-NEXT: [[TMP99:%.*]] = add i64 [[INDEX40]], 2
816 ; CHECK-NEXT: [[TMP100:%.*]] = shl nsw i64 [[TMP99]], 2
817 ; CHECK-NEXT: [[TMP101:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP100]]
818 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP101]], align 8
819 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE48]]
820 ; CHECK: pred.store.continue48:
821 ; CHECK-NEXT: [[TMP102:%.*]] = extractelement <4 x i1> [[TMP90]], i32 3
822 ; CHECK-NEXT: br i1 [[TMP102]], label [[PRED_STORE_IF49:%.*]], label [[PRED_STORE_CONTINUE50]]
823 ; CHECK: pred.store.if49:
824 ; CHECK-NEXT: [[TMP103:%.*]] = add i64 [[INDEX40]], 3
825 ; CHECK-NEXT: [[TMP104:%.*]] = shl nsw i64 [[TMP103]], 2
826 ; CHECK-NEXT: [[TMP105:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP104]]
827 ; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP105]], align 8
828 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE50]]
829 ; CHECK: pred.store.continue50:
830 ; CHECK-NEXT: [[INDEX_NEXT51]] = add nuw i64 [[INDEX40]], 4
831 ; CHECK-NEXT: [[TMP106:%.*]] = icmp eq i64 [[INDEX_NEXT51]], [[N_VEC39]]
832 ; CHECK-NEXT: br i1 [[TMP106]], label [[VEC_EPILOG_MIDDLE_BLOCK:%.*]], label [[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
833 ; CHECK: vec.epilog.middle.block:
834 ; CHECK-NEXT: br label [[VEC_EPILOG_SCALAR_PH]]
835 ; CHECK: vec.epilog.scalar.ph:
836 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC39]], [[VEC_EPILOG_MIDDLE_BLOCK]] ], [ [[N_VEC]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[ITER_CHECK:%.*]] ]
837 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
838 ; CHECK: loop.header:
839 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[VEC_EPILOG_SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
840 ; CHECK-NEXT: [[IV_SHL:%.*]] = shl nsw i64 [[IV]], 2
841 ; CHECK-NEXT: [[GEP_0:%.*]] = getelementptr nusw double, ptr [[A]], i64 [[IV_SHL]]
842 ; CHECK-NEXT: [[L:%.*]] = load double, ptr [[GEP_0]], align 8
843 ; CHECK-NEXT: [[C:%.*]] = fcmp oeq double [[L]], 0.000000e+00
844 ; CHECK-NEXT: br i1 [[C]], label [[IF_THEN:%.*]], label [[LOOP_LATCH]]
846 ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr double, ptr [[A]], i64 [[IV_SHL]]
847 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_1]], align 8
848 ; CHECK-NEXT: br label [[LOOP_LATCH]]
850 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
851 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], [[N]]
852 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT:%.*]], label [[LOOP_HEADER]], !llvm.loop [[LOOP19:![0-9]+]]
854 ; CHECK-NEXT: ret void
857 br label %loop.header
860 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
861 %iv.shl = shl nsw i64 %iv, 2
862 %gep.0 = getelementptr nusw double, ptr %A, i64 %iv.shl
863 %l = load double, ptr %gep.0, align 8
864 %c = fcmp oeq double %l, 0.000000e+00
865 br i1 %c, label %if.then, label %loop.latch
868 %gep.1 = getelementptr double, ptr %A, i64 %iv.shl
869 store double 0.000000e+00, ptr %gep.1, align 8
873 %iv.next = add nsw i64 %iv, 1
874 %ec = icmp eq i64 %iv, %N
875 br i1 %ec, label %exit, label %loop.header
881 define i64 @cost_assume(ptr %end, i64 %N) {
882 ; CHECK-LABEL: @cost_assume(
884 ; CHECK-NEXT: [[END1:%.*]] = ptrtoint ptr [[END:%.*]] to i64
885 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[END1]], -9
886 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[TMP0]], 9
887 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
888 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 8
889 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
891 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 8
892 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
893 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[N:%.*]], i64 0
894 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
895 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i64> [[BROADCAST_SPLAT]], zeroinitializer
896 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
897 ; CHECK: vector.body:
898 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
899 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP7:%.*]], [[VECTOR_BODY]] ]
900 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP8:%.*]], [[VECTOR_BODY]] ]
901 ; CHECK-NEXT: [[VEC_PHI3:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
902 ; CHECK-NEXT: [[VEC_PHI4:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
903 ; CHECK-NEXT: [[TMP7]] = add <2 x i64> [[VEC_PHI]], splat (i64 1)
904 ; CHECK-NEXT: [[TMP8]] = add <2 x i64> [[VEC_PHI2]], splat (i64 1)
905 ; CHECK-NEXT: [[TMP9]] = add <2 x i64> [[VEC_PHI3]], splat (i64 1)
906 ; CHECK-NEXT: [[TMP10]] = add <2 x i64> [[VEC_PHI4]], splat (i64 1)
907 ; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x i1> [[TMP3]], i32 0
908 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
909 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
910 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
911 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
912 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
913 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
914 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
915 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP11]])
916 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
917 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
918 ; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP20:![0-9]+]]
919 ; CHECK: middle.block:
920 ; CHECK-NEXT: [[BIN_RDX:%.*]] = add <2 x i64> [[TMP8]], [[TMP7]]
921 ; CHECK-NEXT: [[BIN_RDX5:%.*]] = add <2 x i64> [[TMP9]], [[BIN_RDX]]
922 ; CHECK-NEXT: [[BIN_RDX6:%.*]] = add <2 x i64> [[TMP10]], [[BIN_RDX5]]
923 ; CHECK-NEXT: [[TMP14:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[BIN_RDX6]])
924 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
925 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
927 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
928 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i64 [ [[TMP14]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
929 ; CHECK-NEXT: br label [[LOOP:%.*]]
931 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
932 ; CHECK-NEXT: [[TMP15:%.*]] = phi i64 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TMP12:%.*]], [[LOOP]] ]
933 ; CHECK-NEXT: [[TMP12]] = add i64 [[TMP15]], 1
934 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
935 ; CHECK-NEXT: [[C:%.*]] = icmp ne i64 [[N]], 0
936 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[C]])
937 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr nusw [9 x i8], ptr null, i64 [[IV_NEXT]]
938 ; CHECK-NEXT: [[EC:%.*]] = icmp eq ptr [[GEP]], [[END]]
939 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP21:![0-9]+]]
941 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i64 [ [[TMP12]], [[LOOP]] ], [ [[TMP14]], [[MIDDLE_BLOCK]] ]
942 ; CHECK-NEXT: ret i64 [[DOTLCSSA]]
948 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
949 %0 = phi i64 [ 0, %entry ], [ %1, %loop ]
951 %iv.next = add nsw i64 %iv, 1
952 %c = icmp ne i64 %N, 0
953 tail call void @llvm.assume(i1 %c)
954 %gep = getelementptr nusw [ 9 x i8 ], ptr null, i64 %iv.next
955 %ec = icmp eq ptr %gep, %end
956 br i1 %ec, label %exit, label %loop
962 ; Test case for https://github.com/llvm/llvm-project/issues/96294 with a stored
963 ; reduction which overwrites an earlier store.
964 define void @reduction_store(ptr noalias %src, ptr %dst, i1 %x) #2 {
965 ; CHECK-LABEL: @reduction_store(
967 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
969 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i1> poison, i1 [[X:%.*]], i64 0
970 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i1> [[BROADCAST_SPLATINSERT]], <4 x i1> poison, <4 x i32> zeroinitializer
971 ; CHECK-NEXT: [[TMP0:%.*]] = zext <4 x i1> [[BROADCAST_SPLAT]] to <4 x i64>
972 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i64> [[TMP0]], splat (i64 12)
973 ; CHECK-NEXT: [[TMP2:%.*]] = trunc <4 x i64> [[TMP1]] to <4 x i32>
974 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
975 ; CHECK: vector.body:
976 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
977 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ <i32 0, i32 -1, i32 -1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP11:%.*]], [[VECTOR_BODY]] ]
978 ; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <4 x i32> [ splat (i32 -1), [[VECTOR_PH]] ], [ [[TMP12:%.*]], [[VECTOR_BODY]] ]
979 ; CHECK-NEXT: [[TMP11]] = and <4 x i32> [[VEC_PHI]], [[TMP2]]
980 ; CHECK-NEXT: [[TMP12]] = and <4 x i32> [[VEC_PHI1]], [[TMP2]]
981 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
982 ; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i32 [[INDEX_NEXT]], 24
983 ; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
984 ; CHECK: middle.block:
985 ; CHECK-NEXT: [[BIN_RDX:%.*]] = and <4 x i32> [[TMP12]], [[TMP11]]
986 ; CHECK-NEXT: [[TMP10:%.*]] = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> [[BIN_RDX]])
987 ; CHECK-NEXT: store i32 [[TMP10]], ptr [[DST:%.*]], align 4
988 ; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]]
990 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 24, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
991 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP10]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
992 ; CHECK-NEXT: br label [[LOOP:%.*]]
994 ; CHECK-NEXT: [[RED:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[RED_NEXT:%.*]], [[LOOP]] ]
995 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
996 ; CHECK-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds i32, ptr [[SRC:%.*]], i32 [[IV]]
997 ; CHECK-NEXT: [[L:%.*]] = load i32, ptr [[GEP_SRC]], align 4
998 ; CHECK-NEXT: [[L_AND:%.*]] = and i32 [[L]], 3
999 ; CHECK-NEXT: store i32 [[L_AND]], ptr [[DST]], align 4
1000 ; CHECK-NEXT: [[X_EXT:%.*]] = zext i1 [[X]] to i64
1001 ; CHECK-NEXT: [[LSHR:%.*]] = lshr i64 [[X_EXT]], 12
1002 ; CHECK-NEXT: [[T:%.*]] = trunc i64 [[LSHR]] to i32
1003 ; CHECK-NEXT: [[RED_NEXT]] = and i32 [[RED]], [[T]]
1004 ; CHECK-NEXT: store i32 [[RED_NEXT]], ptr [[DST]], align 4
1005 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
1006 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i32 [[IV]], 29
1007 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP23:![0-9]+]]
1009 ; CHECK-NEXT: ret void
1015 %red = phi i32 [ 0, %entry ], [ %red.next, %loop ]
1016 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
1017 %gep.src = getelementptr inbounds i32, ptr %src, i32 %iv
1018 %l = load i32, ptr %gep.src
1019 %l.and = and i32 %l, 3
1020 store i32 %l.and, ptr %dst, align 4
1021 %x.ext = zext i1 %x to i64
1022 %lshr = lshr i64 %x.ext, 12
1023 %t = trunc i64 %lshr to i32
1024 %red.next = and i32 %red, %t
1025 store i32 %red.next, ptr %dst, align 4
1026 %iv.next = add i32 %iv, 1
1027 %ec = icmp eq i32 %iv, 29
1028 br i1 %ec, label %exit, label %loop
1034 ; Test case for https://github.com/llvm/llvm-project/issues/105722.
1035 define i64 @live_in_known_1_via_scev() {
1036 ; CHECK-LABEL: @live_in_known_1_via_scev(
1037 ; CHECK-NEXT: entry:
1038 ; CHECK-NEXT: [[SEL:%.*]] = select i1 false, i32 3, i32 0
1039 ; CHECK-NEXT: br label [[PH:%.*]]
1041 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ]
1042 ; CHECK-NEXT: [[N:%.*]] = add nuw nsw i32 [[SEL]], 6
1043 ; CHECK-NEXT: [[P_EXT:%.*]] = zext nneg i32 [[P]] to i64
1044 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1046 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
1047 ; CHECK: vector.body:
1048 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1049 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i64> [ <i64 3, i64 1, i64 1, i64 1>, [[VECTOR_PH]] ], [ [[VEC_PHI]], [[VECTOR_BODY]] ]
1050 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[INDEX]], i64 0
1051 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
1052 ; CHECK-NEXT: [[VEC_IV:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]], <i32 0, i32 1, i32 2, i32 3>
1053 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule <4 x i32> [[VEC_IV]], splat (i32 5)
1054 ; CHECK-NEXT: [[TMP1:%.*]] = select <4 x i1> [[TMP0]], <4 x i64> [[VEC_PHI]], <4 x i64> [[VEC_PHI]]
1055 ; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4
1056 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[INDEX_NEXT]], 8
1057 ; CHECK-NEXT: br i1 [[TMP2]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
1058 ; CHECK: middle.block:
1059 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.vector.reduce.mul.v4i64(<4 x i64> [[TMP1]])
1060 ; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
1062 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 8, [[MIDDLE_BLOCK]] ], [ 0, [[PH]] ]
1063 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i64 [ [[TMP3]], [[MIDDLE_BLOCK]] ], [ 3, [[PH]] ]
1064 ; CHECK-NEXT: br label [[LOOP:%.*]]
1066 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
1067 ; CHECK-NEXT: [[RED:%.*]] = phi i64 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[RED_MUL:%.*]], [[LOOP]] ]
1068 ; CHECK-NEXT: [[RED_MUL]] = mul nsw i64 [[RED]], [[P_EXT]]
1069 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
1070 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i32 [[IV_NEXT]], [[N]]
1071 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP25:![0-9]+]]
1073 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[RED_MUL]], [[LOOP]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
1074 ; CHECK-NEXT: ret i64 [[RES]]
1077 %sel = select i1 false, i32 3, i32 0
1081 %p = phi i32 [ 1, %entry ]
1082 %N = add nuw nsw i32 %sel, 6
1083 %p.ext = zext nneg i32 %p to i64
1087 %iv = phi i32 [ 0, %ph ], [ %iv.next, %loop ]
1088 %red = phi i64 [ 3, %ph ], [ %red.mul, %loop ]
1089 %red.mul = mul nsw i64 %red, %p.ext
1090 %iv.next = add nuw nsw i32 %iv, 1
1091 %ec = icmp eq i32 %iv.next, %N
1092 br i1 %ec, label %exit, label %loop
1095 %res = phi i64 [ %red.mul, %loop ]
1099 ; Test case for https://github.com/llvm/llvm-project/issues/107501.
1100 define i64 @cost_loop_invariant_recipes(i1 %x, i64 %y) {
1101 ; CHECK-LABEL: @cost_loop_invariant_recipes(
1102 ; CHECK-NEXT: entry:
1103 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1105 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i1> poison, i1 [[X:%.*]], i64 0
1106 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i1> [[BROADCAST_SPLATINSERT]], <2 x i1> poison, <2 x i32> zeroinitializer
1107 ; CHECK-NEXT: [[TMP0:%.*]] = xor <2 x i1> [[BROADCAST_SPLAT]], splat (i1 true)
1108 ; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i1> [[TMP0]] to <2 x i64>
1109 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x i64> poison, i64 [[Y:%.*]], i64 0
1110 ; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT1]], <2 x i64> poison, <2 x i32> zeroinitializer
1111 ; CHECK-NEXT: [[TMP2:%.*]] = shl <2 x i64> [[BROADCAST_SPLAT2]], [[TMP1]]
1112 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
1113 ; CHECK: vector.body:
1114 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1115 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <2 x i64> [ splat (i64 1), [[VECTOR_PH]] ], [ [[TMP3:%.*]], [[VECTOR_BODY]] ]
1116 ; CHECK-NEXT: [[TMP3]] = mul <2 x i64> [[TMP2]], [[VEC_PHI]]
1117 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1118 ; CHECK-NEXT: br i1 true, label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
1119 ; CHECK: middle.block:
1120 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> [[TMP3]])
1121 ; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
1123 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 2, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1124 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i64 [ [[TMP4]], [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY]] ]
1125 ; CHECK-NEXT: br label [[LOOP:%.*]]
1127 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT_I_I_I:%.*]], [[LOOP]] ]
1128 ; CHECK-NEXT: [[RED:%.*]] = phi i64 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[RED_MUL:%.*]], [[LOOP]] ]
1129 ; CHECK-NEXT: [[NOT_X:%.*]] = xor i1 [[X]], true
1130 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[NOT_X]] to i64
1131 ; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[Y]], [[EXT]]
1132 ; CHECK-NEXT: [[RED_MUL]] = mul i64 [[SHL]], [[RED]]
1133 ; CHECK-NEXT: [[IV_NEXT_I_I_I]] = add i64 [[IV]], 1
1134 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], 1
1135 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP27:![0-9]+]]
1137 ; CHECK-NEXT: [[RED_MUL_LCSSA:%.*]] = phi i64 [ [[RED_MUL]], [[LOOP]] ], [ [[TMP4]], [[MIDDLE_BLOCK]] ]
1138 ; CHECK-NEXT: ret i64 [[RED_MUL_LCSSA]]
1144 %iv = phi i64 [ 0, %entry ], [ %iv.next.i.i.i, %loop ]
1145 %red = phi i64 [ 1, %entry ], [ %red.mul, %loop ]
1146 %not.x = xor i1 %x, true
1147 %ext = zext i1 %not.x to i64
1148 %shl = shl i64 %y, %ext
1149 %red.mul = mul i64 %shl, %red
1150 %iv.next.i.i.i = add i64 %iv, 1
1151 %ec = icmp eq i64 %iv, 1
1152 br i1 %ec, label %exit, label %loop
1158 ; Test case for https://github.com/llvm/llvm-project/issues/113526.
1159 define i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {
1160 ; CHECK-LABEL: @narrowed_reduction(
1161 ; CHECK-NEXT: entry:
1162 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP:%.*]] to i32
1163 ; CHECK-NEXT: br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1165 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <16 x i32> poison, i32 [[CONV]], i64 0
1166 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <16 x i32> [[BROADCAST_SPLATINSERT]], <16 x i32> poison, <16 x i32> zeroinitializer
1167 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
1168 ; CHECK: vector.body:
1169 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1170 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <16 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP6:%.*]], [[VECTOR_BODY]] ]
1171 ; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <16 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP7:%.*]], [[VECTOR_BODY]] ]
1172 ; CHECK-NEXT: [[TMP0:%.*]] = and <16 x i32> [[VEC_PHI]], splat (i32 1)
1173 ; CHECK-NEXT: [[TMP1:%.*]] = and <16 x i32> [[VEC_PHI1]], splat (i32 1)
1174 ; CHECK-NEXT: [[TMP2:%.*]] = or <16 x i32> [[TMP0]], [[BROADCAST_SPLAT]]
1175 ; CHECK-NEXT: [[TMP3:%.*]] = or <16 x i32> [[TMP1]], [[BROADCAST_SPLAT]]
1176 ; CHECK-NEXT: [[TMP4:%.*]] = trunc <16 x i32> [[TMP2]] to <16 x i1>
1177 ; CHECK-NEXT: [[TMP5:%.*]] = trunc <16 x i32> [[TMP3]] to <16 x i1>
1178 ; CHECK-NEXT: [[TMP6]] = zext <16 x i1> [[TMP4]] to <16 x i32>
1179 ; CHECK-NEXT: [[TMP7]] = zext <16 x i1> [[TMP5]] to <16 x i32>
1180 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 32
1181 ; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[INDEX_NEXT]], 0
1182 ; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
1183 ; CHECK: middle.block:
1184 ; CHECK-NEXT: [[TMP9:%.*]] = trunc <16 x i32> [[TMP6]] to <16 x i1>
1185 ; CHECK-NEXT: [[TMP10:%.*]] = trunc <16 x i32> [[TMP7]] to <16 x i1>
1186 ; CHECK-NEXT: [[BIN_RDX:%.*]] = or <16 x i1> [[TMP10]], [[TMP9]]
1187 ; CHECK-NEXT: [[TMP11:%.*]] = call i1 @llvm.vector.reduce.or.v16i1(<16 x i1> [[BIN_RDX]])
1188 ; CHECK-NEXT: [[TMP12:%.*]] = zext i1 [[TMP11]] to i32
1189 ; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
1191 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 1, [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY:%.*]] ]
1192 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP12]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
1193 ; CHECK-NEXT: br label [[LOOP:%.*]]
1195 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[LOOP]] ]
1196 ; CHECK-NEXT: [[OR13:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[OR:%.*]], [[LOOP]] ]
1197 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[OR13]], 1
1198 ; CHECK-NEXT: [[OR]] = or i32 [[AND]], [[CONV]]
1199 ; CHECK-NEXT: [[INC]] = add i32 [[IV]], 1
1200 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i32 [[IV]], 0
1201 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP29:![0-9]+]]
1203 ; CHECK-NEXT: [[OR_LCSSA:%.*]] = phi i32 [ [[OR]], [[LOOP]] ], [ [[TMP12]], [[MIDDLE_BLOCK]] ]
1204 ; CHECK-NEXT: ret i32 [[OR_LCSSA]]
1207 %conv = zext i1 %cmp to i32
1211 %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]
1212 %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]
1213 %and = and i32 %or13, 1
1214 %or = or i32 %and, %conv
1215 %inc = add i32 %iv, 1
1216 %ec = icmp eq i32 %iv, 0
1217 br i1 %ec, label %exit, label %loop
1223 declare void @llvm.assume(i1 noundef) #0
1225 attributes #0 = { "target-cpu"="penryn" }
1226 attributes #1 = { "target-features"="+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl" }
1227 attributes #2 = { "target-cpu"="znver3" }