1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -passes=gvn -S < %s | FileCheck %s
4 define i32 @f1(i32 %x) {
5 ; CHECK-LABEL: define i32 @f1(
6 ; CHECK-SAME: i32 [[X:%.*]]) {
7 ; CHECK-NEXT: [[BB0:.*:]]
8 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 0
9 ; CHECK-NEXT: br i1 [[CMP]], label %[[BB2:.*]], label %[[BB1:.*]]
11 ; CHECK-NEXT: br label %[[BB2]]
13 ; CHECK-NEXT: ret i32 [[X]]
16 %cmp = icmp eq i32 %x, 0
17 br i1 %cmp, label %bb2, label %bb1
21 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
22 %foo = add i32 %cond, %x
26 define i32 @f2(i32 %x) {
27 ; CHECK-LABEL: define i32 @f2(
28 ; CHECK-SAME: i32 [[X:%.*]]) {
29 ; CHECK-NEXT: [[BB0:.*:]]
30 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X]], 0
31 ; CHECK-NEXT: br i1 [[CMP]], label %[[BB1:.*]], label %[[BB2:.*]]
33 ; CHECK-NEXT: br label %[[BB2]]
35 ; CHECK-NEXT: ret i32 [[X]]
38 %cmp = icmp ne i32 %x, 0
39 br i1 %cmp, label %bb1, label %bb2
43 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
44 %foo = add i32 %cond, %x
48 define i32 @f3(i32 %x) {
49 ; CHECK-LABEL: define i32 @f3(
50 ; CHECK-SAME: i32 [[X:%.*]]) {
51 ; CHECK-NEXT: [[BB0:.*:]]
52 ; CHECK-NEXT: switch i32 [[X]], label %[[BB1:.*]] [
53 ; CHECK-NEXT: i32 0, label %[[BB2:.*]]
56 ; CHECK-NEXT: br label %[[BB2]]
58 ; CHECK-NEXT: ret i32 [[X]]
61 switch i32 %x, label %bb1 [ i32 0, label %bb2]
65 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
66 %foo = add i32 %cond, %x
71 define void @f4(ptr %x) {
72 ; CHECK-LABEL: define void @f4(
73 ; CHECK-SAME: ptr [[X:%.*]]) {
74 ; CHECK-NEXT: [[BB0:.*:]]
75 ; CHECK-NEXT: [[Y:%.*]] = icmp eq ptr null, [[X]]
76 ; CHECK-NEXT: br i1 [[Y]], label %[[BB2:.*]], label %[[BB1:.*]]
78 ; CHECK-NEXT: br label %[[BB2]]
80 ; CHECK-NEXT: call void @g(i1 [[Y]])
81 ; CHECK-NEXT: ret void
84 %y = icmp eq ptr null, %x
85 br i1 %y, label %bb2, label %bb1
89 %zed = icmp eq ptr null, %x
94 define double @fcmp_oeq_not_zero(double %x, double %y) {
95 ; CHECK-LABEL: define double @fcmp_oeq_not_zero(
96 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
97 ; CHECK-NEXT: [[ENTRY:.*]]:
98 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq double [[Y]], 2.000000e+00
99 ; CHECK-NEXT: br i1 [[CMP]], label %[[IF:.*]], label %[[RETURN:.*]]
101 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], 2.000000e+00
102 ; CHECK-NEXT: br label %[[RETURN]]
104 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[IF]] ], [ [[X]], %[[ENTRY]] ]
105 ; CHECK-NEXT: ret double [[RETVAL]]
108 %cmp = fcmp oeq double %y, 2.0
109 br i1 %cmp, label %if, label %return
112 %div = fdiv double %x, %y
116 %retval = phi double [ %div, %if ], [ %x, %entry ]
120 define double @fcmp_une_not_zero(double %x, double %y) {
121 ; CHECK-LABEL: define double @fcmp_une_not_zero(
122 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
123 ; CHECK-NEXT: [[ENTRY:.*]]:
124 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[Y]], 2.000000e+00
125 ; CHECK-NEXT: br i1 [[CMP]], label %[[RETURN:.*]], label %[[ELSE:.*]]
127 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], 2.000000e+00
128 ; CHECK-NEXT: br label %[[RETURN]]
130 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[ELSE]] ], [ [[X]], %[[ENTRY]] ]
131 ; CHECK-NEXT: ret double [[RETVAL]]
134 %cmp = fcmp une double %y, 2.0
135 br i1 %cmp, label %return, label %else
138 %div = fdiv double %x, %y
142 %retval = phi double [ %div, %else ], [ %x, %entry ]
146 define double @fcmp_one_possibly_nan(double %x, double %y) {
147 ; CHECK-LABEL: define double @fcmp_one_possibly_nan(
148 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
149 ; CHECK-NEXT: [[ENTRY:.*]]:
150 ; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[Y]], 2.000000e+00
151 ; CHECK-NEXT: br i1 [[CMP]], label %[[RETURN:.*]], label %[[ELSE:.*]]
153 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], [[Y]]
154 ; CHECK-NEXT: br label %[[RETURN]]
156 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[ELSE]] ], [ [[X]], %[[ENTRY]] ]
157 ; CHECK-NEXT: ret double [[RETVAL]]
160 %cmp = fcmp one double %y, 2.0
161 br i1 %cmp, label %return, label %else
164 %div = fdiv double %x, %y
168 %retval = phi double [ %div, %else ], [ %x, %entry ]
172 define double @fcmp_one_not_zero_or_nan(double %x, double %y) {
173 ; CHECK-LABEL: define double @fcmp_one_not_zero_or_nan(
174 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
175 ; CHECK-NEXT: [[ENTRY:.*]]:
176 ; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan one double [[Y]], 2.000000e+00
177 ; CHECK-NEXT: br i1 [[CMP]], label %[[RETURN:.*]], label %[[ELSE:.*]]
179 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], 2.000000e+00
180 ; CHECK-NEXT: br label %[[RETURN]]
182 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[ELSE]] ], [ [[X]], %[[ENTRY]] ]
183 ; CHECK-NEXT: ret double [[RETVAL]]
186 %cmp = fcmp nnan one double %y, 2.0
187 br i1 %cmp, label %return, label %else
190 %div = fdiv double %x, %y
194 %retval = phi double [ %div, %else ], [ %x, %entry ]
198 ; PR22376 - We can't propagate zero constants because -0.0
199 ; compares equal to 0.0. If %y is -0.0 in this test case,
200 ; we would produce the wrong sign on the infinity return value.
201 define double @fcmp_oeq_zero(double %x, double %y) {
202 ; CHECK-LABEL: define double @fcmp_oeq_zero(
203 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
204 ; CHECK-NEXT: [[ENTRY:.*]]:
205 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq double [[Y]], 0.000000e+00
206 ; CHECK-NEXT: br i1 [[CMP]], label %[[IF:.*]], label %[[RETURN:.*]]
208 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], [[Y]]
209 ; CHECK-NEXT: br label %[[RETURN]]
211 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[IF]] ], [ [[X]], %[[ENTRY]] ]
212 ; CHECK-NEXT: ret double [[RETVAL]]
215 %cmp = fcmp oeq double %y, 0.0
216 br i1 %cmp, label %if, label %return
219 %div = fdiv double %x, %y
223 %retval = phi double [ %div, %if ], [ %x, %entry ]
227 ; Denormals may be flushed to zero in some cases by the backend.
228 ; Hence, treat denormals as 0.
229 define float @fcmp_oeq_denormal(float %x, float %y) {
230 ; CHECK-LABEL: define float @fcmp_oeq_denormal(
231 ; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
232 ; CHECK-NEXT: [[ENTRY:.*]]:
233 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[Y]], 0x3800000000000000
234 ; CHECK-NEXT: br i1 [[CMP]], label %[[IF:.*]], label %[[RETURN:.*]]
236 ; CHECK-NEXT: [[DIV:%.*]] = fdiv float [[X]], [[Y]]
237 ; CHECK-NEXT: br label %[[RETURN]]
239 ; CHECK-NEXT: [[RETVAL:%.*]] = phi float [ [[DIV]], %[[IF]] ], [ [[X]], %[[ENTRY]] ]
240 ; CHECK-NEXT: ret float [[RETVAL]]
243 %cmp = fcmp oeq float %y, 0x3800000000000000
244 br i1 %cmp, label %if, label %return
247 %div = fdiv float %x, %y
251 %retval = phi float [ %div, %if ], [ %x, %entry ]
255 define double @fcmp_une_zero(double %x, double %y) {
256 ; CHECK-LABEL: define double @fcmp_une_zero(
257 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
258 ; CHECK-NEXT: [[ENTRY:.*]]:
259 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[Y]], -0.000000e+00
260 ; CHECK-NEXT: br i1 [[CMP]], label %[[RETURN:.*]], label %[[ELSE:.*]]
262 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], [[Y]]
263 ; CHECK-NEXT: br label %[[RETURN]]
265 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[ELSE]] ], [ [[X]], %[[ENTRY]] ]
266 ; CHECK-NEXT: ret double [[RETVAL]]
269 %cmp = fcmp une double %y, -0.0
270 br i1 %cmp, label %return, label %else
273 %div = fdiv double %x, %y
277 %retval = phi double [ %div, %else ], [ %x, %entry ]
281 ; We also cannot propagate a value if it's not a constant.
282 ; This is because the value could be 0.0, -0.0, or a denormal.
284 define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {
285 ; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(
286 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]], double [[Z1:%.*]], double [[Z2:%.*]]) {
287 ; CHECK-NEXT: [[ENTRY:.*]]:
288 ; CHECK-NEXT: [[Z:%.*]] = fadd double [[Z1]], [[Z2]]
289 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq double [[Y]], [[Z]]
290 ; CHECK-NEXT: br i1 [[CMP]], label %[[IF:.*]], label %[[RETURN:.*]]
292 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], [[Z]]
293 ; CHECK-NEXT: br label %[[RETURN]]
295 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[IF]] ], [ [[X]], %[[ENTRY]] ]
296 ; CHECK-NEXT: ret double [[RETVAL]]
299 %z = fadd double %z1, %z2
300 %cmp = fcmp oeq double %y, %z
301 br i1 %cmp, label %if, label %return
304 %div = fdiv double %x, %z
308 %retval = phi double [ %div, %if ], [ %x, %entry ]
312 define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {
313 ; CHECK-LABEL: define double @fcmp_une_maybe_zero(
314 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]], double [[Z1:%.*]], double [[Z2:%.*]]) {
315 ; CHECK-NEXT: [[ENTRY:.*]]:
316 ; CHECK-NEXT: [[Z:%.*]] = fadd double [[Z1]], [[Z2]]
317 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[Y]], [[Z]]
318 ; CHECK-NEXT: br i1 [[CMP]], label %[[RETURN:.*]], label %[[ELSE:.*]]
320 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], [[Z]]
321 ; CHECK-NEXT: br label %[[RETURN]]
323 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[ELSE]] ], [ [[X]], %[[ENTRY]] ]
324 ; CHECK-NEXT: ret double [[RETVAL]]
327 %z = fadd double %z1, %z2
328 %cmp = fcmp une double %y, %z
329 br i1 %cmp, label %return, label %else
332 %div = fdiv double %x, %z
336 %retval = phi double [ %div, %else ], [ %x, %entry ]
341 define double @fcmp_ueq_possibly_nan(double %x, double %y) {
342 ; CHECK-LABEL: define double @fcmp_ueq_possibly_nan(
343 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
344 ; CHECK-NEXT: [[ENTRY:.*]]:
345 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq double [[Y]], 2.000000e+00
346 ; CHECK-NEXT: br i1 [[CMP]], label %[[DO_DIV:.*]], label %[[RETURN:.*]]
348 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], [[Y]]
349 ; CHECK-NEXT: br label %[[RETURN]]
351 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[DO_DIV]] ], [ [[X]], %[[ENTRY]] ]
352 ; CHECK-NEXT: ret double [[RETVAL]]
355 %cmp = fcmp ueq double %y, 2.0
356 br i1 %cmp, label %do_div, label %return
359 %div = fdiv double %x, %y
363 %retval = phi double [ %div, %do_div ], [ %x, %entry ]
367 define double @fcmp_ueq_not_zero_or_nan(double %x, double %y) {
368 ; CHECK-LABEL: define double @fcmp_ueq_not_zero_or_nan(
369 ; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
370 ; CHECK-NEXT: [[ENTRY:.*]]:
371 ; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ueq double [[Y]], 2.000000e+00
372 ; CHECK-NEXT: br i1 [[CMP]], label %[[DO_DIV:.*]], label %[[RETURN:.*]]
374 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X]], 2.000000e+00
375 ; CHECK-NEXT: br label %[[RETURN]]
377 ; CHECK-NEXT: [[RETVAL:%.*]] = phi double [ [[DIV]], %[[DO_DIV]] ], [ [[X]], %[[ENTRY]] ]
378 ; CHECK-NEXT: ret double [[RETVAL]]
381 %cmp = fcmp nnan ueq double %y, 2.0
382 br i1 %cmp, label %do_div, label %return
385 %div = fdiv double %x, %y
389 %retval = phi double [ %div, %do_div ], [ %x, %entry ]