]>
Commit | Line | Data |
---|---|---|
385399a8 | 1 | /* Tree-based target query functions relating to optabs |
99dee823 | 2 | Copyright (C) 1987-2021 Free Software Foundation, Inc. |
385399a8 RS |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 3, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | #include "target.h" | |
25 | #include "insn-codes.h" | |
dcd2ca63 | 26 | #include "rtl.h" |
385399a8 | 27 | #include "tree.h" |
dcd2ca63 IL |
28 | #include "memmodel.h" |
29 | #include "optabs.h" | |
385399a8 RS |
30 | #include "optabs-tree.h" |
31 | #include "stor-layout.h" | |
32 | ||
33 | /* Return the optab used for computing the operation given by the tree code, | |
34 | CODE and the tree EXP. This function is not always usable (for example, it | |
35 | cannot give complete results for multiplication or division) but probably | |
36 | ought to be relied on more widely throughout the expander. */ | |
37 | optab | |
38 | optab_for_tree_code (enum tree_code code, const_tree type, | |
39 | enum optab_subtype subtype) | |
40 | { | |
41 | bool trapv; | |
42 | switch (code) | |
43 | { | |
44 | case BIT_AND_EXPR: | |
45 | return and_optab; | |
46 | ||
47 | case BIT_IOR_EXPR: | |
48 | return ior_optab; | |
49 | ||
50 | case BIT_NOT_EXPR: | |
51 | return one_cmpl_optab; | |
52 | ||
53 | case BIT_XOR_EXPR: | |
54 | return xor_optab; | |
55 | ||
56 | case MULT_HIGHPART_EXPR: | |
57 | return TYPE_UNSIGNED (type) ? umul_highpart_optab : smul_highpart_optab; | |
58 | ||
59 | case TRUNC_MOD_EXPR: | |
60 | case CEIL_MOD_EXPR: | |
61 | case FLOOR_MOD_EXPR: | |
62 | case ROUND_MOD_EXPR: | |
63 | return TYPE_UNSIGNED (type) ? umod_optab : smod_optab; | |
64 | ||
65 | case RDIV_EXPR: | |
66 | case TRUNC_DIV_EXPR: | |
67 | case CEIL_DIV_EXPR: | |
68 | case FLOOR_DIV_EXPR: | |
69 | case ROUND_DIV_EXPR: | |
70 | case EXACT_DIV_EXPR: | |
71 | if (TYPE_SATURATING (type)) | |
72 | return TYPE_UNSIGNED (type) ? usdiv_optab : ssdiv_optab; | |
73 | return TYPE_UNSIGNED (type) ? udiv_optab : sdiv_optab; | |
74 | ||
75 | case LSHIFT_EXPR: | |
76 | if (TREE_CODE (type) == VECTOR_TYPE) | |
77 | { | |
78 | if (subtype == optab_vector) | |
79 | return TYPE_SATURATING (type) ? unknown_optab : vashl_optab; | |
80 | ||
81 | gcc_assert (subtype == optab_scalar); | |
82 | } | |
83 | if (TYPE_SATURATING (type)) | |
84 | return TYPE_UNSIGNED (type) ? usashl_optab : ssashl_optab; | |
85 | return ashl_optab; | |
86 | ||
87 | case RSHIFT_EXPR: | |
88 | if (TREE_CODE (type) == VECTOR_TYPE) | |
89 | { | |
90 | if (subtype == optab_vector) | |
91 | return TYPE_UNSIGNED (type) ? vlshr_optab : vashr_optab; | |
92 | ||
93 | gcc_assert (subtype == optab_scalar); | |
94 | } | |
95 | return TYPE_UNSIGNED (type) ? lshr_optab : ashr_optab; | |
96 | ||
97 | case LROTATE_EXPR: | |
98 | if (TREE_CODE (type) == VECTOR_TYPE) | |
99 | { | |
100 | if (subtype == optab_vector) | |
101 | return vrotl_optab; | |
102 | ||
103 | gcc_assert (subtype == optab_scalar); | |
104 | } | |
105 | return rotl_optab; | |
106 | ||
107 | case RROTATE_EXPR: | |
108 | if (TREE_CODE (type) == VECTOR_TYPE) | |
109 | { | |
110 | if (subtype == optab_vector) | |
111 | return vrotr_optab; | |
112 | ||
113 | gcc_assert (subtype == optab_scalar); | |
114 | } | |
115 | return rotr_optab; | |
116 | ||
117 | case MAX_EXPR: | |
118 | return TYPE_UNSIGNED (type) ? umax_optab : smax_optab; | |
119 | ||
120 | case MIN_EXPR: | |
121 | return TYPE_UNSIGNED (type) ? umin_optab : smin_optab; | |
122 | ||
123 | case REALIGN_LOAD_EXPR: | |
124 | return vec_realign_load_optab; | |
125 | ||
126 | case WIDEN_SUM_EXPR: | |
127 | return TYPE_UNSIGNED (type) ? usum_widen_optab : ssum_widen_optab; | |
128 | ||
129 | case DOT_PROD_EXPR: | |
130 | return TYPE_UNSIGNED (type) ? udot_prod_optab : sdot_prod_optab; | |
131 | ||
132 | case SAD_EXPR: | |
133 | return TYPE_UNSIGNED (type) ? usad_optab : ssad_optab; | |
134 | ||
135 | case WIDEN_MULT_PLUS_EXPR: | |
136 | return (TYPE_UNSIGNED (type) | |
137 | ? (TYPE_SATURATING (type) | |
138 | ? usmadd_widen_optab : umadd_widen_optab) | |
139 | : (TYPE_SATURATING (type) | |
140 | ? ssmadd_widen_optab : smadd_widen_optab)); | |
141 | ||
142 | case WIDEN_MULT_MINUS_EXPR: | |
143 | return (TYPE_UNSIGNED (type) | |
144 | ? (TYPE_SATURATING (type) | |
145 | ? usmsub_widen_optab : umsub_widen_optab) | |
146 | : (TYPE_SATURATING (type) | |
147 | ? ssmsub_widen_optab : smsub_widen_optab)); | |
148 | ||
385399a8 | 149 | case VEC_WIDEN_MULT_HI_EXPR: |
1bda738b JJ |
150 | return (TYPE_UNSIGNED (type) |
151 | ? vec_widen_umult_hi_optab : vec_widen_smult_hi_optab); | |
385399a8 RS |
152 | |
153 | case VEC_WIDEN_MULT_LO_EXPR: | |
1bda738b JJ |
154 | return (TYPE_UNSIGNED (type) |
155 | ? vec_widen_umult_lo_optab : vec_widen_smult_lo_optab); | |
385399a8 RS |
156 | |
157 | case VEC_WIDEN_MULT_EVEN_EXPR: | |
1bda738b JJ |
158 | return (TYPE_UNSIGNED (type) |
159 | ? vec_widen_umult_even_optab : vec_widen_smult_even_optab); | |
385399a8 RS |
160 | |
161 | case VEC_WIDEN_MULT_ODD_EXPR: | |
1bda738b JJ |
162 | return (TYPE_UNSIGNED (type) |
163 | ? vec_widen_umult_odd_optab : vec_widen_smult_odd_optab); | |
385399a8 RS |
164 | |
165 | case VEC_WIDEN_LSHIFT_HI_EXPR: | |
1bda738b JJ |
166 | return (TYPE_UNSIGNED (type) |
167 | ? vec_widen_ushiftl_hi_optab : vec_widen_sshiftl_hi_optab); | |
385399a8 RS |
168 | |
169 | case VEC_WIDEN_LSHIFT_LO_EXPR: | |
1bda738b JJ |
170 | return (TYPE_UNSIGNED (type) |
171 | ? vec_widen_ushiftl_lo_optab : vec_widen_sshiftl_lo_optab); | |
385399a8 | 172 | |
9fc9573f JH |
173 | case VEC_WIDEN_PLUS_LO_EXPR: |
174 | return (TYPE_UNSIGNED (type) | |
175 | ? vec_widen_uaddl_lo_optab : vec_widen_saddl_lo_optab); | |
176 | ||
177 | case VEC_WIDEN_PLUS_HI_EXPR: | |
178 | return (TYPE_UNSIGNED (type) | |
179 | ? vec_widen_uaddl_hi_optab : vec_widen_saddl_hi_optab); | |
180 | ||
181 | case VEC_WIDEN_MINUS_LO_EXPR: | |
182 | return (TYPE_UNSIGNED (type) | |
183 | ? vec_widen_usubl_lo_optab : vec_widen_ssubl_lo_optab); | |
184 | ||
185 | case VEC_WIDEN_MINUS_HI_EXPR: | |
186 | return (TYPE_UNSIGNED (type) | |
187 | ? vec_widen_usubl_hi_optab : vec_widen_ssubl_hi_optab); | |
188 | ||
385399a8 | 189 | case VEC_UNPACK_HI_EXPR: |
1bda738b JJ |
190 | return (TYPE_UNSIGNED (type) |
191 | ? vec_unpacku_hi_optab : vec_unpacks_hi_optab); | |
385399a8 RS |
192 | |
193 | case VEC_UNPACK_LO_EXPR: | |
1bda738b JJ |
194 | return (TYPE_UNSIGNED (type) |
195 | ? vec_unpacku_lo_optab : vec_unpacks_lo_optab); | |
385399a8 RS |
196 | |
197 | case VEC_UNPACK_FLOAT_HI_EXPR: | |
198 | /* The signedness is determined from input operand. */ | |
1bda738b JJ |
199 | return (TYPE_UNSIGNED (type) |
200 | ? vec_unpacku_float_hi_optab : vec_unpacks_float_hi_optab); | |
385399a8 RS |
201 | |
202 | case VEC_UNPACK_FLOAT_LO_EXPR: | |
203 | /* The signedness is determined from input operand. */ | |
1bda738b JJ |
204 | return (TYPE_UNSIGNED (type) |
205 | ? vec_unpacku_float_lo_optab : vec_unpacks_float_lo_optab); | |
206 | ||
207 | case VEC_UNPACK_FIX_TRUNC_HI_EXPR: | |
208 | /* The signedness is determined from output operand. */ | |
209 | return (TYPE_UNSIGNED (type) | |
210 | ? vec_unpack_ufix_trunc_hi_optab | |
211 | : vec_unpack_sfix_trunc_hi_optab); | |
212 | ||
213 | case VEC_UNPACK_FIX_TRUNC_LO_EXPR: | |
214 | /* The signedness is determined from output operand. */ | |
215 | return (TYPE_UNSIGNED (type) | |
216 | ? vec_unpack_ufix_trunc_lo_optab | |
217 | : vec_unpack_sfix_trunc_lo_optab); | |
385399a8 RS |
218 | |
219 | case VEC_PACK_TRUNC_EXPR: | |
220 | return vec_pack_trunc_optab; | |
221 | ||
222 | case VEC_PACK_SAT_EXPR: | |
223 | return TYPE_UNSIGNED (type) ? vec_pack_usat_optab : vec_pack_ssat_optab; | |
224 | ||
225 | case VEC_PACK_FIX_TRUNC_EXPR: | |
226 | /* The signedness is determined from output operand. */ | |
1bda738b JJ |
227 | return (TYPE_UNSIGNED (type) |
228 | ? vec_pack_ufix_trunc_optab : vec_pack_sfix_trunc_optab); | |
229 | ||
230 | case VEC_PACK_FLOAT_EXPR: | |
231 | /* The signedness is determined from input operand. */ | |
232 | return (TYPE_UNSIGNED (type) | |
233 | ? vec_packu_float_optab : vec_packs_float_optab); | |
385399a8 | 234 | |
be4c1d4a RS |
235 | case VEC_DUPLICATE_EXPR: |
236 | return vec_duplicate_optab; | |
237 | ||
9adab579 RS |
238 | case VEC_SERIES_EXPR: |
239 | return vec_series_optab; | |
240 | ||
385399a8 RS |
241 | default: |
242 | break; | |
243 | } | |
244 | ||
245 | trapv = INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type); | |
246 | switch (code) | |
247 | { | |
248 | case POINTER_PLUS_EXPR: | |
249 | case PLUS_EXPR: | |
250 | if (TYPE_SATURATING (type)) | |
251 | return TYPE_UNSIGNED (type) ? usadd_optab : ssadd_optab; | |
252 | return trapv ? addv_optab : add_optab; | |
253 | ||
1af4ebf5 | 254 | case POINTER_DIFF_EXPR: |
385399a8 RS |
255 | case MINUS_EXPR: |
256 | if (TYPE_SATURATING (type)) | |
257 | return TYPE_UNSIGNED (type) ? ussub_optab : sssub_optab; | |
258 | return trapv ? subv_optab : sub_optab; | |
259 | ||
260 | case MULT_EXPR: | |
261 | if (TYPE_SATURATING (type)) | |
262 | return TYPE_UNSIGNED (type) ? usmul_optab : ssmul_optab; | |
263 | return trapv ? smulv_optab : smul_optab; | |
264 | ||
265 | case NEGATE_EXPR: | |
266 | if (TYPE_SATURATING (type)) | |
267 | return TYPE_UNSIGNED (type) ? usneg_optab : ssneg_optab; | |
268 | return trapv ? negv_optab : neg_optab; | |
269 | ||
270 | case ABS_EXPR: | |
271 | return trapv ? absv_optab : abs_optab; | |
272 | ||
e197e64e KV |
273 | case ABSU_EXPR: |
274 | return abs_optab; | |
385399a8 RS |
275 | default: |
276 | return unknown_optab; | |
277 | } | |
278 | } | |
279 | ||
385399a8 RS |
280 | /* Function supportable_convert_operation |
281 | ||
282 | Check whether an operation represented by the code CODE is a | |
283 | convert operation that is supported by the target platform in | |
284 | vector form (i.e., when operating on arguments of type VECTYPE_IN | |
285 | producing a result of type VECTYPE_OUT). | |
286 | ||
287 | Convert operations we currently support directly are FIX_TRUNC and FLOAT. | |
288 | This function checks if these operations are supported | |
477daf83 | 289 | by the target platform directly (via vector tree-codes). |
385399a8 RS |
290 | |
291 | Output: | |
292 | - CODE1 is code of vector operation to be used when | |
477daf83 | 293 | vectorizing the operation, if available. */ |
385399a8 RS |
294 | |
295 | bool | |
296 | supportable_convert_operation (enum tree_code code, | |
297 | tree vectype_out, tree vectype_in, | |
477daf83 | 298 | enum tree_code *code1) |
385399a8 RS |
299 | { |
300 | machine_mode m1,m2; | |
301 | bool truncp; | |
302 | ||
b6268016 RS |
303 | gcc_assert (VECTOR_TYPE_P (vectype_out) && VECTOR_TYPE_P (vectype_in)); |
304 | ||
385399a8 RS |
305 | m1 = TYPE_MODE (vectype_out); |
306 | m2 = TYPE_MODE (vectype_in); | |
307 | ||
b6268016 RS |
308 | if (!VECTOR_MODE_P (m1) || !VECTOR_MODE_P (m2)) |
309 | return false; | |
310 | ||
385399a8 RS |
311 | /* First check if we can done conversion directly. */ |
312 | if ((code == FIX_TRUNC_EXPR | |
313 | && can_fix_p (m1,m2,TYPE_UNSIGNED (vectype_out), &truncp) | |
314 | != CODE_FOR_nothing) | |
315 | || (code == FLOAT_EXPR | |
316 | && can_float_p (m1,m2,TYPE_UNSIGNED (vectype_in)) | |
317 | != CODE_FOR_nothing)) | |
318 | { | |
319 | *code1 = code; | |
320 | return true; | |
321 | } | |
322 | ||
9c437a10 RS |
323 | if (GET_MODE_UNIT_PRECISION (m1) > GET_MODE_UNIT_PRECISION (m2) |
324 | && can_extend_p (m1, m2, TYPE_UNSIGNED (vectype_in))) | |
325 | { | |
326 | *code1 = code; | |
327 | return true; | |
328 | } | |
329 | ||
330 | if (GET_MODE_UNIT_PRECISION (m1) < GET_MODE_UNIT_PRECISION (m2) | |
331 | && convert_optab_handler (trunc_optab, m1, m2) != CODE_FOR_nothing) | |
332 | { | |
333 | *code1 = code; | |
334 | return true; | |
335 | } | |
336 | ||
385399a8 RS |
337 | return false; |
338 | } | |
339 | ||
3940daff IL |
340 | /* Return true iff vec_cmp_optab/vec_cmpu_optab can handle a vector comparison |
341 | for code CODE, comparing operands of type VALUE_TYPE and producing a result | |
342 | of type MASK_TYPE. */ | |
343 | ||
344 | static bool | |
345 | vec_cmp_icode_p (tree value_type, tree mask_type, enum tree_code code) | |
346 | { | |
347 | enum rtx_code rcode = get_rtx_code_1 (code, TYPE_UNSIGNED (value_type)); | |
348 | if (rcode == UNKNOWN) | |
349 | return false; | |
350 | ||
351 | return can_vec_cmp_compare_p (rcode, TYPE_MODE (value_type), | |
352 | TYPE_MODE (mask_type)); | |
353 | } | |
354 | ||
355 | /* Return true iff vec_cmpeq_optab can handle a vector comparison for code | |
356 | CODE, comparing operands of type VALUE_TYPE and producing a result of type | |
357 | MASK_TYPE. */ | |
358 | ||
359 | static bool | |
360 | vec_cmp_eq_icode_p (tree value_type, tree mask_type, enum tree_code code) | |
361 | { | |
362 | if (code != EQ_EXPR && code != NE_EXPR) | |
363 | return false; | |
364 | ||
365 | return get_vec_cmp_eq_icode (TYPE_MODE (value_type), TYPE_MODE (mask_type)) | |
366 | != CODE_FOR_nothing; | |
367 | } | |
368 | ||
42fd8198 IE |
369 | /* Return TRUE if appropriate vector insn is available |
370 | for vector comparison expr with vector type VALUE_TYPE | |
371 | and resulting mask with MASK_TYPE. */ | |
372 | ||
373 | bool | |
96592eed | 374 | expand_vec_cmp_expr_p (tree value_type, tree mask_type, enum tree_code code) |
42fd8198 | 375 | { |
3940daff IL |
376 | return vec_cmp_icode_p (value_type, mask_type, code) |
377 | || vec_cmp_eq_icode_p (value_type, mask_type, code); | |
42fd8198 IE |
378 | } |
379 | ||
dcd2ca63 IL |
380 | /* Return true iff vcond_optab/vcondu_optab can handle a vector |
381 | comparison for code CODE, comparing operands of type CMP_OP_TYPE and | |
382 | producing a result of type VALUE_TYPE. */ | |
383 | ||
384 | static bool | |
385 | vcond_icode_p (tree value_type, tree cmp_op_type, enum tree_code code) | |
386 | { | |
3940daff IL |
387 | enum rtx_code rcode = get_rtx_code_1 (code, TYPE_UNSIGNED (cmp_op_type)); |
388 | if (rcode == UNKNOWN) | |
389 | return false; | |
390 | ||
391 | return can_vcond_compare_p (rcode, TYPE_MODE (value_type), | |
392 | TYPE_MODE (cmp_op_type)); | |
dcd2ca63 IL |
393 | } |
394 | ||
395 | /* Return true iff vcondeq_optab can handle a vector comparison for code CODE, | |
396 | comparing operands of type CMP_OP_TYPE and producing a result of type | |
397 | VALUE_TYPE. */ | |
398 | ||
399 | static bool | |
400 | vcond_eq_icode_p (tree value_type, tree cmp_op_type, enum tree_code code) | |
401 | { | |
402 | if (code != EQ_EXPR && code != NE_EXPR) | |
403 | return false; | |
404 | ||
405 | return get_vcond_eq_icode (TYPE_MODE (value_type), TYPE_MODE (cmp_op_type)) | |
406 | != CODE_FOR_nothing; | |
407 | } | |
408 | ||
385399a8 RS |
409 | /* Return TRUE iff, appropriate vector insns are available |
410 | for vector cond expr with vector type VALUE_TYPE and a comparison | |
411 | with operand vector types in CMP_OP_TYPE. */ | |
412 | ||
413 | bool | |
96592eed | 414 | expand_vec_cond_expr_p (tree value_type, tree cmp_op_type, enum tree_code code) |
385399a8 RS |
415 | { |
416 | machine_mode value_mode = TYPE_MODE (value_type); | |
417 | machine_mode cmp_op_mode = TYPE_MODE (cmp_op_type); | |
0d99886f AP |
418 | if (VECTOR_BOOLEAN_TYPE_P (cmp_op_type) |
419 | && get_vcond_mask_icode (TYPE_MODE (value_type), | |
420 | TYPE_MODE (cmp_op_type)) != CODE_FOR_nothing) | |
421 | return true; | |
422 | ||
e29dd0eb | 423 | if (maybe_ne (GET_MODE_NUNITS (value_mode), GET_MODE_NUNITS (cmp_op_mode))) |
385399a8 | 424 | return false; |
96592eed | 425 | |
dcd2ca63 IL |
426 | if (TREE_CODE_CLASS (code) != tcc_comparison) |
427 | /* This may happen, for example, if code == SSA_NAME, in which case we | |
428 | cannot be certain whether a vector insn is available. */ | |
96592eed JJ |
429 | return false; |
430 | ||
dcd2ca63 IL |
431 | return vcond_icode_p (value_type, cmp_op_type, code) |
432 | || vcond_eq_icode_p (value_type, cmp_op_type, code); | |
385399a8 RS |
433 | } |
434 | ||
435 | /* Use the current target and options to initialize | |
436 | TREE_OPTIMIZATION_OPTABS (OPTNODE). */ | |
437 | ||
438 | void | |
439 | init_tree_optimization_optabs (tree optnode) | |
440 | { | |
441 | /* Quick exit if we have already computed optabs for this target. */ | |
442 | if (TREE_OPTIMIZATION_BASE_OPTABS (optnode) == this_target_optabs) | |
443 | return; | |
444 | ||
445 | /* Forget any previous information and set up for the current target. */ | |
446 | TREE_OPTIMIZATION_BASE_OPTABS (optnode) = this_target_optabs; | |
447 | struct target_optabs *tmp_optabs = (struct target_optabs *) | |
448 | TREE_OPTIMIZATION_OPTABS (optnode); | |
449 | if (tmp_optabs) | |
450 | memset (tmp_optabs, 0, sizeof (struct target_optabs)); | |
451 | else | |
bfaa08b7 | 452 | tmp_optabs = ggc_cleared_alloc<target_optabs> (); |
385399a8 RS |
453 | |
454 | /* Generate a new set of optabs into tmp_optabs. */ | |
455 | init_all_optabs (tmp_optabs); | |
456 | ||
457 | /* If the optabs changed, record it. */ | |
458 | if (memcmp (tmp_optabs, this_target_optabs, sizeof (struct target_optabs))) | |
459 | TREE_OPTIMIZATION_OPTABS (optnode) = tmp_optabs; | |
460 | else | |
461 | { | |
462 | TREE_OPTIMIZATION_OPTABS (optnode) = NULL; | |
463 | ggc_free (tmp_optabs); | |
464 | } | |
465 | } | |
71f82be9 JG |
466 | |
467 | /* Return TRUE if the target has support for vector right shift of an | |
468 | operand of type TYPE. If OT_TYPE is OPTAB_DEFAULT, check for existence | |
469 | of a shift by either a scalar or a vector. Otherwise, check only | |
470 | for a shift that matches OT_TYPE. */ | |
471 | ||
472 | bool | |
473 | target_supports_op_p (tree type, enum tree_code code, | |
474 | enum optab_subtype ot_subtype) | |
475 | { | |
476 | optab ot = optab_for_tree_code (code, type, ot_subtype); | |
477 | return (ot != unknown_optab | |
478 | && optab_handler (ot, TYPE_MODE (type)) != CODE_FOR_nothing); | |
479 | } | |
480 |