1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -jump-threading < %s | FileCheck %s
4 ; Check that the heuristic for avoiding accidental introduction of irreducible
5 ; loops doesn't also prevent us from threading simple constructs where this
8 declare void @opaque_body()
10 define void @jump_threading_loopheader() {
11 ; CHECK-LABEL: @jump_threading_loopheader(
13 ; CHECK-NEXT: br label [[ENTRY:%.*]]
15 ; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]
16 ; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 1
17 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 10
18 ; CHECK-NEXT: br i1 [[CMP]], label [[LATCH]], label [[EXIT:%.*]]
20 ; CHECK-NEXT: call void @opaque_body()
21 ; CHECK-NEXT: br label [[ENTRY]]
23 ; CHECK-NEXT: ret void
29 %ind = phi i32 [0, %top], [%nextind, %latch]
30 %nextind = add i32 %ind, 1
31 %cmp = icmp ule i32 %ind, 10
32 br i1 %cmp, label %body, label %latch
35 call void @opaque_body()
39 %cond = phi i2 [1, %entry], [2, %body]
40 switch i2 %cond, label %unreach [
52 ; We also need to check the opposite order of the branches, in the switch
53 ; instruction because jump-threading relies on that to decide which edge to
54 ; try to thread first.
55 define void @jump_threading_loopheader2() {
56 ; CHECK-LABEL: @jump_threading_loopheader2(
58 ; CHECK-NEXT: br label [[ENTRY:%.*]]
60 ; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]
61 ; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 1
62 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 10
63 ; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LATCH]]
65 ; CHECK-NEXT: br label [[ENTRY]]
67 ; CHECK-NEXT: call void @opaque_body()
68 ; CHECK-NEXT: ret void
74 %ind = phi i32 [0, %top], [%nextind, %latch]
75 %nextind = add i32 %ind, 1
76 %cmp = icmp ule i32 %ind, 10
77 br i1 %cmp, label %body, label %latch
80 call void @opaque_body()
84 %cond = phi i2 [1, %entry], [2, %body]
85 switch i2 %cond, label %unreach [
97 ; Check if we can handle undef branch condition.
98 define void @jump_threading_loopheader3() {
99 ; CHECK-LABEL: @jump_threading_loopheader3(
101 ; CHECK-NEXT: br label [[ENTRY:%.*]]
103 ; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]
104 ; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 1
105 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 10
106 ; CHECK-NEXT: br i1 [[CMP]], label [[LATCH]], label [[EXIT:%.*]]
108 ; CHECK-NEXT: call void @opaque_body()
109 ; CHECK-NEXT: br label [[ENTRY]]
111 ; CHECK-NEXT: ret void
117 %ind = phi i32 [0, %top], [%nextind, %latch]
118 %nextind = add i32 %ind, 1
119 %cmp = icmp ule i32 %ind, 10
120 br i1 %cmp, label %body, label %latch
123 call void @opaque_body()
127 %phi = phi i32 [undef, %entry], [0, %body]
128 %cmp1 = icmp eq i32 %phi, 0
129 br i1 %cmp1, label %entry, label %exit