1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 ; This used to cause on infinite instcombine loop.
6 define void @test(i1 %c, ptr %p) {
9 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB17:%.*]], label [[BB24:%.*]]
11 ; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[DOTIN1:%.*]], [[BB47:%.*]] ], [ undef, [[BB16:%.*]] ]
12 ; CHECK-NEXT: store ptr [[I]], ptr [[P:%.*]], align 8
13 ; CHECK-NEXT: ret void
15 ; CHECK-NEXT: br i1 [[C]], label [[BB44:%.*]], label [[BB49:%.*]]
17 ; CHECK-NEXT: [[TMP46:%.*]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
18 ; CHECK-NEXT: br label [[BB47]]
20 ; CHECK-NEXT: [[DOTIN1]] = phi ptr [ [[DOTIN:%.*]], [[BB150:%.*]] ], [ [[TMP122:%.*]], [[BB119:%.*]] ], [ [[TMP103:%.*]], [[BB101:%.*]] ], [ [[TMP93:%.*]], [[BB91:%.*]] ], [ [[TMP83:%.*]], [[BB81:%.*]] ], [ [[TMP70:%.*]], [[BB67:%.*]] ], [ [[TMP58:%.*]], [[BB56:%.*]] ], [ [[TMP46]], [[BB44]] ]
21 ; CHECK-NEXT: br label [[BB17]]
23 ; CHECK-NEXT: br i1 [[C]], label [[BB56]], label [[BB59:%.*]]
25 ; CHECK-NEXT: [[TMP58]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
26 ; CHECK-NEXT: br label [[BB47]]
28 ; CHECK-NEXT: br i1 [[C]], label [[BB67]], label [[BB71:%.*]]
30 ; CHECK-NEXT: [[TMP70]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
31 ; CHECK-NEXT: br label [[BB47]]
33 ; CHECK-NEXT: br i1 [[C]], label [[BB81]], label [[BB84:%.*]]
35 ; CHECK-NEXT: [[TMP83]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
36 ; CHECK-NEXT: br label [[BB47]]
38 ; CHECK-NEXT: br i1 [[C]], label [[BB91]], label [[BB94:%.*]]
40 ; CHECK-NEXT: [[TMP93]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
41 ; CHECK-NEXT: br label [[BB47]]
43 ; CHECK-NEXT: br i1 [[C]], label [[BB101]], label [[BB104:%.*]]
45 ; CHECK-NEXT: [[TMP103]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
46 ; CHECK-NEXT: br label [[BB47]]
48 ; CHECK-NEXT: br i1 [[C]], label [[BB119]], label [[BB123:%.*]]
50 ; CHECK-NEXT: [[TMP122]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
51 ; CHECK-NEXT: br label [[BB47]]
53 ; CHECK-NEXT: br i1 [[C]], label [[BB147:%.*]], label [[BB152:%.*]]
55 ; CHECK-NEXT: [[TMP149:%.*]] = load ptr, ptr inttoptr (i64 16 to ptr), align 16
56 ; CHECK-NEXT: br label [[BB150]]
58 ; CHECK-NEXT: [[DOTIN]] = phi ptr [ poison, [[BB152]] ], [ [[TMP149]], [[BB147]] ]
59 ; CHECK-NEXT: br label [[BB47]]
61 ; CHECK-NEXT: store i1 true, ptr poison, align 1
62 ; CHECK-NEXT: br label [[BB150]]
65 br i1 %c, label %bb17, label %bb24
67 bb17: ; preds = %bb47, %bb16
68 %i = phi ptr [ %.in1, %bb47 ], [ undef, %bb16 ]
69 store ptr %i, ptr %p, align 8
73 br i1 %c, label %bb44, label %bb49
76 %tmp46 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
79 bb47: ; preds = %bb150, %bb119, %bb101, %bb91, %bb81, %bb67, %bb56, %bb44
80 %.in1 = phi ptr [ %.in, %bb150 ], [ %tmp122, %bb119 ], [ %tmp103, %bb101 ], [ %tmp93, %bb91 ], [ %tmp83, %bb81 ], [ %tmp70, %bb67 ], [ %tmp58, %bb56 ], [ %tmp46, %bb44 ]
84 br i1 %c, label %bb56, label %bb59
87 %tmp58 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
91 br i1 %c, label %bb67, label %bb71
94 %tmp70 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
98 br i1 %c, label %bb81, label %bb84
100 bb81: ; preds = %bb71
101 %tmp83 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
104 bb84: ; preds = %bb71
105 br i1 %c, label %bb91, label %bb94
107 bb91: ; preds = %bb84
108 %tmp93 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
111 bb94: ; preds = %bb84
112 br i1 %c, label %bb101, label %bb104
114 bb101: ; preds = %bb94
115 %tmp103 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
118 bb104: ; preds = %bb94
119 br i1 %c, label %bb119, label %bb123
121 bb119: ; preds = %bb104
122 %tmp122 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
125 bb123: ; preds = %bb104
126 br i1 %c, label %bb147, label %bb152
128 bb147: ; preds = %bb123
129 %tmp149 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
132 bb150: ; preds = %bb152, %bb147
133 %.in = phi ptr [ %tmp184, %bb152 ], [ %tmp149, %bb147 ]
136 bb152: ; preds = %bb123
137 %tmp184 = load ptr, ptr inttoptr (i64 16 to ptr), align 16
143 ; This used to cause an instcombine loop when the problem above was
144 ; addressed in a non-robust fashion.
149 define void @test_2(i1 %c) local_unnamed_addr {
150 ; CHECK-LABEL: @test_2(
152 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
154 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
156 ; CHECK-NEXT: br i1 [[C:%.*]], label [[COND_TRUE133:%.*]], label [[COND_FALSE138:%.*]]
157 ; CHECK: cond.true133:
158 ; CHECK-NEXT: br label [[COND_END144:%.*]]
159 ; CHECK: cond.false138:
160 ; CHECK-NEXT: br label [[COND_END144]]
161 ; CHECK: cond.end144:
162 ; CHECK-NEXT: store i1 true, ptr poison, align 1
163 ; CHECK-NEXT: br label [[WHILE_COND]]
168 while.cond: ; preds = %cond.end144, %entry
169 %link.0 = phi ptr [ undef, %entry ], [ %cond145, %cond.end144 ]
172 for.cond: ; preds = %while.cond
173 br i1 %c, label %cond.true133, label %cond.false138
175 cond.true133: ; preds = %for.cond
176 %i = load ptr, ptr undef, align 8
177 br label %cond.end144
179 cond.false138: ; preds = %for.cond
180 %i1 = load ptr, ptr undef, align 8
181 br label %cond.end144
183 cond.end144: ; preds = %cond.false138, %cond.true133
184 %cond145 = phi ptr [ %i, %cond.true133 ], [ %i1, %cond.false138 ]