1; RUN: opt -jump-threading -S %s | FileCheck %s 2 3; Check that we thread arg2neg -> checkpos -> end. 4; 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) 7 8; CHECK-LABEL: @test_jump_threading 9; CHECK: arg2neg: 10; CHECK-NEXT: br i1 %arg1, label %end, label %checkpos.thread 11; CHECK: checkpos.thread: 12; CHECK-NEXT: br label %end 13 14define i32 @test_jump_threading(i1 %arg1, i32 %arg2) { 15checkneg: 16 %cmp = icmp slt i32 %arg2, 0 17 br i1 %cmp, label %arg2neg, label %checkpos 18 19arg2neg: 20 br i1 %arg1, label %end, label %checkpos 21 22checkpos: 23 %cmp2 = icmp sgt i32 %arg2, 0 24 br i1 %cmp2, label %arg2pos, label %end 25 26arg2pos: 27 br label %end 28 29end: 30 %0 = phi i32 [ 1, %arg2neg ], [ 2, %checkpos ], [ 3, %arg2pos ] 31 ret i32 %0 32} 33 34 35; arg2neg has an edge back to itself. If LazyValueInfo is not careful when 36; visiting predecessors, it could get into an infinite loop. 37 38; CHECK-LABEL: test_infinite_loop 39 40define i32 @test_infinite_loop(i1 %arg1, i32 %arg2) { 41checkneg: 42 %cmp = icmp slt i32 %arg2, 0 43 br i1 %cmp, label %arg2neg, label %checkpos 44 45arg2neg: 46 br i1 %arg1, label %arg2neg, label %checkpos 47 48checkpos: 49 %cmp2 = icmp sgt i32 %arg2, 0 50 br i1 %cmp2, label %arg2pos, label %end 51 52arg2pos: 53 br label %end 54 55end: 56 %0 = phi i32 [ 2, %checkpos ], [ 3, %arg2pos ] 57 ret i32 %0 58} 59