1; RUN: opt -S -jump-threading < %s | FileCheck %s 2 3; Check that the heuristic for avoiding accidental introduction of irreducible 4; loops doesn't also prevent us from threading simple constructs where this 5; isn't a problem. 6 7declare void @opaque_body() 8 9define void @jump_threading_loopheader() { 10; CHECK-LABEL: @jump_threading_loopheader 11top: 12 br label %entry 13 14entry: 15 %ind = phi i32 [0, %top], [%nextind, %latch] 16 %nextind = add i32 %ind, 1 17 %cmp = icmp ule i32 %ind, 10 18; CHECK: br i1 %cmp, label %latch, label %exit 19 br i1 %cmp, label %body, label %latch 20 21body: 22 call void @opaque_body() 23; CHECK: br label %entry 24 br label %latch 25 26latch: 27 %cond = phi i2 [1, %entry], [2, %body] 28 switch i2 %cond, label %unreach [ 29 i2 2, label %entry 30 i2 1, label %exit 31 ] 32 33unreach: 34 unreachable 35 36exit: 37 ret void 38} 39 40; We also need to check the opposite order of the branches, in the switch 41; instruction because jump-threading relies on that to decide which edge to 42; try to thread first. 43define void @jump_threading_loopheader2() { 44; CHECK-LABEL: @jump_threading_loopheader2 45top: 46 br label %entry 47 48entry: 49 %ind = phi i32 [0, %top], [%nextind, %latch] 50 %nextind = add i32 %ind, 1 51 %cmp = icmp ule i32 %ind, 10 52; CHECK: br i1 %cmp, label %exit, label %latch 53 br i1 %cmp, label %body, label %latch 54 55body: 56 call void @opaque_body() 57; CHECK: br label %entry 58 br label %latch 59 60latch: 61 %cond = phi i2 [1, %entry], [2, %body] 62 switch i2 %cond, label %unreach [ 63 i2 1, label %entry 64 i2 2, label %exit 65 ] 66 67unreach: 68 unreachable 69 70exit: 71 ret void 72} 73 74; Check if we can handle undef branch condition. 75define void @jump_threading_loopheader3() { 76; CHECK-LABEL: @jump_threading_loopheader3 77top: 78 br label %entry 79 80entry: 81 %ind = phi i32 [0, %top], [%nextind, %latch] 82 %nextind = add i32 %ind, 1 83 %cmp = icmp ule i32 %ind, 10 84; CHECK: br i1 %cmp, label %latch, label %exit 85 br i1 %cmp, label %body, label %latch 86 87body: 88 call void @opaque_body() 89; CHECK: br label %entry 90 br label %latch 91 92latch: 93 %phi = phi i32 [undef, %entry], [0, %body] 94 %cmp1 = icmp eq i32 %phi, 0 95 br i1 %cmp1, label %entry, label %exit 96 97exit: 98 ret void 99} 100