1 ; RUN: opt -S -jump-threading < %s | FileCheck %s
3 ; Check that the heuristic for avoiding accidental introduction of irreducible
4 ; loops doesn't also prevent us from threading simple constructs where this
7 declare void @opaque_body()
9 define void @jump_threading_loopheader() {
10 ; CHECK-LABEL: @jump_threading_loopheader
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
22 call void @opaque_body()
23 ; CHECK: br label %entry
27 %cond = phi i2 [1, %entry], [2, %body]
28 switch i2 %cond, label %unreach [
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.
43 define void @jump_threading_loopheader2() {
44 ; CHECK-LABEL: @jump_threading_loopheader2
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
56 call void @opaque_body()
57 ; CHECK: br label %entry
61 %cond = phi i2 [1, %entry], [2, %body]
62 switch i2 %cond, label %unreach [
74 ; Check if we can handle undef branch condition.
75 define void @jump_threading_loopheader3() {
76 ; CHECK-LABEL: @jump_threading_loopheader3
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
88 call void @opaque_body()
89 ; CHECK: br label %entry
93 %phi = phi i32 [undef, %entry], [0, %body]
94 %cmp1 = icmp eq i32 %phi, 0
95 br i1 %cmp1, label %entry, label %exit