1; RUN: opt -S -jump-threading %s | FileCheck %s 2 3; Value of predicate known on all inputs (trivial case) 4; Note: InstCombine/EarlyCSE would also get this case 5define void @test(i8* %p, i8** %addr) { 6; CHECK-LABEL: @test 7entry: 8 %cmp0 = icmp eq i8* %p, null 9 br i1 %cmp0, label %exit, label %loop 10loop: 11; CHECK-LABEL: loop: 12; CHECK-NEXT: phi 13; CHECK-NEXT: br label %loop 14 %p1 = phi i8* [%p, %entry], [%p1, %loop] 15 %cmp1 = icmp eq i8* %p1, null 16 br i1 %cmp1, label %exit, label %loop 17exit: 18 ret void 19} 20 21; Value of predicate known on all inputs (non-trivial) 22define void @test2(i8* %p) { 23; CHECK-LABEL: @test2 24entry: 25 %cmp0 = icmp eq i8* %p, null 26 br i1 %cmp0, label %exit, label %loop 27loop: 28 %p1 = phi i8* [%p, %entry], [%p2, %backedge] 29 %cmp1 = icmp eq i8* %p1, null 30 br i1 %cmp1, label %exit, label %backedge 31backedge: 32; CHECK-LABEL: backedge: 33; CHECK-NEXT: phi 34; CHECK-NEXT: bitcast 35; CHECK-NEXT: load 36; CHECK-NEXT: cmp 37; CHECK-NEXT: br 38; CHECK-DAG: label %backedge 39 %addr = bitcast i8* %p1 to i8** 40 %p2 = load i8*, i8** %addr 41 %cmp2 = icmp eq i8* %p2, null 42 br i1 %cmp2, label %exit, label %loop 43exit: 44 ret void 45} 46 47; If the inputs don't branch the same way, we can't rewrite 48; Well, we could unroll this loop exactly twice, but that's 49; a different transform. 50define void @test_mixed(i8* %p) { 51; CHECK-LABEL: @test_mixed 52entry: 53 %cmp0 = icmp eq i8* %p, null 54 br i1 %cmp0, label %exit, label %loop 55loop: 56; CHECK-LABEL: loop: 57; CHECK-NEXT: phi 58; CHECK-NEXT: %cmp1 = icmp 59; CHECK-NEXT: br i1 %cmp1 60 %p1 = phi i8* [%p, %entry], [%p1, %loop] 61 %cmp1 = icmp ne i8* %p1, null 62 br i1 %cmp1, label %exit, label %loop 63exit: 64 ret void 65} 66 67