Debian Codegraph @

gcc/testsuite/g++.target/i386/pr103973-1.C

raw
1 // PR target/103973
2 // { dg-do run }
3 // { dg-options "-O2 -std=c++20 -save-temps" }
4 // { dg-final { scan-assembler-not "'\t\[v\]?ucomisd" { target { ! ia32 } } } }
5 // { dg-final { scan-assembler-times "\t\[v\]?comisd" 2 { target { ! ia32 } } } }
6
7 #include <compare>
8
9 #ifndef double_type
10 #define double_type double
11 #endif
12
13 __attribute__((noipa)) auto
14 foo (double_type a, double_type b)
15 {
16 return a <=> b;
17 }
18
19 __attribute__((noipa)) int
20 bar (double_type a, double_type b)
21 {
22 auto c = foo (a, b);
23 if (c == std::partial_ordering::less)
24 return -1;
25 if (c == std::partial_ordering::equivalent)
26 return 0;
27 if (c == std::partial_ordering::greater)
28 return 1;
29 return 2;
30 }
31
32 __attribute__((noipa)) auto
33 baz (double_type a)
34 {
35 return a <=> 0.0f;
36 }
37
38 __attribute__((noipa)) int
39 qux (double_type a)
40 {
41 auto c = baz (a);
42 if (c == std::partial_ordering::less)
43 return -1;
44 if (c == std::partial_ordering::equivalent)
45 return 0;
46 if (c == std::partial_ordering::greater)
47 return 1;
48 return 2;
49 }
50
51 int
52 main ()
53 {
54 double_type m5 = -5.0;
55 double_type p5 = 5.0;
56 volatile double_type p0 = 0.0;
57 double_type nan = p0 / p0;
58 if (bar (p5, p5) != 0 || bar (m5, m5) != 0)
59 __builtin_abort ();
60 if (bar (m5, p5) != -1 || bar (p5, m5) != 1)
61 __builtin_abort ();
62 if (bar (m5, nan) != 2 || bar (nan, p5) != 2)
63 __builtin_abort ();
64 if (bar (nan, nan) != 2)
65 __builtin_abort ();
66 if (qux (p0) != 0 || qux (nan) != 2)
67 __builtin_abort ();
68 if (qux (m5) != -1 || qux (p5) != 1)
69 __builtin_abort ();
70 return 0;
71 }