1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -jump-threading-freeze-select-cond -jump-threading < %s | FileCheck %s
10 define void @test_switch_cmp(i1 %cond, i32 %val, i8 %value) nounwind {
11 ; CHECK-LABEL: @test_switch_cmp(
13 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[L0:%.*]], label [[L0_THREAD:%.*]]
15 ; CHECK-NEXT: [[VAL_PHI:%.*]] = phi i32 [ [[VAL:%.*]], [[ENTRY:%.*]] ]
16 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[VAL_PHI]], 0
17 ; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[CMP]]
18 ; CHECK-NEXT: br i1 [[COND_FR]], label [[L1:%.*]], label [[TMP0:%.*]]
20 ; CHECK-NEXT: [[TMP1:%.*]] = phi i8 [ [[VALUE:%.*]], [[L0]] ]
21 ; CHECK-NEXT: switch i8 [[TMP1]], label [[L3:%.*]] [
22 ; CHECK-NEXT: i8 1, label [[L1]]
23 ; CHECK-NEXT: i8 2, label [[L2:%.*]]
26 ; CHECK-NEXT: call void @foo()
27 ; CHECK-NEXT: ret void
29 ; CHECK-NEXT: call void @bar()
30 ; CHECK-NEXT: ret void
32 ; CHECK-NEXT: call void @baz()
33 ; CHECK-NEXT: ret void
35 ; CHECK-NEXT: call void @quux()
36 ; CHECK-NEXT: br label [[L1]]
39 br i1 %cond, label %L0, label %L4
41 %val.phi = phi i32 [%val, %entry], [-1, %L4]
42 %cmp = icmp slt i32 %val.phi, 0
43 %expr = select i1 %cmp, i8 1, i8 %value
44 switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]
60 define i32 @unfold3(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind {
61 ; CHECK-LABEL: @unfold3(
63 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[J:%.*]], 2
64 ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[U:%.*]], [[V:%.*]]
65 ; CHECK-NEXT: br i1 [[CMP_I]], label [[DOTEXIT_THREAD4:%.*]], label [[COND_FALSE_I:%.*]]
66 ; CHECK: cond.false.i:
67 ; CHECK-NEXT: [[CMP4_I:%.*]] = icmp sgt i32 [[U]], [[V]]
68 ; CHECK-NEXT: br i1 [[CMP4_I]], label [[DOTEXIT_THREAD:%.*]], label [[COND_FALSE_6_I:%.*]]
69 ; CHECK: cond.false.6.i:
70 ; CHECK-NEXT: [[CMP8_I:%.*]] = icmp slt i32 [[W:%.*]], [[X:%.*]]
71 ; CHECK-NEXT: br i1 [[CMP8_I]], label [[DOTEXIT_THREAD4]], label [[COND_FALSE_10_I:%.*]]
72 ; CHECK: cond.false.10.i:
73 ; CHECK-NEXT: [[CMP13_I:%.*]] = icmp sgt i32 [[W]], [[X]]
74 ; CHECK-NEXT: br i1 [[CMP13_I]], label [[DOTEXIT_THREAD]], label [[DOTEXIT:%.*]]
76 ; CHECK-NEXT: [[PHITMP:%.*]] = icmp sge i32 [[Y:%.*]], [[Z:%.*]]
77 ; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[PHITMP]]
78 ; CHECK-NEXT: br i1 [[COND_FR]], label [[DOTEXIT_THREAD]], label [[DOTEXIT_THREAD4]]
79 ; CHECK: .exit.thread:
80 ; CHECK-NEXT: br label [[DOTEXIT_THREAD4]]
81 ; CHECK: .exit.thread4:
82 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[J]], [[DOTEXIT_THREAD]] ], [ [[ADD3]], [[DOTEXIT]] ], [ [[ADD3]], [[ENTRY:%.*]] ], [ [[ADD3]], [[COND_FALSE_6_I]] ]
83 ; CHECK-NEXT: ret i32 [[TMP0]]
86 %add3 = add nsw i32 %j, 2
87 %cmp.i = icmp slt i32 %u, %v
88 br i1 %cmp.i, label %.exit, label %cond.false.i
90 cond.false.i: ; preds = %entry
91 %cmp4.i = icmp sgt i32 %u, %v
92 br i1 %cmp4.i, label %.exit, label %cond.false.6.i
94 cond.false.6.i: ; preds = %cond.false.i
95 %cmp8.i = icmp slt i32 %w, %x
96 br i1 %cmp8.i, label %.exit, label %cond.false.10.i
98 cond.false.10.i: ; preds = %cond.false.6.i
99 %cmp13.i = icmp sgt i32 %w, %x
100 br i1 %cmp13.i, label %.exit, label %cond.false.15.i
102 cond.false.15.i: ; preds = %cond.false.10.i
103 %phitmp = icmp sge i32 %y, %z
106 .exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i
107 %cond23.i = phi i1 [ false, %entry ], [ true, %cond.false.i ], [ false, %cond.false.6.i ], [ %phitmp, %cond.false.15.i ], [ true, %cond.false.10.i ]
108 %j.add3 = select i1 %cond23.i, i32 %j, i32 %add3
112 define i32 @unfold4(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind {
113 ; CHECK-LABEL: @unfold4(
115 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[J:%.*]], 2
116 ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[U:%.*]], [[V:%.*]]
117 ; CHECK-NEXT: br i1 [[CMP_I]], label [[DOTEXIT_THREAD:%.*]], label [[COND_FALSE_I:%.*]]
118 ; CHECK: cond.false.i:
119 ; CHECK-NEXT: [[CMP4_I:%.*]] = icmp sgt i32 [[U]], [[V]]
120 ; CHECK-NEXT: br i1 [[CMP4_I]], label [[DOTEXIT_THREAD5:%.*]], label [[COND_FALSE_6_I:%.*]]
121 ; CHECK: cond.false.6.i:
122 ; CHECK-NEXT: [[CMP8_I:%.*]] = icmp slt i32 [[W:%.*]], [[X:%.*]]
123 ; CHECK-NEXT: br i1 [[CMP8_I]], label [[DOTEXIT_THREAD]], label [[COND_FALSE_10_I:%.*]]
124 ; CHECK: cond.false.10.i:
125 ; CHECK-NEXT: [[CMP13_I:%.*]] = icmp sgt i32 [[W]], [[X]]
126 ; CHECK-NEXT: br i1 [[CMP13_I]], label [[DOTEXIT_THREAD5]], label [[DOTEXIT:%.*]]
128 ; CHECK-NEXT: [[CMP19_I:%.*]] = icmp sge i32 [[Y:%.*]], [[Z:%.*]]
129 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP19_I]] to i32
130 ; CHECK-NEXT: [[LNOT_I18:%.*]] = icmp eq i32 [[CONV]], 1
131 ; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[LNOT_I18]]
132 ; CHECK-NEXT: br i1 [[COND_FR]], label [[DOTEXIT_THREAD]], label [[DOTEXIT_THREAD5]]
133 ; CHECK: .exit.thread:
134 ; CHECK-NEXT: br label [[DOTEXIT_THREAD5]]
135 ; CHECK: .exit.thread5:
136 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[J]], [[DOTEXIT_THREAD]] ], [ [[ADD3]], [[DOTEXIT]] ], [ [[ADD3]], [[COND_FALSE_I]] ], [ [[ADD3]], [[COND_FALSE_10_I]] ]
137 ; CHECK-NEXT: ret i32 [[TMP0]]
140 %add3 = add nsw i32 %j, 2
141 %cmp.i = icmp slt i32 %u, %v
142 br i1 %cmp.i, label %.exit, label %cond.false.i
144 cond.false.i: ; preds = %entry
145 %cmp4.i = icmp sgt i32 %u, %v
146 br i1 %cmp4.i, label %.exit, label %cond.false.6.i
148 cond.false.6.i: ; preds = %cond.false.i
149 %cmp8.i = icmp slt i32 %w, %x
150 br i1 %cmp8.i, label %.exit, label %cond.false.10.i
152 cond.false.10.i: ; preds = %cond.false.6.i
153 %cmp13.i = icmp sgt i32 %w, %x
154 br i1 %cmp13.i, label %.exit, label %cond.false.15.i
156 cond.false.15.i: ; preds = %cond.false.10.i
157 %cmp19.i = icmp sge i32 %y, %z
158 %conv = zext i1 %cmp19.i to i32
161 .exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i
162 %cond23.i = phi i32 [ 1, %entry ], [ 0, %cond.false.i ], [ 1, %cond.false.6.i ], [ %conv, %cond.false.15.i ], [ 0, %cond.false.10.i ]
163 %lnot.i18 = icmp eq i32 %cond23.i, 1
164 %j.add3 = select i1 %lnot.i18, i32 %j, i32 %add3
168 ; TODO: cond23_i should be constant-folded.
169 define i32 @unfold5(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind {
170 ; CHECK-LABEL: @unfold5(
172 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[J:%.*]], 2
173 ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[U:%.*]], [[V:%.*]]
174 ; CHECK-NEXT: br i1 [[CMP_I]], label [[DOTEXIT_THREAD:%.*]], label [[COND_FALSE_I:%.*]]
175 ; CHECK: cond.false.i:
176 ; CHECK-NEXT: [[CMP4_I:%.*]] = icmp sgt i32 [[U]], [[V]]
177 ; CHECK-NEXT: br i1 [[CMP4_I]], label [[DOTEXIT_THREAD]], label [[COND_FALSE_6_I:%.*]]
178 ; CHECK: cond.false.6.i:
179 ; CHECK-NEXT: [[CMP8_I:%.*]] = icmp slt i32 [[W:%.*]], [[X:%.*]]
180 ; CHECK-NEXT: br i1 [[CMP8_I]], label [[DOTEXIT_THREAD]], label [[COND_FALSE_10_I:%.*]]
181 ; CHECK: cond.false.10.i:
182 ; CHECK-NEXT: [[CMP13_I:%.*]] = icmp sgt i32 [[W]], [[X]]
183 ; CHECK-NEXT: br i1 [[CMP13_I]], label [[TMP0:%.*]], label [[COND_FALSE_15_I:%.*]]
184 ; CHECK: cond.false.15.i:
185 ; CHECK-NEXT: [[CMP19_I:%.*]] = icmp sge i32 [[Y:%.*]], [[Z:%.*]]
186 ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP19_I]] to i32
187 ; CHECK-NEXT: br label [[DOTEXIT_THREAD]]
189 ; CHECK-NEXT: [[COND23_I:%.*]] = phi i32 [ 7, [[COND_FALSE_10_I]] ]
190 ; CHECK-NEXT: [[LNOT_I18:%.*]] = icmp sgt i32 [[COND23_I]], 5
191 ; CHECK-NEXT: br label [[DOTEXIT_THREAD]]
192 ; CHECK: .exit.thread:
193 ; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[J]], [[TMP0]] ], [ [[CONV]], [[COND_FALSE_15_I]] ], [ 1, [[COND_FALSE_6_I]] ], [ 3, [[COND_FALSE_I]] ], [ 2, [[ENTRY:%.*]] ]
194 ; CHECK-NEXT: ret i32 [[TMP1]]
197 %add3 = add nsw i32 %j, 2
198 %cmp.i = icmp slt i32 %u, %v
199 br i1 %cmp.i, label %.exit, label %cond.false.i
201 cond.false.i: ; preds = %entry
202 %cmp4.i = icmp sgt i32 %u, %v
203 br i1 %cmp4.i, label %.exit, label %cond.false.6.i
205 cond.false.6.i: ; preds = %cond.false.i
206 %cmp8.i = icmp slt i32 %w, %x
207 br i1 %cmp8.i, label %.exit, label %cond.false.10.i
209 cond.false.10.i: ; preds = %cond.false.6.i
210 %cmp13.i = icmp sgt i32 %w, %x
211 br i1 %cmp13.i, label %.exit, label %cond.false.15.i
213 cond.false.15.i: ; preds = %cond.false.10.i
214 %cmp19.i = icmp sge i32 %y, %z
215 %conv = zext i1 %cmp19.i to i32
218 .exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i
219 %cond23.i = phi i32 [ 2, %entry ], [ 3, %cond.false.i ], [ 1, %cond.false.6.i ], [ %conv, %cond.false.15.i ], [ 7, %cond.false.10.i ]
220 %lnot.i18 = icmp sgt i32 %cond23.i, 5
221 %j.add3 = select i1 %lnot.i18, i32 %j, i32 %cond23.i
225 define i32 @TryToUnfoldSelectInCurrBB(i1 %b, i1 %ui, i32 %s, i1 %x) {
226 ; CHECK-LABEL: @TryToUnfoldSelectInCurrBB(
228 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_END_THREAD:%.*]], label [[IF_END:%.*]]
230 ; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[X:%.*]]
231 ; CHECK-NEXT: br i1 [[COND_FR]], label [[TMP0:%.*]], label [[IF_END_THREAD]]
233 ; CHECK-NEXT: br label [[IF_END_THREAD]]
234 ; CHECK: if.end.thread:
235 ; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[S:%.*]], [[TMP0]] ], [ 42, [[IF_END]] ], [ 42, [[ENTRY:%.*]] ]
236 ; CHECK-NEXT: ret i32 [[TMP1]]
239 br i1 %b, label %if.end, label %if.else
245 %v = phi i1 [ %x, %if.else ], [ false, %entry ]
246 %v1 = select i1 %v, i32 %s, i32 42