1 ; RUN: opt < %s -jump-threading -S | FileCheck %s
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=jump-threading -S | FileCheck %s
4 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
5 target triple = "i386-apple-darwin7"
7 ; Test that we can thread through the block with the partially redundant load (%2).
9 define i32 @test1(i32* %P) nounwind {
10 ; CHECK-LABEL: @test1(
12 %0 = tail call i32 (...) @f1() nounwind ; <i32> [#uses=1]
13 %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
14 br i1 %1, label %bb1, label %bb
19 ; CHECK: br label %bb3
20 store i32 42, i32* %P, align 4
23 bb1: ; preds = %entry, %bb
24 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ] ; <i32> [#uses=2]
25 %2 = load i32, i32* %P, align 4 ; <i32> [#uses=1]
26 %3 = icmp sgt i32 %2, 36 ; <i1> [#uses=1]
27 br i1 %3, label %bb3, label %bb2
30 %4 = tail call i32 (...) @f2() nounwind ; <i32> [#uses=0]
35 ; CHECK: %res.02 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ]
36 ; CHECK: ret i32 %res.02
45 ;; Check that we preserve TBAA information.
48 define i32 @test2(i32* %P) nounwind {
49 ; CHECK-LABEL: @test2(
51 %0 = tail call i32 (...) @f1() nounwind ; <i32> [#uses=1]
52 %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
53 br i1 %1, label %bb1, label %bb
57 ; CHECK: store{{.*}}, !tbaa !0
58 ; CHECK: br label %bb3
59 store i32 42, i32* %P, align 4, !tbaa !0
62 bb1: ; preds = %entry, %bb
63 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
64 %2 = load i32, i32* %P, align 4, !tbaa !0
65 %3 = icmp sgt i32 %2, 36
66 br i1 %3, label %bb3, label %bb2
69 %4 = tail call i32 (...) @f2() nounwind
74 ; CHECK: %res.02 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ]
75 ; CHECK: ret i32 %res.02
79 define i32 @test3(i8** %x, i1 %f) {
80 ; Correctly thread loads of different (but compatible) types, placing bitcasts
81 ; as necessary in the predecessors. This is especially tricky because the same
82 ; predecessor ends up with two entries in the PHI node and they must share
84 ; CHECK-LABEL: @test3(
86 %0 = bitcast i8** %x to i32**
87 %1 = load i32*, i32** %0, align 8
88 br i1 %f, label %if.end57, label %if.then56
89 ; CHECK: %[[LOAD:.*]] = load i32*, i32**
90 ; CHECK: %[[CAST:.*]] = bitcast i32* %[[LOAD]] to i8*
96 %2 = load i8*, i8** %x, align 8
97 %tobool59 = icmp eq i8* %2, null
98 br i1 %tobool59, label %return, label %if.then60
99 ; CHECK: %[[PHI:.*]] = phi i8* [ %[[CAST]], %[[PRED:[^ ]+]] ], [ %[[CAST]], %[[PRED]] ]
100 ; CHECK-NEXT: %[[CMP:.*]] = icmp eq i8* %[[PHI]], null
101 ; CHECK-NEXT: br i1 %[[CMP]]
110 define i32 @test4(i32* %P) {
111 ; CHECK-LABEL: @test4(
113 %v0 = tail call i32 (...) @f1()
114 %v1 = icmp eq i32 %v0, 0
115 br i1 %v1, label %bb1, label %bb
119 ; CHECK: store atomic
120 ; CHECK: br label %bb3
121 store atomic i32 42, i32* %P unordered, align 4
128 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
129 %v2 = load atomic i32, i32* %P unordered, align 4
130 %v3 = icmp sgt i32 %v2, 36
131 br i1 %v3, label %bb3, label %bb2
134 %v4 = tail call i32 (...) @f2()
141 define i32 @test5(i32* %P) {
144 ; CHECK-LABEL: @test5(
146 %v0 = tail call i32 (...) @f1()
147 %v1 = icmp eq i32 %v0, 0
148 br i1 %v1, label %bb1, label %bb
152 ; CHECK-NEXT: store atomic i32 42, i32* %P release, align 4
153 ; CHECK-NEXT: br label %bb1
154 store atomic i32 42, i32* %P release, align 4
159 ; CHECK-NEXT: %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
160 ; CHECK-NEXT: %v2 = load atomic i32, i32* %P acquire, align 4
161 ; CHECK-NEXT: %v3 = icmp sgt i32 %v2, 36
162 ; CHECK-NEXT: br i1 %v3, label %bb3, label %bb2
164 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
165 %v2 = load atomic i32, i32* %P acquire, align 4
166 %v3 = icmp sgt i32 %v2, 36
167 br i1 %v3, label %bb3, label %bb2
170 %v4 = tail call i32 (...) @f2()
177 define i32 @test6(i32* %P) {
180 ; CHECK-LABEL: @test6(
182 %v0 = tail call i32 (...) @f1()
183 %v1 = icmp eq i32 %v0, 0
184 br i1 %v1, label %bb1, label %bb
188 ; CHECK-NEXT: store i32 42, i32* %P
189 ; CHECK-NEXT: br label %bb1
190 store i32 42, i32* %P
195 ; CHECK-NEXT: %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
196 ; CHECK-NEXT: %v2 = load atomic i32, i32* %P acquire, align 4
197 ; CHECK-NEXT: %v3 = icmp sgt i32 %v2, 36
198 ; CHECK-NEXT: br i1 %v3, label %bb3, label %bb2
200 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
201 %v2 = load atomic i32, i32* %P acquire, align 4
202 %v3 = icmp sgt i32 %v2, 36
203 br i1 %v3, label %bb3, label %bb2
206 %v4 = tail call i32 (...) @f2()
213 define i32 @test7(i32* %P) {
216 ; CHECK-LABEL: @test7(
218 %v0 = tail call i32 (...) @f1()
219 %v1 = icmp eq i32 %v0, 0
220 br i1 %v1, label %bb1, label %bb
224 ; CHECK-NEXT: %val = load i32, i32* %P
225 ; CHECK-NEXT: br label %bb1
226 %val = load i32, i32* %P
231 ; CHECK-NEXT: %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
232 ; CHECK-NEXT: %v2 = load atomic i32, i32* %P acquire, align 4
233 ; CHECK-NEXT: %v3 = icmp sgt i32 %v2, 36
234 ; CHECK-NEXT: br i1 %v3, label %bb3, label %bb2
236 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
237 %v2 = load atomic i32, i32* %P acquire, align 4
238 %v3 = icmp sgt i32 %v2, 36
239 br i1 %v3, label %bb3, label %bb2
242 %v4 = tail call i32 (...) @f2()
249 ; Make sure we merge the aliasing metadata. We keep the range metadata for the
250 ; first load, as it dominates the second load. Hence we can eliminate the
252 define void @test8(i32*, i32*, i32*) {
253 ; CHECK-LABEL: @test8(
254 ; CHECK: %a = load i32, i32* %0, !range ![[RANGE4:[0-9]+]]
255 ; CHECK-NEXT: store i32 %a
256 ; CHECK-NEXT: %xxx = tail call i32 (...) @f1()
257 ; CHECK-NEXT: ret void
258 %a = load i32, i32* %0, !tbaa !0, !range !4, !alias.scope !9, !noalias !10
259 %b = load i32, i32* %0, !range !5
260 store i32 %a, i32* %1
261 %c = icmp eq i32 %b, 8
262 br i1 %c, label %ret1, label %ret2
268 %xxx = tail call i32 (...) @f1() nounwind
272 ; Make sure we merge/PRE aliasing metadata correctly. That means that
273 ; we need to remove metadata from the existing load, and add appropriate
274 ; metadata to the newly inserted load.
275 define void @test9(i32*, i32*, i32*, i1 %c) {
276 ; CHECK-LABEL: @test9(
277 br i1 %c, label %d1, label %d2
280 ; CHECK-NEXT: %a = load i32, i32* %0{{$}}
282 %a = load i32, i32* %0, !range !4, !alias.scope !9, !noalias !10
286 ; CHECK-NEXT: %xxxx = tail call i32 (...) @f1()
287 ; CHECK-NEXT: %b.pr = load i32, i32* %0, !tbaa !0{{$}}
289 %xxxx = tail call i32 (...) @f1() nounwind
293 %p = phi i32 [ 1, %d2 ], [ %a, %d1 ]
294 %b = load i32, i32* %0, !tbaa !0
295 store i32 %p, i32* %1
296 %c2 = icmp eq i32 %b, 8
297 br i1 %c2, label %ret1, label %ret2
303 %xxx = tail call i32 (...) @f1() nounwind
307 define i32 @fn_noalias(i1 %c2,i64* noalias %P, i64* noalias %P2) {
308 ; CHECK-LABEL: @fn_noalias
309 ; CHECK-LABEL: cond1:
310 ; CHECK: %[[LD1:.*]] = load i64, i64* %P
311 ; CHECK: br i1 %c, label %[[THREAD:.*]], label %end
312 ; CHECK-LABEL: cond2:
313 ; CHECK: %[[LD2:.*]] = load i64, i64* %P
314 ; CHECK-LABEL: cond3:
315 ; CHECK: %[[PHI:.*]] = phi i64 [ %[[LD1]], %[[THREAD]] ], [ %[[LD2]], %cond2 ]
316 ; CHECK: call void @fn3(i64 %[[PHI]])
318 br i1 %c2, label %cond2, label %cond1
321 %l1 = load i64, i64* %P
322 store i64 42, i64* %P2
323 %c = icmp eq i64 %l1, 0
324 br i1 %c, label %cond2, label %end
327 %l2 = load i64, i64* %P
328 call void @fn2(i64 %l2)
329 %c3 = icmp eq i64 %l2, 0
330 br i1 %c3, label %cond3, label %end
333 call void @fn3(i64 %l2)
340 ; This tests if we can thread from %sw.bb.i to %do.body.preheader.i67 through
341 ; %sw.bb21.i. To make this happen, %l2 should be detected as a partically
342 ; redundant load with %l3 across the store to %phase in %sw.bb21.i.
344 %struct.NEXT_MOVE = type { i32, i32, i32* }
345 @hash_move = unnamed_addr global [65 x i32] zeroinitializer, align 4
346 @current_move = internal global [65 x i32] zeroinitializer, align 4
347 @last = internal unnamed_addr global [65 x i32*] zeroinitializer, align 8
348 @next_status = internal unnamed_addr global [65 x %struct.NEXT_MOVE] zeroinitializer, align 8
349 define fastcc i32 @Search(i64 %idxprom.i, i64 %idxprom.i89, i32 %c) {
350 ; CHECK-LABEL: @Search
351 ; CHECK-LABEL: sw.bb.i:
352 ; CHECK: %[[LD1:.*]] = load i32, i32* %arrayidx185, align 4
353 ; CHECK: %[[C1:.*]] = icmp eq i32 %[[LD1]], 0
354 ; CHECK: br i1 %[[C1]], label %sw.bb21.i.thread, label %if.then.i64
355 ; CHECK-LABEL: sw.bb21.i.thread:
356 ; CHECK: br label %[[THREAD_TO:.*]]
357 ; CHECK-LABEL: sw.bb21.i:
358 ; CHECK: %[[LD2:.*]] = load i32, i32* %arrayidx185, align 4
359 ; CHECK: %[[C2:.*]] = icmp eq i32 %[[LD2]], 0
360 ; CHECK:br i1 %[[C2]], label %[[THREAD_TO]], label %cleanup
362 %arrayidx185 = getelementptr inbounds [65 x i32], [65 x i32]* @hash_move, i64 0, i64 %idxprom.i
363 %arrayidx307 = getelementptr inbounds [65 x i32], [65 x i32]* @current_move, i64 0, i64 %idxprom.i
364 %arrayidx89 = getelementptr inbounds [65 x i32*], [65 x i32*]* @last, i64 0, i64 %idxprom.i
365 %phase = getelementptr inbounds [65 x %struct.NEXT_MOVE], [65 x %struct.NEXT_MOVE]* @next_status, i64 0, i64 %idxprom.i, i32 0
366 br label %cond.true282
369 switch i32 %c, label %sw.default.i [
370 i32 1, label %sw.bb.i
371 i32 0, label %sw.bb21.i
378 %call.i62 = call fastcc i32* @GenerateCheckEvasions()
379 store i32* %call.i62, i32** %arrayidx89, align 8
380 %l2 = load i32, i32* %arrayidx185, align 4
381 %tobool.i63 = icmp eq i32 %l2, 0
382 br i1 %tobool.i63, label %sw.bb21.i, label %if.then.i64
384 if.then.i64: ; preds = %sw.bb.i
385 store i32 7, i32* %phase, align 8
386 store i32 %l2, i32* %arrayidx307, align 4
387 %call16.i = call fastcc i32 @ValidMove(i32 %l2)
388 %tobool17.i = icmp eq i32 %call16.i, 0
389 br i1 %tobool17.i, label %if.else.i65, label %cleanup
396 store i32 10, i32* %phase, align 8
397 %l3= load i32, i32* %arrayidx185, align 4
398 %tobool27.i = icmp eq i32 %l3, 0
399 br i1 %tobool27.i, label %do.body.preheader.i67, label %cleanup
401 do.body.preheader.i67:
410 declare fastcc i32* @GenerateCheckEvasions()
411 declare fastcc i32 @ValidMove(i32 %move)
413 declare void @Cleanup()
416 define i32 @fn_SinglePred(i1 %c2,i64* %P) {
417 ; CHECK-LABEL: @fn_SinglePred
418 ; CHECK-LABEL: entry:
419 ; CHECK: %[[L1:.*]] = load i64, i64* %P
420 ; CHECK: br i1 %c, label %cond3, label %cond1
421 ; CHECK-LABEL: cond2:
423 ; CHECK: %[[PHI:.*]] = phi i64 [ %[[L1]], %cond1 ]
424 ; CHECK: call void @fn2(i64 %[[PHI]])
425 ; CHECK: br label %end
426 ; CHECK-LABEL: cond3:
427 ; CHECK: call void @fn2(i64 %l1)
428 ; CHECK: call void @fn3(i64 %l1)
431 %l1 = load i64, i64* %P
432 %c = icmp eq i64 %l1, 0
433 br i1 %c, label %cond2, label %cond1
436 br i1 %c2, label %cond2, label %end
439 %l2 = load i64, i64* %P
440 call void @fn2(i64 %l2)
441 %c3 = icmp eq i64 %l2, 0
442 br i1 %c3, label %cond3, label %end
445 call void @fn3(i64 %l2)
452 define i32 @fn_SinglePredMultihop(i1 %c1, i1 %c2,i64* %P) {
453 ; CHECK-LABEL: @fn_SinglePredMultihop
454 ; CHECK-LABEL: entry:
455 ; CHECK: %[[L1:.*]] = load i64, i64* %P
456 ; CHECK: br i1 %c0, label %cond3, label %cond0
457 ; CHECK-LABEL: cond2:
459 ; CHECK: %[[PHI:.*]] = phi i64 [ %[[L1]], %cond1 ]
460 ; CHECK: call void @fn2(i64 %[[PHI]])
461 ; CHECK: br label %end
462 ; CHECK-LABEL: cond3:
463 ; CHECK: call void @fn2(i64 %l1)
464 ; CHECK: call void @fn3(i64 %l1)
467 %l1 = load i64, i64* %P
468 %c0 = icmp eq i64 %l1, 0
469 br i1 %c0, label %cond2, label %cond0
472 br i1 %c1, label %cond1, label %end
475 br i1 %c2, label %cond2, label %end
478 %l2 = load i64, i64* %P
479 call void @fn2(i64 %l2)
480 %c3 = icmp eq i64 %l2, 0
481 br i1 %c3, label %cond3, label %end
484 call void @fn3(i64 %l2)
491 declare void @fn2(i64)
492 declare void @fn3(i64)
495 ; Make sure we phi-translate and make the partially redundant load in
496 ; merge fully redudant and then we can jump-thread the block with the
499 ; CHECK-LABEL: define i32 @phi_translate_partial_redundant_loads(i32 %0, i32* %1, i32* %2
500 ; CHECK: merge.thread:
502 ; CHECK: br label %left_x
505 ; CHECK-NEXT: ret i32 20
506 define i32 @phi_translate_partial_redundant_loads(i32, i32*, i32*) {
507 %cmp0 = icmp ne i32 %0, 0
508 br i1 %cmp0, label %left, label %right
511 store i32 1, i32* %1, align 4
518 %phiptr = phi i32* [ %1, %left ], [ %2, %right ]
519 %newload = load i32, i32* %phiptr, align 4
520 %cmp1 = icmp slt i32 %newload, 5
521 br i1 %cmp1, label %left_x, label %right_x
530 ; CHECK: ![[RANGE4]] = !{i32 0, i32 1}
532 !0 = !{!3, !3, i64 0}
533 !1 = !{!"omnipotent char", !2}
534 !2 = !{!"Simple C/C++ TBAA"}
536 !4 = !{ i32 0, i32 1 }
537 !5 = !{ i32 8, i32 10 }