Debian Codegraph @

gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-mavx512fp16 -O2" } */
3
4 #include <immintrin.h>
5
6 typedef __bf16 __v16bf __attribute__ ((__vector_size__ (32)));
7 typedef __bf16 __m256bf16 __attribute__ ((__vector_size__ (32), __may_alias__));
8
9 __bf16 glob_bfloat;
10 __m256bf16 glob_bfloat_vec;
11
12 __m256 is_a_float_vec;
13
14 __m256h *float_ptr;
15 __m256h is_a_float16_vec;
16
17 __v8si is_an_int_vec;
18 __m256i is_a_long_int_pair;
19 __v16hi is_a_short_vec;
20
21 int is_an_int;
22 short is_a_short_int;
23 float is_a_float;
24 float is_a_float16;
25 double is_a_double;
26
27 __m256bf16 footest (__m256bf16 vector0)
28 {
29 /* Initialisation */
30
31 __m256bf16 vector1_1;
32 __m256bf16 vector1_2 = glob_bfloat_vec;
33 __m256bf16 vector1_3 = is_a_float_vec; /* { dg-error {incompatible types when initializing type '__m256bf16' {aka '__vector\(16\) __bf16'} using type '__m256'} } */
34 __m256bf16 vector1_4 = is_an_int_vec; /* { dg-error {incompatible types when initializing type '__m256bf16' {aka '__vector\(16\) __bf16'} using type '__v8si'} } */
35 __m256bf16 vector1_5 = is_a_float16_vec; /* { dg-error {incompatible types when initializing type '__m256bf16' {aka '__vector\(16\) __bf16'} using type '__m256h'} } */
36 __m256bf16 vector1_7 = is_a_long_int_pair; /* { dg-error {incompatible types when initializing type '__m256bf16' {aka '__vector\(16\) __bf16'} using type '__m256i'} } */
37 __m256bf16 vector1_8 = is_a_short_vec; /* { dg-error {incompatible types when initializing type '__m256bf16' {aka '__vector\(16\) __bf16'} using type '__v16hi'} } */
38
39 __v8si initi_1_1 = glob_bfloat_vec; /* { dg-error {incompatible types when initializing type '__v8si' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
40 __m256 initi_1_2 = glob_bfloat_vec; /* { dg-error {incompatible types when initializing type '__m256' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
41 __m256h initi_1_3 = glob_bfloat_vec; /* { dg-error {incompatible types when initializing type '__m256h' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
42 __m256i initi_1_5 = glob_bfloat_vec; /* { dg-error {incompatible types when initializing type '__m256i' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
43 __v16hi initi_1_6 = glob_bfloat_vec; /* { dg-error {incompatible types when initializing type '__v16hi' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
44
45 __m256bf16 vector2_1 = {};
46 __m256bf16 vector2_2 = { glob_bfloat };
47 __m256bf16 vector2_3 = { glob_bfloat, glob_bfloat, glob_bfloat, glob_bfloat };
48 __m256bf16 vector2_4 = { 0 };
49 __m256bf16 vector2_5 = { 0.1 };
50 __m256bf16 vector2_6 = { is_a_float16 };
51 __m256bf16 vector2_7 = { is_a_float };
52 __m256bf16 vector2_8 = { is_an_int };
53 __m256bf16 vector2_9 = { is_a_short_int };
54 __m256bf16 vector2_10 = { 0.0, 0, is_a_short_int, is_a_float };
55
56 __v8si initi_2_1 = { glob_bfloat };
57 __m256 initi_2_2 = { glob_bfloat };
58 __m256h initi_2_3 = { glob_bfloat };
59 __m256i initi_2_5 = { glob_bfloat };
60 __v16hi initi_2_6 = { glob_bfloat };
61
62 /* Assignments to/from vectors. */
63
64 glob_bfloat_vec = glob_bfloat_vec;
65 glob_bfloat_vec = 0; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type 'int'} } */
66 glob_bfloat_vec = 0.1; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type 'double'} } */
67 glob_bfloat_vec = is_a_float_vec; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type '__m256'} } */
68 glob_bfloat_vec = is_an_int_vec; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type '__v8si'} } */
69 glob_bfloat_vec = is_a_float16_vec; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type '__m256h'} } */
70 glob_bfloat_vec = is_a_long_int_pair; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type '__m256i'} } */
71 glob_bfloat_vec = is_a_short_vec; /* { dg-error {incompatible types when assigning to type '__m256bf16' {aka '__vector\(16\) __bf16'} from type '__v16hi'} } */
72
73 is_an_int_vec = glob_bfloat_vec; /* { dg-error {incompatible types when assigning to type '__v8si' from type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
74 is_a_float_vec = glob_bfloat_vec; /* { dg-error {incompatible types when assigning to type '__m256' from type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
75 is_a_float16_vec = glob_bfloat_vec; /* { dg-error {incompatible types when assigning to type '__m256h' from type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
76 is_a_long_int_pair = glob_bfloat_vec; /* { dg-error {incompatible types when assigning to type '__m256i' from type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
77 is_a_short_vec = glob_bfloat_vec;/* { dg-error {incompatible types when assigning to type '__v16hi' from type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
78
79 /* Assignments to/from elements. */
80
81 vector2_3[0] = glob_bfloat;
82 vector2_3[0] = is_an_int;
83 vector2_3[0] = is_a_short_int;
84 vector2_3[0] = is_a_float;
85 vector2_3[0] = is_a_float16;
86 vector2_3[0] = 0;
87 vector2_3[0] = 0.1;
88
89 glob_bfloat = vector2_3[0];
90 is_an_int = vector2_3[0];
91 is_a_short_int = vector2_3[0];
92 is_a_float = vector2_3[0];
93 is_a_float16 = vector2_3[0];
94
95 /* Compound literals. */
96
97 (__m256bf16) {};
98
99 (__m256bf16) { 0 };
100 (__m256bf16) { 0.1 };
101 (__m256bf16) { is_a_float_vec }; /* { dg-error {incompatible types when initializing type '__bf16' using type '__m256'} } */
102 (__m256bf16) { is_an_int_vec }; /* { dg-error {incompatible types when initializing type '__bf16' using type '__v8si'} } */
103 (__m256bf16) { is_a_long_int_pair }; /* { dg-error {incompatible types when initializing type '__bf16' using type '__m256i'} } */
104 (__m256bf16) { is_a_float16_vec }; /* { dg-error {incompatible types when initializing type '__bf16' using type '__m256h'} } */
105 (__m256bf16) { is_a_short_vec }; /* { dg-error {incompatible types when initializing type '__bf16' using type '__v16hi'} } */
106
107 (__m256bf16) { glob_bfloat_vec }; /* { dg-error {incompatible types when initializing type '__bf16' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
108 (__v8si) { glob_bfloat_vec }; /* { dg-error {incompatible types when initializing type 'int' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
109 (__m256) { glob_bfloat_vec }; /* { dg-error {incompatible types when initializing type 'float' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
110 (__m256i) { glob_bfloat_vec }; /* { dg-error {incompatible types when initializing type 'long long int' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
111 (__m256h) { glob_bfloat_vec }; /* { dg-error {incompatible types when initializing type '_Float16' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
112 (__v16hi) { glob_bfloat_vec }; /* { dg-error {incompatible types when initializing type 'short int' using type '__m256bf16' {aka '__vector\(16\) __bf16'}} } */
113
114 /* Casting. */
115
116 (void) glob_bfloat_vec;
117 (__m256bf16) glob_bfloat_vec;
118
119 (__bf16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
120 (short) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m256bf16' {aka '__vector\(16\) __bf16'} to type 'short int' which has different size} } */
121 (int) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m256bf16' {aka '__vector\(16\) __bf16'} to type 'int' which has different size} } */
122 (_Float16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
123 (float) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
124 (double) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */
125
126 (__v8si) glob_bfloat_vec;
127 (__m256) glob_bfloat_vec;
128 (__m256h) glob_bfloat_vec;
129 (__m256i) glob_bfloat_vec;
130 (__v16hi) glob_bfloat_vec;
131
132 (__m256bf16) is_an_int_vec;
133 (__m256bf16) is_a_float_vec;
134 (__m256bf16) is_a_float16_vec;
135 (__m256bf16) is_a_long_int_pair;
136 (__m256bf16) is_a_short_vec;
137
138 /* Arrays and Structs. */
139
140 typedef __m256bf16 array_type[2];
141 extern __m256bf16 extern_array[];
142
143 __m256bf16 array[2];
144 __m256bf16 zero_length_array[0];
145 __m256bf16 empty_init_array[] = {};
146 typedef __m256bf16 some_other_type[is_an_int];
147
148 struct struct1 {
149 __m256bf16 a;
150 };
151
152 union union1 {
153 __m256bf16 a;
154 };
155
156 /* Addressing and dereferencing. */
157
158 __m256bf16 *bfloat_ptr = &vector0;
159 vector0 = *bfloat_ptr;
160
161 /* Pointer assignment. */
162
163 __m256bf16 *bfloat_ptr2 = bfloat_ptr;
164 __m256bf16 *bfloat_ptr3 = array;
165
166 /* Pointer arithmetic. */
167
168 ++bfloat_ptr;
169 --bfloat_ptr;
170 bfloat_ptr++;
171 bfloat_ptr--;
172 bfloat_ptr += 1;
173 bfloat_ptr -= 1;
174 bfloat_ptr - bfloat_ptr2;
175 bfloat_ptr = &bfloat_ptr3[0];
176 bfloat_ptr = &bfloat_ptr3[1];
177
178 /* Simple comparison. */
179 vector0 > glob_bfloat_vec;
180 glob_bfloat_vec == vector0;
181 vector0 > is_a_float_vec; /* { dg-error {comparing vectors with different element types} } */
182 is_a_float_vec == vector0; /* { dg-error {comparing vectors with different element types} } */
183 vector0 > 0;
184 0 == vector0;
185 vector0 > 0.1; /* { dg-error {conversion of scalar 'double' to vector '__m256bf16'} } */
186 0.1 == vector0; /* { dg-error {conversion of scalar 'double' to vector '__m256bf16'} } */
187 vector0 > is_an_int_vec; /* { dg-error {comparing vectors with different element types} } */
188 is_an_int_vec == vector0; /* { dg-error {comparing vectors with different element types} } */
189
190 /* Pointer comparison. */
191
192 bfloat_ptr == &vector0;
193 bfloat_ptr != &vector0;
194 bfloat_ptr < &vector0;
195 bfloat_ptr <= &vector0;
196 bfloat_ptr > &vector0;
197 bfloat_ptr >= &vector0;
198 bfloat_ptr == bfloat_ptr2;
199 bfloat_ptr != bfloat_ptr2;
200 bfloat_ptr < bfloat_ptr2;
201 bfloat_ptr <= bfloat_ptr2;
202 bfloat_ptr > bfloat_ptr2;
203 bfloat_ptr >= bfloat_ptr2;
204
205 /* Conditional expressions. */
206
207 0 ? vector0 : vector0;
208 0 ? vector0 : is_a_float_vec; /* { dg-error {type mismatch in conditional expression} } */
209 0 ? is_a_float_vec : vector0; /* { dg-error {type mismatch in conditional expression} } */
210 0 ? vector0 : is_a_float16_vec; /* { dg-error {type mismatch in conditional expression} } */
211 0 ? is_a_float16_vec : vector0; /* { dg-error {type mismatch in conditional expression} } */
212 0 ? vector0 : 0; /* { dg-error {type mismatch in conditional expression} } */
213 0 ? 0 : vector0; /* { dg-error {type mismatch in conditional expression} } */
214 0 ? 0.1 : vector0; /* { dg-error {type mismatch in conditional expression} } */
215 0 ? vector0 : 0.1; /* { dg-error {type mismatch in conditional expression} } */
216 0 ? bfloat_ptr : bfloat_ptr2;
217 0 ? bfloat_ptr : float_ptr; /* { dg-error {pointer type mismatch in conditional expression} } */
218 0 ? float_ptr : bfloat_ptr; /* { dg-error {pointer type mismatch in conditional expression} } */
219
220 vector0 ? vector0 : vector0; /* { dg-error {used vector type where scalar is required} } */
221 vector0 ? is_a_float16_vec : vector0; /* { dg-error {used vector type where scalar is required} } */
222 vector0 ? vector0 : is_a_float16_vec; /* { dg-error {used vector type where scalar is required} } */
223 vector0 ? is_a_float16_vec : is_a_float16_vec; /* { dg-error {used vector type where scalar is required} } */
224
225 /* Unary operators. */
226
227 +vector0;
228 -vector0;
229 ~vector0; /* { dg-error {wrong type argument to bit-complement} } */
230 !vector0; /* { dg-error {wrong type argument to unary exclamation mark} } */
231 *vector0; /* { dg-error {invalid type argument of unary '\*'} } */
232 __real vector0; /* { dg-error {wrong type argument to __real} } */
233 __imag vector0; /* { dg-error {wrong type argument to __imag} } */
234 ++vector0;
235 --vector0;
236 vector0++;
237 vector0--;
238
239 /* Binary arithmetic operations. */
240
241 vector0 = glob_bfloat_vec + *bfloat_ptr;
242 vector0 = glob_bfloat_vec + 0.1; /* { dg-error {conversion of scalar 'double' to vector '__m256bf16'} } */
243 vector0 = glob_bfloat_vec + 0;
244 vector0 = glob_bfloat_vec + is_a_float_vec; /* { dg-error {invalid operands to binary \+} } */
245
246 return vector0;
247 }
248