1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basic-aa -gvn -enable-load-pre -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline=basic-aa -passes="gvn<load-pre>" -enable-load-pre=false -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"
6 define i32 @test1(i32* %p, i1 %C) {
9 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
11 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, i32* [[P:%.*]], align 4
12 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
14 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
15 ; CHECK-NEXT: br label [[BLOCK4]]
17 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
18 ; CHECK-NEXT: ret i32 [[PRE]]
21 br i1 %C, label %block2, label %block3
31 %PRE = load i32, i32* %p
35 ; This is a simple phi translation case.
36 define i32 @test2(i32* %p, i32* %q, i1 %C) {
37 ; CHECK-LABEL: @test2(
39 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
41 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, i32* [[Q:%.*]], align 4
42 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
44 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
45 ; CHECK-NEXT: br label [[BLOCK4]]
47 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
48 ; CHECK-NEXT: [[P2:%.*]] = phi i32* [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
49 ; CHECK-NEXT: ret i32 [[PRE]]
52 br i1 %C, label %block2, label %block3
62 %P2 = phi i32* [%p, %block3], [%q, %block2]
63 %PRE = load i32, i32* %P2
67 ; This is a PRE case that requires phi translation through a GEP.
68 define i32 @test3(i32* %p, i32* %q, i32** %Hack, i1 %C) {
69 ; CHECK-LABEL: @test3(
71 ; CHECK-NEXT: [[B:%.*]] = getelementptr i32, i32* [[Q:%.*]], i32 1
72 ; CHECK-NEXT: store i32* [[B]], i32** [[HACK:%.*]], align 8
73 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
75 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, i32* [[B]], align 4
76 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
78 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, i32* [[P:%.*]], i32 1
79 ; CHECK-NEXT: store i32 0, i32* [[A]], align 4
80 ; CHECK-NEXT: br label [[BLOCK4]]
82 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
83 ; CHECK-NEXT: [[P2:%.*]] = phi i32* [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
84 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, i32* [[P2]], i32 1
85 ; CHECK-NEXT: ret i32 [[PRE]]
88 %B = getelementptr i32, i32* %q, i32 1
89 store i32* %B, i32** %Hack
90 br i1 %C, label %block2, label %block3
96 %A = getelementptr i32, i32* %p, i32 1
101 %P2 = phi i32* [%p, %block3], [%q, %block2]
102 %P3 = getelementptr i32, i32* %P2, i32 1
103 %PRE = load i32, i32* %P3
107 ;; Here the loaded address is available, but the computation is in 'block3'
108 ;; which does not dominate 'block2'.
109 define i32 @test4(i32* %p, i32* %q, i32** %Hack, i1 %C) {
110 ; CHECK-LABEL: @test4(
111 ; CHECK-NEXT: block1:
112 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
114 ; CHECK-NEXT: [[P3_PHI_TRANS_INSERT:%.*]] = getelementptr i32, i32* [[Q:%.*]], i32 1
115 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, i32* [[P3_PHI_TRANS_INSERT]], align 4
116 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
118 ; CHECK-NEXT: [[B:%.*]] = getelementptr i32, i32* [[Q]], i32 1
119 ; CHECK-NEXT: store i32* [[B]], i32** [[HACK:%.*]], align 8
120 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, i32* [[P:%.*]], i32 1
121 ; CHECK-NEXT: store i32 0, i32* [[A]], align 4
122 ; CHECK-NEXT: br label [[BLOCK4]]
124 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
125 ; CHECK-NEXT: [[P2:%.*]] = phi i32* [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
126 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, i32* [[P2]], i32 1
127 ; CHECK-NEXT: ret i32 [[PRE]]
130 br i1 %C, label %block2, label %block3
136 %B = getelementptr i32, i32* %q, i32 1
137 store i32* %B, i32** %Hack
139 %A = getelementptr i32, i32* %p, i32 1
144 %P2 = phi i32* [%p, %block3], [%q, %block2]
145 %P3 = getelementptr i32, i32* %P2, i32 1
146 %PRE = load i32, i32* %P3
150 ;void test5(int N, double *G) {
152 ; for (j = 0; j < N - 1; j++)
153 ; G[j] = G[j] + G[j+1];
156 define void @test5(i32 %N, double* nocapture %G) nounwind ssp {
157 ; CHECK-LABEL: @test5(
159 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
160 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 0
161 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
163 ; CHECK-NEXT: [[TMP:%.*]] = zext i32 [[TMP0]] to i64
164 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, double* [[G:%.*]], align 8
165 ; CHECK-NEXT: br label [[BB:%.*]]
167 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP3:%.*]], [[BB]] ]
168 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP6:%.*]], [[BB]] ]
169 ; CHECK-NEXT: [[TMP6]] = add i64 [[INDVAR]], 1
170 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, double* [[G]], i64 [[TMP6]]
171 ; CHECK-NEXT: [[SCEVGEP7:%.*]] = getelementptr double, double* [[G]], i64 [[INDVAR]]
172 ; CHECK-NEXT: [[TMP3]] = load double, double* [[SCEVGEP]], align 8
173 ; CHECK-NEXT: [[TMP4:%.*]] = fadd double [[TMP2]], [[TMP3]]
174 ; CHECK-NEXT: store double [[TMP4]], double* [[SCEVGEP7]], align 8
175 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP6]], [[TMP]]
176 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
178 ; CHECK-NEXT: ret void
182 %1 = icmp sgt i32 %0, 0
183 br i1 %1, label %bb.nph, label %return
186 %tmp = zext i32 %0 to i64
191 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp6, %bb ]
192 %tmp6 = add i64 %indvar, 1
193 %scevgep = getelementptr double, double* %G, i64 %tmp6
194 %scevgep7 = getelementptr double, double* %G, i64 %indvar
195 %2 = load double, double* %scevgep7, align 8
196 %3 = load double, double* %scevgep, align 8
197 %4 = fadd double %2, %3
198 store double %4, double* %scevgep7, align 8
199 %exitcond = icmp eq i64 %tmp6, %tmp
200 br i1 %exitcond, label %return, label %bb
202 ; Should only be one load in the loop.
208 ;void test6(int N, double *G) {
210 ; for (j = 0; j < N - 1; j++)
211 ; G[j+1] = G[j] + G[j+1];
214 define void @test6(i32 %N, double* nocapture %G) nounwind ssp {
215 ; CHECK-LABEL: @test6(
217 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
218 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 0
219 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
221 ; CHECK-NEXT: [[TMP:%.*]] = zext i32 [[TMP0]] to i64
222 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, double* [[G:%.*]], align 8
223 ; CHECK-NEXT: br label [[BB:%.*]]
225 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP4:%.*]], [[BB]] ]
226 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP6:%.*]], [[BB]] ]
227 ; CHECK-NEXT: [[TMP6]] = add i64 [[INDVAR]], 1
228 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, double* [[G]], i64 [[TMP6]]
229 ; CHECK-NEXT: [[SCEVGEP7:%.*]] = getelementptr double, double* [[G]], i64 [[INDVAR]]
230 ; CHECK-NEXT: [[TMP3:%.*]] = load double, double* [[SCEVGEP]], align 8
231 ; CHECK-NEXT: [[TMP4]] = fadd double [[TMP2]], [[TMP3]]
232 ; CHECK-NEXT: store double [[TMP4]], double* [[SCEVGEP]], align 8
233 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP6]], [[TMP]]
234 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
236 ; CHECK-NEXT: ret void
240 %1 = icmp sgt i32 %0, 0
241 br i1 %1, label %bb.nph, label %return
244 %tmp = zext i32 %0 to i64
249 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp6, %bb ]
250 %tmp6 = add i64 %indvar, 1
251 %scevgep = getelementptr double, double* %G, i64 %tmp6
252 %scevgep7 = getelementptr double, double* %G, i64 %indvar
253 %2 = load double, double* %scevgep7, align 8
254 %3 = load double, double* %scevgep, align 8
255 %4 = fadd double %2, %3
256 store double %4, double* %scevgep, align 8
257 %exitcond = icmp eq i64 %tmp6, %tmp
258 br i1 %exitcond, label %return, label %bb
260 ; Should only be one load in the loop.
266 ;void test7(int N, double* G) {
269 ; for (j = 1; j < N - 1; j++)
270 ; G[j+1] = G[j] + G[j+1];
273 ; This requires phi translation of the adds.
274 define void @test7(i32 %N, double* nocapture %G) nounwind ssp {
275 ; CHECK-LABEL: @test7(
277 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds double, double* [[G:%.*]], i64 1
278 ; CHECK-NEXT: store double 1.000000e+00, double* [[TMP0]], align 8
279 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[N:%.*]], -1
280 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], 1
281 ; CHECK-NEXT: br i1 [[TMP2]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
283 ; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[TMP1]] to i64
284 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[TMP]], -1
285 ; CHECK-NEXT: br label [[BB:%.*]]
287 ; CHECK-NEXT: [[TMP3:%.*]] = phi double [ 1.000000e+00, [[BB_NPH]] ], [ [[TMP5:%.*]], [[BB]] ]
288 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP9:%.*]], [[BB]] ]
289 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[INDVAR]], 2
290 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, double* [[G]], i64 [[TMP8]]
291 ; CHECK-NEXT: [[TMP9]] = add i64 [[INDVAR]], 1
292 ; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr double, double* [[G]], i64 [[TMP9]]
293 ; CHECK-NEXT: [[TMP4:%.*]] = load double, double* [[SCEVGEP]], align 8
294 ; CHECK-NEXT: [[TMP5]] = fadd double [[TMP3]], [[TMP4]]
295 ; CHECK-NEXT: store double [[TMP5]], double* [[SCEVGEP]], align 8
296 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP9]], [[TMP7]]
297 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
299 ; CHECK-NEXT: ret void
302 %0 = getelementptr inbounds double, double* %G, i64 1
303 store double 1.000000e+00, double* %0, align 8
305 %2 = icmp sgt i32 %1, 1
306 br i1 %2, label %bb.nph, label %return
309 %tmp = sext i32 %1 to i64
310 %tmp7 = add i64 %tmp, -1
314 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp9, %bb ]
315 %tmp8 = add i64 %indvar, 2
316 %scevgep = getelementptr double, double* %G, i64 %tmp8
317 %tmp9 = add i64 %indvar, 1
318 %scevgep10 = getelementptr double, double* %G, i64 %tmp9
319 %3 = load double, double* %scevgep10, align 8
320 %4 = load double, double* %scevgep, align 8
321 %5 = fadd double %3, %4
322 store double %5, double* %scevgep, align 8
323 %exitcond = icmp eq i64 %tmp9, %tmp7
324 br i1 %exitcond, label %return, label %bb
326 ; Should only be one load in the loop.
332 ;; Here the loaded address isn't available in 'block2' at all, requiring a new
333 ;; GEP to be inserted into it.
334 define i32 @test8(i32* %p, i32* %q, i32** %Hack, i1 %C) {
335 ; CHECK-LABEL: @test8(
336 ; CHECK-NEXT: block1:
337 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
339 ; CHECK-NEXT: [[P3_PHI_TRANS_INSERT:%.*]] = getelementptr i32, i32* [[Q:%.*]], i32 1
340 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, i32* [[P3_PHI_TRANS_INSERT]], align 4
341 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
343 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, i32* [[P:%.*]], i32 1
344 ; CHECK-NEXT: store i32 0, i32* [[A]], align 4
345 ; CHECK-NEXT: br label [[BLOCK4]]
347 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
348 ; CHECK-NEXT: [[P2:%.*]] = phi i32* [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
349 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, i32* [[P2]], i32 1
350 ; CHECK-NEXT: ret i32 [[PRE]]
353 br i1 %C, label %block2, label %block3
359 %A = getelementptr i32, i32* %p, i32 1
364 %P2 = phi i32* [%p, %block3], [%q, %block2]
365 %P3 = getelementptr i32, i32* %P2, i32 1
366 %PRE = load i32, i32* %P3
370 ;void test9(int N, double* G) {
372 ; for (j = 1; j < N - 1; j++)
373 ; G[j+1] = G[j] + G[j+1];
376 ; This requires phi translation of the adds.
377 define void @test9(i32 %N, double* nocapture %G) nounwind ssp {
378 ; CHECK-LABEL: @test9(
380 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
381 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 1
382 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
384 ; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[TMP0]] to i64
385 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[TMP]], -1
386 ; CHECK-NEXT: [[SCEVGEP10_PHI_TRANS_INSERT:%.*]] = getelementptr double, double* [[G:%.*]], i64 1
387 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, double* [[SCEVGEP10_PHI_TRANS_INSERT]], align 8
388 ; CHECK-NEXT: br label [[BB:%.*]]
390 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP4:%.*]], [[BB]] ]
391 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP9:%.*]], [[BB]] ]
392 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[INDVAR]], 2
393 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, double* [[G]], i64 [[TMP8]]
394 ; CHECK-NEXT: [[TMP9]] = add i64 [[INDVAR]], 1
395 ; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr double, double* [[G]], i64 [[TMP9]]
396 ; CHECK-NEXT: [[TMP3:%.*]] = load double, double* [[SCEVGEP]], align 8
397 ; CHECK-NEXT: [[TMP4]] = fadd double [[TMP2]], [[TMP3]]
398 ; CHECK-NEXT: store double [[TMP4]], double* [[SCEVGEP]], align 8
399 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP9]], [[TMP7]]
400 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
402 ; CHECK-NEXT: ret void
407 %2 = icmp sgt i32 %1, 1
408 br i1 %2, label %bb.nph, label %return
411 %tmp = sext i32 %1 to i64
412 %tmp7 = add i64 %tmp, -1
417 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp9, %bb ]
418 %tmp8 = add i64 %indvar, 2
419 %scevgep = getelementptr double, double* %G, i64 %tmp8
420 %tmp9 = add i64 %indvar, 1
421 %scevgep10 = getelementptr double, double* %G, i64 %tmp9
422 %3 = load double, double* %scevgep10, align 8
423 %4 = load double, double* %scevgep, align 8
424 %5 = fadd double %3, %4
425 store double %5, double* %scevgep, align 8
426 %exitcond = icmp eq i64 %tmp9, %tmp7
427 br i1 %exitcond, label %return, label %bb
429 ; Should only be one load in the loop.
435 ;void test10(int N, double* G) {
437 ; for (j = 1; j < N - 1; j++)
438 ; G[j] = G[j] + G[j+1] + G[j-1];
442 define void @test10(i32 %N, double* nocapture %G) nounwind ssp {
443 ; CHECK-LABEL: @test10(
445 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
446 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 1
447 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
449 ; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[TMP0]] to i64
450 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[TMP]], -1
451 ; CHECK-NEXT: [[SCEVGEP12_PHI_TRANS_INSERT:%.*]] = getelementptr double, double* [[G:%.*]], i64 1
452 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, double* [[SCEVGEP12_PHI_TRANS_INSERT]], align 8
453 ; CHECK-NEXT: [[DOTPRE1:%.*]] = load double, double* [[G]], align 8
454 ; CHECK-NEXT: br label [[BB:%.*]]
456 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE1]], [[BB_NPH]] ], [ [[TMP6:%.*]], [[BB]] ]
457 ; CHECK-NEXT: [[TMP3:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP4:%.*]], [[BB]] ]
458 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP11:%.*]], [[BB]] ]
459 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, double* [[G]], i64 [[INDVAR]]
460 ; CHECK-NEXT: [[TMP9:%.*]] = add i64 [[INDVAR]], 2
461 ; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr double, double* [[G]], i64 [[TMP9]]
462 ; CHECK-NEXT: [[TMP11]] = add i64 [[INDVAR]], 1
463 ; CHECK-NEXT: [[SCEVGEP12:%.*]] = getelementptr double, double* [[G]], i64 [[TMP11]]
464 ; CHECK-NEXT: [[TMP4]] = load double, double* [[SCEVGEP10]], align 8
465 ; CHECK-NEXT: [[TMP5:%.*]] = fadd double [[TMP3]], [[TMP4]]
466 ; CHECK-NEXT: [[TMP6]] = fadd double [[TMP5]], [[TMP2]]
467 ; CHECK-NEXT: store double [[TMP6]], double* [[SCEVGEP12]], align 8
468 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP11]], [[TMP8]]
469 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
471 ; CHECK-NEXT: ret void
475 %1 = icmp sgt i32 %0, 1
476 br i1 %1, label %bb.nph, label %return
479 %tmp = sext i32 %0 to i64
480 %tmp8 = add i64 %tmp, -1
485 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp11, %bb ]
486 %scevgep = getelementptr double, double* %G, i64 %indvar
487 %tmp9 = add i64 %indvar, 2
488 %scevgep10 = getelementptr double, double* %G, i64 %tmp9
489 %tmp11 = add i64 %indvar, 1
490 %scevgep12 = getelementptr double, double* %G, i64 %tmp11
491 %2 = load double, double* %scevgep12, align 8
492 %3 = load double, double* %scevgep10, align 8
493 %4 = fadd double %2, %3
494 %5 = load double, double* %scevgep, align 8
495 %6 = fadd double %4, %5
496 store double %6, double* %scevgep12, align 8
497 %exitcond = icmp eq i64 %tmp11, %tmp8
498 br i1 %exitcond, label %return, label %bb
500 ; Should only be one load in the loop.
506 ; Test critical edge splitting.
507 define i32 @test11(i32* %p, i1 %C, i32 %N) {
508 ; CHECK-LABEL: @test11(
509 ; CHECK-NEXT: block1:
510 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
512 ; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[N:%.*]], 1
513 ; CHECK-NEXT: br i1 [[COND]], label [[BLOCK2_BLOCK4_CRIT_EDGE:%.*]], label [[BLOCK5:%.*]]
514 ; CHECK: block2.block4_crit_edge:
515 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, i32* [[P:%.*]], align 4
516 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
518 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
519 ; CHECK-NEXT: br label [[BLOCK4]]
521 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ [[PRE_PRE]], [[BLOCK2_BLOCK4_CRIT_EDGE]] ], [ 0, [[BLOCK3]] ]
522 ; CHECK-NEXT: br label [[BLOCK5]]
524 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ 0, [[BLOCK2]] ], [ [[PRE]], [[BLOCK4]] ]
525 ; CHECK-NEXT: ret i32 [[RET]]
528 br i1 %C, label %block2, label %block3
531 %cond = icmp sgt i32 %N, 1
532 br i1 %cond, label %block4, label %block5
539 %PRE = load i32, i32* %p
543 %ret = phi i32 [ 0, %block2 ], [ %PRE, %block4 ]
549 declare i32 @__CxxFrameHandler3(...)
551 ; Test that loads aren't PRE'd into EH pads.
552 define void @test12(i32* %p) personality i32 (...)* @__CxxFrameHandler3 {
553 ; CHECK-LABEL: @test12(
554 ; CHECK-NEXT: block1:
555 ; CHECK-NEXT: invoke void @f()
556 ; CHECK-NEXT: to label [[BLOCK2:%.*]] unwind label [[CATCH_DISPATCH:%.*]]
558 ; CHECK-NEXT: invoke void @f()
559 ; CHECK-NEXT: to label [[BLOCK3:%.*]] unwind label [[CLEANUP:%.*]]
561 ; CHECK-NEXT: ret void
562 ; CHECK: catch.dispatch:
563 ; CHECK-NEXT: [[CS1:%.*]] = catchswitch within none [label %catch] unwind label [[CLEANUP2:%.*]]
565 ; CHECK-NEXT: [[C:%.*]] = catchpad within [[CS1]] []
566 ; CHECK-NEXT: catchret from [[C]] to label [[BLOCK2]]
568 ; CHECK-NEXT: [[C1:%.*]] = cleanuppad within none []
569 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
570 ; CHECK-NEXT: cleanupret from [[C1]] unwind label [[CLEANUP2]]
572 ; CHECK-NEXT: [[C2:%.*]] = cleanuppad within none []
573 ; CHECK-NEXT: [[NOTPRE:%.*]] = load i32, i32* [[P]], align 4
574 ; CHECK-NEXT: call void @g(i32 [[NOTPRE]])
575 ; CHECK-NEXT: cleanupret from [[C2]] unwind to caller
579 to label %block2 unwind label %catch.dispatch
583 to label %block3 unwind label %cleanup
589 %cs1 = catchswitch within none [label %catch] unwind label %cleanup2
592 %c = catchpad within %cs1 []
593 catchret from %c to label %block2
596 %c1 = cleanuppad within none []
598 cleanupret from %c1 unwind label %cleanup2
601 %c2 = cleanuppad within none []
602 %NOTPRE = load i32, i32* %p
603 call void @g(i32 %NOTPRE)
604 cleanupret from %c2 unwind to caller
607 ; Don't PRE load across potentially throwing calls.
609 define i32 @test13(i32* noalias nocapture readonly %x, i32* noalias nocapture %r, i32 %a) {
610 ; CHECK-LABEL: @test13(
612 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
613 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
615 ; CHECK-NEXT: [[UU:%.*]] = load i32, i32* [[X:%.*]], align 4
616 ; CHECK-NEXT: store i32 [[UU]], i32* [[R:%.*]], align 4
617 ; CHECK-NEXT: br label [[IF_END]]
619 ; CHECK-NEXT: call void @f()
620 ; CHECK-NEXT: [[VV:%.*]] = load i32, i32* [[X]], align 4
621 ; CHECK-NEXT: ret i32 [[VV]]
625 %tobool = icmp eq i32 %a, 0
626 br i1 %tobool, label %if.end, label %if.then
630 %uu = load i32, i32* %x, align 4
631 store i32 %uu, i32* %r, align 4
637 %vv = load i32, i32* %x, align 4
641 ; Same as test13, but now the blocking function is not immediately in load's
644 define i32 @test14(i32* noalias nocapture readonly %x, i32* noalias nocapture %r, i32 %a) {
645 ; CHECK-LABEL: @test14(
647 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
648 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
650 ; CHECK-NEXT: [[UU:%.*]] = load i32, i32* [[X:%.*]], align 4
651 ; CHECK-NEXT: store i32 [[UU]], i32* [[R:%.*]], align 4
652 ; CHECK-NEXT: br label [[IF_END]]
654 ; CHECK-NEXT: call void @f()
655 ; CHECK-NEXT: [[VV:%.*]] = load i32, i32* [[X]], align 4
656 ; CHECK-NEXT: ret i32 [[VV]]
660 %tobool = icmp eq i32 %a, 0
661 br i1 %tobool, label %if.end, label %if.then
665 %uu = load i32, i32* %x, align 4
666 store i32 %uu, i32* %r, align 4
678 %vv = load i32, i32* %x, align 4
682 ; Same as test13, but %x here is dereferenceable. A pointer that is
683 ; dereferenceable can be loaded from speculatively without a risk of trapping.
684 ; Since it is OK to speculate, PRE is allowed.
686 define i32 @test15(i32* noalias nocapture readonly dereferenceable(8) align 4 %x, i32* noalias nocapture %r, i32 %a) nofree nosync {
687 ; CHECK-LABEL: @test15(
689 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
690 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[ENTRY_IF_END_CRIT_EDGE:%.*]], label [[IF_THEN:%.*]]
691 ; CHECK: entry.if.end_crit_edge:
692 ; CHECK-NEXT: [[VV_PRE:%.*]] = load i32, i32* [[X:%.*]], align 4
693 ; CHECK-NEXT: br label [[IF_END:%.*]]
695 ; CHECK-NEXT: [[UU:%.*]] = load i32, i32* [[X]], align 4
696 ; CHECK-NEXT: store i32 [[UU]], i32* [[R:%.*]], align 4
697 ; CHECK-NEXT: br label [[IF_END]]
699 ; CHECK-NEXT: [[VV:%.*]] = phi i32 [ [[VV_PRE]], [[ENTRY_IF_END_CRIT_EDGE]] ], [ [[UU]], [[IF_THEN]] ]
700 ; CHECK-NEXT: call void @f()
701 ; CHECK-NEXT: ret i32 [[VV]]
705 %tobool = icmp eq i32 %a, 0
706 br i1 %tobool, label %if.end, label %if.then
710 %uu = load i32, i32* %x, align 4
711 store i32 %uu, i32* %r, align 4
717 %vv = load i32, i32* %x, align 4
723 ; Same as test14, but %x here is dereferenceable. A pointer that is
724 ; dereferenceable can be loaded from speculatively without a risk of trapping.
725 ; Since it is OK to speculate, PRE is allowed.
727 define i32 @test16(i32* noalias nocapture readonly dereferenceable(8) align 4 %x, i32* noalias nocapture %r, i32 %a) nofree nosync {
728 ; CHECK-LABEL: @test16(
730 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
731 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[ENTRY_IF_END_CRIT_EDGE:%.*]], label [[IF_THEN:%.*]]
732 ; CHECK: entry.if.end_crit_edge:
733 ; CHECK-NEXT: [[VV_PRE:%.*]] = load i32, i32* [[X:%.*]], align 4
734 ; CHECK-NEXT: br label [[IF_END:%.*]]
736 ; CHECK-NEXT: [[UU:%.*]] = load i32, i32* [[X]], align 4
737 ; CHECK-NEXT: store i32 [[UU]], i32* [[R:%.*]], align 4
738 ; CHECK-NEXT: br label [[IF_END]]
740 ; CHECK-NEXT: [[VV:%.*]] = phi i32 [ [[VV_PRE]], [[ENTRY_IF_END_CRIT_EDGE]] ], [ [[UU]], [[IF_THEN]] ]
741 ; CHECK-NEXT: call void @f()
742 ; CHECK-NEXT: ret i32 [[VV]]
746 %tobool = icmp eq i32 %a, 0
747 br i1 %tobool, label %if.end, label %if.then
751 %uu = load i32, i32* %x, align 4
752 store i32 %uu, i32* %r, align 4
765 %vv = load i32, i32* %x, align 4