1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -loop-deletion -S | FileCheck %s
3 ; RUN: opt < %s -passes='loop(loop-deletion)' -S | FileCheck %s
5 ; Make sure we do not get the miscompile on this test with irreducible CFG.
6 define i16 @test_01(i16 %j, i16 %k, i16 %recurs) { ; If we have %j: 1, %k: 1, %recurs: 0
7 ; CHECK-LABEL: @test_01(
9 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i16 [[RECURS:%.*]], 0
10 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
12 ; CHECK-NEXT: [[CALL:%.*]] = tail call i16 @test_01(i16 0, i16 0, i16 0)
13 ; CHECK-NEXT: br label [[IF_END]]
15 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[J:%.*]], 0
16 ; CHECK-NEXT: br label [[BB2:%.*]]
18 ; CHECK-NEXT: [[K_ADDR_0:%.*]] = phi i16 [ [[K:%.*]], [[IF_END]] ], [ [[K_ADDR_2:%.*]], [[BB12:%.*]] ]
19 ; CHECK-NEXT: [[RESULT_0:%.*]] = phi i16 [ 0, [[IF_END]] ], [ 20, [[BB12]] ]
20 ; CHECK-NEXT: br i1 [[CMP]], label [[BB12]], label [[BB4:%.*]]
22 ; CHECK-NEXT: [[K_ADDR_1:%.*]] = phi i16 [ [[K_ADDR_0]], [[BB2]] ], [ [[K_ADDR_2]], [[BB12]] ]
23 ; CHECK-NEXT: [[X_1:%.*]] = phi i16 [ 0, [[BB2]] ], [ 1, [[BB12]] ]
24 ; CHECK-NEXT: [[RESULT_1:%.*]] = phi i16 [ [[RESULT_0]], [[BB2]] ], [ 10, [[BB12]] ]
25 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i16 [[K_ADDR_1]], 0
26 ; CHECK-NEXT: br i1 [[CMP2]], label [[BB13:%.*]], label [[BB12]]
28 ; CHECK-NEXT: [[K_ADDR_2]] = phi i16 [ [[K_ADDR_0]], [[BB2]] ], [ 0, [[BB4]] ]
29 ; CHECK-NEXT: [[X_2:%.*]] = phi i16 [ 1, [[BB2]] ], [ [[X_1]], [[BB4]] ]
30 ; CHECK-NEXT: [[CMP5:%.*]] = icmp eq i16 [[X_2]], 0
31 ; CHECK-NEXT: br i1 [[CMP5]], label [[BB2]], label [[BB4]]
33 ; CHECK-NEXT: [[RESULT_1_LCSSA:%.*]] = phi i16 [ [[RESULT_1]], [[BB4]] ]
34 ; CHECK-NEXT: ret i16 [[RESULT_1_LCSSA]]
37 %tobool.not = icmp eq i16 %recurs, 0 ; 1
38 br i1 %tobool.not, label %if.end, label %if.then ; -> if.end
40 if.then: ; preds = %entry
41 %call = tail call i16 @test_01(i16 0, i16 0, i16 0)
44 if.end: ; preds = %if.then, %entry
45 %cmp = icmp eq i16 %j, 0 ; 0
46 br label %bb2 ; -> bb2
48 bb2: ; preds = %bb12, %if.end
49 %k.addr.0 = phi i16 [ %k, %if.end ], [ %k.addr.2, %bb12 ] ; 1
50 %result.0 = phi i16 [ 0, %if.end ], [ 20, %bb12 ] ; 0
51 br i1 %cmp, label %bb12, label %bb4 ; %cmp: 0 -> bb4
53 bb4: ; preds = %bb12, %bb2
54 %k.addr.1 = phi i16 [ %k.addr.0, %bb2 ], [ %k.addr.2, %bb12 ] ; 1
55 %x.1 = phi i16 [ 0, %bb2 ], [ 1, %bb12 ] ; 0
56 %result.1 = phi i16 [ %result.0, %bb2 ], [ 10, %bb12 ]
57 %cmp2 = icmp eq i16 %k.addr.1, 0 ; 0
58 br i1 %cmp2, label %bb13, label %bb12 ; -> bb12
60 bb12: ; preds = %bb4, %bb2
61 %k.addr.2 = phi i16 [ %k.addr.0, %bb2 ], [ 0, %bb4 ] ; 0
62 %x.2 = phi i16 [ 1, %bb2 ], [ %x.1, %bb4 ] ; 0
63 %cmp5 = icmp eq i16 %x.2, 0 ; 1
64 br i1 %cmp5, label %bb2, label %bb4 ; -> bb2
67 %result.1.lcssa = phi i16 [ %result.1, %bb4 ]
68 ret i16 %result.1.lcssa
71 ; Another nasty case of irreducible CFG. Make sure we do not crash here.
72 define void @test_02() {
73 ; CHECK-LABEL: @test_02(
75 ; CHECK-NEXT: br label [[BB17:%.*]]
77 ; CHECK-NEXT: ret void
79 ; CHECK-NEXT: unreachable
81 ; CHECK-NEXT: unreachable
83 ; CHECK-NEXT: unreachable
85 ; CHECK-NEXT: unreachable
87 ; CHECK-NEXT: unreachable
89 ; CHECK-NEXT: unreachable
91 ; CHECK-NEXT: unreachable
93 ; CHECK-NEXT: switch i8 undef, label [[BB13:%.*]] [
94 ; CHECK-NEXT: i8 3, label [[BB10:%.*]]
95 ; CHECK-NEXT: i8 43, label [[BB10]]
96 ; CHECK-NEXT: i8 37, label [[BB11:%.*]]
97 ; CHECK-NEXT: i8 2, label [[BB12:%.*]]
98 ; CHECK-NEXT: i8 4, label [[BB12]]
99 ; CHECK-NEXT: i8 20, label [[BB12]]
100 ; CHECK-NEXT: i8 42, label [[BB12]]
101 ; CHECK-NEXT: i8 44, label [[BB12]]
102 ; CHECK-NEXT: i8 54, label [[BB12]]
105 ; CHECK-NEXT: unreachable
107 ; CHECK-NEXT: unreachable
109 ; CHECK-NEXT: br label [[BB19:%.*]]
111 ; CHECK-NEXT: unreachable
113 ; CHECK-NEXT: unreachable
115 ; CHECK-NEXT: unreachable
117 ; CHECK-NEXT: br label [[BB17]]
119 ; CHECK-NEXT: [[TMP:%.*]] = icmp sgt i32 0, 1
120 ; CHECK-NEXT: br i1 [[TMP]], label [[BB18:%.*]], label [[BB19]]
122 ; CHECK-NEXT: br label [[BB20:%.*]]
124 ; CHECK-NEXT: br label [[BB20]]
126 ; CHECK-NEXT: switch i8 undef, label [[BB16:%.*]] [
127 ; CHECK-NEXT: i8 0, label [[BB1:%.*]]
128 ; CHECK-NEXT: i8 1, label [[BB1]]
129 ; CHECK-NEXT: i8 8, label [[BB1]]
130 ; CHECK-NEXT: i8 9, label [[BB1]]
131 ; CHECK-NEXT: i8 12, label [[BB1]]
132 ; CHECK-NEXT: i8 13, label [[BB1]]
133 ; CHECK-NEXT: i8 40, label [[BB1]]
134 ; CHECK-NEXT: i8 41, label [[BB1]]
135 ; CHECK-NEXT: i8 52, label [[BB1]]
136 ; CHECK-NEXT: i8 53, label [[BB1]]
137 ; CHECK-NEXT: i8 55, label [[BB15:%.*]]
138 ; CHECK-NEXT: i8 15, label [[BB14:%.*]]
139 ; CHECK-NEXT: i8 29, label [[BB9:%.*]]
140 ; CHECK-NEXT: i8 37, label [[BB8:%.*]]
141 ; CHECK-NEXT: i8 69, label [[BB3:%.*]]
142 ; CHECK-NEXT: i8 89, label [[BB7:%.*]]
143 ; CHECK-NEXT: i8 85, label [[BB6:%.*]]
144 ; CHECK-NEXT: i8 81, label [[BB5:%.*]]
145 ; CHECK-NEXT: i8 65, label [[BB2:%.*]]
146 ; CHECK-NEXT: i8 73, label [[BB4:%.*]]
152 bb1: ; preds = %bb20, %bb20, %bb20, %bb20, %bb20, %bb20, %bb20, %bb20, %bb20, %bb20
177 switch i8 undef, label %bb13 [
189 bb10: ; preds = %bb9, %bb9
195 bb12: ; preds = %bb9, %bb9, %bb9, %bb9, %bb9, %bb9
201 bb14: ; preds = %bb20
204 bb15: ; preds = %bb20
207 bb16: ; preds = %bb20
210 bb17: ; preds = %bb16, %bb
211 %tmp = icmp sgt i32 0, 1
212 br i1 %tmp, label %bb18, label %bb19
214 bb18: ; preds = %bb17
217 bb19: ; preds = %bb17, %bb12
220 bb20: ; preds = %bb19, %bb18
221 switch i8 undef, label %bb16 [