1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=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(ptr %p, i1 %C) {
9 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
11 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[P:%.*]], align 4
12 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
14 ; CHECK-NEXT: store i32 0, ptr [[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, ptr %p
35 ; This is a simple phi translation case.
36 define i32 @test2(ptr %p, ptr %q, i1 %C) {
37 ; CHECK-LABEL: @test2(
39 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
41 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[Q:%.*]], align 4
42 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
44 ; CHECK-NEXT: store i32 0, ptr [[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 ptr [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
49 ; CHECK-NEXT: ret i32 [[PRE]]
52 br i1 %C, label %block2, label %block3
62 %P2 = phi ptr [%p, %block3], [%q, %block2]
63 %PRE = load i32, ptr %P2
67 ; This is a PRE case that requires phi translation through a GEP.
68 define i32 @test3(ptr %p, ptr %q, ptr %Hack, i1 %C) {
69 ; CHECK-LABEL: @test3(
71 ; CHECK-NEXT: [[B:%.*]] = getelementptr i32, ptr [[Q:%.*]], i32 1
72 ; CHECK-NEXT: store ptr [[B]], ptr [[HACK:%.*]], align 8
73 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
75 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[B]], align 4
76 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
78 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 1
79 ; CHECK-NEXT: store i32 0, ptr [[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 ptr [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
84 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P2]], i32 1
85 ; CHECK-NEXT: ret i32 [[PRE]]
88 %B = getelementptr i32, ptr %q, i32 1
89 store ptr %B, ptr %Hack
90 br i1 %C, label %block2, label %block3
96 %A = getelementptr i32, ptr %p, i32 1
101 %P2 = phi ptr [%p, %block3], [%q, %block2]
102 %P3 = getelementptr i32, ptr %P2, i32 1
103 %PRE = load i32, ptr %P3
107 ;; Here the loaded address is available, but the computation is in 'block3'
108 ;; which does not dominate 'block2'.
109 define i32 @test4(ptr %p, ptr %q, ptr %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, ptr [[Q:%.*]], i32 1
115 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[P3_PHI_TRANS_INSERT]], align 4
116 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
118 ; CHECK-NEXT: [[B:%.*]] = getelementptr i32, ptr [[Q]], i32 1
119 ; CHECK-NEXT: store ptr [[B]], ptr [[HACK:%.*]], align 8
120 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 1
121 ; CHECK-NEXT: store i32 0, ptr [[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 ptr [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
126 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P2]], i32 1
127 ; CHECK-NEXT: ret i32 [[PRE]]
130 br i1 %C, label %block2, label %block3
136 %B = getelementptr i32, ptr %q, i32 1
137 store ptr %B, ptr %Hack
139 %A = getelementptr i32, ptr %p, i32 1
144 %P2 = phi ptr [%p, %block3], [%q, %block2]
145 %P3 = getelementptr i32, ptr %P2, i32 1
146 %PRE = load i32, ptr %P3
150 ; Same as test4, with a nuw flag on the GEP.
151 define i32 @test4_nuw(ptr %p, ptr %q, ptr %Hack, i1 %C) {
152 ; CHECK-LABEL: @test4_nuw(
153 ; CHECK-NEXT: block1:
154 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
156 ; CHECK-NEXT: [[P3_PHI_TRANS_INSERT:%.*]] = getelementptr nuw i32, ptr [[Q:%.*]], i32 1
157 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[P3_PHI_TRANS_INSERT]], align 4
158 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
160 ; CHECK-NEXT: [[B:%.*]] = getelementptr i32, ptr [[Q]], i32 1
161 ; CHECK-NEXT: store ptr [[B]], ptr [[HACK:%.*]], align 8
162 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 1
163 ; CHECK-NEXT: store i32 0, ptr [[A]], align 4
164 ; CHECK-NEXT: br label [[BLOCK4]]
166 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
167 ; CHECK-NEXT: [[P2:%.*]] = phi ptr [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
168 ; CHECK-NEXT: [[P3:%.*]] = getelementptr nuw i32, ptr [[P2]], i32 1
169 ; CHECK-NEXT: ret i32 [[PRE]]
172 br i1 %C, label %block2, label %block3
178 %B = getelementptr i32, ptr %q, i32 1
179 store ptr %B, ptr %Hack
181 %A = getelementptr i32, ptr %p, i32 1
186 %P2 = phi ptr [%p, %block3], [%q, %block2]
187 %P3 = getelementptr nuw i32, ptr %P2, i32 1
188 %PRE = load i32, ptr %P3
192 ;void test5(int N, ptr G) {
194 ; for (j = 0; j < N - 1; j++)
195 ; G[j] = G[j] + G[j+1];
198 define void @test5(i32 %N, ptr nocapture %G) nounwind ssp {
199 ; CHECK-LABEL: @test5(
201 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
202 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 0
203 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
205 ; CHECK-NEXT: [[TMP:%.*]] = zext i32 [[TMP0]] to i64
206 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, ptr [[G:%.*]], align 8
207 ; CHECK-NEXT: br label [[BB:%.*]]
209 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP3:%.*]], [[BB]] ]
210 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP6:%.*]], [[BB]] ]
211 ; CHECK-NEXT: [[TMP6]] = add i64 [[INDVAR]], 1
212 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP6]]
213 ; CHECK-NEXT: [[SCEVGEP7:%.*]] = getelementptr double, ptr [[G]], i64 [[INDVAR]]
214 ; CHECK-NEXT: [[TMP3]] = load double, ptr [[SCEVGEP]], align 8
215 ; CHECK-NEXT: [[TMP4:%.*]] = fadd double [[TMP2]], [[TMP3]]
216 ; CHECK-NEXT: store double [[TMP4]], ptr [[SCEVGEP7]], align 8
217 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP6]], [[TMP]]
218 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
220 ; CHECK-NEXT: ret void
224 %1 = icmp sgt i32 %0, 0
225 br i1 %1, label %bb.nph, label %return
228 %tmp = zext i32 %0 to i64
233 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp6, %bb ]
234 %tmp6 = add i64 %indvar, 1
235 %scevgep = getelementptr double, ptr %G, i64 %tmp6
236 %scevgep7 = getelementptr double, ptr %G, i64 %indvar
237 %2 = load double, ptr %scevgep7, align 8
238 %3 = load double, ptr %scevgep, align 8
239 %4 = fadd double %2, %3
240 store double %4, ptr %scevgep7, align 8
241 %exitcond = icmp eq i64 %tmp6, %tmp
242 br i1 %exitcond, label %return, label %bb
244 ; Should only be one load in the loop.
250 ;void test6(int N, ptr G) {
252 ; for (j = 0; j < N - 1; j++)
253 ; G[j+1] = G[j] + G[j+1];
256 define void @test6(i32 %N, ptr nocapture %G) nounwind ssp {
257 ; CHECK-LABEL: @test6(
259 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
260 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 0
261 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
263 ; CHECK-NEXT: [[TMP:%.*]] = zext i32 [[TMP0]] to i64
264 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, ptr [[G:%.*]], align 8
265 ; CHECK-NEXT: br label [[BB:%.*]]
267 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP4:%.*]], [[BB]] ]
268 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP6:%.*]], [[BB]] ]
269 ; CHECK-NEXT: [[TMP6]] = add i64 [[INDVAR]], 1
270 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP6]]
271 ; CHECK-NEXT: [[SCEVGEP7:%.*]] = getelementptr double, ptr [[G]], i64 [[INDVAR]]
272 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr [[SCEVGEP]], align 8
273 ; CHECK-NEXT: [[TMP4]] = fadd double [[TMP2]], [[TMP3]]
274 ; CHECK-NEXT: store double [[TMP4]], ptr [[SCEVGEP]], align 8
275 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP6]], [[TMP]]
276 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
278 ; CHECK-NEXT: ret void
282 %1 = icmp sgt i32 %0, 0
283 br i1 %1, label %bb.nph, label %return
286 %tmp = zext i32 %0 to i64
291 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp6, %bb ]
292 %tmp6 = add i64 %indvar, 1
293 %scevgep = getelementptr double, ptr %G, i64 %tmp6
294 %scevgep7 = getelementptr double, ptr %G, i64 %indvar
295 %2 = load double, ptr %scevgep7, align 8
296 %3 = load double, ptr %scevgep, align 8
297 %4 = fadd double %2, %3
298 store double %4, ptr %scevgep, align 8
299 %exitcond = icmp eq i64 %tmp6, %tmp
300 br i1 %exitcond, label %return, label %bb
302 ; Should only be one load in the loop.
308 ;void test7(int N, ptr G) {
311 ; for (j = 1; j < N - 1; j++)
312 ; G[j+1] = G[j] + G[j+1];
315 ; This requires phi translation of the adds.
316 define void @test7(i32 %N, ptr nocapture %G) nounwind ssp {
317 ; CHECK-LABEL: @test7(
319 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds double, ptr [[G:%.*]], i64 1
320 ; CHECK-NEXT: store double 1.000000e+00, ptr [[TMP0]], align 8
321 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[N:%.*]], -1
322 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], 1
323 ; CHECK-NEXT: br i1 [[TMP2]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
325 ; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[TMP1]] to i64
326 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[TMP]], -1
327 ; CHECK-NEXT: br label [[BB:%.*]]
329 ; CHECK-NEXT: [[TMP3:%.*]] = phi double [ 1.000000e+00, [[BB_NPH]] ], [ [[TMP5:%.*]], [[BB]] ]
330 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP9:%.*]], [[BB]] ]
331 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[INDVAR]], 2
332 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP8]]
333 ; CHECK-NEXT: [[TMP9]] = add i64 [[INDVAR]], 1
334 ; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP9]]
335 ; CHECK-NEXT: [[TMP4:%.*]] = load double, ptr [[SCEVGEP]], align 8
336 ; CHECK-NEXT: [[TMP5]] = fadd double [[TMP3]], [[TMP4]]
337 ; CHECK-NEXT: store double [[TMP5]], ptr [[SCEVGEP]], align 8
338 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP9]], [[TMP7]]
339 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
341 ; CHECK-NEXT: ret void
344 %0 = getelementptr inbounds double, ptr %G, i64 1
345 store double 1.000000e+00, ptr %0, align 8
347 %2 = icmp sgt i32 %1, 1
348 br i1 %2, label %bb.nph, label %return
351 %tmp = sext i32 %1 to i64
352 %tmp7 = add i64 %tmp, -1
356 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp9, %bb ]
357 %tmp8 = add i64 %indvar, 2
358 %scevgep = getelementptr double, ptr %G, i64 %tmp8
359 %tmp9 = add i64 %indvar, 1
360 %scevgep10 = getelementptr double, ptr %G, i64 %tmp9
361 %3 = load double, ptr %scevgep10, align 8
362 %4 = load double, ptr %scevgep, align 8
363 %5 = fadd double %3, %4
364 store double %5, ptr %scevgep, align 8
365 %exitcond = icmp eq i64 %tmp9, %tmp7
366 br i1 %exitcond, label %return, label %bb
368 ; Should only be one load in the loop.
374 ;; Here the loaded address isn't available in 'block2' at all, requiring a new
375 ;; GEP to be inserted into it.
376 define i32 @test8(ptr %p, ptr %q, ptr %Hack, i1 %C) {
377 ; CHECK-LABEL: @test8(
378 ; CHECK-NEXT: block1:
379 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
381 ; CHECK-NEXT: [[P3_PHI_TRANS_INSERT:%.*]] = getelementptr i32, ptr [[Q:%.*]], i32 1
382 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[P3_PHI_TRANS_INSERT]], align 4
383 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
385 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 1
386 ; CHECK-NEXT: store i32 0, ptr [[A]], align 4
387 ; CHECK-NEXT: br label [[BLOCK4]]
389 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ 0, [[BLOCK3]] ], [ [[PRE_PRE]], [[BLOCK2]] ]
390 ; CHECK-NEXT: [[P2:%.*]] = phi ptr [ [[P]], [[BLOCK3]] ], [ [[Q]], [[BLOCK2]] ]
391 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P2]], i32 1
392 ; CHECK-NEXT: ret i32 [[PRE]]
395 br i1 %C, label %block2, label %block3
401 %A = getelementptr i32, ptr %p, i32 1
406 %P2 = phi ptr [%p, %block3], [%q, %block2]
407 %P3 = getelementptr i32, ptr %P2, i32 1
408 %PRE = load i32, ptr %P3
412 ;void test9(int N, ptr G) {
414 ; for (j = 1; j < N - 1; j++)
415 ; G[j+1] = G[j] + G[j+1];
418 ; This requires phi translation of the adds.
419 define void @test9(i32 %N, ptr nocapture %G) nounwind ssp {
420 ; CHECK-LABEL: @test9(
422 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
423 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 1
424 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
426 ; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[TMP0]] to i64
427 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[TMP]], -1
428 ; CHECK-NEXT: [[SCEVGEP10_PHI_TRANS_INSERT:%.*]] = getelementptr double, ptr [[G:%.*]], i64 1
429 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, ptr [[SCEVGEP10_PHI_TRANS_INSERT]], align 8
430 ; CHECK-NEXT: br label [[BB:%.*]]
432 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP4:%.*]], [[BB]] ]
433 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP9:%.*]], [[BB]] ]
434 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[INDVAR]], 2
435 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP8]]
436 ; CHECK-NEXT: [[TMP9]] = add i64 [[INDVAR]], 1
437 ; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP9]]
438 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr [[SCEVGEP]], align 8
439 ; CHECK-NEXT: [[TMP4]] = fadd double [[TMP2]], [[TMP3]]
440 ; CHECK-NEXT: store double [[TMP4]], ptr [[SCEVGEP]], align 8
441 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP9]], [[TMP7]]
442 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
444 ; CHECK-NEXT: ret void
449 %2 = icmp sgt i32 %1, 1
450 br i1 %2, label %bb.nph, label %return
453 %tmp = sext i32 %1 to i64
454 %tmp7 = add i64 %tmp, -1
459 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp9, %bb ]
460 %tmp8 = add i64 %indvar, 2
461 %scevgep = getelementptr double, ptr %G, i64 %tmp8
462 %tmp9 = add i64 %indvar, 1
463 %scevgep10 = getelementptr double, ptr %G, i64 %tmp9
464 %3 = load double, ptr %scevgep10, align 8
465 %4 = load double, ptr %scevgep, align 8
466 %5 = fadd double %3, %4
467 store double %5, ptr %scevgep, align 8
468 %exitcond = icmp eq i64 %tmp9, %tmp7
469 br i1 %exitcond, label %return, label %bb
471 ; Should only be one load in the loop.
477 ;void test10(int N, ptr G) {
479 ; for (j = 1; j < N - 1; j++)
480 ; G[j] = G[j] + G[j+1] + G[j-1];
484 define void @test10(i32 %N, ptr nocapture %G) nounwind ssp {
485 ; CHECK-LABEL: @test10(
487 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
488 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 1
489 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB_NPH:%.*]], label [[RETURN:%.*]]
491 ; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[TMP0]] to i64
492 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[TMP]], -1
493 ; CHECK-NEXT: [[SCEVGEP12_PHI_TRANS_INSERT:%.*]] = getelementptr double, ptr [[G:%.*]], i64 1
494 ; CHECK-NEXT: [[DOTPRE:%.*]] = load double, ptr [[SCEVGEP12_PHI_TRANS_INSERT]], align 8
495 ; CHECK-NEXT: [[DOTPRE1:%.*]] = load double, ptr [[G]], align 8
496 ; CHECK-NEXT: br label [[BB:%.*]]
498 ; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE1]], [[BB_NPH]] ], [ [[TMP6:%.*]], [[BB]] ]
499 ; CHECK-NEXT: [[TMP3:%.*]] = phi double [ [[DOTPRE]], [[BB_NPH]] ], [ [[TMP4:%.*]], [[BB]] ]
500 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH]] ], [ [[TMP11:%.*]], [[BB]] ]
501 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr double, ptr [[G]], i64 [[INDVAR]]
502 ; CHECK-NEXT: [[TMP9:%.*]] = add i64 [[INDVAR]], 2
503 ; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP9]]
504 ; CHECK-NEXT: [[TMP11]] = add i64 [[INDVAR]], 1
505 ; CHECK-NEXT: [[SCEVGEP12:%.*]] = getelementptr double, ptr [[G]], i64 [[TMP11]]
506 ; CHECK-NEXT: [[TMP4]] = load double, ptr [[SCEVGEP10]], align 8
507 ; CHECK-NEXT: [[TMP5:%.*]] = fadd double [[TMP3]], [[TMP4]]
508 ; CHECK-NEXT: [[TMP6]] = fadd double [[TMP5]], [[TMP2]]
509 ; CHECK-NEXT: store double [[TMP6]], ptr [[SCEVGEP12]], align 8
510 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[TMP11]], [[TMP8]]
511 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[RETURN]], label [[BB]]
513 ; CHECK-NEXT: ret void
517 %1 = icmp sgt i32 %0, 1
518 br i1 %1, label %bb.nph, label %return
521 %tmp = sext i32 %0 to i64
522 %tmp8 = add i64 %tmp, -1
527 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp11, %bb ]
528 %scevgep = getelementptr double, ptr %G, i64 %indvar
529 %tmp9 = add i64 %indvar, 2
530 %scevgep10 = getelementptr double, ptr %G, i64 %tmp9
531 %tmp11 = add i64 %indvar, 1
532 %scevgep12 = getelementptr double, ptr %G, i64 %tmp11
533 %2 = load double, ptr %scevgep12, align 8
534 %3 = load double, ptr %scevgep10, align 8
535 %4 = fadd double %2, %3
536 %5 = load double, ptr %scevgep, align 8
537 %6 = fadd double %4, %5
538 store double %6, ptr %scevgep12, align 8
539 %exitcond = icmp eq i64 %tmp11, %tmp8
540 br i1 %exitcond, label %return, label %bb
542 ; Should only be one load in the loop.
548 ; Test critical edge splitting.
549 define i32 @test11(ptr %p, i1 %C, i32 %N) {
550 ; CHECK-LABEL: @test11(
551 ; CHECK-NEXT: block1:
552 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BLOCK2:%.*]], label [[BLOCK3:%.*]]
554 ; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[N:%.*]], 1
555 ; CHECK-NEXT: br i1 [[COND]], label [[BLOCK2_BLOCK4_CRIT_EDGE:%.*]], label [[BLOCK5:%.*]]
556 ; CHECK: block2.block4_crit_edge:
557 ; CHECK-NEXT: [[PRE_PRE:%.*]] = load i32, ptr [[P:%.*]], align 4
558 ; CHECK-NEXT: br label [[BLOCK4:%.*]]
560 ; CHECK-NEXT: store i32 0, ptr [[P]], align 4
561 ; CHECK-NEXT: br label [[BLOCK4]]
563 ; CHECK-NEXT: [[PRE:%.*]] = phi i32 [ [[PRE_PRE]], [[BLOCK2_BLOCK4_CRIT_EDGE]] ], [ 0, [[BLOCK3]] ]
564 ; CHECK-NEXT: br label [[BLOCK5]]
566 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ 0, [[BLOCK2]] ], [ [[PRE]], [[BLOCK4]] ]
567 ; CHECK-NEXT: ret i32 [[RET]]
570 br i1 %C, label %block2, label %block3
573 %cond = icmp sgt i32 %N, 1
574 br i1 %cond, label %block4, label %block5
581 %PRE = load i32, ptr %p
585 %ret = phi i32 [ 0, %block2 ], [ %PRE, %block4 ]
591 declare i32 @__CxxFrameHandler3(...)
593 ; Test that loads aren't PRE'd into EH pads.
594 define void @test12(ptr %p) personality ptr @__CxxFrameHandler3 {
595 ; CHECK-LABEL: @test12(
596 ; CHECK-NEXT: block1:
597 ; CHECK-NEXT: invoke void @f()
598 ; CHECK-NEXT: to label [[BLOCK2:%.*]] unwind label [[CATCH_DISPATCH:%.*]]
600 ; CHECK-NEXT: invoke void @f()
601 ; CHECK-NEXT: to label [[BLOCK3:%.*]] unwind label [[CLEANUP:%.*]]
603 ; CHECK-NEXT: ret void
604 ; CHECK: catch.dispatch:
605 ; CHECK-NEXT: [[CS1:%.*]] = catchswitch within none [label %catch] unwind label [[CLEANUP2:%.*]]
607 ; CHECK-NEXT: [[C:%.*]] = catchpad within [[CS1]] []
608 ; CHECK-NEXT: catchret from [[C]] to label [[BLOCK2]]
610 ; CHECK-NEXT: [[C1:%.*]] = cleanuppad within none []
611 ; CHECK-NEXT: store i32 0, ptr [[P:%.*]], align 4
612 ; CHECK-NEXT: cleanupret from [[C1]] unwind label [[CLEANUP2]]
614 ; CHECK-NEXT: [[C2:%.*]] = cleanuppad within none []
615 ; CHECK-NEXT: [[NOTPRE:%.*]] = load i32, ptr [[P]], align 4
616 ; CHECK-NEXT: call void @g(i32 [[NOTPRE]])
617 ; CHECK-NEXT: cleanupret from [[C2]] unwind to caller
621 to label %block2 unwind label %catch.dispatch
625 to label %block3 unwind label %cleanup
631 %cs1 = catchswitch within none [label %catch] unwind label %cleanup2
634 %c = catchpad within %cs1 []
635 catchret from %c to label %block2
638 %c1 = cleanuppad within none []
640 cleanupret from %c1 unwind label %cleanup2
643 %c2 = cleanuppad within none []
644 %NOTPRE = load i32, ptr %p
645 call void @g(i32 %NOTPRE)
646 cleanupret from %c2 unwind to caller
649 ; Don't PRE load across potentially throwing calls.
651 define i32 @test13(ptr noalias nocapture readonly %x, ptr noalias nocapture %r, i32 %a) {
652 ; CHECK-LABEL: @test13(
654 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
655 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
657 ; CHECK-NEXT: [[UU:%.*]] = load i32, ptr [[X:%.*]], align 4
658 ; CHECK-NEXT: store i32 [[UU]], ptr [[R:%.*]], align 4
659 ; CHECK-NEXT: br label [[IF_END]]
661 ; CHECK-NEXT: call void @f()
662 ; CHECK-NEXT: [[VV:%.*]] = load i32, ptr [[X]], align 4
663 ; CHECK-NEXT: ret i32 [[VV]]
667 %tobool = icmp eq i32 %a, 0
668 br i1 %tobool, label %if.end, label %if.then
672 %uu = load i32, ptr %x, align 4
673 store i32 %uu, ptr %r, align 4
679 %vv = load i32, ptr %x, align 4
683 ; Same as test13, but now the blocking function is not immediately in load's
686 define i32 @test14(ptr noalias nocapture readonly %x, ptr noalias nocapture %r, i32 %a) {
687 ; CHECK-LABEL: @test14(
689 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
690 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
692 ; CHECK-NEXT: [[UU:%.*]] = load i32, ptr [[X:%.*]], align 4
693 ; CHECK-NEXT: store i32 [[UU]], ptr [[R:%.*]], align 4
694 ; CHECK-NEXT: br label [[IF_END]]
696 ; CHECK-NEXT: call void @f()
697 ; CHECK-NEXT: [[VV:%.*]] = load i32, ptr [[X]], align 4
698 ; CHECK-NEXT: ret i32 [[VV]]
702 %tobool = icmp eq i32 %a, 0
703 br i1 %tobool, label %if.end, label %if.then
707 %uu = load i32, ptr %x, align 4
708 store i32 %uu, ptr %r, align 4
720 %vv = load i32, ptr %x, align 4
724 ; Same as test13, but %x here is dereferenceable. A pointer that is
725 ; dereferenceable can be loaded from speculatively without a risk of trapping.
726 ; Since it is OK to speculate, PRE is allowed.
728 define i32 @test15(ptr noalias nocapture readonly dereferenceable(8) align 4 %x, ptr noalias nocapture %r, i32 %a) nofree nosync {
729 ; CHECK-LABEL: @test15(
731 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
732 ; CHECK-NEXT: [[VV_PRE:%.*]] = load i32, ptr [[X:%.*]], align 4
733 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
735 ; CHECK-NEXT: store i32 [[VV_PRE]], ptr [[R:%.*]], align 4
736 ; CHECK-NEXT: br label [[IF_END]]
738 ; CHECK-NEXT: call void @f()
739 ; CHECK-NEXT: ret i32 [[VV_PRE]]
743 %tobool = icmp eq i32 %a, 0
744 br i1 %tobool, label %if.end, label %if.then
748 %uu = load i32, ptr %x, align 4
749 store i32 %uu, ptr %r, align 4
755 %vv = load i32, ptr %x, align 4
761 ; Same as test14, but %x here is dereferenceable. A pointer that is
762 ; dereferenceable can be loaded from speculatively without a risk of trapping.
763 ; Since it is OK to speculate, PRE is allowed.
765 define i32 @test16(ptr noalias nocapture readonly dereferenceable(8) align 4 %x, ptr noalias nocapture %r, i32 %a) nofree nosync {
766 ; CHECK-LABEL: @test16(
768 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
769 ; CHECK-NEXT: [[VV_PRE:%.*]] = load i32, ptr [[X:%.*]], align 4
770 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
772 ; CHECK-NEXT: store i32 [[VV_PRE]], ptr [[R:%.*]], align 4
773 ; CHECK-NEXT: br label [[IF_END]]
775 ; CHECK-NEXT: call void @f()
776 ; CHECK-NEXT: ret i32 [[VV_PRE]]
780 %tobool = icmp eq i32 %a, 0
781 br i1 %tobool, label %if.end, label %if.then
785 %uu = load i32, ptr %x, align 4
786 store i32 %uu, ptr %r, align 4
799 %vv = load i32, ptr %x, align 4
806 ; %v3 is partially redundant, bb3 has multiple predecessors coming through
807 ; critical edges. The other successors of those predecessors have same loads.
808 ; We can move all loads into predecessors.
810 define void @test17(ptr %p1, ptr %p2, ptr %p3, ptr %p4)
811 ; CHECK-LABEL: @test17(
813 ; CHECK-NEXT: [[V1:%.*]] = load i64, ptr [[P1:%.*]], align 8
814 ; CHECK-NEXT: [[COND1:%.*]] = icmp sgt i64 [[V1]], 200
815 ; CHECK-NEXT: br i1 [[COND1]], label [[BB200:%.*]], label [[BB1:%.*]]
817 ; CHECK-NEXT: [[COND2:%.*]] = icmp sgt i64 [[V1]], 100
818 ; CHECK-NEXT: br i1 [[COND2]], label [[BB100:%.*]], label [[BB2:%.*]]
820 ; CHECK-NEXT: [[V2:%.*]] = add nsw i64 [[V1]], 1
821 ; CHECK-NEXT: store i64 [[V2]], ptr [[P1]], align 8
822 ; CHECK-NEXT: br label [[BB3:%.*]]
824 ; CHECK-NEXT: [[V3:%.*]] = phi i64 [ [[V3_PRE:%.*]], [[BB200]] ], [ [[V3_PRE1:%.*]], [[BB100]] ], [ [[V2]], [[BB2]] ]
825 ; CHECK-NEXT: store i64 [[V3]], ptr [[P2:%.*]], align 8
826 ; CHECK-NEXT: ret void
828 ; CHECK-NEXT: [[COND3:%.*]] = call i1 @foo()
829 ; CHECK-NEXT: [[V3_PRE1]] = load i64, ptr [[P1]], align 8
830 ; CHECK-NEXT: br i1 [[COND3]], label [[BB3]], label [[BB101:%.*]]
832 ; CHECK-NEXT: store i64 [[V3_PRE1]], ptr [[P3:%.*]], align 8
833 ; CHECK-NEXT: ret void
835 ; CHECK-NEXT: [[COND4:%.*]] = call i1 @bar()
836 ; CHECK-NEXT: [[V3_PRE]] = load i64, ptr [[P1]], align 8
837 ; CHECK-NEXT: br i1 [[COND4]], label [[BB3]], label [[BB201:%.*]]
839 ; CHECK-NEXT: store i64 [[V3_PRE]], ptr [[P4:%.*]], align 8
840 ; CHECK-NEXT: ret void
844 %v1 = load i64, ptr %p1, align 8
845 %cond1 = icmp sgt i64 %v1, 200
846 br i1 %cond1, label %bb200, label %bb1
849 %cond2 = icmp sgt i64 %v1, 100
850 br i1 %cond2, label %bb100, label %bb2
853 %v2 = add nsw i64 %v1, 1
854 store i64 %v2, ptr %p1, align 8
858 %v3 = load i64, ptr %p1, align 8
859 store i64 %v3, ptr %p2, align 8
863 %cond3 = call i1 @foo()
864 br i1 %cond3, label %bb3, label %bb101
867 %v4 = load i64, ptr %p1, align 8
868 store i64 %v4, ptr %p3, align 8
872 %cond4 = call i1 @bar()
873 br i1 %cond4, label %bb3, label %bb201
876 %v5 = load i64, ptr %p1, align 8
877 store i64 %v5, ptr %p4, align 8
881 ; The output value from %if.then block is %dec, not loaded %v1.
882 ; So ValuesPerBlock[%if.then] should not be replaced when the load instruction
883 ; is moved to %entry.
884 define void @test18(i1 %cond, ptr %p1, ptr %p2) {
885 ; CHECK-LABEL: @test18(
887 ; CHECK-NEXT: [[V2_PRE:%.*]] = load i16, ptr [[P1:%.*]], align 2
888 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
890 ; CHECK-NEXT: [[DEC:%.*]] = add i16 [[V2_PRE]], -1
891 ; CHECK-NEXT: store i16 [[DEC]], ptr [[P1]], align 2
892 ; CHECK-NEXT: br label [[IF_END]]
894 ; CHECK-NEXT: [[V2:%.*]] = phi i16 [ [[DEC]], [[IF_THEN]] ], [ [[V2_PRE]], [[ENTRY:%.*]] ]
895 ; CHECK-NEXT: store i16 [[V2]], ptr [[P2:%.*]], align 2
896 ; CHECK-NEXT: ret void
899 br i1 %cond, label %if.end, label %if.then
902 %v1 = load i16, ptr %p1
903 %dec = add i16 %v1, -1
904 store i16 %dec, ptr %p1
908 %v2 = load i16, ptr %p1
909 store i16 %v2, ptr %p2
913 ; PRE of load instructions should not cross exception handling instructions.
914 define void @test19(i1 %cond, ptr %p1, ptr %p2)
915 ; CHECK-LABEL: @test19(
917 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[THEN:%.*]], label [[ELSE:%.*]]
919 ; CHECK-NEXT: [[V2:%.*]] = load i64, ptr [[P2:%.*]], align 8
920 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[V2]], 1
921 ; CHECK-NEXT: store i64 [[ADD]], ptr [[P1:%.*]], align 8
922 ; CHECK-NEXT: br label [[END:%.*]]
924 ; CHECK-NEXT: invoke void @f()
925 ; CHECK-NEXT: to label [[ELSE_END_CRIT_EDGE:%.*]] unwind label [[LPAD:%.*]]
926 ; CHECK: else.end_crit_edge:
927 ; CHECK-NEXT: [[V1_PRE:%.*]] = load i64, ptr [[P1]], align 8
928 ; CHECK-NEXT: br label [[END]]
930 ; CHECK-NEXT: [[V1:%.*]] = phi i64 [ [[V1_PRE]], [[ELSE_END_CRIT_EDGE]] ], [ [[ADD]], [[THEN]] ]
931 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[V1]], 100
932 ; CHECK-NEXT: store i64 [[AND]], ptr [[P2]], align 8
933 ; CHECK-NEXT: ret void
935 ; CHECK-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
936 ; CHECK-NEXT: cleanup
937 ; CHECK-NEXT: [[V3:%.*]] = load i64, ptr [[P1]], align 8
938 ; CHECK-NEXT: [[OR:%.*]] = or i64 [[V3]], 200
939 ; CHECK-NEXT: store i64 [[OR]], ptr [[P1]], align 8
940 ; CHECK-NEXT: resume { ptr, i32 } [[LP]]
942 personality ptr @__CxxFrameHandler3 {
944 br i1 %cond, label %then, label %else
947 %v2 = load i64, ptr %p2
948 %add = add i64 %v2, 1
949 store i64 %add, ptr %p1
954 to label %end unwind label %lpad
957 %v1 = load i64, ptr %p1
958 %and = and i64 %v1, 100
959 store i64 %and, ptr %p2
963 %lp = landingpad { ptr, i32 }
965 %v3 = load i64, ptr %p1
966 %or = or i64 %v3, 200
967 store i64 %or, ptr %p1
968 resume { ptr, i32 } %lp
971 ; A predecessor BB has both successors to the same BB, for simplicity we don't
972 ; handle it, nothing should be changed.
973 define void @test20(i1 %cond, i1 %cond2, ptr %p1, ptr %p2) {
974 ; CHECK-LABEL: @test20(
976 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
978 ; CHECK-NEXT: [[V1:%.*]] = load i16, ptr [[P1:%.*]], align 2
979 ; CHECK-NEXT: [[DEC:%.*]] = add i16 [[V1]], -1
980 ; CHECK-NEXT: store i16 [[DEC]], ptr [[P1]], align 2
981 ; CHECK-NEXT: br label [[IF_END:%.*]]
983 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_END]], label [[IF_END]]
985 ; CHECK-NEXT: [[V2:%.*]] = load i16, ptr [[P1]], align 2
986 ; CHECK-NEXT: store i16 [[V2]], ptr [[P2:%.*]], align 2
987 ; CHECK-NEXT: ret void
990 br i1 %cond, label %if.then, label %if.else
993 %v1 = load i16, ptr %p1
994 %dec = add i16 %v1, -1
995 store i16 %dec, ptr %p1
999 br i1 %cond2, label %if.end, label %if.end
1002 %v2 = load i16, ptr %p1
1003 store i16 %v2, ptr %p2
1007 ; More edges from the same BB to LoadBB. Don't change anything.
1008 define void @test21(i1 %cond, i32 %code, ptr %p1, ptr %p2) {
1009 ; CHECK-LABEL: @test21(
1010 ; CHECK-NEXT: entry:
1011 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1013 ; CHECK-NEXT: [[V1:%.*]] = load i16, ptr [[P1:%.*]], align 2
1014 ; CHECK-NEXT: [[DEC:%.*]] = add i16 [[V1]], -1
1015 ; CHECK-NEXT: store i16 [[DEC]], ptr [[P1]], align 2
1016 ; CHECK-NEXT: br label [[IF_END:%.*]]
1018 ; CHECK-NEXT: switch i32 [[CODE:%.*]], label [[IF_END]] [
1019 ; CHECK-NEXT: i32 1, label [[IF_END]]
1020 ; CHECK-NEXT: i32 2, label [[IF_END]]
1021 ; CHECK-NEXT: i32 3, label [[IF_END]]
1024 ; CHECK-NEXT: [[V2:%.*]] = load i16, ptr [[P1]], align 2
1025 ; CHECK-NEXT: store i16 [[V2]], ptr [[P2:%.*]], align 2
1026 ; CHECK-NEXT: ret void
1029 br i1 %cond, label %if.then, label %if.else
1032 %v1 = load i16, ptr %p1
1033 %dec = add i16 %v1, -1
1034 store i16 %dec, ptr %p1
1038 switch i32 %code, label %if.end [
1039 i32 1, label %if.end
1040 i32 2, label %if.end
1041 i32 3, label %if.end
1045 %v2 = load i16, ptr %p1
1046 store i16 %v2, ptr %p2
1050 ; Call to function @maybethrow may cause exception, so the load of %v3 can't
1051 ; be hoisted to block %if.else.
1052 define void @test22(i1 %cond, ptr %p1, ptr %p2) {
1053 ; CHECK-LABEL: @test22(
1054 ; CHECK-NEXT: entry:
1055 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1057 ; CHECK-NEXT: [[V1:%.*]] = load i64, ptr [[P1:%.*]], align 8
1058 ; CHECK-NEXT: [[DEC:%.*]] = add i64 [[V1]], -1
1059 ; CHECK-NEXT: store i64 [[DEC]], ptr [[P1]], align 8
1060 ; CHECK-NEXT: br label [[IF_END:%.*]]
1062 ; CHECK-NEXT: [[V2:%.*]] = phi i64 [ [[V2_PRE:%.*]], [[IF_ELSE_IF_END_CRIT_EDGE:%.*]] ], [ [[DEC]], [[IF_THEN]] ]
1063 ; CHECK-NEXT: store i64 [[V2]], ptr [[P2:%.*]], align 8
1064 ; CHECK-NEXT: ret void
1066 ; CHECK-NEXT: [[COND2:%.*]] = call i1 @foo()
1067 ; CHECK-NEXT: br i1 [[COND2]], label [[IF_ELSE_IF_END_CRIT_EDGE]], label [[EXIT:%.*]]
1068 ; CHECK: if.else.if.end_crit_edge:
1069 ; CHECK-NEXT: [[V2_PRE]] = load i64, ptr [[P1]], align 8
1070 ; CHECK-NEXT: br label [[IF_END]]
1072 ; CHECK-NEXT: [[_:%.*]] = call i1 @maybethrow()
1073 ; CHECK-NEXT: [[V3:%.*]] = load i64, ptr [[P1]], align 8
1074 ; CHECK-NEXT: store i64 [[V3]], ptr [[P2]], align 8
1075 ; CHECK-NEXT: ret void
1078 br i1 %cond, label %if.then, label %if.else
1081 %v1 = load i64, ptr %p1
1082 %dec = add i64 %v1, -1
1083 store i64 %dec, ptr %p1
1087 %v2 = load i64, ptr %p1
1088 store i64 %v2, ptr %p2
1092 %cond2 = call i1 @foo()
1093 br i1 %cond2, label %if.end, label %exit
1096 %_ = call i1 @maybethrow()
1097 %v3 = load i64, ptr %p1
1098 store i64 %v3, ptr %p2
1102 declare void @maybethrow() readnone
1103 @B = external global i64, align 8
1105 ; When BB in ValuesPerBlock(BB, OldLoad) is not OldLoad->getParent(), it should
1106 ; also be replaced by ValuesPerBlock(BB, NewLoad). So we'll not use the deleted
1107 ; OldLoad in later PHI instruction.
1108 define void @test23(i1 %cond1, i1 %cond2) {
1109 ; CHECK-LABEL: @test23(
1110 ; CHECK-NEXT: entry:
1111 ; CHECK-NEXT: [[G:%.*]] = alloca i64, align 8
1112 ; CHECK-NEXT: [[VAL1_PRE:%.*]] = load i64, ptr @B, align 8
1113 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[THEN:%.*]], label [[WRONG:%.*]]
1115 ; CHECK-NEXT: br i1 [[COND1:%.*]], label [[STORE:%.*]], label [[EXIT:%.*]]
1117 ; CHECK-NEXT: store i64 [[VAL1_PRE]], ptr @B, align 8
1118 ; CHECK-NEXT: br label [[WRONG]]
1120 ; CHECK-NEXT: store i64 [[VAL1_PRE]], ptr [[G]], align 8
1121 ; CHECK-NEXT: ret void
1123 ; CHECK-NEXT: ret void
1126 %G = alloca i64, align 8
1127 br i1 %cond2, label %then, label %wrong
1130 %val2 = load i64, ptr @B, align 8
1131 br i1 %cond1, label %store, label %exit
1134 store i64 %val2, ptr @B, align 8
1138 %val1 = load i64, ptr @B, align 8
1139 store i64 %val1, ptr %G, align 8