1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -instsimplify | FileCheck %s
6 define i1 @nnan_call() {
7 ; CHECK-LABEL: @nnan_call(
8 ; CHECK-NEXT: [[OP:%.*]] = call nnan double @func()
9 ; CHECK-NEXT: ret i1 true
11 %op = call nnan double @func()
12 %tmp = fcmp ord double %op, %op
16 define i1 @nnan_fabs_src(double %arg) {
17 ; CHECK-LABEL: @nnan_fabs_src(
18 ; CHECK-NEXT: ret i1 false
20 %nnan = fadd nnan double %arg, 1.0
21 %op = call double @llvm.fabs.f64(double %nnan)
22 %tmp = fcmp uno double %op, %op
26 define i1 @nnan_canonicalize_src(double %arg) {
27 ; CHECK-LABEL: @nnan_canonicalize_src(
28 ; CHECK-NEXT: ret i1 true
30 %nnan = fadd nnan double %arg, 1.0
31 %op = call double @llvm.canonicalize.f64(double %nnan)
32 %tmp = fcmp ord double %op, %op
36 define i1 @nnan_copysign_src(double %arg0, double %arg1) {
37 ; CHECK-LABEL: @nnan_copysign_src(
38 ; CHECK-NEXT: ret i1 false
40 %nnan = fadd nnan double %arg0, 1.0
41 %op = call double @llvm.copysign.f64(double %nnan, double %arg1)
42 %tmp = fcmp uno double %op, %op
46 define i1 @fabs_sqrt_src(double %arg0, double %arg1) {
47 ; CHECK-LABEL: @fabs_sqrt_src(
48 ; CHECK-NEXT: ret i1 true
50 %nnan = fadd nnan double %arg0, 1.0
51 %fabs = call double @llvm.fabs.f64(double %nnan)
52 %op = call double @llvm.sqrt.f64(double %fabs)
53 %tmp = fcmp ord double %op, %op
57 define i1 @fabs_sqrt_src_maybe_nan(double %arg0, double %arg1) {
58 ; CHECK-LABEL: @fabs_sqrt_src_maybe_nan(
59 ; CHECK-NEXT: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[ARG0:%.*]])
60 ; CHECK-NEXT: [[OP:%.*]] = call double @llvm.sqrt.f64(double [[FABS]])
61 ; CHECK-NEXT: [[TMP:%.*]] = fcmp uno double [[OP]], [[OP]]
62 ; CHECK-NEXT: ret i1 [[TMP]]
64 %fabs = call double @llvm.fabs.f64(double %arg0)
65 %op = call double @llvm.sqrt.f64(double %fabs)
66 %tmp = fcmp uno double %op, %op
70 define i1 @exp_nnan_src(double %arg) {
71 ; CHECK-LABEL: @exp_nnan_src(
72 ; CHECK-NEXT: ret i1 true
74 %nnan = fadd nnan double %arg, 1.0
75 %op = call double @llvm.exp.f64(double %nnan)
76 %tmp = fcmp ord double %op, %op
80 define i1 @exp2_nnan_src(double %arg) {
81 ; CHECK-LABEL: @exp2_nnan_src(
82 ; CHECK-NEXT: ret i1 false
84 %nnan = fadd nnan double %arg, 1.0
85 %op = call double @llvm.exp2.f64(double %nnan)
86 %tmp = fcmp uno double %op, %op
90 define i1 @floor_nnan_src(double %arg) {
91 ; CHECK-LABEL: @floor_nnan_src(
92 ; CHECK-NEXT: ret i1 true
94 %nnan = fadd nnan double %arg, 1.0
95 %op = call double @llvm.floor.f64(double %nnan)
96 %tmp = fcmp ord double %op, %op
100 define i1 @ceil_nnan_src(double %arg) {
101 ; CHECK-LABEL: @ceil_nnan_src(
102 ; CHECK-NEXT: ret i1 false
104 %nnan = fadd nnan double %arg, 1.0
105 %op = call double @llvm.ceil.f64(double %nnan)
106 %tmp = fcmp uno double %op, %op
110 define i1 @trunc_nnan_src(double %arg) {
111 ; CHECK-LABEL: @trunc_nnan_src(
112 ; CHECK-NEXT: ret i1 true
114 %nnan = fadd nnan double %arg, 1.0
115 %op = call double @llvm.trunc.f64(double %nnan)
116 %tmp = fcmp ord double %op, %op
120 define i1 @rint_nnan_src(double %arg) {
121 ; CHECK-LABEL: @rint_nnan_src(
122 ; CHECK-NEXT: ret i1 false
124 %nnan = fadd nnan double %arg, 1.0
125 %op = call double @llvm.rint.f64(double %nnan)
126 %tmp = fcmp uno double %op, %op
130 define i1 @nearbyint_nnan_src(double %arg) {
131 ; CHECK-LABEL: @nearbyint_nnan_src(
132 ; CHECK-NEXT: ret i1 true
134 %nnan = fadd nnan double %arg, 1.0
135 %op = call double @llvm.nearbyint.f64(double %nnan)
136 %tmp = fcmp ord double %op, %op
140 define i1 @round_nnan_src(double %arg) {
141 ; CHECK-LABEL: @round_nnan_src(
142 ; CHECK-NEXT: ret i1 false
144 %nnan = fadd nnan double %arg, 1.0
145 %op = call double @llvm.round.f64(double %nnan)
146 %tmp = fcmp uno double %op, %op
150 define i1 @roundeven_nnan_src(double %arg) {
151 ; CHECK-LABEL: @roundeven_nnan_src(
152 ; CHECK-NEXT: ret i1 false
154 %nnan = fadd nnan double %arg, 1.0
155 %op = call double @llvm.roundeven.f64(double %nnan)
156 %tmp = fcmp uno double %op, %op
160 define i1 @known_nan_select(i1 %cond, double %arg0, double %arg1) {
161 ; CHECK-LABEL: @known_nan_select(
162 ; CHECK-NEXT: ret i1 true
164 %lhs = fadd nnan double %arg0, 1.0
165 %rhs = fadd nnan double %arg1, 2.0
166 %op = select i1 %cond, double %lhs, double %rhs
167 %tmp = fcmp ord double %op, %op
171 define i1 @nnan_ninf_known_nan_select(i1 %cond, double %arg0, double %arg1) {
172 ; CHECK-LABEL: @nnan_ninf_known_nan_select(
173 ; CHECK-NEXT: ret i1 true
175 %lhs = fadd nnan ninf double %arg0, 1.0
176 %rhs = fadd nnan ninf double %arg1, 2.0
177 %op = select i1 %cond, double %lhs, double %rhs
178 %mul = fmul double %op, 2.0
179 %tmp = fcmp ord double %mul, %mul
183 define i1 @select_maybe_nan_lhs(i1 %cond, double %lhs, double %arg1) {
184 ; CHECK-LABEL: @select_maybe_nan_lhs(
185 ; CHECK-NEXT: [[RHS:%.*]] = fadd nnan double [[ARG1:%.*]], 1.000000e+00
186 ; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], double [[LHS:%.*]], double [[RHS]]
187 ; CHECK-NEXT: [[TMP:%.*]] = fcmp uno double [[OP]], [[OP]]
188 ; CHECK-NEXT: ret i1 [[TMP]]
190 %rhs = fadd nnan double %arg1, 1.0
191 %op = select i1 %cond, double %lhs, double %rhs
192 %tmp = fcmp uno double %op, %op
196 define i1 @select_maybe_nan_rhs(i1 %cond, double %arg0, double %rhs) {
197 ; CHECK-LABEL: @select_maybe_nan_rhs(
198 ; CHECK-NEXT: [[LHS:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
199 ; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], double [[LHS]], double [[RHS:%.*]]
200 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[OP]], [[OP]]
201 ; CHECK-NEXT: ret i1 [[TMP]]
203 %lhs = fadd nnan double %arg0, 1.0
204 %op = select i1 %cond, double %lhs, double %rhs
205 %tmp = fcmp ord double %op, %op
209 define i1 @nnan_fadd(double %arg0, double %arg1) {
210 ; CHECK-LABEL: @nnan_fadd(
211 ; CHECK-NEXT: [[NNAN_ARG0:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
212 ; CHECK-NEXT: [[NNAN_ARG1:%.*]] = fadd nnan double [[ARG0]], 2.000000e+00
213 ; CHECK-NEXT: [[OP:%.*]] = fadd double [[NNAN_ARG0]], [[NNAN_ARG1]]
214 ; CHECK-NEXT: [[TMP:%.*]] = fcmp uno double [[OP]], [[OP]]
215 ; CHECK-NEXT: ret i1 [[TMP]]
217 %nnan.arg0 = fadd nnan double %arg0, 1.0
218 %nnan.arg1 = fadd nnan double %arg0, 2.0
219 %op = fadd double %nnan.arg0, %nnan.arg1
220 %tmp = fcmp uno double %op, %op
224 define i1 @nnan_fadd_maybe_nan_lhs(double %arg0, double %arg1) {
225 ; CHECK-LABEL: @nnan_fadd_maybe_nan_lhs(
226 ; CHECK-NEXT: [[NNAN_ARG1:%.*]] = fadd nnan double [[ARG1:%.*]], 1.000000e+00
227 ; CHECK-NEXT: [[OP:%.*]] = fadd double [[ARG0:%.*]], [[NNAN_ARG1]]
228 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[OP]], [[OP]]
229 ; CHECK-NEXT: ret i1 [[TMP]]
231 %nnan.arg1 = fadd nnan double %arg1, 1.0
232 %op = fadd double %arg0, %nnan.arg1
233 %tmp = fcmp ord double %op, %op
237 define i1 @nnan_fadd_maybe_nan_rhs(double %arg0, double %arg1) {
238 ; CHECK-LABEL: @nnan_fadd_maybe_nan_rhs(
239 ; CHECK-NEXT: [[NNAN_ARG0:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
240 ; CHECK-NEXT: [[OP:%.*]] = fadd double [[NNAN_ARG0]], [[ARG1:%.*]]
241 ; CHECK-NEXT: [[TMP:%.*]] = fcmp uno double [[OP]], [[OP]]
242 ; CHECK-NEXT: ret i1 [[TMP]]
244 %nnan.arg0 = fadd nnan double %arg0, 1.0
245 %op = fadd double %nnan.arg0, %arg1
246 %tmp = fcmp uno double %op, %op
250 define i1 @nnan_fmul(double %arg0, double %arg1) {
251 ; CHECK-LABEL: @nnan_fmul(
252 ; CHECK-NEXT: [[NNAN_ARG0:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
253 ; CHECK-NEXT: [[NNAN_ARG1:%.*]] = fadd nnan double [[ARG0]], 2.000000e+00
254 ; CHECK-NEXT: [[OP:%.*]] = fmul double [[NNAN_ARG0]], [[NNAN_ARG1]]
255 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[OP]], [[OP]]
256 ; CHECK-NEXT: ret i1 [[TMP]]
258 %nnan.arg0 = fadd nnan double %arg0, 1.0
259 %nnan.arg1 = fadd nnan double %arg0, 2.0
260 %op = fmul double %nnan.arg0, %nnan.arg1
261 %tmp = fcmp ord double %op, %op
265 define i1 @nnan_fsub(double %arg0, double %arg1) {
266 ; CHECK-LABEL: @nnan_fsub(
267 ; CHECK-NEXT: [[NNAN_ARG0:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
268 ; CHECK-NEXT: [[NNAN_ARG1:%.*]] = fadd nnan double [[ARG0]], 2.000000e+00
269 ; CHECK-NEXT: [[OP:%.*]] = fsub double [[NNAN_ARG0]], [[NNAN_ARG1]]
270 ; CHECK-NEXT: [[TMP:%.*]] = fcmp uno double [[OP]], [[OP]]
271 ; CHECK-NEXT: ret i1 [[TMP]]
273 %nnan.arg0 = fadd nnan double %arg0, 1.0
274 %nnan.arg1 = fadd nnan double %arg0, 2.0
275 %op = fsub double %nnan.arg0, %nnan.arg1
276 %tmp = fcmp uno double %op, %op
280 define i1 @nnan_binary_fneg() {
281 ; CHECK-LABEL: @nnan_binary_fneg(
282 ; CHECK-NEXT: [[NNAN:%.*]] = call nnan double @func()
283 ; CHECK-NEXT: ret i1 true
285 %nnan = call nnan double @func()
286 %op = fsub double -0.0, %nnan
287 %tmp = fcmp ord double %op, %op
291 define i1 @nnan_unary_fneg() {
292 ; CHECK-LABEL: @nnan_unary_fneg(
293 ; CHECK-NEXT: [[NNAN:%.*]] = call nnan double @func()
294 ; CHECK-NEXT: [[OP:%.*]] = fneg double [[NNAN]]
295 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[OP]], [[OP]]
296 ; CHECK-NEXT: ret i1 [[TMP]]
298 %nnan = call nnan double @func()
299 %op = fneg double %nnan
300 %tmp = fcmp ord double %op, %op
304 define i1 @sitofp(i32 %arg0) {
305 ; CHECK-LABEL: @sitofp(
306 ; CHECK-NEXT: ret i1 false
308 %op = sitofp i32 %arg0 to double
309 %tmp = fcmp uno double %op, %op
313 define i1 @uitofp(i32 %arg0) {
314 ; CHECK-LABEL: @uitofp(
315 ; CHECK-NEXT: ret i1 true
317 %op = uitofp i32 %arg0 to double
318 %tmp = fcmp ord double %op, %op
322 define i1 @uitofp_add(i32 %arg0) {
323 ; CHECK-LABEL: @uitofp_add(
324 ; CHECK-NEXT: ret i1 true
326 %op = uitofp i32 %arg0 to double
327 %add = fadd double %op, %op
328 %tmp = fcmp ord double %add, %add
332 define i1 @uitofp_add_big(i1024 %arg0) {
333 ; CHECK-LABEL: @uitofp_add_big(
334 ; CHECK-NEXT: [[OP:%.*]] = uitofp i1024 [[ARG0:%.*]] to double
335 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[OP]], [[OP]]
336 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[ADD]], [[ADD]]
337 ; CHECK-NEXT: ret i1 [[TMP]]
339 %op = uitofp i1024 %arg0 to double
340 %add = fadd double %op, %op
341 %tmp = fcmp ord double %add, %add
345 define i1 @fpext(float %arg0) {
346 ; CHECK-LABEL: @fpext(
347 ; CHECK-NEXT: ret i1 false
349 %arg0.nnan = fadd nnan float %arg0, 1.0
350 %op = fpext float %arg0.nnan to double
351 %tmp = fcmp uno double %op, %op
355 define i1 @fpext_maybe_nan(float %arg0) {
356 ; CHECK-LABEL: @fpext_maybe_nan(
357 ; CHECK-NEXT: [[OP:%.*]] = fpext float [[ARG0:%.*]] to double
358 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[OP]], [[OP]]
359 ; CHECK-NEXT: ret i1 [[TMP]]
361 %op = fpext float %arg0 to double
362 %tmp = fcmp ord double %op, %op
366 define i1 @fptrunc(double %arg0) {
367 ; CHECK-LABEL: @fptrunc(
368 ; CHECK-NEXT: ret i1 false
370 %arg0.nnan = fadd nnan double %arg0, 1.0
371 %op = fptrunc double %arg0.nnan to float
372 %tmp = fcmp uno float %op, %op
376 define i1 @fptrunc_maybe_nan(double %arg0) {
377 ; CHECK-LABEL: @fptrunc_maybe_nan(
378 ; CHECK-NEXT: [[OP:%.*]] = fptrunc double [[ARG0:%.*]] to float
379 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord float [[OP]], [[OP]]
380 ; CHECK-NEXT: ret i1 [[TMP]]
382 %op = fptrunc double %arg0 to float
383 %tmp = fcmp ord float %op, %op
387 define i1 @nnan_fdiv(double %arg0, double %arg1) {
388 ; CHECK-LABEL: @nnan_fdiv(
389 ; CHECK-NEXT: [[NNAN_ARG0:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
390 ; CHECK-NEXT: [[NNAN_ARG1:%.*]] = fadd nnan double [[ARG0]], 2.000000e+00
391 ; CHECK-NEXT: [[OP:%.*]] = fdiv double [[NNAN_ARG0]], [[NNAN_ARG1]]
392 ; CHECK-NEXT: [[TMP:%.*]] = fcmp uno double [[OP]], [[OP]]
393 ; CHECK-NEXT: ret i1 [[TMP]]
395 %nnan.arg0 = fadd nnan double %arg0, 1.0
396 %nnan.arg1 = fadd nnan double %arg0, 2.0
397 %op = fdiv double %nnan.arg0, %nnan.arg1
398 %tmp = fcmp uno double %op, %op
402 define i1 @nnan_frem(double %arg0, double %arg1) {
403 ; CHECK-LABEL: @nnan_frem(
404 ; CHECK-NEXT: [[NNAN_ARG0:%.*]] = fadd nnan double [[ARG0:%.*]], 1.000000e+00
405 ; CHECK-NEXT: [[NNAN_ARG1:%.*]] = fadd nnan double [[ARG0]], 2.000000e+00
406 ; CHECK-NEXT: [[OP:%.*]] = frem double [[NNAN_ARG0]], [[NNAN_ARG1]]
407 ; CHECK-NEXT: [[TMP:%.*]] = fcmp ord double [[OP]], [[OP]]
408 ; CHECK-NEXT: ret i1 [[TMP]]
410 %nnan.arg0 = fadd nnan double %arg0, 1.0
411 %nnan.arg1 = fadd nnan double %arg0, 2.0
412 %op = frem double %nnan.arg0, %nnan.arg1
413 %tmp = fcmp ord double %op, %op
417 declare double @llvm.sqrt.f64(double)
418 declare double @llvm.fabs.f64(double)
419 declare double @llvm.canonicalize.f64(double)
420 declare double @llvm.copysign.f64(double, double)
421 declare double @llvm.exp.f64(double)
422 declare double @llvm.exp2.f64(double)
423 declare double @llvm.floor.f64(double)
424 declare double @llvm.ceil.f64(double)
425 declare double @llvm.trunc.f64(double)
426 declare double @llvm.rint.f64(double)
427 declare double @llvm.nearbyint.f64(double)
428 declare double @llvm.round.f64(double)
429 declare double @llvm.roundeven.f64(double)