1 /* Tree-based target query functions relating to optabs
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
25 #include "insn-codes.h"
27 #include "optabs-tree.h"
28 #include "stor-layout.h"
30 /* Return the optab used for computing the operation given by the tree code,
31 CODE and the tree EXP. This function is not always usable (for example, it
32 cannot give complete results for multiplication or division) but probably
33 ought to be relied on more widely throughout the expander. */
35 optab_for_tree_code (enum tree_code code
, const_tree type
,
36 enum optab_subtype subtype
)
48 return one_cmpl_optab
;
53 case MULT_HIGHPART_EXPR
:
54 return TYPE_UNSIGNED (type
) ? umul_highpart_optab
: smul_highpart_optab
;
60 return TYPE_UNSIGNED (type
) ? umod_optab
: smod_optab
;
68 if (TYPE_SATURATING (type
))
69 return TYPE_UNSIGNED (type
) ? usdiv_optab
: ssdiv_optab
;
70 return TYPE_UNSIGNED (type
) ? udiv_optab
: sdiv_optab
;
73 if (TREE_CODE (type
) == VECTOR_TYPE
)
75 if (subtype
== optab_vector
)
76 return TYPE_SATURATING (type
) ? unknown_optab
: vashl_optab
;
78 gcc_assert (subtype
== optab_scalar
);
80 if (TYPE_SATURATING (type
))
81 return TYPE_UNSIGNED (type
) ? usashl_optab
: ssashl_optab
;
85 if (TREE_CODE (type
) == VECTOR_TYPE
)
87 if (subtype
== optab_vector
)
88 return TYPE_UNSIGNED (type
) ? vlshr_optab
: vashr_optab
;
90 gcc_assert (subtype
== optab_scalar
);
92 return TYPE_UNSIGNED (type
) ? lshr_optab
: ashr_optab
;
95 if (TREE_CODE (type
) == VECTOR_TYPE
)
97 if (subtype
== optab_vector
)
100 gcc_assert (subtype
== optab_scalar
);
105 if (TREE_CODE (type
) == VECTOR_TYPE
)
107 if (subtype
== optab_vector
)
110 gcc_assert (subtype
== optab_scalar
);
115 return TYPE_UNSIGNED (type
) ? umax_optab
: smax_optab
;
118 return TYPE_UNSIGNED (type
) ? umin_optab
: smin_optab
;
120 case REALIGN_LOAD_EXPR
:
121 return vec_realign_load_optab
;
124 return TYPE_UNSIGNED (type
) ? usum_widen_optab
: ssum_widen_optab
;
127 return TYPE_UNSIGNED (type
) ? udot_prod_optab
: sdot_prod_optab
;
130 return TYPE_UNSIGNED (type
) ? usad_optab
: ssad_optab
;
132 case WIDEN_MULT_PLUS_EXPR
:
133 return (TYPE_UNSIGNED (type
)
134 ? (TYPE_SATURATING (type
)
135 ? usmadd_widen_optab
: umadd_widen_optab
)
136 : (TYPE_SATURATING (type
)
137 ? ssmadd_widen_optab
: smadd_widen_optab
));
139 case WIDEN_MULT_MINUS_EXPR
:
140 return (TYPE_UNSIGNED (type
)
141 ? (TYPE_SATURATING (type
)
142 ? usmsub_widen_optab
: umsub_widen_optab
)
143 : (TYPE_SATURATING (type
)
144 ? ssmsub_widen_optab
: smsub_widen_optab
));
146 case VEC_WIDEN_MULT_HI_EXPR
:
147 return TYPE_UNSIGNED (type
) ?
148 vec_widen_umult_hi_optab
: vec_widen_smult_hi_optab
;
150 case VEC_WIDEN_MULT_LO_EXPR
:
151 return TYPE_UNSIGNED (type
) ?
152 vec_widen_umult_lo_optab
: vec_widen_smult_lo_optab
;
154 case VEC_WIDEN_MULT_EVEN_EXPR
:
155 return TYPE_UNSIGNED (type
) ?
156 vec_widen_umult_even_optab
: vec_widen_smult_even_optab
;
158 case VEC_WIDEN_MULT_ODD_EXPR
:
159 return TYPE_UNSIGNED (type
) ?
160 vec_widen_umult_odd_optab
: vec_widen_smult_odd_optab
;
162 case VEC_WIDEN_LSHIFT_HI_EXPR
:
163 return TYPE_UNSIGNED (type
) ?
164 vec_widen_ushiftl_hi_optab
: vec_widen_sshiftl_hi_optab
;
166 case VEC_WIDEN_LSHIFT_LO_EXPR
:
167 return TYPE_UNSIGNED (type
) ?
168 vec_widen_ushiftl_lo_optab
: vec_widen_sshiftl_lo_optab
;
170 case VEC_UNPACK_HI_EXPR
:
171 return TYPE_UNSIGNED (type
) ?
172 vec_unpacku_hi_optab
: vec_unpacks_hi_optab
;
174 case VEC_UNPACK_LO_EXPR
:
175 return TYPE_UNSIGNED (type
) ?
176 vec_unpacku_lo_optab
: vec_unpacks_lo_optab
;
178 case VEC_UNPACK_FLOAT_HI_EXPR
:
179 /* The signedness is determined from input operand. */
180 return TYPE_UNSIGNED (type
) ?
181 vec_unpacku_float_hi_optab
: vec_unpacks_float_hi_optab
;
183 case VEC_UNPACK_FLOAT_LO_EXPR
:
184 /* The signedness is determined from input operand. */
185 return TYPE_UNSIGNED (type
) ?
186 vec_unpacku_float_lo_optab
: vec_unpacks_float_lo_optab
;
188 case VEC_PACK_TRUNC_EXPR
:
189 return vec_pack_trunc_optab
;
191 case VEC_PACK_SAT_EXPR
:
192 return TYPE_UNSIGNED (type
) ? vec_pack_usat_optab
: vec_pack_ssat_optab
;
194 case VEC_PACK_FIX_TRUNC_EXPR
:
195 /* The signedness is determined from output operand. */
196 return TYPE_UNSIGNED (type
) ?
197 vec_pack_ufix_trunc_optab
: vec_pack_sfix_trunc_optab
;
199 case VEC_DUPLICATE_EXPR
:
200 return vec_duplicate_optab
;
202 case VEC_SERIES_EXPR
:
203 return vec_series_optab
;
209 trapv
= INTEGRAL_TYPE_P (type
) && TYPE_OVERFLOW_TRAPS (type
);
212 case POINTER_PLUS_EXPR
:
214 if (TYPE_SATURATING (type
))
215 return TYPE_UNSIGNED (type
) ? usadd_optab
: ssadd_optab
;
216 return trapv
? addv_optab
: add_optab
;
218 case POINTER_DIFF_EXPR
:
220 if (TYPE_SATURATING (type
))
221 return TYPE_UNSIGNED (type
) ? ussub_optab
: sssub_optab
;
222 return trapv
? subv_optab
: sub_optab
;
225 if (TYPE_SATURATING (type
))
226 return TYPE_UNSIGNED (type
) ? usmul_optab
: ssmul_optab
;
227 return trapv
? smulv_optab
: smul_optab
;
230 if (TYPE_SATURATING (type
))
231 return TYPE_UNSIGNED (type
) ? usneg_optab
: ssneg_optab
;
232 return trapv
? negv_optab
: neg_optab
;
235 return trapv
? absv_optab
: abs_optab
;
238 return unknown_optab
;
242 /* Function supportable_convert_operation
244 Check whether an operation represented by the code CODE is a
245 convert operation that is supported by the target platform in
246 vector form (i.e., when operating on arguments of type VECTYPE_IN
247 producing a result of type VECTYPE_OUT).
249 Convert operations we currently support directly are FIX_TRUNC and FLOAT.
250 This function checks if these operations are supported
251 by the target platform either directly (via vector tree-codes), or via
255 - CODE1 is code of vector operation to be used when
256 vectorizing the operation, if available.
257 - DECL is decl of target builtin functions to be used
258 when vectorizing the operation, if available. In this case,
259 CODE1 is CALL_EXPR. */
262 supportable_convert_operation (enum tree_code code
,
263 tree vectype_out
, tree vectype_in
,
264 tree
*decl
, enum tree_code
*code1
)
269 m1
= TYPE_MODE (vectype_out
);
270 m2
= TYPE_MODE (vectype_in
);
272 /* First check if we can done conversion directly. */
273 if ((code
== FIX_TRUNC_EXPR
274 && can_fix_p (m1
,m2
,TYPE_UNSIGNED (vectype_out
), &truncp
)
276 || (code
== FLOAT_EXPR
277 && can_float_p (m1
,m2
,TYPE_UNSIGNED (vectype_in
))
278 != CODE_FOR_nothing
))
284 /* Now check for builtin. */
285 if (targetm
.vectorize
.builtin_conversion
286 && targetm
.vectorize
.builtin_conversion (code
, vectype_out
, vectype_in
))
289 *decl
= targetm
.vectorize
.builtin_conversion (code
, vectype_out
,
296 /* Return TRUE if appropriate vector insn is available
297 for vector comparison expr with vector type VALUE_TYPE
298 and resulting mask with MASK_TYPE. */
301 expand_vec_cmp_expr_p (tree value_type
, tree mask_type
, enum tree_code code
)
303 if (get_vec_cmp_icode (TYPE_MODE (value_type
), TYPE_MODE (mask_type
),
304 TYPE_UNSIGNED (value_type
)) != CODE_FOR_nothing
)
306 if ((code
== EQ_EXPR
|| code
== NE_EXPR
)
307 && (get_vec_cmp_eq_icode (TYPE_MODE (value_type
), TYPE_MODE (mask_type
))
308 != CODE_FOR_nothing
))
313 /* Return TRUE iff, appropriate vector insns are available
314 for vector cond expr with vector type VALUE_TYPE and a comparison
315 with operand vector types in CMP_OP_TYPE. */
318 expand_vec_cond_expr_p (tree value_type
, tree cmp_op_type
, enum tree_code code
)
320 machine_mode value_mode
= TYPE_MODE (value_type
);
321 machine_mode cmp_op_mode
= TYPE_MODE (cmp_op_type
);
322 if (VECTOR_BOOLEAN_TYPE_P (cmp_op_type
)
323 && get_vcond_mask_icode (TYPE_MODE (value_type
),
324 TYPE_MODE (cmp_op_type
)) != CODE_FOR_nothing
)
327 if (maybe_ne (GET_MODE_SIZE (value_mode
), GET_MODE_SIZE (cmp_op_mode
))
328 || maybe_ne (GET_MODE_NUNITS (value_mode
), GET_MODE_NUNITS (cmp_op_mode
)))
331 if (get_vcond_icode (TYPE_MODE (value_type
), TYPE_MODE (cmp_op_type
),
332 TYPE_UNSIGNED (cmp_op_type
)) == CODE_FOR_nothing
333 && ((code
!= EQ_EXPR
&& code
!= NE_EXPR
)
334 || get_vcond_eq_icode (TYPE_MODE (value_type
),
335 TYPE_MODE (cmp_op_type
)) == CODE_FOR_nothing
))
341 /* Use the current target and options to initialize
342 TREE_OPTIMIZATION_OPTABS (OPTNODE). */
345 init_tree_optimization_optabs (tree optnode
)
347 /* Quick exit if we have already computed optabs for this target. */
348 if (TREE_OPTIMIZATION_BASE_OPTABS (optnode
) == this_target_optabs
)
351 /* Forget any previous information and set up for the current target. */
352 TREE_OPTIMIZATION_BASE_OPTABS (optnode
) = this_target_optabs
;
353 struct target_optabs
*tmp_optabs
= (struct target_optabs
*)
354 TREE_OPTIMIZATION_OPTABS (optnode
);
356 memset (tmp_optabs
, 0, sizeof (struct target_optabs
));
358 tmp_optabs
= ggc_cleared_alloc
<target_optabs
> ();
360 /* Generate a new set of optabs into tmp_optabs. */
361 init_all_optabs (tmp_optabs
);
363 /* If the optabs changed, record it. */
364 if (memcmp (tmp_optabs
, this_target_optabs
, sizeof (struct target_optabs
)))
365 TREE_OPTIMIZATION_OPTABS (optnode
) = tmp_optabs
;
368 TREE_OPTIMIZATION_OPTABS (optnode
) = NULL
;
369 ggc_free (tmp_optabs
);
373 /* Return TRUE if the target has support for vector right shift of an
374 operand of type TYPE. If OT_TYPE is OPTAB_DEFAULT, check for existence
375 of a shift by either a scalar or a vector. Otherwise, check only
376 for a shift that matches OT_TYPE. */
379 target_supports_op_p (tree type
, enum tree_code code
,
380 enum optab_subtype ot_subtype
)
382 optab ot
= optab_for_tree_code (code
, type
, ot_subtype
);
383 return (ot
!= unknown_optab
384 && optab_handler (ot
, TYPE_MODE (type
)) != CODE_FOR_nothing
);