1 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
2 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-pc-win64 -o - | FileCheck %s --check-prefix=X86
3 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple i686-unknown-unknown -o - | FileCheck %s --check-prefix=X86
4 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple powerpc-unknown-unknown -o - | FileCheck %s --check-prefix=PPC
5 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
6 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
7 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s --check-prefix=ARM7K
8 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple aarch64-unknown-unknown -ffast-math -ffp-contract=fast -o - | FileCheck %s --check-prefix=AARCH64-FASTMATH
9 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple spir -o - | FileCheck %s --check-prefix=SPIR
11 float _Complex
add_float_rr(float a
, float b
) {
12 // X86-LABEL: @add_float_rr(
18 float _Complex
add_float_cr(float _Complex a
, float b
) {
19 // X86-LABEL: @add_float_cr(
25 float _Complex
add_float_rc(float a
, float _Complex b
) {
26 // X86-LABEL: @add_float_rc(
32 float _Complex
add_float_cc(float _Complex a
, float _Complex b
) {
33 // X86-LABEL: @add_float_cc(
41 float _Complex
sub_float_rr(float a
, float b
) {
42 // X86-LABEL: @sub_float_rr(
48 float _Complex
sub_float_cr(float _Complex a
, float b
) {
49 // X86-LABEL: @sub_float_cr(
55 float _Complex
sub_float_rc(float a
, float _Complex b
) {
56 // X86-LABEL: @sub_float_rc(
63 float _Complex
sub_float_cc(float _Complex a
, float _Complex b
) {
64 // X86-LABEL: @sub_float_cc(
72 float _Complex
mul_float_rr(float a
, float b
) {
73 // X86-LABEL: @mul_float_rr(
79 float _Complex
mul_float_cr(float _Complex a
, float b
) {
80 // X86-LABEL: @mul_float_cr(
87 float _Complex
mul_float_rc(float a
, float _Complex b
) {
88 // X86-LABEL: @mul_float_rc(
96 float _Complex
mul_float_cc(float _Complex a
, float _Complex b
) {
97 // X86-LABEL: @mul_float_cc(
98 // X86: %[[AC:[^ ]+]] = fmul
99 // X86: %[[BD:[^ ]+]] = fmul
100 // X86: %[[AD:[^ ]+]] = fmul
101 // X86: %[[BC:[^ ]+]] = fmul
102 // X86: %[[RR:[^ ]+]] = fsub
103 // X86: %[[RI:[^ ]+]] = fadd
107 // X86: fcmp uno float %[[RR]]
108 // X86: fcmp uno float %[[RI]]
109 // X86: call {{.*}} @__mulsc3(
111 // SPIR: call spir_func {{.*}} @__mulsc3(
115 float _Complex
div_float_rr(float a
, float b
) {
116 // X86-LABEL: @div_float_rr(
122 float _Complex
div_float_cr(float _Complex a
, float b
) {
123 // X86-LABEL: @div_float_cr(
130 float _Complex
div_float_rc(float a
, float _Complex b
) {
131 // X86-LABEL: @div_float_rc(
133 // X86: call {{.*}} @__divsc3(
136 // SPIR: call spir_func {{.*}} @__divsc3(
138 // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
139 // AARCH64-FASTMATH-LABEL: @div_float_rc(float noundef nofpclass(nan inf) %a, [2 x float] noundef nofpclass(nan inf) alignstack(8) %b.coerce)
143 // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float
147 // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float
148 // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast float
149 // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float
152 // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float
154 // AARCH64-FASTMATH: fdiv fast float
155 // AARCH64-FASTMATH: fdiv fast float
156 // AARCH64-FASTMATH: ret
159 float _Complex
div_float_cc(float _Complex a
, float _Complex b
) {
160 // X86-LABEL: @div_float_cc(
162 // X86: call {{.*}} @__divsc3(
165 // SPIR: call spir_func {{.*}} @__divsc3(
167 // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
168 // AARCH64-FASTMATH-LABEL: @div_float_cc([2 x float] noundef nofpclass(nan inf) alignstack(8) %a.coerce, [2 x float] noundef nofpclass(nan inf) alignstack(8) %b.coerce)
170 // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float
171 // AARCH64-FASTMATH: [[BD:%.*]] = fmul fast float
172 // AARCH64-FASTMATH: [[ACpBD:%.*]] = fadd fast float
174 // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float
175 // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast float
176 // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float
178 // AARCH64-FASTMATH: [[BC:%.*]] = fmul fast float
179 // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float
180 // AARCH64-FASTMATH: [[BCmAD:%.*]] = fsub fast float
182 // AARCH64-FASTMATH: fdiv fast float
183 // AARCH64-FASTMATH: fdiv fast float
184 // AARCH64-FASTMATH: ret
188 double _Complex
add_double_rr(double a
, double b
) {
189 // X86-LABEL: @add_double_rr(
195 double _Complex
add_double_cr(double _Complex a
, double b
) {
196 // X86-LABEL: @add_double_cr(
202 double _Complex
add_double_rc(double a
, double _Complex b
) {
203 // X86-LABEL: @add_double_rc(
209 double _Complex
add_double_cc(double _Complex a
, double _Complex b
) {
210 // X86-LABEL: @add_double_cc(
218 double _Complex
sub_double_rr(double a
, double b
) {
219 // X86-LABEL: @sub_double_rr(
225 double _Complex
sub_double_cr(double _Complex a
, double b
) {
226 // X86-LABEL: @sub_double_cr(
232 double _Complex
sub_double_rc(double a
, double _Complex b
) {
233 // X86-LABEL: @sub_double_rc(
240 double _Complex
sub_double_cc(double _Complex a
, double _Complex b
) {
241 // X86-LABEL: @sub_double_cc(
249 double _Complex
mul_double_rr(double a
, double b
) {
250 // X86-LABEL: @mul_double_rr(
256 double _Complex
mul_double_cr(double _Complex a
, double b
) {
257 // X86-LABEL: @mul_double_cr(
264 double _Complex
mul_double_rc(double a
, double _Complex b
) {
265 // X86-LABEL: @mul_double_rc(
272 double _Complex
mul_double_cc(double _Complex a
, double _Complex b
) {
273 // X86-LABEL: @mul_double_cc(
274 // X86: %[[AC:[^ ]+]] = fmul
275 // X86: %[[BD:[^ ]+]] = fmul
276 // X86: %[[AD:[^ ]+]] = fmul
277 // X86: %[[BC:[^ ]+]] = fmul
278 // X86: %[[RR:[^ ]+]] = fsub double %[[AC]], %[[BD]]
279 // X86: %[[RI:[^ ]+]] = fadd double
283 // X86: fcmp uno double %[[RR]]
284 // X86: fcmp uno double %[[RI]]
285 // X86: call {{.*}} @__muldc3(
288 // SPIR: call spir_func {{.*}} @__muldc3(
292 double _Complex
div_double_rr(double a
, double b
) {
293 // X86-LABEL: @div_double_rr(
299 double _Complex
div_double_cr(double _Complex a
, double b
) {
300 // X86-LABEL: @div_double_cr(
307 double _Complex
div_double_rc(double a
, double _Complex b
) {
308 // X86-LABEL: @div_double_rc(
310 // X86: call {{.*}} @__divdc3(
313 // SPIR: call spir_func {{.*}} @__divdc3(
315 // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
316 // AARCH64-FASTMATH-LABEL: @div_double_rc(double noundef nofpclass(nan inf) %a, [2 x double] noundef nofpclass(nan inf) alignstack(8) %b.coerce)
320 // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast double
324 // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast double
325 // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast double
326 // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast double
329 // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast double
331 // AARCH64-FASTMATH: fdiv fast double
332 // AARCH64-FASTMATH: fdiv fast double
333 // AARCH64-FASTMATH: ret
336 double _Complex
div_double_cc(double _Complex a
, double _Complex b
) {
337 // X86-LABEL: @div_double_cc(
339 // X86: call {{.*}} @__divdc3(
342 // SPIR: call spir_func {{.*}} @__divdc3(
344 // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
345 // AARCH64-FASTMATH-LABEL: @div_double_cc([2 x double] noundef nofpclass(nan inf) alignstack(8) %a.coerce, [2 x double] noundef nofpclass(nan inf) alignstack(8) %b.coerce)
347 // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast double
348 // AARCH64-FASTMATH: [[BD:%.*]] = fmul fast double
349 // AARCH64-FASTMATH: [[ACpBD:%.*]] = fadd fast double
351 // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast double
352 // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast double
353 // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast double
355 // AARCH64-FASTMATH: [[BC:%.*]] = fmul fast double
356 // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast double
357 // AARCH64-FASTMATH: [[BCmAD:%.*]] = fsub fast double
359 // AARCH64-FASTMATH: fdiv fast double
360 // AARCH64-FASTMATH: fdiv fast double
361 // AARCH64-FASTMATH: ret
365 long double _Complex
add_long_double_rr(long double a
, long double b
) {
366 // X86-LABEL: @add_long_double_rr(
372 long double _Complex
add_long_double_cr(long double _Complex a
, long double b
) {
373 // X86-LABEL: @add_long_double_cr(
379 long double _Complex
add_long_double_rc(long double a
, long double _Complex b
) {
380 // X86-LABEL: @add_long_double_rc(
386 long double _Complex
add_long_double_cc(long double _Complex a
, long double _Complex b
) {
387 // X86-LABEL: @add_long_double_cc(
395 long double _Complex
sub_long_double_rr(long double a
, long double b
) {
396 // X86-LABEL: @sub_long_double_rr(
402 long double _Complex
sub_long_double_cr(long double _Complex a
, long double b
) {
403 // X86-LABEL: @sub_long_double_cr(
409 long double _Complex
sub_long_double_rc(long double a
, long double _Complex b
) {
410 // X86-LABEL: @sub_long_double_rc(
417 long double _Complex
sub_long_double_cc(long double _Complex a
, long double _Complex b
) {
418 // X86-LABEL: @sub_long_double_cc(
426 long double _Complex
mul_long_double_rr(long double a
, long double b
) {
427 // X86-LABEL: @mul_long_double_rr(
433 long double _Complex
mul_long_double_cr(long double _Complex a
, long double b
) {
434 // X86-LABEL: @mul_long_double_cr(
441 long double _Complex
mul_long_double_rc(long double a
, long double _Complex b
) {
442 // X86-LABEL: @mul_long_double_rc(
449 long double _Complex
mul_long_double_cc(long double _Complex a
, long double _Complex b
) {
450 // X86-LABEL: @mul_long_double_cc(
451 // X86: %[[AC:[^ ]+]] = fmul
452 // X86: %[[BD:[^ ]+]] = fmul
453 // X86: %[[AD:[^ ]+]] = fmul
454 // X86: %[[BC:[^ ]+]] = fmul
455 // X86: %[[RR:[^ ]+]] = fsub x86_fp80 %[[AC]], %[[BD]]
456 // X86: %[[RI:[^ ]+]] = fadd x86_fp80
460 // X86: fcmp uno x86_fp80 %[[RR]]
461 // X86: fcmp uno x86_fp80 %[[RI]]
462 // X86: call {{.*}} @__mulxc3(
464 // PPC-LABEL: @mul_long_double_cc(
465 // PPC: %[[AC:[^ ]+]] = fmul
466 // PPC: %[[BD:[^ ]+]] = fmul
467 // PPC: %[[AD:[^ ]+]] = fmul
468 // PPC: %[[BC:[^ ]+]] = fmul
469 // PPC: %[[RR:[^ ]+]] = fsub ppc_fp128 %[[AC]], %[[BD]]
470 // PPC: %[[RI:[^ ]+]] = fadd ppc_fp128
474 // PPC: fcmp uno ppc_fp128 %[[RR]]
475 // PPC: fcmp uno ppc_fp128 %[[RI]]
476 // PPC: call {{.*}} @__multc3(
478 // SPIR: call spir_func {{.*}} @__muldc3(
482 long double _Complex
div_long_double_rr(long double a
, long double b
) {
483 // X86-LABEL: @div_long_double_rr(
489 long double _Complex
div_long_double_cr(long double _Complex a
, long double b
) {
490 // X86-LABEL: @div_long_double_cr(
497 long double _Complex
div_long_double_rc(long double a
, long double _Complex b
) {
498 // X86-LABEL: @div_long_double_rc(
500 // X86: call {{.*}} @__divxc3(
502 // PPC-LABEL: @div_long_double_rc(
504 // PPC: call {{.*}} @__divtc3(
506 // SPIR: call spir_func {{.*}} @__divdc3(
508 // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
509 // AARCH64-FASTMATH-LABEL: @div_long_double_rc(fp128 noundef nofpclass(nan inf) %a, [2 x fp128] noundef nofpclass(nan inf) alignstack(16) %b.coerce)
513 // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast fp128
517 // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast fp128
518 // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast fp128
519 // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast fp128
522 // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast fp128
524 // AARCH64-FASTMATH: fdiv fast fp128
525 // AARCH64-FASTMATH: fdiv fast fp128
526 // AARCH64-FASTMATH: ret
529 long double _Complex
div_long_double_cc(long double _Complex a
, long double _Complex b
) {
530 // X86-LABEL: @div_long_double_cc(
532 // X86: call {{.*}} @__divxc3(
534 // PPC-LABEL: @div_long_double_cc(
536 // PPC: call {{.*}} @__divtc3(
538 // SPIR: call spir_func {{.*}} @__divdc3(
540 // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
541 // AARCH64-FASTMATH-LABEL: @div_long_double_cc([2 x fp128] noundef nofpclass(nan inf) alignstack(16) %a.coerce, [2 x fp128] noundef nofpclass(nan inf) alignstack(16) %b.coerce)
543 // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast fp128
544 // AARCH64-FASTMATH: [[BD:%.*]] = fmul fast fp128
545 // AARCH64-FASTMATH: [[ACpBD:%.*]] = fadd fast fp128
547 // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast fp128
548 // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast fp128
549 // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast fp128
551 // AARCH64-FASTMATH: [[BC:%.*]] = fmul fast fp128
552 // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast fp128
553 // AARCH64-FASTMATH: [[BCmAD:%.*]] = fsub fast fp128
555 // AARCH64-FASTMATH: fdiv fast fp128
556 // AARCH64-FASTMATH: fdiv fast fp128
557 // AARCH64-FASTMATH: ret
561 // Comparison operators don't rely on library calls or have interseting math
562 // properties, but test that mixed types work correctly here.
563 _Bool
eq_float_cr(float _Complex a
, float b
) {
564 // X86-LABEL: @eq_float_cr(
571 _Bool
eq_float_rc(float a
, float _Complex b
) {
572 // X86-LABEL: @eq_float_rc(
579 _Bool
eq_float_cc(float _Complex a
, float _Complex b
) {
580 // X86-LABEL: @eq_float_cc(
587 _Bool
ne_float_cr(float _Complex a
, float b
) {
588 // X86-LABEL: @ne_float_cr(
595 _Bool
ne_float_rc(float a
, float _Complex b
) {
596 // X86-LABEL: @ne_float_rc(
603 _Bool
ne_float_cc(float _Complex a
, float _Complex b
) {
604 // X86-LABEL: @ne_float_cc(
612 // Check that the libcall will obtain proper calling convention on ARM
613 _Complex
double foo(_Complex
double a
, _Complex
double b
) {
614 // These functions are not defined as floating point helper functions in
615 // Run-time ABI for the ARM architecture document so they must not always
616 // use the base AAPCS.
619 // ARM: call void @__muldc3
621 // SPIR: call spir_func void @__muldc3
623 // ARMHF-LABEL: @foo(
624 // ARMHF: call { double, double } @__muldc3
626 // ARM7K-LABEL: @foo(
627 // ARM7K: call { double, double } @__muldc3
631 typedef _Complex
double ComplexDouble
;
632 typedef double Double
;
634 float _Complex
double_cr_sugar(ComplexDouble a
, Double b
) {
635 // X86-LABEL: @double_cr_sugar(