1 ; RUN: opt -jump-threading -S %s | FileCheck %s
3 ; Check that we thread arg2neg -> checkpos -> end.
5 ; LazyValueInfo would previously fail to analyze the value of %arg in arg2neg
6 ; because its predecessing blocks (checkneg) hadn't been processed yet (PR21238)
8 ; CHECK-LABEL: @test_jump_threading
10 ; CHECK-NEXT: br i1 %arg1, label %end, label %checkpos.thread
11 ; CHECK: checkpos.thread:
12 ; CHECK-NEXT: br label %end
14 define i32 @test_jump_threading(i1 %arg1, i32 %arg2) {
16 %cmp = icmp slt i32 %arg2, 0
17 br i1 %cmp, label %arg2neg, label %checkpos
20 br i1 %arg1, label %end, label %checkpos
23 %cmp2 = icmp sgt i32 %arg2, 0
24 br i1 %cmp2, label %arg2pos, label %end
30 %0 = phi i32 [ 1, %arg2neg ], [ 2, %checkpos ], [ 3, %arg2pos ]
35 ; arg2neg has an edge back to itself. If LazyValueInfo is not careful when
36 ; visiting predecessors, it could get into an infinite loop.
38 ; CHECK-LABEL: test_infinite_loop
40 define i32 @test_infinite_loop(i1 %arg1, i32 %arg2) {
42 %cmp = icmp slt i32 %arg2, 0
43 br i1 %cmp, label %arg2neg, label %checkpos
46 br i1 %arg1, label %arg2neg, label %checkpos
49 %cmp2 = icmp sgt i32 %arg2, 0
50 br i1 %cmp2, label %arg2pos, label %end
56 %0 = phi i32 [ 2, %checkpos ], [ 3, %arg2pos ]