1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.8.0"
6 define i1 @test1(float %x, float %y) {
8 ; CHECK-NEXT: [[CEIL:%.*]] = call float @llvm.ceil.f32(float %x)
9 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[CEIL]], %y
10 ; CHECK-NEXT: ret i1 [[CMP]]
12 %x.ext = fpext float %x to double
13 %ceil = call double @ceil(double %x.ext) nounwind readnone
14 %ext.y = fpext float %y to double
15 %cmp = fcmp oeq double %ceil, %ext.y
19 define i1 @test1_intrin(float %x, float %y) {
20 ; CHECK-LABEL: @test1_intrin(
21 ; CHECK-NEXT: [[CEIL:%.*]] = call float @llvm.ceil.f32(float %x)
22 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[CEIL]], %y
23 ; CHECK-NEXT: ret i1 [[CMP]]
25 %x.ext = fpext float %x to double
26 %ceil = call double @llvm.ceil.f64(double %x.ext) nounwind readnone
27 %ext.y = fpext float %y to double
28 %cmp = fcmp oeq double %ceil, %ext.y
32 define i1 @test2(float %x, float %y) {
33 ; CHECK-LABEL: @test2(
34 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float %x)
35 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FABS]], %y
36 ; CHECK-NEXT: ret i1 [[CMP]]
38 %x.ext = fpext float %x to double
39 %fabs = call double @fabs(double %x.ext) nounwind readnone
40 %y.ext = fpext float %y to double
41 %cmp = fcmp oeq double %fabs, %y.ext
45 define i1 @test2_intrin(float %x, float %y) {
46 ; CHECK-LABEL: @test2_intrin(
47 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float %x)
48 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FABS]], %y
49 ; CHECK-NEXT: ret i1 [[CMP]]
51 %x.ext = fpext float %x to double
52 %fabs = call double @llvm.fabs.f64(double %x.ext) nounwind readnone
53 %y.ext = fpext float %y to double
54 %cmp = fcmp oeq double %fabs, %y.ext
58 define i1 @fmf_test2(float %x, float %y) {
59 ; CHECK-LABEL: @fmf_test2(
60 ; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.fabs.f32(float %x)
61 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp oeq float [[TMP1]], %y
62 ; CHECK-NEXT: ret i1 [[TMP2]]
64 %1 = fpext float %x to double
65 %2 = call nnan double @fabs(double %1) nounwind readnone
66 %3 = fpext float %y to double
67 %4 = fcmp oeq double %2, %3
71 define i1 @test3(float %x, float %y) {
72 ; CHECK-LABEL: @test3(
73 ; CHECK-NEXT: [[FLOOR:%.*]] = call float @llvm.floor.f32(float %x)
74 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FLOOR]], %y
75 ; CHECK-NEXT: ret i1 [[CMP]]
77 %x.ext = fpext float %x to double
78 %floor = call double @floor(double %x.ext) nounwind readnone
79 %y.ext = fpext float %y to double
80 %cmp = fcmp oeq double %floor, %y.ext
85 define i1 @test3_intrin(float %x, float %y) {
86 ; CHECK-LABEL: @test3_intrin(
87 ; CHECK-NEXT: [[FLOOR:%.*]] = call float @llvm.floor.f32(float %x)
88 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FLOOR]], %y
89 ; CHECK-NEXT: ret i1 [[CMP]]
91 %x.ext = fpext float %x to double
92 %floor = call double @llvm.floor.f64(double %x.ext) nounwind readnone
93 %y.ext = fpext float %y to double
94 %cmp = fcmp oeq double %floor, %y.ext
98 define i1 @test4(float %x, float %y) {
99 ; CHECK-LABEL: @test4(
100 ; CHECK-NEXT: [[NEARBYINT:%.*]] = call float @llvm.nearbyint.f32(float %x)
101 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[NEARBYINT]], %y
102 ; CHECK-NEXT: ret i1 [[CMP]]
104 %x.ext = fpext float %x to double
105 %nearbyint = call double @nearbyint(double %x.ext) nounwind
106 %y.ext = fpext float %y to double
107 %cmp = fcmp oeq double %nearbyint, %y.ext
111 define i1 @shrink_nearbyint_intrin(float %x, float %y) {
112 ; CHECK-LABEL: @shrink_nearbyint_intrin(
113 ; CHECK-NEXT: [[NEARBYINT:%.*]] = call float @llvm.nearbyint.f32(float %x)
114 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[NEARBYINT]], %y
115 ; CHECK-NEXT: ret i1 [[CMP]]
117 %x.ext = fpext float %x to double
118 %nearbyint = call double @llvm.nearbyint.f64(double %x.ext) nounwind
119 %y.ext = fpext float %y to double
120 %cmp = fcmp oeq double %nearbyint, %y.ext
124 define i1 @test5(float %x, float %y) {
125 ; CHECK-LABEL: @test5(
126 ; CHECK-NEXT: [[RINT:%.*]] = call float @llvm.rint.f32(float %x)
127 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[RINT]], %y
128 ; CHECK-NEXT: ret i1 [[CMP]]
130 %x.ext = fpext float %x to double
131 %rint = call double @rint(double %x.ext) nounwind
132 %y.ext = fpext float %y to double
133 %cmp = fcmp oeq double %rint, %y.ext
137 define i1 @test6(float %x, float %y) {
138 ; CHECK-LABEL: @test6(
139 ; CHECK-NEXT: [[ROUND:%.*]] = call float @llvm.round.f32(float %x)
140 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ROUND]], %y
141 ; CHECK-NEXT: ret i1 [[CMP]]
143 %x.ext = fpext float %x to double
144 %round = call double @round(double %x.ext) nounwind readnone
145 %y.ext = fpext float %y to double
146 %cmp = fcmp oeq double %round, %y.ext
150 define i1 @test6_intrin(float %x, float %y) {
151 ; CHECK-LABEL: @test6_intrin(
152 ; CHECK-NEXT: [[ROUND:%.*]] = call float @llvm.round.f32(float %x)
153 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ROUND]], %y
154 ; CHECK-NEXT: ret i1 [[CMP]]
156 %x.ext = fpext float %x to double
157 %round = call double @llvm.round.f64(double %x.ext) nounwind readnone
158 %y.ext = fpext float %y to double
159 %cmp = fcmp oeq double %round, %y.ext
163 define i1 @test7(float %x, float %y) {
164 ; CHECK-LABEL: @test7(
165 ; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.trunc.f32(float %x)
166 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[TRUNC]], %y
167 ; CHECK-NEXT: ret i1 [[CMP]]
169 %x.ext = fpext float %x to double
170 %trunc = call double @trunc(double %x.ext) nounwind
171 %y.ext = fpext float %y to double
172 %cmp = fcmp oeq double %trunc, %y.ext
176 define i1 @test7_intrin(float %x, float %y) {
177 ; CHECK-LABEL: @test7_intrin(
178 ; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.trunc.f32(float %x)
179 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[TRUNC]], %y
180 ; CHECK-NEXT: ret i1 [[CMP]]
182 %x.ext = fpext float %x to double
183 %trunc = call double @llvm.trunc.f64(double %x.ext) nounwind
184 %y.ext = fpext float %y to double
185 %cmp = fcmp oeq double %trunc, %y.ext
189 define i1 @test8(float %x, float %y) {
190 ; CHECK-LABEL: @test8(
191 ; CHECK-NEXT: [[CEIL:%.*]] = call float @llvm.ceil.f32(float %x)
192 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[CEIL]], %y
193 ; CHECK-NEXT: ret i1 [[CMP]]
195 %x.ext = fpext float %x to double
196 %y.ext = fpext float %y to double
197 %ceil = call double @ceil(double %x.ext) nounwind readnone
198 %cmp = fcmp oeq double %y.ext, %ceil
202 define i1 @test8_intrin(float %x, float %y) {
203 ; CHECK-LABEL: @test8_intrin(
204 ; CHECK-NEXT: [[CEIL:%.*]] = call float @llvm.ceil.f32(float %x)
205 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[CEIL]], %y
206 ; CHECK-NEXT: ret i1 [[CMP]]
208 %x.ext = fpext float %x to double
209 %y.ext = fpext float %y to double
210 %ceil = call double @llvm.ceil.f64(double %x.ext) nounwind readnone
211 %cmp = fcmp oeq double %y.ext, %ceil
215 define i1 @test9(float %x, float %y) {
216 ; CHECK-LABEL: @test9(
217 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float %x)
218 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FABS]], %y
219 ; CHECK-NEXT: ret i1 [[CMP]]
221 %x.ext = fpext float %x to double
222 %y.ext = fpext float %y to double
223 %fabs = call double @fabs(double %x.ext) nounwind readnone
224 %cmp = fcmp oeq double %y.ext, %fabs
228 define i1 @test9_intrin(float %x, float %y) {
229 ; CHECK-LABEL: @test9_intrin(
230 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float %x)
231 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FABS]], %y
232 ; CHECK-NEXT: ret i1 [[CMP]]
234 %x.ext = fpext float %x to double
235 %y.ext = fpext float %y to double
236 %fabs = call double @llvm.fabs.f64(double %x.ext) nounwind readnone
237 %cmp = fcmp oeq double %y.ext, %fabs
241 define i1 @test10(float %x, float %y) {
242 ; CHECK-LABEL: @test10(
243 ; CHECK-NEXT: [[FLOOR:%.*]] = call float @llvm.floor.f32(float %x)
244 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FLOOR]], %y
245 ; CHECK-NEXT: ret i1 [[CMP]]
247 %x.ext = fpext float %x to double
248 %y.ext = fpext float %y to double
249 %floor = call double @floor(double %x.ext) nounwind readnone
250 %cmp = fcmp oeq double %floor, %y.ext
254 define i1 @test10_intrin(float %x, float %y) {
255 ; CHECK-LABEL: @test10_intrin(
256 ; CHECK-NEXT: [[FLOOR:%.*]] = call float @llvm.floor.f32(float %x)
257 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FLOOR]], %y
258 ; CHECK-NEXT: ret i1 [[CMP]]
260 %x.ext = fpext float %x to double
261 %y.ext = fpext float %y to double
262 %floor = call double @llvm.floor.f64(double %x.ext) nounwind readnone
263 %cmp = fcmp oeq double %floor, %y.ext
267 define i1 @test11(float %x, float %y) {
268 ; CHECK-LABEL: @test11(
269 ; CHECK-NEXT: [[NEARBYINT:%.*]] = call float @llvm.nearbyint.f32(float %x)
270 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[NEARBYINT]], %y
271 ; CHECK-NEXT: ret i1 [[CMP]]
273 %x.ext = fpext float %x to double
274 %y.ext = fpext float %y to double
275 %nearbyint = call double @nearbyint(double %x.ext) nounwind
276 %cmp = fcmp oeq double %nearbyint, %y.ext
280 define i1 @test11_intrin(float %x, float %y) {
281 ; CHECK-LABEL: @test11_intrin(
282 ; CHECK-NEXT: [[NEARBYINT:%.*]] = call float @llvm.nearbyint.f32(float %x)
283 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[NEARBYINT]], %y
284 ; CHECK-NEXT: ret i1 [[CMP]]
286 %x.ext = fpext float %x to double
287 %y.ext = fpext float %y to double
288 %nearbyint = call double @llvm.nearbyint.f64(double %x.ext) nounwind
289 %cmp = fcmp oeq double %nearbyint, %y.ext
293 define i1 @test12(float %x, float %y) {
294 ; CHECK-LABEL: @test12(
295 ; CHECK-NEXT: [[RINT:%.*]] = call float @llvm.rint.f32(float %x)
296 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[RINT]], %y
297 ; CHECK-NEXT: ret i1 [[CMP]]
299 %x.ext = fpext float %x to double
300 %y.ext = fpext float %y to double
301 %rint = call double @rint(double %x.ext) nounwind
302 %cmp = fcmp oeq double %y.ext, %rint
306 define i1 @test13(float %x, float %y) {
307 ; CHECK-LABEL: @test13(
308 ; CHECK-NEXT: [[ROUND:%.*]] = call float @llvm.round.f32(float %x)
309 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ROUND]], %y
310 ; CHECK-NEXT: ret i1 [[CMP]]
312 %x.ext = fpext float %x to double
313 %y.ext = fpext float %y to double
314 %round = call double @round(double %x.ext) nounwind readnone
315 %cmp = fcmp oeq double %y.ext, %round
319 define i1 @test13_intrin(float %x, float %y) {
320 ; CHECK-LABEL: @test13_intrin(
321 ; CHECK-NEXT: [[ROUND:%.*]] = call float @llvm.round.f32(float %x)
322 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ROUND]], %y
323 ; CHECK-NEXT: ret i1 [[CMP]]
325 %x.ext = fpext float %x to double
326 %y.ext = fpext float %y to double
327 %round = call double @llvm.round.f64(double %x.ext) nounwind readnone
328 %cmp = fcmp oeq double %y.ext, %round
332 define i1 @test14(float %x, float %y) {
333 ; CHECK-LABEL: @test14(
334 ; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.trunc.f32(float %x)
335 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[TRUNC]], %y
336 ; CHECK-NEXT: ret i1 [[CMP]]
338 %x.ext = fpext float %x to double
339 %y.ext = fpext float %y to double
340 %trunc = call double @trunc(double %x.ext) nounwind
341 %cmp = fcmp oeq double %y.ext, %trunc
345 define i1 @test14_intrin(float %x, float %y) {
346 ; CHECK-LABEL: @test14_intrin(
347 ; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.trunc.f32(float %x)
348 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[TRUNC]], %y
349 ; CHECK-NEXT: ret i1 [[CMP]]
351 %x.ext = fpext float %x to double
352 %y.ext = fpext float %y to double
353 %trunc = call double @llvm.trunc.f64(double %x.ext) nounwind
354 %cmp = fcmp oeq double %y.ext, %trunc
358 define i1 @test15(float %x, float %y, float %z) {
359 ; CHECK-LABEL: @test15(
360 ; CHECK-NEXT: [[TMP1:%.*]] = call nsz float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
361 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp oeq float [[TMP1]], [[Z:%.*]]
362 ; CHECK-NEXT: ret i1 [[TMP2]]
364 %1 = fpext float %x to double
365 %2 = fpext float %y to double
366 %3 = call double @fmin(double %1, double %2) nounwind
367 %4 = fpext float %z to double
368 %5 = fcmp oeq double %3, %4
372 define i1 @test16(float %x, float %y, float %z) {
373 ; CHECK-LABEL: @test16(
374 ; CHECK-NEXT: [[TMP1:%.*]] = call nsz float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
375 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp oeq float [[TMP1]], [[Z:%.*]]
376 ; CHECK-NEXT: ret i1 [[TMP2]]
378 %1 = fpext float %z to double
379 %2 = fpext float %x to double
380 %3 = fpext float %y to double
381 %4 = call double @fmin(double %2, double %3) nounwind
382 %5 = fcmp oeq double %1, %4
386 define i1 @test17(float %x, float %y, float %z) {
387 ; CHECK-LABEL: @test17(
388 ; CHECK-NEXT: [[TMP1:%.*]] = call nsz float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
389 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp oeq float [[TMP1]], [[Z:%.*]]
390 ; CHECK-NEXT: ret i1 [[TMP2]]
392 %1 = fpext float %x to double
393 %2 = fpext float %y to double
394 %3 = call double @fmax(double %1, double %2) nounwind
395 %4 = fpext float %z to double
396 %5 = fcmp oeq double %3, %4
400 define i1 @test18(float %x, float %y, float %z) {
401 ; CHECK-LABEL: @test18(
402 ; CHECK-NEXT: [[TMP1:%.*]] = call nsz float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
403 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp oeq float [[TMP1]], [[Z:%.*]]
404 ; CHECK-NEXT: ret i1 [[TMP2]]
406 %1 = fpext float %z to double
407 %2 = fpext float %x to double
408 %3 = fpext float %y to double
409 %4 = call double @fmax(double %2, double %3) nounwind
410 %5 = fcmp oeq double %1, %4
414 define i1 @test19(float %x, float %y, float %z) {
415 ; CHECK-LABEL: @test19(
416 ; CHECK-NEXT: [[COPYSIGNF:%.*]] = call float @copysignf(float %x, float %y) #0
417 ; CHECK-NEXT: [[TMP1:%.*]] = fcmp oeq float [[COPYSIGNF]], %z
418 ; CHECK-NEXT: ret i1 [[TMP1]]
420 %1 = fpext float %x to double
421 %2 = fpext float %y to double
422 %3 = call double @copysign(double %1, double %2) nounwind
423 %4 = fpext float %z to double
424 %5 = fcmp oeq double %3, %4
428 define i1 @test20(float %x, float %y) {
429 ; CHECK-LABEL: @test20(
430 ; CHECK-NEXT: [[TMP1:%.*]] = call nsz float @llvm.minnum.f32(float [[X:%.*]], float 1.000000e+00)
431 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp oeq float [[TMP1]], [[Y:%.*]]
432 ; CHECK-NEXT: ret i1 [[TMP2]]
434 %1 = fpext float %y to double
435 %2 = fpext float %x to double
436 %3 = call double @fmin(double 1.000000e+00, double %2) nounwind
437 %4 = fcmp oeq double %1, %3
441 ; should not be changed to fminf as the constant would lose precision
443 define i1 @test21(float %x, float %y) {
444 ; CHECK-LABEL: @test21(
445 ; CHECK-NEXT: [[TMP1:%.*]] = fpext float [[Y:%.*]] to double
446 ; CHECK-NEXT: [[TMP2:%.*]] = fpext float [[X:%.*]] to double
447 ; CHECK-NEXT: [[TMP3:%.*]] = call nsz double @llvm.minnum.f64(double [[TMP2]], double 1.300000e+00)
448 ; CHECK-NEXT: [[TMP4:%.*]] = fcmp oeq double [[TMP3]], [[TMP1]]
449 ; CHECK-NEXT: ret i1 [[TMP4]]
451 %1 = fpext float %y to double
452 %2 = fpext float %x to double
453 %3 = call double @fmin(double 1.300000e+00, double %2) nounwind
454 %4 = fcmp oeq double %1, %3
458 declare double @fabs(double) nounwind readnone
459 declare double @ceil(double) nounwind readnone
460 declare double @copysign(double, double) nounwind readnone
461 declare double @floor(double) nounwind readnone
462 declare double @nearbyint(double) nounwind readnone
463 declare double @rint(double) nounwind readnone
464 declare double @round(double) nounwind readnone
465 declare double @trunc(double) nounwind readnone
466 declare double @fmin(double, double) nounwind readnone
467 declare double @fmax(double, double) nounwind readnone
469 declare double @llvm.fabs.f64(double) nounwind readnone
470 declare double @llvm.ceil.f64(double) nounwind readnone
471 declare double @llvm.floor.f64(double) nounwind readnone
472 declare double @llvm.nearbyint.f64(double) nounwind readnone
473 declare double @llvm.round.f64(double) nounwind readnone
474 declare double @llvm.trunc.f64(double) nounwind readnone