Daily bump.
[official-gcc.git] / gcc / tree-vectorizer.h
blobbd6f334d15fae4ffbe8c5ffb496ed0a820971638
1 /* Vectorizer
2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_TREE_VECTORIZER_H
22 #define GCC_TREE_VECTORIZER_H
24 typedef class _stmt_vec_info *stmt_vec_info;
26 #include "tree-data-ref.h"
27 #include "tree-hash-traits.h"
28 #include "target.h"
29 #include "internal-fn.h"
30 #include "tree-ssa-operands.h"
32 /* Used for naming of new temporaries. */
33 enum vect_var_kind {
34 vect_simple_var,
35 vect_pointer_var,
36 vect_scalar_var,
37 vect_mask_var
40 /* Defines type of operation. */
41 enum operation_type {
42 unary_op = 1,
43 binary_op,
44 ternary_op
47 /* Define type of available alignment support. */
48 enum dr_alignment_support {
49 dr_unaligned_unsupported,
50 dr_unaligned_supported,
51 dr_explicit_realign,
52 dr_explicit_realign_optimized,
53 dr_aligned
56 /* Define type of def-use cross-iteration cycle. */
57 enum vect_def_type {
58 vect_uninitialized_def = 0,
59 vect_constant_def = 1,
60 vect_external_def,
61 vect_internal_def,
62 vect_induction_def,
63 vect_reduction_def,
64 vect_double_reduction_def,
65 vect_nested_cycle,
66 vect_unknown_def_type
69 /* Define type of reduction. */
70 enum vect_reduction_type {
71 TREE_CODE_REDUCTION,
72 COND_REDUCTION,
73 INTEGER_INDUC_COND_REDUCTION,
74 CONST_COND_REDUCTION,
76 /* Retain a scalar phi and use a FOLD_EXTRACT_LAST within the loop
77 to implement:
79 for (int i = 0; i < VF; ++i)
80 res = cond[i] ? val[i] : res; */
81 EXTRACT_LAST_REDUCTION,
83 /* Use a folding reduction within the loop to implement:
85 for (int i = 0; i < VF; ++i)
86 res = res OP val[i];
88 (with no reassocation). */
89 FOLD_LEFT_REDUCTION
92 #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
93 || ((D) == vect_double_reduction_def) \
94 || ((D) == vect_nested_cycle))
96 /* Structure to encapsulate information about a group of like
97 instructions to be presented to the target cost model. */
98 struct stmt_info_for_cost {
99 int count;
100 enum vect_cost_for_stmt kind;
101 enum vect_cost_model_location where;
102 stmt_vec_info stmt_info;
103 tree vectype;
104 int misalign;
107 typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
109 /* Maps base addresses to an innermost_loop_behavior and the stmt it was
110 derived from that gives the maximum known alignment for that base. */
111 typedef hash_map<tree_operand_hash,
112 std::pair<stmt_vec_info, innermost_loop_behavior *> >
113 vec_base_alignments;
115 /************************************************************************
117 ************************************************************************/
118 typedef struct _slp_tree *slp_tree;
119 typedef vec<std::pair<unsigned, unsigned> > lane_permutation_t;
120 typedef vec<unsigned> load_permutation_t;
122 /* A computation tree of an SLP instance. Each node corresponds to a group of
123 stmts to be packed in a SIMD stmt. */
124 struct _slp_tree {
125 _slp_tree ();
126 ~_slp_tree ();
128 /* Nodes that contain def-stmts of this node statements operands. */
129 vec<slp_tree> children;
131 /* A group of scalar stmts to be vectorized together. */
132 vec<stmt_vec_info> stmts;
133 /* A group of scalar operands to be vectorized together. */
134 vec<tree> ops;
135 /* The representative that should be used for analysis and
136 code generation. */
137 stmt_vec_info representative;
139 /* Load permutation relative to the stores, NULL if there is no
140 permutation. */
141 load_permutation_t load_permutation;
142 /* Lane permutation of the operands scalar lanes encoded as pairs
143 of { operand number, lane number }. The number of elements
144 denotes the number of output lanes. */
145 lane_permutation_t lane_permutation;
147 tree vectype;
148 /* Vectorized stmt/s. */
149 vec<gimple *> vec_stmts;
150 vec<tree> vec_defs;
151 /* Number of vector stmts that are created to replace the group of scalar
152 stmts. It is calculated during the transformation phase as the number of
153 scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
154 divided by vector size. */
155 unsigned int vec_stmts_size;
157 /* Reference count in the SLP graph. */
158 unsigned int refcnt;
159 /* The maximum number of vector elements for the subtree rooted
160 at this node. */
161 poly_uint64 max_nunits;
162 /* The DEF type of this node. */
163 enum vect_def_type def_type;
164 /* The number of scalar lanes produced by this node. */
165 unsigned int lanes;
166 /* The operation of this node. */
167 enum tree_code code;
169 int vertex;
171 /* If not NULL this is a cached failed SLP discovery attempt with
172 the lanes that failed during SLP discovery as 'false'. This is
173 a copy of the matches array. */
174 bool *failed;
176 /* Allocate from slp_tree_pool. */
177 static void *operator new (size_t);
179 /* Return memory to slp_tree_pool. */
180 static void operator delete (void *, size_t);
182 /* Linked list of nodes to release when we free the slp_tree_pool. */
183 slp_tree next_node;
184 slp_tree prev_node;
187 /* The enum describes the type of operations that an SLP instance
188 can perform. */
190 enum slp_instance_kind {
191 slp_inst_kind_store,
192 slp_inst_kind_reduc_group,
193 slp_inst_kind_reduc_chain,
194 slp_inst_kind_bb_reduc,
195 slp_inst_kind_ctor
198 /* SLP instance is a sequence of stmts in a loop that can be packed into
199 SIMD stmts. */
200 typedef class _slp_instance {
201 public:
202 /* The root of SLP tree. */
203 slp_tree root;
205 /* For vector constructors, the constructor stmt that the SLP tree is built
206 from, NULL otherwise. */
207 vec<stmt_vec_info> root_stmts;
209 /* The unrolling factor required to vectorized this SLP instance. */
210 poly_uint64 unrolling_factor;
212 /* The group of nodes that contain loads of this SLP instance. */
213 vec<slp_tree> loads;
215 /* The SLP node containing the reduction PHIs. */
216 slp_tree reduc_phis;
218 /* Vector cost of this entry to the SLP graph. */
219 stmt_vector_for_cost cost_vec;
221 /* If this instance is the main entry of a subgraph the set of
222 entries into the same subgraph, including itself. */
223 vec<_slp_instance *> subgraph_entries;
225 /* The type of operation the SLP instance is performing. */
226 slp_instance_kind kind;
228 dump_user_location_t location () const;
229 } *slp_instance;
232 /* Access Functions. */
233 #define SLP_INSTANCE_TREE(S) (S)->root
234 #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
235 #define SLP_INSTANCE_LOADS(S) (S)->loads
236 #define SLP_INSTANCE_ROOT_STMTS(S) (S)->root_stmts
237 #define SLP_INSTANCE_KIND(S) (S)->kind
239 #define SLP_TREE_CHILDREN(S) (S)->children
240 #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
241 #define SLP_TREE_SCALAR_OPS(S) (S)->ops
242 #define SLP_TREE_REF_COUNT(S) (S)->refcnt
243 #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
244 #define SLP_TREE_VEC_DEFS(S) (S)->vec_defs
245 #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
246 #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
247 #define SLP_TREE_LANE_PERMUTATION(S) (S)->lane_permutation
248 #define SLP_TREE_DEF_TYPE(S) (S)->def_type
249 #define SLP_TREE_VECTYPE(S) (S)->vectype
250 #define SLP_TREE_REPRESENTATIVE(S) (S)->representative
251 #define SLP_TREE_LANES(S) (S)->lanes
252 #define SLP_TREE_CODE(S) (S)->code
254 /* Key for map that records association between
255 scalar conditions and corresponding loop mask, and
256 is populated by vect_record_loop_mask. */
258 struct scalar_cond_masked_key
260 scalar_cond_masked_key (tree t, unsigned ncopies_)
261 : ncopies (ncopies_)
263 get_cond_ops_from_tree (t);
266 void get_cond_ops_from_tree (tree);
268 unsigned ncopies;
269 bool inverted_p;
270 tree_code code;
271 tree op0;
272 tree op1;
275 template<>
276 struct default_hash_traits<scalar_cond_masked_key>
278 typedef scalar_cond_masked_key compare_type;
279 typedef scalar_cond_masked_key value_type;
281 static inline hashval_t
282 hash (value_type v)
284 inchash::hash h;
285 h.add_int (v.code);
286 inchash::add_expr (v.op0, h, 0);
287 inchash::add_expr (v.op1, h, 0);
288 h.add_int (v.ncopies);
289 h.add_flag (v.inverted_p);
290 return h.end ();
293 static inline bool
294 equal (value_type existing, value_type candidate)
296 return (existing.ncopies == candidate.ncopies
297 && existing.code == candidate.code
298 && existing.inverted_p == candidate.inverted_p
299 && operand_equal_p (existing.op0, candidate.op0, 0)
300 && operand_equal_p (existing.op1, candidate.op1, 0));
303 static const bool empty_zero_p = true;
305 static inline void
306 mark_empty (value_type &v)
308 v.ncopies = 0;
309 v.inverted_p = false;
312 static inline bool
313 is_empty (value_type v)
315 return v.ncopies == 0;
318 static inline void mark_deleted (value_type &) {}
320 static inline bool is_deleted (const value_type &)
322 return false;
325 static inline void remove (value_type &) {}
328 typedef hash_set<scalar_cond_masked_key> scalar_cond_masked_set_type;
330 /* Describes two objects whose addresses must be unequal for the vectorized
331 loop to be valid. */
332 typedef std::pair<tree, tree> vec_object_pair;
334 /* Records that vectorization is only possible if abs (EXPR) >= MIN_VALUE.
335 UNSIGNED_P is true if we can assume that abs (EXPR) == EXPR. */
336 class vec_lower_bound {
337 public:
338 vec_lower_bound () {}
339 vec_lower_bound (tree e, bool u, poly_uint64 m)
340 : expr (e), unsigned_p (u), min_value (m) {}
342 tree expr;
343 bool unsigned_p;
344 poly_uint64 min_value;
347 /* Vectorizer state shared between different analyses like vector sizes
348 of the same CFG region. */
349 class vec_info_shared {
350 public:
351 vec_info_shared();
352 ~vec_info_shared();
354 void save_datarefs();
355 void check_datarefs();
357 /* The number of scalar stmts. */
358 unsigned n_stmts;
360 /* All data references. Freed by free_data_refs, so not an auto_vec. */
361 vec<data_reference_p> datarefs;
362 vec<data_reference> datarefs_copy;
364 /* The loop nest in which the data dependences are computed. */
365 auto_vec<loop_p> loop_nest;
367 /* All data dependences. Freed by free_dependence_relations, so not
368 an auto_vec. */
369 vec<ddr_p> ddrs;
372 /* Vectorizer state common between loop and basic-block vectorization. */
373 class vec_info {
374 public:
375 typedef hash_set<int_hash<machine_mode, E_VOIDmode, E_BLKmode> > mode_set;
376 enum vec_kind { bb, loop };
378 vec_info (vec_kind, vec_info_shared *);
379 ~vec_info ();
381 stmt_vec_info add_stmt (gimple *);
382 stmt_vec_info add_pattern_stmt (gimple *, stmt_vec_info);
383 stmt_vec_info lookup_stmt (gimple *);
384 stmt_vec_info lookup_def (tree);
385 stmt_vec_info lookup_single_use (tree);
386 class dr_vec_info *lookup_dr (data_reference *);
387 void move_dr (stmt_vec_info, stmt_vec_info);
388 void remove_stmt (stmt_vec_info);
389 void replace_stmt (gimple_stmt_iterator *, stmt_vec_info, gimple *);
390 void insert_on_entry (stmt_vec_info, gimple *);
391 void insert_seq_on_entry (stmt_vec_info, gimple_seq);
393 /* The type of vectorization. */
394 vec_kind kind;
396 /* Shared vectorizer state. */
397 vec_info_shared *shared;
399 /* The mapping of GIMPLE UID to stmt_vec_info. */
400 vec<stmt_vec_info> stmt_vec_infos;
401 /* Whether the above mapping is complete. */
402 bool stmt_vec_info_ro;
404 /* The SLP graph. */
405 auto_vec<slp_instance> slp_instances;
407 /* Maps base addresses to an innermost_loop_behavior that gives the maximum
408 known alignment for that base. */
409 vec_base_alignments base_alignments;
411 /* All interleaving chains of stores, represented by the first
412 stmt in the chain. */
413 auto_vec<stmt_vec_info> grouped_stores;
415 /* The set of vector modes used in the vectorized region. */
416 mode_set used_vector_modes;
418 /* The argument we should pass to related_vector_mode when looking up
419 the vector mode for a scalar mode, or VOIDmode if we haven't yet
420 made any decisions about which vector modes to use. */
421 machine_mode vector_mode;
423 private:
424 stmt_vec_info new_stmt_vec_info (gimple *stmt);
425 void set_vinfo_for_stmt (gimple *, stmt_vec_info, bool = true);
426 void free_stmt_vec_infos ();
427 void free_stmt_vec_info (stmt_vec_info);
430 class _loop_vec_info;
431 class _bb_vec_info;
433 template<>
434 template<>
435 inline bool
436 is_a_helper <_loop_vec_info *>::test (vec_info *i)
438 return i->kind == vec_info::loop;
441 template<>
442 template<>
443 inline bool
444 is_a_helper <_bb_vec_info *>::test (vec_info *i)
446 return i->kind == vec_info::bb;
449 /* In general, we can divide the vector statements in a vectorized loop
450 into related groups ("rgroups") and say that for each rgroup there is
451 some nS such that the rgroup operates on nS values from one scalar
452 iteration followed by nS values from the next. That is, if VF is the
453 vectorization factor of the loop, the rgroup operates on a sequence:
455 (1,1) (1,2) ... (1,nS) (2,1) ... (2,nS) ... (VF,1) ... (VF,nS)
457 where (i,j) represents a scalar value with index j in a scalar
458 iteration with index i.
460 [ We use the term "rgroup" to emphasise that this grouping isn't
461 necessarily the same as the grouping of statements used elsewhere.
462 For example, if we implement a group of scalar loads using gather
463 loads, we'll use a separate gather load for each scalar load, and
464 thus each gather load will belong to its own rgroup. ]
466 In general this sequence will occupy nV vectors concatenated
467 together. If these vectors have nL lanes each, the total number
468 of scalar values N is given by:
470 N = nS * VF = nV * nL
472 None of nS, VF, nV and nL are required to be a power of 2. nS and nV
473 are compile-time constants but VF and nL can be variable (if the target
474 supports variable-length vectors).
476 In classical vectorization, each iteration of the vector loop would
477 handle exactly VF iterations of the original scalar loop. However,
478 in vector loops that are able to operate on partial vectors, a
479 particular iteration of the vector loop might handle fewer than VF
480 iterations of the scalar loop. The vector lanes that correspond to
481 iterations of the scalar loop are said to be "active" and the other
482 lanes are said to be "inactive".
484 In such vector loops, many rgroups need to be controlled to ensure
485 that they have no effect for the inactive lanes. Conceptually, each
486 such rgroup needs a sequence of booleans in the same order as above,
487 but with each (i,j) replaced by a boolean that indicates whether
488 iteration i is active. This sequence occupies nV vector controls
489 that again have nL lanes each. Thus the control sequence as a whole
490 consists of VF independent booleans that are each repeated nS times.
492 Taking mask-based approach as a partially-populated vectors example.
493 We make the simplifying assumption that if a sequence of nV masks is
494 suitable for one (nS,nL) pair, we can reuse it for (nS/2,nL/2) by
495 VIEW_CONVERTing it. This holds for all current targets that support
496 fully-masked loops. For example, suppose the scalar loop is:
498 float *f;
499 double *d;
500 for (int i = 0; i < n; ++i)
502 f[i * 2 + 0] += 1.0f;
503 f[i * 2 + 1] += 2.0f;
504 d[i] += 3.0;
507 and suppose that vectors have 256 bits. The vectorized f accesses
508 will belong to one rgroup and the vectorized d access to another:
510 f rgroup: nS = 2, nV = 1, nL = 8
511 d rgroup: nS = 1, nV = 1, nL = 4
512 VF = 4
514 [ In this simple example the rgroups do correspond to the normal
515 SLP grouping scheme. ]
517 If only the first three lanes are active, the masks we need are:
519 f rgroup: 1 1 | 1 1 | 1 1 | 0 0
520 d rgroup: 1 | 1 | 1 | 0
522 Here we can use a mask calculated for f's rgroup for d's, but not
523 vice versa.
525 Thus for each value of nV, it is enough to provide nV masks, with the
526 mask being calculated based on the highest nL (or, equivalently, based
527 on the highest nS) required by any rgroup with that nV. We therefore
528 represent the entire collection of masks as a two-level table, with the
529 first level being indexed by nV - 1 (since nV == 0 doesn't exist) and
530 the second being indexed by the mask index 0 <= i < nV. */
532 /* The controls (like masks or lengths) needed by rgroups with nV vectors,
533 according to the description above. */
534 struct rgroup_controls {
535 /* The largest nS for all rgroups that use these controls. */
536 unsigned int max_nscalars_per_iter;
538 /* For the largest nS recorded above, the loop controls divide each scalar
539 into FACTOR equal-sized pieces. This is useful if we need to split
540 element-based accesses into byte-based accesses. */
541 unsigned int factor;
543 /* This is a vector type with MAX_NSCALARS_PER_ITER * VF / nV elements.
544 For mask-based controls, it is the type of the masks in CONTROLS.
545 For length-based controls, it can be any vector type that has the
546 specified number of elements; the type of the elements doesn't matter. */
547 tree type;
549 /* A vector of nV controls, in iteration order. */
550 vec<tree> controls;
553 typedef auto_vec<rgroup_controls> vec_loop_masks;
555 typedef auto_vec<rgroup_controls> vec_loop_lens;
557 typedef auto_vec<std::pair<data_reference*, tree> > drs_init_vec;
559 /* Information about a reduction accumulator from the main loop that could
560 conceivably be reused as the input to a reduction in an epilogue loop. */
561 struct vect_reusable_accumulator {
562 /* The final value of the accumulator, which forms the input to the
563 reduction operation. */
564 tree reduc_input;
566 /* The stmt_vec_info that describes the reduction (i.e. the one for
567 which is_reduc_info is true). */
568 stmt_vec_info reduc_info;
571 /*-----------------------------------------------------------------*/
572 /* Info on vectorized loops. */
573 /*-----------------------------------------------------------------*/
574 typedef class _loop_vec_info : public vec_info {
575 public:
576 _loop_vec_info (class loop *, vec_info_shared *);
577 ~_loop_vec_info ();
579 /* The loop to which this info struct refers to. */
580 class loop *loop;
582 /* The loop basic blocks. */
583 basic_block *bbs;
585 /* Number of latch executions. */
586 tree num_itersm1;
587 /* Number of iterations. */
588 tree num_iters;
589 /* Number of iterations of the original loop. */
590 tree num_iters_unchanged;
591 /* Condition under which this loop is analyzed and versioned. */
592 tree num_iters_assumptions;
594 /* The cost of the vector code. */
595 class vector_costs *vector_costs;
597 /* The cost of the scalar code. */
598 class vector_costs *scalar_costs;
600 /* Threshold of number of iterations below which vectorization will not be
601 performed. It is calculated from MIN_PROFITABLE_ITERS and
602 param_min_vect_loop_bound. */
603 unsigned int th;
605 /* When applying loop versioning, the vector form should only be used
606 if the number of scalar iterations is >= this value, on top of all
607 the other requirements. Ignored when loop versioning is not being
608 used. */
609 poly_uint64 versioning_threshold;
611 /* Unrolling factor */
612 poly_uint64 vectorization_factor;
614 /* If this loop is an epilogue loop whose main loop can be skipped,
615 MAIN_LOOP_EDGE is the edge from the main loop to this loop's
616 preheader. SKIP_MAIN_LOOP_EDGE is then the edge that skips the
617 main loop and goes straight to this loop's preheader.
619 Both fields are null otherwise. */
620 edge main_loop_edge;
621 edge skip_main_loop_edge;
623 /* If this loop is an epilogue loop that might be skipped after executing
624 the main loop, this edge is the one that skips the epilogue. */
625 edge skip_this_loop_edge;
627 /* The vectorized form of a standard reduction replaces the original
628 scalar code's final result (a loop-closed SSA PHI) with the result
629 of a vector-to-scalar reduction operation. After vectorization,
630 this variable maps these vector-to-scalar results to information
631 about the reductions that generated them. */
632 hash_map<tree, vect_reusable_accumulator> reusable_accumulators;
634 /* Maximum runtime vectorization factor, or MAX_VECTORIZATION_FACTOR
635 if there is no particular limit. */
636 unsigned HOST_WIDE_INT max_vectorization_factor;
638 /* The masks that a fully-masked loop should use to avoid operating
639 on inactive scalars. */
640 vec_loop_masks masks;
642 /* The lengths that a loop with length should use to avoid operating
643 on inactive scalars. */
644 vec_loop_lens lens;
646 /* Set of scalar conditions that have loop mask applied. */
647 scalar_cond_masked_set_type scalar_cond_masked_set;
649 /* If we are using a loop mask to align memory addresses, this variable
650 contains the number of vector elements that we should skip in the
651 first iteration of the vector loop (i.e. the number of leading
652 elements that should be false in the first mask). */
653 tree mask_skip_niters;
655 /* The type that the loop control IV should be converted to before
656 testing which of the VF scalars are active and inactive.
657 Only meaningful if LOOP_VINFO_USING_PARTIAL_VECTORS_P. */
658 tree rgroup_compare_type;
660 /* For #pragma omp simd if (x) loops the x expression. If constant 0,
661 the loop should not be vectorized, if constant non-zero, simd_if_cond
662 shouldn't be set and loop vectorized normally, if SSA_NAME, the loop
663 should be versioned on that condition, using scalar loop if the condition
664 is false and vectorized loop otherwise. */
665 tree simd_if_cond;
667 /* The type that the vector loop control IV should have when
668 LOOP_VINFO_USING_PARTIAL_VECTORS_P is true. */
669 tree rgroup_iv_type;
671 /* Unknown DRs according to which loop was peeled. */
672 class dr_vec_info *unaligned_dr;
674 /* peeling_for_alignment indicates whether peeling for alignment will take
675 place, and what the peeling factor should be:
676 peeling_for_alignment = X means:
677 If X=0: Peeling for alignment will not be applied.
678 If X>0: Peel first X iterations.
679 If X=-1: Generate a runtime test to calculate the number of iterations
680 to be peeled, using the dataref recorded in the field
681 unaligned_dr. */
682 int peeling_for_alignment;
684 /* The mask used to check the alignment of pointers or arrays. */
685 int ptr_mask;
687 /* Data Dependence Relations defining address ranges that are candidates
688 for a run-time aliasing check. */
689 auto_vec<ddr_p> may_alias_ddrs;
691 /* Data Dependence Relations defining address ranges together with segment
692 lengths from which the run-time aliasing check is built. */
693 auto_vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
695 /* Check that the addresses of each pair of objects is unequal. */
696 auto_vec<vec_object_pair> check_unequal_addrs;
698 /* List of values that are required to be nonzero. This is used to check
699 whether things like "x[i * n] += 1;" are safe and eventually gets added
700 to the checks for lower bounds below. */
701 auto_vec<tree> check_nonzero;
703 /* List of values that need to be checked for a minimum value. */
704 auto_vec<vec_lower_bound> lower_bounds;
706 /* Statements in the loop that have data references that are candidates for a
707 runtime (loop versioning) misalignment check. */
708 auto_vec<stmt_vec_info> may_misalign_stmts;
710 /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
711 auto_vec<stmt_vec_info> reductions;
713 /* All reduction chains in the loop, represented by the first
714 stmt in the chain. */
715 auto_vec<stmt_vec_info> reduction_chains;
717 /* Cost vector for a single scalar iteration. */
718 auto_vec<stmt_info_for_cost> scalar_cost_vec;
720 /* Map of IV base/step expressions to inserted name in the preheader. */
721 hash_map<tree_operand_hash, tree> *ivexpr_map;
723 /* Map of OpenMP "omp simd array" scan variables to corresponding
724 rhs of the store of the initializer. */
725 hash_map<tree, tree> *scan_map;
727 /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
728 applied to the loop, i.e., no unrolling is needed, this is 1. */
729 poly_uint64 slp_unrolling_factor;
731 /* The factor used to over weight those statements in an inner loop
732 relative to the loop being vectorized. */
733 unsigned int inner_loop_cost_factor;
735 /* Is the loop vectorizable? */
736 bool vectorizable;
738 /* Records whether we still have the option of vectorizing this loop
739 using partially-populated vectors; in other words, whether it is
740 still possible for one iteration of the vector loop to handle
741 fewer than VF scalars. */
742 bool can_use_partial_vectors_p;
744 /* True if we've decided to use partially-populated vectors, so that
745 the vector loop can handle fewer than VF scalars. */
746 bool using_partial_vectors_p;
748 /* True if we've decided to use partially-populated vectors for the
749 epilogue of loop. */
750 bool epil_using_partial_vectors_p;
752 /* When we have grouped data accesses with gaps, we may introduce invalid
753 memory accesses. We peel the last iteration of the loop to prevent
754 this. */
755 bool peeling_for_gaps;
757 /* When the number of iterations is not a multiple of the vector size
758 we need to peel off iterations at the end to form an epilogue loop. */
759 bool peeling_for_niter;
761 /* True if there are no loop carried data dependencies in the loop.
762 If loop->safelen <= 1, then this is always true, either the loop
763 didn't have any loop carried data dependencies, or the loop is being
764 vectorized guarded with some runtime alias checks, or couldn't
765 be vectorized at all, but then this field shouldn't be used.
766 For loop->safelen >= 2, the user has asserted that there are no
767 backward dependencies, but there still could be loop carried forward
768 dependencies in such loops. This flag will be false if normal
769 vectorizer data dependency analysis would fail or require versioning
770 for alias, but because of loop->safelen >= 2 it has been vectorized
771 even without versioning for alias. E.g. in:
772 #pragma omp simd
773 for (int i = 0; i < m; i++)
774 a[i] = a[i + k] * c;
775 (or #pragma simd or #pragma ivdep) we can vectorize this and it will
776 DTRT even for k > 0 && k < m, but without safelen we would not
777 vectorize this, so this field would be false. */
778 bool no_data_dependencies;
780 /* Mark loops having masked stores. */
781 bool has_mask_store;
783 /* Queued scaling factor for the scalar loop. */
784 profile_probability scalar_loop_scaling;
786 /* If if-conversion versioned this loop before conversion, this is the
787 loop version without if-conversion. */
788 class loop *scalar_loop;
790 /* For loops being epilogues of already vectorized loops
791 this points to the original vectorized loop. Otherwise NULL. */
792 _loop_vec_info *orig_loop_info;
794 /* Used to store loop_vec_infos of epilogues of this loop during
795 analysis. */
796 vec<_loop_vec_info *> epilogue_vinfos;
798 } *loop_vec_info;
800 /* Access Functions. */
801 #define LOOP_VINFO_LOOP(L) (L)->loop
802 #define LOOP_VINFO_BBS(L) (L)->bbs
803 #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
804 #define LOOP_VINFO_NITERS(L) (L)->num_iters
805 /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
806 prologue peeling retain total unchanged scalar loop iterations for
807 cost model. */
808 #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
809 #define LOOP_VINFO_NITERS_ASSUMPTIONS(L) (L)->num_iters_assumptions
810 #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
811 #define LOOP_VINFO_VERSIONING_THRESHOLD(L) (L)->versioning_threshold
812 #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
813 #define LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P(L) (L)->can_use_partial_vectors_p
814 #define LOOP_VINFO_USING_PARTIAL_VECTORS_P(L) (L)->using_partial_vectors_p
815 #define LOOP_VINFO_EPIL_USING_PARTIAL_VECTORS_P(L) \
816 (L)->epil_using_partial_vectors_p
817 #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
818 #define LOOP_VINFO_MAX_VECT_FACTOR(L) (L)->max_vectorization_factor
819 #define LOOP_VINFO_MASKS(L) (L)->masks
820 #define LOOP_VINFO_LENS(L) (L)->lens
821 #define LOOP_VINFO_MASK_SKIP_NITERS(L) (L)->mask_skip_niters
822 #define LOOP_VINFO_RGROUP_COMPARE_TYPE(L) (L)->rgroup_compare_type
823 #define LOOP_VINFO_RGROUP_IV_TYPE(L) (L)->rgroup_iv_type
824 #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
825 #define LOOP_VINFO_N_STMTS(L) (L)->shared->n_stmts
826 #define LOOP_VINFO_LOOP_NEST(L) (L)->shared->loop_nest
827 #define LOOP_VINFO_DATAREFS(L) (L)->shared->datarefs
828 #define LOOP_VINFO_DDRS(L) (L)->shared->ddrs
829 #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
830 #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
831 #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
832 #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
833 #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
834 #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
835 #define LOOP_VINFO_CHECK_UNEQUAL_ADDRS(L) (L)->check_unequal_addrs
836 #define LOOP_VINFO_CHECK_NONZERO(L) (L)->check_nonzero
837 #define LOOP_VINFO_LOWER_BOUNDS(L) (L)->lower_bounds
838 #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
839 #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
840 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
841 #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
842 #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
843 #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
844 #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
845 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
846 #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
847 #define LOOP_VINFO_SCALAR_LOOP_SCALING(L) (L)->scalar_loop_scaling
848 #define LOOP_VINFO_HAS_MASK_STORE(L) (L)->has_mask_store
849 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
850 #define LOOP_VINFO_ORIG_LOOP_INFO(L) (L)->orig_loop_info
851 #define LOOP_VINFO_SIMD_IF_COND(L) (L)->simd_if_cond
852 #define LOOP_VINFO_INNER_LOOP_COST_FACTOR(L) (L)->inner_loop_cost_factor
854 #define LOOP_VINFO_FULLY_MASKED_P(L) \
855 (LOOP_VINFO_USING_PARTIAL_VECTORS_P (L) \
856 && !LOOP_VINFO_MASKS (L).is_empty ())
858 #define LOOP_VINFO_FULLY_WITH_LENGTH_P(L) \
859 (LOOP_VINFO_USING_PARTIAL_VECTORS_P (L) \
860 && !LOOP_VINFO_LENS (L).is_empty ())
862 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
863 ((L)->may_misalign_stmts.length () > 0)
864 #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
865 ((L)->comp_alias_ddrs.length () > 0 \
866 || (L)->check_unequal_addrs.length () > 0 \
867 || (L)->lower_bounds.length () > 0)
868 #define LOOP_REQUIRES_VERSIONING_FOR_NITERS(L) \
869 (LOOP_VINFO_NITERS_ASSUMPTIONS (L))
870 #define LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND(L) \
871 (LOOP_VINFO_SIMD_IF_COND (L))
872 #define LOOP_REQUIRES_VERSIONING(L) \
873 (LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (L) \
874 || LOOP_REQUIRES_VERSIONING_FOR_ALIAS (L) \
875 || LOOP_REQUIRES_VERSIONING_FOR_NITERS (L) \
876 || LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND (L))
878 #define LOOP_VINFO_NITERS_KNOWN_P(L) \
879 (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
881 #define LOOP_VINFO_EPILOGUE_P(L) \
882 (LOOP_VINFO_ORIG_LOOP_INFO (L) != NULL)
884 #define LOOP_VINFO_ORIG_MAX_VECT_FACTOR(L) \
885 (LOOP_VINFO_MAX_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO (L)))
887 /* Wrapper for loop_vec_info, for tracking success/failure, where a non-NULL
888 value signifies success, and a NULL value signifies failure, supporting
889 propagating an opt_problem * describing the failure back up the call
890 stack. */
891 typedef opt_pointer_wrapper <loop_vec_info> opt_loop_vec_info;
893 static inline loop_vec_info
894 loop_vec_info_for_loop (class loop *loop)
896 return (loop_vec_info) loop->aux;
899 struct slp_root
901 slp_root (slp_instance_kind kind_, vec<stmt_vec_info> stmts_,
902 vec<stmt_vec_info> roots_)
903 : kind(kind_), stmts(stmts_), roots(roots_) {}
904 slp_instance_kind kind;
905 vec<stmt_vec_info> stmts;
906 vec<stmt_vec_info> roots;
909 typedef class _bb_vec_info : public vec_info
911 public:
912 _bb_vec_info (vec<basic_block> bbs, vec_info_shared *);
913 ~_bb_vec_info ();
915 /* The region we are operating on. bbs[0] is the entry, excluding
916 its PHI nodes. In the future we might want to track an explicit
917 entry edge to cover bbs[0] PHI nodes and have a region entry
918 insert location. */
919 vec<basic_block> bbs;
921 vec<slp_root> roots;
922 } *bb_vec_info;
924 #define BB_VINFO_BB(B) (B)->bb
925 #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
926 #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
927 #define BB_VINFO_DATAREFS(B) (B)->shared->datarefs
928 #define BB_VINFO_DDRS(B) (B)->shared->ddrs
930 /*-----------------------------------------------------------------*/
931 /* Info on vectorized defs. */
932 /*-----------------------------------------------------------------*/
933 enum stmt_vec_info_type {
934 undef_vec_info_type = 0,
935 load_vec_info_type,
936 store_vec_info_type,
937 shift_vec_info_type,
938 op_vec_info_type,
939 call_vec_info_type,
940 call_simd_clone_vec_info_type,
941 assignment_vec_info_type,
942 condition_vec_info_type,
943 comparison_vec_info_type,
944 reduc_vec_info_type,
945 induc_vec_info_type,
946 type_promotion_vec_info_type,
947 type_demotion_vec_info_type,
948 type_conversion_vec_info_type,
949 cycle_phi_info_type,
950 lc_phi_info_type,
951 phi_info_type,
952 loop_exit_ctrl_vec_info_type
955 /* Indicates whether/how a variable is used in the scope of loop/basic
956 block. */
957 enum vect_relevant {
958 vect_unused_in_scope = 0,
960 /* The def is only used outside the loop. */
961 vect_used_only_live,
962 /* The def is in the inner loop, and the use is in the outer loop, and the
963 use is a reduction stmt. */
964 vect_used_in_outer_by_reduction,
965 /* The def is in the inner loop, and the use is in the outer loop (and is
966 not part of reduction). */
967 vect_used_in_outer,
969 /* defs that feed computations that end up (only) in a reduction. These
970 defs may be used by non-reduction stmts, but eventually, any
971 computations/values that are affected by these defs are used to compute
972 a reduction (i.e. don't get stored to memory, for example). We use this
973 to identify computations that we can change the order in which they are
974 computed. */
975 vect_used_by_reduction,
977 vect_used_in_scope
980 /* The type of vectorization that can be applied to the stmt: regular loop-based
981 vectorization; pure SLP - the stmt is a part of SLP instances and does not
982 have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
983 a part of SLP instance and also must be loop-based vectorized, since it has
984 uses outside SLP sequences.
986 In the loop context the meanings of pure and hybrid SLP are slightly
987 different. By saying that pure SLP is applied to the loop, we mean that we
988 exploit only intra-iteration parallelism in the loop; i.e., the loop can be
989 vectorized without doing any conceptual unrolling, cause we don't pack
990 together stmts from different iterations, only within a single iteration.
991 Loop hybrid SLP means that we exploit both intra-iteration and
992 inter-iteration parallelism (e.g., number of elements in the vector is 4
993 and the slp-group-size is 2, in which case we don't have enough parallelism
994 within an iteration, so we obtain the rest of the parallelism from subsequent
995 iterations by unrolling the loop by 2). */
996 enum slp_vect_type {
997 loop_vect = 0,
998 pure_slp,
999 hybrid
1002 /* Says whether a statement is a load, a store of a vectorized statement
1003 result, or a store of an invariant value. */
1004 enum vec_load_store_type {
1005 VLS_LOAD,
1006 VLS_STORE,
1007 VLS_STORE_INVARIANT
1010 /* Describes how we're going to vectorize an individual load or store,
1011 or a group of loads or stores. */
1012 enum vect_memory_access_type {
1013 /* An access to an invariant address. This is used only for loads. */
1014 VMAT_INVARIANT,
1016 /* A simple contiguous access. */
1017 VMAT_CONTIGUOUS,
1019 /* A contiguous access that goes down in memory rather than up,
1020 with no additional permutation. This is used only for stores
1021 of invariants. */
1022 VMAT_CONTIGUOUS_DOWN,
1024 /* A simple contiguous access in which the elements need to be permuted
1025 after loading or before storing. Only used for loop vectorization;
1026 SLP uses separate permutes. */
1027 VMAT_CONTIGUOUS_PERMUTE,
1029 /* A simple contiguous access in which the elements need to be reversed
1030 after loading or before storing. */
1031 VMAT_CONTIGUOUS_REVERSE,
1033 /* An access that uses IFN_LOAD_LANES or IFN_STORE_LANES. */
1034 VMAT_LOAD_STORE_LANES,
1036 /* An access in which each scalar element is loaded or stored
1037 individually. */
1038 VMAT_ELEMENTWISE,
1040 /* A hybrid of VMAT_CONTIGUOUS and VMAT_ELEMENTWISE, used for grouped
1041 SLP accesses. Each unrolled iteration uses a contiguous load
1042 or store for the whole group, but the groups from separate iterations
1043 are combined in the same way as for VMAT_ELEMENTWISE. */
1044 VMAT_STRIDED_SLP,
1046 /* The access uses gather loads or scatter stores. */
1047 VMAT_GATHER_SCATTER
1050 class dr_vec_info {
1051 public:
1052 /* The data reference itself. */
1053 data_reference *dr;
1054 /* The statement that contains the data reference. */
1055 stmt_vec_info stmt;
1056 /* The analysis group this DR belongs to when doing BB vectorization.
1057 DRs of the same group belong to the same conditional execution context. */
1058 unsigned group;
1059 /* The misalignment in bytes of the reference, or -1 if not known. */
1060 int misalignment;
1061 /* The byte alignment that we'd ideally like the reference to have,
1062 and the value that misalignment is measured against. */
1063 poly_uint64 target_alignment;
1064 /* If true the alignment of base_decl needs to be increased. */
1065 bool base_misaligned;
1066 tree base_decl;
1068 /* Stores current vectorized loop's offset. To be added to the DR's
1069 offset to calculate current offset of data reference. */
1070 tree offset;
1073 typedef struct data_reference *dr_p;
1075 class _stmt_vec_info {
1076 public:
1078 enum stmt_vec_info_type type;
1080 /* Indicates whether this stmts is part of a computation whose result is
1081 used outside the loop. */
1082 bool live;
1084 /* Stmt is part of some pattern (computation idiom) */
1085 bool in_pattern_p;
1087 /* True if the statement was created during pattern recognition as
1088 part of the replacement for RELATED_STMT. This implies that the
1089 statement isn't part of any basic block, although for convenience
1090 its gimple_bb is the same as for RELATED_STMT. */
1091 bool pattern_stmt_p;
1093 /* Is this statement vectorizable or should it be skipped in (partial)
1094 vectorization. */
1095 bool vectorizable;
1097 /* The stmt to which this info struct refers to. */
1098 gimple *stmt;
1100 /* The vector type to be used for the LHS of this statement. */
1101 tree vectype;
1103 /* The vectorized stmts. */
1104 vec<gimple *> vec_stmts;
1106 /* The following is relevant only for stmts that contain a non-scalar
1107 data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
1108 at most one such data-ref. */
1110 dr_vec_info dr_aux;
1112 /* Information about the data-ref relative to this loop
1113 nest (the loop that is being considered for vectorization). */
1114 innermost_loop_behavior dr_wrt_vec_loop;
1116 /* For loop PHI nodes, the base and evolution part of it. This makes sure
1117 this information is still available in vect_update_ivs_after_vectorizer
1118 where we may not be able to re-analyze the PHI nodes evolution as
1119 peeling for the prologue loop can make it unanalyzable. The evolution
1120 part is still correct after peeling, but the base may have changed from
1121 the version here. */
1122 tree loop_phi_evolution_base_unchanged;
1123 tree loop_phi_evolution_part;
1125 /* Used for various bookkeeping purposes, generally holding a pointer to
1126 some other stmt S that is in some way "related" to this stmt.
1127 Current use of this field is:
1128 If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
1129 true): S is the "pattern stmt" that represents (and replaces) the
1130 sequence of stmts that constitutes the pattern. Similarly, the
1131 related_stmt of the "pattern stmt" points back to this stmt (which is
1132 the last stmt in the original sequence of stmts that constitutes the
1133 pattern). */
1134 stmt_vec_info related_stmt;
1136 /* Used to keep a sequence of def stmts of a pattern stmt if such exists.
1137 The sequence is attached to the original statement rather than the
1138 pattern statement. */
1139 gimple_seq pattern_def_seq;
1141 /* Selected SIMD clone's function info. First vector element
1142 is SIMD clone's function decl, followed by a pair of trees (base + step)
1143 for linear arguments (pair of NULLs for other arguments). */
1144 vec<tree> simd_clone_info;
1146 /* Classify the def of this stmt. */
1147 enum vect_def_type def_type;
1149 /* Whether the stmt is SLPed, loop-based vectorized, or both. */
1150 enum slp_vect_type slp_type;
1152 /* Interleaving and reduction chains info. */
1153 /* First element in the group. */
1154 stmt_vec_info first_element;
1155 /* Pointer to the next element in the group. */
1156 stmt_vec_info next_element;
1157 /* The size of the group. */
1158 unsigned int size;
1159 /* For stores, number of stores from this group seen. We vectorize the last
1160 one. */
1161 unsigned int store_count;
1162 /* For loads only, the gap from the previous load. For consecutive loads, GAP
1163 is 1. */
1164 unsigned int gap;
1166 /* The minimum negative dependence distance this stmt participates in
1167 or zero if none. */
1168 unsigned int min_neg_dist;
1170 /* Not all stmts in the loop need to be vectorized. e.g, the increment
1171 of the loop induction variable and computation of array indexes. relevant
1172 indicates whether the stmt needs to be vectorized. */
1173 enum vect_relevant relevant;
1175 /* For loads if this is a gather, for stores if this is a scatter. */
1176 bool gather_scatter_p;
1178 /* True if this is an access with loop-invariant stride. */
1179 bool strided_p;
1181 /* For both loads and stores. */
1182 unsigned simd_lane_access_p : 3;
1184 /* Classifies how the load or store is going to be implemented
1185 for loop vectorization. */
1186 vect_memory_access_type memory_access_type;
1188 /* For INTEGER_INDUC_COND_REDUCTION, the initial value to be used. */
1189 tree induc_cond_initial_val;
1191 /* If not NULL the value to be added to compute final reduction value. */
1192 tree reduc_epilogue_adjustment;
1194 /* On a reduction PHI the reduction type as detected by
1195 vect_is_simple_reduction and vectorizable_reduction. */
1196 enum vect_reduction_type reduc_type;
1198 /* The original reduction code, to be used in the epilogue. */
1199 enum tree_code reduc_code;
1200 /* An internal function we should use in the epilogue. */
1201 internal_fn reduc_fn;
1203 /* On a stmt participating in the reduction the index of the operand
1204 on the reduction SSA cycle. */
1205 int reduc_idx;
1207 /* On a reduction PHI the def returned by vect_force_simple_reduction.
1208 On the def returned by vect_force_simple_reduction the
1209 corresponding PHI. */
1210 stmt_vec_info reduc_def;
1212 /* The vector input type relevant for reduction vectorization. */
1213 tree reduc_vectype_in;
1215 /* The vector type for performing the actual reduction. */
1216 tree reduc_vectype;
1218 /* If IS_REDUC_INFO is true and if the vector code is performing
1219 N scalar reductions in parallel, this variable gives the initial
1220 scalar values of those N reductions. */
1221 vec<tree> reduc_initial_values;
1223 /* If IS_REDUC_INFO is true and if the vector code is performing
1224 N scalar reductions in parallel, this variable gives the vectorized code's
1225 final (scalar) result for each of those N reductions. In other words,
1226 REDUC_SCALAR_RESULTS[I] replaces the original scalar code's loop-closed
1227 SSA PHI for reduction number I. */
1228 vec<tree> reduc_scalar_results;
1230 /* Only meaningful if IS_REDUC_INFO. If non-null, the reduction is
1231 being performed by an epilogue loop and we have decided to reuse
1232 this accumulator from the main loop. */
1233 vect_reusable_accumulator *reused_accumulator;
1235 /* Whether we force a single cycle PHI during reduction vectorization. */
1236 bool force_single_cycle;
1238 /* Whether on this stmt reduction meta is recorded. */
1239 bool is_reduc_info;
1241 /* If nonzero, the lhs of the statement could be truncated to this
1242 many bits without affecting any users of the result. */
1243 unsigned int min_output_precision;
1245 /* If nonzero, all non-boolean input operands have the same precision,
1246 and they could each be truncated to this many bits without changing
1247 the result. */
1248 unsigned int min_input_precision;
1250 /* If OPERATION_BITS is nonzero, the statement could be performed on
1251 an integer with the sign and number of bits given by OPERATION_SIGN
1252 and OPERATION_BITS without changing the result. */
1253 unsigned int operation_precision;
1254 signop operation_sign;
1256 /* If the statement produces a boolean result, this value describes
1257 how we should choose the associated vector type. The possible
1258 values are:
1260 - an integer precision N if we should use the vector mask type
1261 associated with N-bit integers. This is only used if all relevant
1262 input booleans also want the vector mask type for N-bit integers,
1263 or if we can convert them into that form by pattern-matching.
1265 - ~0U if we considered choosing a vector mask type but decided
1266 to treat the boolean as a normal integer type instead.
1268 - 0 otherwise. This means either that the operation isn't one that
1269 could have a vector mask type (and so should have a normal vector
1270 type instead) or that we simply haven't made a choice either way. */
1271 unsigned int mask_precision;
1273 /* True if this is only suitable for SLP vectorization. */
1274 bool slp_vect_only_p;
1276 /* True if this is a pattern that can only be handled by SLP
1277 vectorization. */
1278 bool slp_vect_pattern_only_p;
1281 /* Information about a gather/scatter call. */
1282 struct gather_scatter_info {
1283 /* The internal function to use for the gather/scatter operation,
1284 or IFN_LAST if a built-in function should be used instead. */
1285 internal_fn ifn;
1287 /* The FUNCTION_DECL for the built-in gather/scatter function,
1288 or null if an internal function should be used instead. */
1289 tree decl;
1291 /* The loop-invariant base value. */
1292 tree base;
1294 /* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
1295 tree offset;
1297 /* Each offset element should be multiplied by this amount before
1298 being added to the base. */
1299 int scale;
1301 /* The definition type for the vectorized offset. */
1302 enum vect_def_type offset_dt;
1304 /* The type of the vectorized offset. */
1305 tree offset_vectype;
1307 /* The type of the scalar elements after loading or before storing. */
1308 tree element_type;
1310 /* The type of the scalar elements being loaded or stored. */
1311 tree memory_type;
1314 /* Access Functions. */
1315 #define STMT_VINFO_TYPE(S) (S)->type
1316 #define STMT_VINFO_STMT(S) (S)->stmt
1317 #define STMT_VINFO_RELEVANT(S) (S)->relevant
1318 #define STMT_VINFO_LIVE_P(S) (S)->live
1319 #define STMT_VINFO_VECTYPE(S) (S)->vectype
1320 #define STMT_VINFO_VEC_STMTS(S) (S)->vec_stmts
1321 #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
1322 #define STMT_VINFO_DATA_REF(S) ((S)->dr_aux.dr + 0)
1323 #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
1324 #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
1325 #define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
1326 #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
1327 #define STMT_VINFO_VEC_INDUC_COND_INITIAL_VAL(S) (S)->induc_cond_initial_val
1328 #define STMT_VINFO_REDUC_EPILOGUE_ADJUSTMENT(S) (S)->reduc_epilogue_adjustment
1329 #define STMT_VINFO_REDUC_IDX(S) (S)->reduc_idx
1330 #define STMT_VINFO_FORCE_SINGLE_CYCLE(S) (S)->force_single_cycle
1332 #define STMT_VINFO_DR_WRT_VEC_LOOP(S) (S)->dr_wrt_vec_loop
1333 #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_wrt_vec_loop.base_address
1334 #define STMT_VINFO_DR_INIT(S) (S)->dr_wrt_vec_loop.init
1335 #define STMT_VINFO_DR_OFFSET(S) (S)->dr_wrt_vec_loop.offset
1336 #define STMT_VINFO_DR_STEP(S) (S)->dr_wrt_vec_loop.step
1337 #define STMT_VINFO_DR_BASE_ALIGNMENT(S) (S)->dr_wrt_vec_loop.base_alignment
1338 #define STMT_VINFO_DR_BASE_MISALIGNMENT(S) \
1339 (S)->dr_wrt_vec_loop.base_misalignment
1340 #define STMT_VINFO_DR_OFFSET_ALIGNMENT(S) \
1341 (S)->dr_wrt_vec_loop.offset_alignment
1342 #define STMT_VINFO_DR_STEP_ALIGNMENT(S) \
1343 (S)->dr_wrt_vec_loop.step_alignment
1345 #define STMT_VINFO_DR_INFO(S) \
1346 (gcc_checking_assert ((S)->dr_aux.stmt == (S)), &(S)->dr_aux)
1348 #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
1349 #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
1350 #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
1351 #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
1352 #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
1353 #define STMT_VINFO_GROUPED_ACCESS(S) \
1354 ((S)->dr_aux.dr && DR_GROUP_FIRST_ELEMENT(S))
1355 #define STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED(S) (S)->loop_phi_evolution_base_unchanged
1356 #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
1357 #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
1358 #define STMT_VINFO_REDUC_TYPE(S) (S)->reduc_type
1359 #define STMT_VINFO_REDUC_CODE(S) (S)->reduc_code
1360 #define STMT_VINFO_REDUC_FN(S) (S)->reduc_fn
1361 #define STMT_VINFO_REDUC_DEF(S) (S)->reduc_def
1362 #define STMT_VINFO_REDUC_VECTYPE(S) (S)->reduc_vectype
1363 #define STMT_VINFO_REDUC_VECTYPE_IN(S) (S)->reduc_vectype_in
1364 #define STMT_VINFO_SLP_VECT_ONLY(S) (S)->slp_vect_only_p
1365 #define STMT_VINFO_SLP_VECT_ONLY_PATTERN(S) (S)->slp_vect_pattern_only_p
1367 #define DR_GROUP_FIRST_ELEMENT(S) \
1368 (gcc_checking_assert ((S)->dr_aux.dr), (S)->first_element)
1369 #define DR_GROUP_NEXT_ELEMENT(S) \
1370 (gcc_checking_assert ((S)->dr_aux.dr), (S)->next_element)
1371 #define DR_GROUP_SIZE(S) \
1372 (gcc_checking_assert ((S)->dr_aux.dr), (S)->size)
1373 #define DR_GROUP_STORE_COUNT(S) \
1374 (gcc_checking_assert ((S)->dr_aux.dr), (S)->store_count)
1375 #define DR_GROUP_GAP(S) \
1376 (gcc_checking_assert ((S)->dr_aux.dr), (S)->gap)
1378 #define REDUC_GROUP_FIRST_ELEMENT(S) \
1379 (gcc_checking_assert (!(S)->dr_aux.dr), (S)->first_element)
1380 #define REDUC_GROUP_NEXT_ELEMENT(S) \
1381 (gcc_checking_assert (!(S)->dr_aux.dr), (S)->next_element)
1382 #define REDUC_GROUP_SIZE(S) \
1383 (gcc_checking_assert (!(S)->dr_aux.dr), (S)->size)
1385 #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
1387 #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
1388 #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
1389 #define STMT_SLP_TYPE(S) (S)->slp_type
1391 /* Contains the scalar or vector costs for a vec_info. */
1392 class vector_costs
1394 public:
1395 vector_costs (vec_info *, bool);
1396 virtual ~vector_costs () {}
1398 /* Update the costs in response to adding COUNT copies of a statement.
1400 - WHERE specifies whether the cost occurs in the loop prologue,
1401 the loop body, or the loop epilogue.
1402 - KIND is the kind of statement, which is always meaningful.
1403 - STMT_INFO, if nonnull, describes the statement that will be
1404 vectorized.
1405 - VECTYPE, if nonnull, is the vector type that the vectorized
1406 statement will operate on. Note that this should be used in
1407 preference to STMT_VINFO_VECTYPE (STMT_INFO) since the latter
1408 is not correct for SLP.
1409 - for unaligned_load and unaligned_store statements, MISALIGN is
1410 the byte misalignment of the load or store relative to the target's
1411 preferred alignment for VECTYPE, or DR_MISALIGNMENT_UNKNOWN
1412 if the misalignment is not known.
1414 Return the calculated cost as well as recording it. The return
1415 value is used for dumping purposes. */
1416 virtual unsigned int add_stmt_cost (int count, vect_cost_for_stmt kind,
1417 stmt_vec_info stmt_info, tree vectype,
1418 int misalign,
1419 vect_cost_model_location where);
1421 /* Finish calculating the cost of the code. The results can be
1422 read back using the functions below.
1424 If the costs describe vector code, SCALAR_COSTS gives the costs
1425 of the corresponding scalar code, otherwise it is null. */
1426 virtual void finish_cost (const vector_costs *scalar_costs);
1428 /* The costs in THIS and OTHER both describe ways of vectorizing
1429 a main loop. Return true if the costs described by THIS are
1430 cheaper than the costs described by OTHER. Return false if any
1431 of the following are true:
1433 - THIS and OTHER are of equal cost
1434 - OTHER is better than THIS
1435 - we can't be sure about the relative costs of THIS and OTHER. */
1436 virtual bool better_main_loop_than_p (const vector_costs *other) const;
1438 /* Likewise, but the costs in THIS and OTHER both describe ways of
1439 vectorizing an epilogue loop of MAIN_LOOP. */
1440 virtual bool better_epilogue_loop_than_p (const vector_costs *other,
1441 loop_vec_info main_loop) const;
1443 unsigned int prologue_cost () const;
1444 unsigned int body_cost () const;
1445 unsigned int epilogue_cost () const;
1446 unsigned int outside_cost () const;
1447 unsigned int total_cost () const;
1449 protected:
1450 unsigned int record_stmt_cost (stmt_vec_info, vect_cost_model_location,
1451 unsigned int);
1452 unsigned int adjust_cost_for_freq (stmt_vec_info, vect_cost_model_location,
1453 unsigned int);
1454 int compare_inside_loop_cost (const vector_costs *) const;
1455 int compare_outside_loop_cost (const vector_costs *) const;
1457 /* The region of code that we're considering vectorizing. */
1458 vec_info *m_vinfo;
1460 /* True if we're costing the scalar code, false if we're costing
1461 the vector code. */
1462 bool m_costing_for_scalar;
1464 /* The costs of the three regions, indexed by vect_cost_model_location. */
1465 unsigned int m_costs[3];
1467 /* True if finish_cost has been called. */
1468 bool m_finished;
1471 /* Create costs for VINFO. COSTING_FOR_SCALAR is true if the costs
1472 are for scalar code, false if they are for vector code. */
1474 inline
1475 vector_costs::vector_costs (vec_info *vinfo, bool costing_for_scalar)
1476 : m_vinfo (vinfo),
1477 m_costing_for_scalar (costing_for_scalar),
1478 m_costs (),
1479 m_finished (false)
1483 /* Return the cost of the prologue code (in abstract units). */
1485 inline unsigned int
1486 vector_costs::prologue_cost () const
1488 gcc_checking_assert (m_finished);
1489 return m_costs[vect_prologue];
1492 /* Return the cost of the body code (in abstract units). */
1494 inline unsigned int
1495 vector_costs::body_cost () const
1497 gcc_checking_assert (m_finished);
1498 return m_costs[vect_body];
1501 /* Return the cost of the epilogue code (in abstract units). */
1503 inline unsigned int
1504 vector_costs::epilogue_cost () const
1506 gcc_checking_assert (m_finished);
1507 return m_costs[vect_epilogue];
1510 /* Return the cost of the prologue and epilogue code (in abstract units). */
1512 inline unsigned int
1513 vector_costs::outside_cost () const
1515 return prologue_cost () + epilogue_cost ();
1518 /* Return the cost of the prologue, body and epilogue code
1519 (in abstract units). */
1521 inline unsigned int
1522 vector_costs::total_cost () const
1524 return body_cost () + outside_cost ();
1527 #define VECT_MAX_COST 1000
1529 /* The maximum number of intermediate steps required in multi-step type
1530 conversion. */
1531 #define MAX_INTERM_CVT_STEPS 3
1533 #define MAX_VECTORIZATION_FACTOR INT_MAX
1535 /* Nonzero if TYPE represents a (scalar) boolean type or type
1536 in the middle-end compatible with it (unsigned precision 1 integral
1537 types). Used to determine which types should be vectorized as
1538 VECTOR_BOOLEAN_TYPE_P. */
1540 #define VECT_SCALAR_BOOLEAN_TYPE_P(TYPE) \
1541 (TREE_CODE (TYPE) == BOOLEAN_TYPE \
1542 || ((TREE_CODE (TYPE) == INTEGER_TYPE \
1543 || TREE_CODE (TYPE) == ENUMERAL_TYPE) \
1544 && TYPE_PRECISION (TYPE) == 1 \
1545 && TYPE_UNSIGNED (TYPE)))
1547 static inline bool
1548 nested_in_vect_loop_p (class loop *loop, stmt_vec_info stmt_info)
1550 return (loop->inner
1551 && (loop->inner == (gimple_bb (stmt_info->stmt))->loop_father));
1554 /* PHI is either a scalar reduction phi or a scalar induction phi.
1555 Return the initial value of the variable on entry to the containing
1556 loop. */
1558 static inline tree
1559 vect_phi_initial_value (gphi *phi)
1561 basic_block bb = gimple_bb (phi);
1562 edge pe = loop_preheader_edge (bb->loop_father);
1563 gcc_assert (pe->dest == bb);
1564 return PHI_ARG_DEF_FROM_EDGE (phi, pe);
1567 /* Return true if STMT_INFO should produce a vector mask type rather than
1568 a normal nonmask type. */
1570 static inline bool
1571 vect_use_mask_type_p (stmt_vec_info stmt_info)
1573 return stmt_info->mask_precision && stmt_info->mask_precision != ~0U;
1576 /* Return TRUE if a statement represented by STMT_INFO is a part of a
1577 pattern. */
1579 static inline bool
1580 is_pattern_stmt_p (stmt_vec_info stmt_info)
1582 return stmt_info->pattern_stmt_p;
1585 /* If STMT_INFO is a pattern statement, return the statement that it
1586 replaces, otherwise return STMT_INFO itself. */
1588 inline stmt_vec_info
1589 vect_orig_stmt (stmt_vec_info stmt_info)
1591 if (is_pattern_stmt_p (stmt_info))
1592 return STMT_VINFO_RELATED_STMT (stmt_info);
1593 return stmt_info;
1596 /* Return the later statement between STMT1_INFO and STMT2_INFO. */
1598 static inline stmt_vec_info
1599 get_later_stmt (stmt_vec_info stmt1_info, stmt_vec_info stmt2_info)
1601 if (gimple_uid (vect_orig_stmt (stmt1_info)->stmt)
1602 > gimple_uid (vect_orig_stmt (stmt2_info)->stmt))
1603 return stmt1_info;
1604 else
1605 return stmt2_info;
1608 /* If STMT_INFO has been replaced by a pattern statement, return the
1609 replacement statement, otherwise return STMT_INFO itself. */
1611 inline stmt_vec_info
1612 vect_stmt_to_vectorize (stmt_vec_info stmt_info)
1614 if (STMT_VINFO_IN_PATTERN_P (stmt_info))
1615 return STMT_VINFO_RELATED_STMT (stmt_info);
1616 return stmt_info;
1619 /* Return true if BB is a loop header. */
1621 static inline bool
1622 is_loop_header_bb_p (basic_block bb)
1624 if (bb == (bb->loop_father)->header)
1625 return true;
1626 gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
1627 return false;
1630 /* Return pow2 (X). */
1632 static inline int
1633 vect_pow2 (int x)
1635 int i, res = 1;
1637 for (i = 0; i < x; i++)
1638 res *= 2;
1640 return res;
1643 /* Alias targetm.vectorize.builtin_vectorization_cost. */
1645 static inline int
1646 builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
1647 tree vectype, int misalign)
1649 return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
1650 vectype, misalign);
1653 /* Get cost by calling cost target builtin. */
1655 static inline
1656 int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
1658 return builtin_vectorization_cost (type_of_cost, NULL, 0);
1661 /* Alias targetm.vectorize.init_cost. */
1663 static inline vector_costs *
1664 init_cost (vec_info *vinfo, bool costing_for_scalar)
1666 return targetm.vectorize.create_costs (vinfo, costing_for_scalar);
1669 extern void dump_stmt_cost (FILE *, int, enum vect_cost_for_stmt,
1670 stmt_vec_info, tree, int, unsigned,
1671 enum vect_cost_model_location);
1673 /* Alias targetm.vectorize.add_stmt_cost. */
1675 static inline unsigned
1676 add_stmt_cost (vector_costs *costs, int count,
1677 enum vect_cost_for_stmt kind,
1678 stmt_vec_info stmt_info, tree vectype, int misalign,
1679 enum vect_cost_model_location where)
1681 unsigned cost = costs->add_stmt_cost (count, kind, stmt_info, vectype,
1682 misalign, where);
1683 if (dump_file && (dump_flags & TDF_DETAILS))
1684 dump_stmt_cost (dump_file, count, kind, stmt_info, vectype, misalign,
1685 cost, where);
1686 return cost;
1689 /* Alias targetm.vectorize.add_stmt_cost. */
1691 static inline unsigned
1692 add_stmt_cost (vector_costs *costs, stmt_info_for_cost *i)
1694 return add_stmt_cost (costs, i->count, i->kind, i->stmt_info,
1695 i->vectype, i->misalign, i->where);
1698 /* Alias targetm.vectorize.finish_cost. */
1700 static inline void
1701 finish_cost (vector_costs *costs, const vector_costs *scalar_costs,
1702 unsigned *prologue_cost, unsigned *body_cost,
1703 unsigned *epilogue_cost)
1705 costs->finish_cost (scalar_costs);
1706 *prologue_cost = costs->prologue_cost ();
1707 *body_cost = costs->body_cost ();
1708 *epilogue_cost = costs->epilogue_cost ();
1711 inline void
1712 add_stmt_costs (vector_costs *costs, stmt_vector_for_cost *cost_vec)
1714 stmt_info_for_cost *cost;
1715 unsigned i;
1716 FOR_EACH_VEC_ELT (*cost_vec, i, cost)
1717 add_stmt_cost (costs, cost->count, cost->kind, cost->stmt_info,
1718 cost->vectype, cost->misalign, cost->where);
1721 /*-----------------------------------------------------------------*/
1722 /* Info on data references alignment. */
1723 /*-----------------------------------------------------------------*/
1724 #define DR_MISALIGNMENT_UNKNOWN (-1)
1725 #define DR_MISALIGNMENT_UNINITIALIZED (-2)
1727 inline void
1728 set_dr_misalignment (dr_vec_info *dr_info, int val)
1730 dr_info->misalignment = val;
1733 extern int dr_misalignment (dr_vec_info *dr_info, tree vectype,
1734 poly_int64 offset = 0);
1736 #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
1738 /* Only defined once DR_MISALIGNMENT is defined. */
1739 static inline const poly_uint64
1740 dr_target_alignment (dr_vec_info *dr_info)
1742 if (STMT_VINFO_GROUPED_ACCESS (dr_info->stmt))
1743 dr_info = STMT_VINFO_DR_INFO (DR_GROUP_FIRST_ELEMENT (dr_info->stmt));
1744 return dr_info->target_alignment;
1746 #define DR_TARGET_ALIGNMENT(DR) dr_target_alignment (DR)
1748 static inline void
1749 set_dr_target_alignment (dr_vec_info *dr_info, poly_uint64 val)
1751 dr_info->target_alignment = val;
1753 #define SET_DR_TARGET_ALIGNMENT(DR, VAL) set_dr_target_alignment (DR, VAL)
1755 /* Return true if data access DR_INFO is aligned to the targets
1756 preferred alignment for VECTYPE (which may be less than a full vector). */
1758 static inline bool
1759 aligned_access_p (dr_vec_info *dr_info, tree vectype)
1761 return (dr_misalignment (dr_info, vectype) == 0);
1764 /* Return TRUE if the (mis-)alignment of the data access is known with
1765 respect to the targets preferred alignment for VECTYPE, and FALSE
1766 otherwise. */
1768 static inline bool
1769 known_alignment_for_access_p (dr_vec_info *dr_info, tree vectype)
1771 return (dr_misalignment (dr_info, vectype) != DR_MISALIGNMENT_UNKNOWN);
1774 /* Return the minimum alignment in bytes that the vectorized version
1775 of DR_INFO is guaranteed to have. */
1777 static inline unsigned int
1778 vect_known_alignment_in_bytes (dr_vec_info *dr_info, tree vectype)
1780 int misalignment = dr_misalignment (dr_info, vectype);
1781 if (misalignment == DR_MISALIGNMENT_UNKNOWN)
1782 return TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_info->dr)));
1783 else if (misalignment == 0)
1784 return known_alignment (DR_TARGET_ALIGNMENT (dr_info));
1785 return misalignment & -misalignment;
1788 /* Return the behavior of DR_INFO with respect to the vectorization context
1789 (which for outer loop vectorization might not be the behavior recorded
1790 in DR_INFO itself). */
1792 static inline innermost_loop_behavior *
1793 vect_dr_behavior (vec_info *vinfo, dr_vec_info *dr_info)
1795 stmt_vec_info stmt_info = dr_info->stmt;
1796 loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
1797 if (loop_vinfo == NULL
1798 || !nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo), stmt_info))
1799 return &DR_INNERMOST (dr_info->dr);
1800 else
1801 return &STMT_VINFO_DR_WRT_VEC_LOOP (stmt_info);
1804 /* Return the offset calculated by adding the offset of this DR_INFO to the
1805 corresponding data_reference's offset. If CHECK_OUTER then use
1806 vect_dr_behavior to select the appropriate data_reference to use. */
1808 inline tree
1809 get_dr_vinfo_offset (vec_info *vinfo,
1810 dr_vec_info *dr_info, bool check_outer = false)
1812 innermost_loop_behavior *base;
1813 if (check_outer)
1814 base = vect_dr_behavior (vinfo, dr_info);
1815 else
1816 base = &dr_info->dr->innermost;
1818 tree offset = base->offset;
1820 if (!dr_info->offset)
1821 return offset;
1823 offset = fold_convert (sizetype, offset);
1824 return fold_build2 (PLUS_EXPR, TREE_TYPE (dr_info->offset), offset,
1825 dr_info->offset);
1829 /* Return the vect cost model for LOOP. */
1830 static inline enum vect_cost_model
1831 loop_cost_model (loop_p loop)
1833 if (loop != NULL
1834 && loop->force_vectorize
1835 && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
1836 return flag_simd_cost_model;
1837 return flag_vect_cost_model;
1840 /* Return true if the vect cost model is unlimited. */
1841 static inline bool
1842 unlimited_cost_model (loop_p loop)
1844 return loop_cost_model (loop) == VECT_COST_MODEL_UNLIMITED;
1847 /* Return true if the loop described by LOOP_VINFO is fully-masked and
1848 if the first iteration should use a partial mask in order to achieve
1849 alignment. */
1851 static inline bool
1852 vect_use_loop_mask_for_alignment_p (loop_vec_info loop_vinfo)
1854 return (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
1855 && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo));
1858 /* Return the number of vectors of type VECTYPE that are needed to get
1859 NUNITS elements. NUNITS should be based on the vectorization factor,
1860 so it is always a known multiple of the number of elements in VECTYPE. */
1862 static inline unsigned int
1863 vect_get_num_vectors (poly_uint64 nunits, tree vectype)
1865 return exact_div (nunits, TYPE_VECTOR_SUBPARTS (vectype)).to_constant ();
1868 /* Return the number of copies needed for loop vectorization when
1869 a statement operates on vectors of type VECTYPE. This is the
1870 vectorization factor divided by the number of elements in
1871 VECTYPE and is always known at compile time. */
1873 static inline unsigned int
1874 vect_get_num_copies (loop_vec_info loop_vinfo, tree vectype)
1876 return vect_get_num_vectors (LOOP_VINFO_VECT_FACTOR (loop_vinfo), vectype);
1879 /* Update maximum unit count *MAX_NUNITS so that it accounts for
1880 NUNITS. *MAX_NUNITS can be 1 if we haven't yet recorded anything. */
1882 static inline void
1883 vect_update_max_nunits (poly_uint64 *max_nunits, poly_uint64 nunits)
1885 /* All unit counts have the form vec_info::vector_size * X for some
1886 rational X, so two unit sizes must have a common multiple.
1887 Everything is a multiple of the initial value of 1. */
1888 *max_nunits = force_common_multiple (*max_nunits, nunits);
1891 /* Update maximum unit count *MAX_NUNITS so that it accounts for
1892 the number of units in vector type VECTYPE. *MAX_NUNITS can be 1
1893 if we haven't yet recorded any vector types. */
1895 static inline void
1896 vect_update_max_nunits (poly_uint64 *max_nunits, tree vectype)
1898 vect_update_max_nunits (max_nunits, TYPE_VECTOR_SUBPARTS (vectype));
1901 /* Return the vectorization factor that should be used for costing
1902 purposes while vectorizing the loop described by LOOP_VINFO.
1903 Pick a reasonable estimate if the vectorization factor isn't
1904 known at compile time. */
1906 static inline unsigned int
1907 vect_vf_for_cost (loop_vec_info loop_vinfo)
1909 return estimated_poly_value (LOOP_VINFO_VECT_FACTOR (loop_vinfo));
1912 /* Estimate the number of elements in VEC_TYPE for costing purposes.
1913 Pick a reasonable estimate if the exact number isn't known at
1914 compile time. */
1916 static inline unsigned int
1917 vect_nunits_for_cost (tree vec_type)
1919 return estimated_poly_value (TYPE_VECTOR_SUBPARTS (vec_type));
1922 /* Return the maximum possible vectorization factor for LOOP_VINFO. */
1924 static inline unsigned HOST_WIDE_INT
1925 vect_max_vf (loop_vec_info loop_vinfo)
1927 unsigned HOST_WIDE_INT vf;
1928 if (LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&vf))
1929 return vf;
1930 return MAX_VECTORIZATION_FACTOR;
1933 /* Return the size of the value accessed by unvectorized data reference
1934 DR_INFO. This is only valid once STMT_VINFO_VECTYPE has been calculated
1935 for the associated gimple statement, since that guarantees that DR_INFO
1936 accesses either a scalar or a scalar equivalent. ("Scalar equivalent"
1937 here includes things like V1SI, which can be vectorized in the same way
1938 as a plain SI.) */
1940 inline unsigned int
1941 vect_get_scalar_dr_size (dr_vec_info *dr_info)
1943 return tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_info->dr))));
1946 /* Return true if LOOP_VINFO requires a runtime check for whether the
1947 vector loop is profitable. */
1949 inline bool
1950 vect_apply_runtime_profitability_check_p (loop_vec_info loop_vinfo)
1952 unsigned int th = LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo);
1953 return (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
1954 && th >= vect_vf_for_cost (loop_vinfo));
1957 /* Source location + hotness information. */
1958 extern dump_user_location_t vect_location;
1960 /* A macro for calling:
1961 dump_begin_scope (MSG, vect_location);
1962 via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc,
1963 and then calling
1964 dump_end_scope ();
1965 once the object goes out of scope, thus capturing the nesting of
1966 the scopes.
1968 These scopes affect dump messages within them: dump messages at the
1969 top level implicitly default to MSG_PRIORITY_USER_FACING, whereas those
1970 in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
1972 #define DUMP_VECT_SCOPE(MSG) \
1973 AUTO_DUMP_SCOPE (MSG, vect_location)
1975 /* A sentinel class for ensuring that the "vect_location" global gets
1976 reset at the end of a scope.
1978 The "vect_location" global is used during dumping and contains a
1979 location_t, which could contain references to a tree block via the
1980 ad-hoc data. This data is used for tracking inlining information,
1981 but it's not a GC root; it's simply assumed that such locations never
1982 get accessed if the blocks are optimized away.
1984 Hence we need to ensure that such locations are purged at the end
1985 of any operations using them (e.g. via this class). */
1987 class auto_purge_vect_location
1989 public:
1990 ~auto_purge_vect_location ();
1993 /*-----------------------------------------------------------------*/
1994 /* Function prototypes. */
1995 /*-----------------------------------------------------------------*/
1997 /* Simple loop peeling and versioning utilities for vectorizer's purposes -
1998 in tree-vect-loop-manip.c. */
1999 extern void vect_set_loop_condition (class loop *, loop_vec_info,
2000 tree, tree, tree, bool);
2001 extern bool slpeel_can_duplicate_loop_p (const class loop *, const_edge);
2002 class loop *slpeel_tree_duplicate_loop_to_edge_cfg (class loop *,
2003 class loop *, edge);
2004 class loop *vect_loop_versioning (loop_vec_info, gimple *);
2005 extern class loop *vect_do_peeling (loop_vec_info, tree, tree,
2006 tree *, tree *, tree *, int, bool, bool,
2007 tree *);
2008 extern tree vect_get_main_loop_result (loop_vec_info, tree, tree);
2009 extern void vect_prepare_for_masked_peels (loop_vec_info);
2010 extern dump_user_location_t find_loop_location (class loop *);
2011 extern bool vect_can_advance_ivs_p (loop_vec_info);
2012 extern void vect_update_inits_of_drs (loop_vec_info, tree, tree_code);
2014 /* In tree-vect-stmts.c. */
2015 extern tree get_related_vectype_for_scalar_type (machine_mode, tree,
2016 poly_uint64 = 0);
2017 extern tree get_vectype_for_scalar_type (vec_info *, tree, unsigned int = 0);
2018 extern tree get_vectype_for_scalar_type (vec_info *, tree, slp_tree);
2019 extern tree get_mask_type_for_scalar_type (vec_info *, tree, unsigned int = 0);
2020 extern tree get_same_sized_vectype (tree, tree);
2021 extern bool vect_chooses_same_modes_p (vec_info *, machine_mode);
2022 extern bool vect_get_loop_mask_type (loop_vec_info);
2023 extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *,
2024 stmt_vec_info * = NULL, gimple ** = NULL);
2025 extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *,
2026 tree *, stmt_vec_info * = NULL,
2027 gimple ** = NULL);
2028 extern bool vect_is_simple_use (vec_info *, stmt_vec_info, slp_tree,
2029 unsigned, tree *, slp_tree *,
2030 enum vect_def_type *,
2031 tree *, stmt_vec_info * = NULL);
2032 extern bool vect_maybe_update_slp_op_vectype (slp_tree, tree);
2033 extern bool supportable_widening_operation (vec_info *,
2034 enum tree_code, stmt_vec_info,
2035 tree, tree, enum tree_code *,
2036 enum tree_code *, int *,
2037 vec<tree> *);
2038 extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
2039 enum tree_code *, int *,
2040 vec<tree> *);
2042 extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
2043 enum vect_cost_for_stmt, stmt_vec_info,
2044 tree, int, enum vect_cost_model_location);
2046 /* Overload of record_stmt_cost with VECTYPE derived from STMT_INFO. */
2048 static inline unsigned
2049 record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
2050 enum vect_cost_for_stmt kind, stmt_vec_info stmt_info,
2051 int misalign, enum vect_cost_model_location where)
2053 return record_stmt_cost (body_cost_vec, count, kind, stmt_info,
2054 STMT_VINFO_VECTYPE (stmt_info), misalign, where);
2057 extern void vect_finish_replace_stmt (vec_info *, stmt_vec_info, gimple *);
2058 extern void vect_finish_stmt_generation (vec_info *, stmt_vec_info, gimple *,
2059 gimple_stmt_iterator *);
2060 extern opt_result vect_mark_stmts_to_be_vectorized (loop_vec_info, bool *);
2061 extern tree vect_get_store_rhs (stmt_vec_info);
2062 void vect_get_vec_defs_for_operand (vec_info *vinfo, stmt_vec_info, unsigned,
2063 tree op, vec<tree> *, tree = NULL);
2064 void vect_get_vec_defs (vec_info *, stmt_vec_info, slp_tree, unsigned,
2065 tree, vec<tree> *,
2066 tree = NULL, vec<tree> * = NULL,
2067 tree = NULL, vec<tree> * = NULL,
2068 tree = NULL, vec<tree> * = NULL);
2069 void vect_get_vec_defs (vec_info *, stmt_vec_info, slp_tree, unsigned,
2070 tree, vec<tree> *, tree,
2071 tree = NULL, vec<tree> * = NULL, tree = NULL,
2072 tree = NULL, vec<tree> * = NULL, tree = NULL,
2073 tree = NULL, vec<tree> * = NULL, tree = NULL);
2074 extern tree vect_init_vector (vec_info *, stmt_vec_info, tree, tree,
2075 gimple_stmt_iterator *);
2076 extern tree vect_get_slp_vect_def (slp_tree, unsigned);
2077 extern bool vect_transform_stmt (vec_info *, stmt_vec_info,
2078 gimple_stmt_iterator *,
2079 slp_tree, slp_instance);
2080 extern void vect_remove_stores (vec_info *, stmt_vec_info);
2081 extern bool vect_nop_conversion_p (stmt_vec_info);
2082 extern opt_result vect_analyze_stmt (vec_info *, stmt_vec_info, bool *,
2083 slp_tree,
2084 slp_instance, stmt_vector_for_cost *);
2085 extern void vect_get_load_cost (vec_info *, stmt_vec_info, int,
2086 dr_alignment_support, int, bool,
2087 unsigned int *, unsigned int *,
2088 stmt_vector_for_cost *,
2089 stmt_vector_for_cost *, bool);
2090 extern void vect_get_store_cost (vec_info *, stmt_vec_info, int,
2091 dr_alignment_support, int,
2092 unsigned int *, stmt_vector_for_cost *);
2093 extern bool vect_supportable_shift (vec_info *, enum tree_code, tree);
2094 extern tree vect_gen_perm_mask_any (tree, const vec_perm_indices &);
2095 extern tree vect_gen_perm_mask_checked (tree, const vec_perm_indices &);
2096 extern void optimize_mask_stores (class loop*);
2097 extern tree vect_gen_while (gimple_seq *, tree, tree, tree,
2098 const char * = nullptr);
2099 extern tree vect_gen_while_not (gimple_seq *, tree, tree, tree);
2100 extern opt_result vect_get_vector_types_for_stmt (vec_info *,
2101 stmt_vec_info, tree *,
2102 tree *, unsigned int = 0);
2103 extern opt_tree vect_get_mask_type_for_stmt (stmt_vec_info, unsigned int = 0);
2105 /* In tree-vect-data-refs.c. */
2106 extern bool vect_can_force_dr_alignment_p (const_tree, poly_uint64);
2107 extern enum dr_alignment_support vect_supportable_dr_alignment
2108 (vec_info *, dr_vec_info *, tree, int);
2109 extern tree vect_get_smallest_scalar_type (stmt_vec_info, tree);
2110 extern opt_result vect_analyze_data_ref_dependences (loop_vec_info, unsigned int *);
2111 extern bool vect_slp_analyze_instance_dependence (vec_info *, slp_instance);
2112 extern opt_result vect_enhance_data_refs_alignment (loop_vec_info);
2113 extern opt_result vect_analyze_data_refs_alignment (loop_vec_info);
2114 extern bool vect_slp_analyze_instance_alignment (vec_info *, slp_instance);
2115 extern opt_result vect_analyze_data_ref_accesses (vec_info *, vec<int> *);
2116 extern opt_result vect_prune_runtime_alias_test_list (loop_vec_info);
2117 extern bool vect_gather_scatter_fn_p (vec_info *, bool, bool, tree, tree,
2118 tree, int, internal_fn *, tree *);
2119 extern bool vect_check_gather_scatter (stmt_vec_info, loop_vec_info,
2120 gather_scatter_info *);
2121 extern opt_result vect_find_stmt_data_reference (loop_p, gimple *,
2122 vec<data_reference_p> *,
2123 vec<int> *, int);
2124 extern opt_result vect_analyze_data_refs (vec_info *, poly_uint64 *, bool *);
2125 extern void vect_record_base_alignments (vec_info *);
2126 extern tree vect_create_data_ref_ptr (vec_info *,
2127 stmt_vec_info, tree, class loop *, tree,
2128 tree *, gimple_stmt_iterator *,
2129 gimple **, bool,
2130 tree = NULL_TREE);
2131 extern tree bump_vector_ptr (vec_info *, tree, gimple *, gimple_stmt_iterator *,
2132 stmt_vec_info, tree);
2133 extern void vect_copy_ref_info (tree, tree);
2134 extern tree vect_create_destination_var (tree, tree);
2135 extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
2136 extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT, bool);
2137 extern bool vect_grouped_load_supported (tree, bool, unsigned HOST_WIDE_INT);
2138 extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT, bool);
2139 extern void vect_permute_store_chain (vec_info *, vec<tree> &,
2140 unsigned int, stmt_vec_info,
2141 gimple_stmt_iterator *, vec<tree> *);
2142 extern tree vect_setup_realignment (vec_info *,
2143 stmt_vec_info, gimple_stmt_iterator *,
2144 tree *, enum dr_alignment_support, tree,
2145 class loop **);
2146 extern void vect_transform_grouped_load (vec_info *, stmt_vec_info, vec<tree>,
2147 int, gimple_stmt_iterator *);
2148 extern void vect_record_grouped_load_vectors (vec_info *,
2149 stmt_vec_info, vec<tree>);
2150 extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
2151 extern tree vect_get_new_ssa_name (tree, enum vect_var_kind,
2152 const char * = NULL);
2153 extern tree vect_create_addr_base_for_vector_ref (vec_info *,
2154 stmt_vec_info, gimple_seq *,
2155 tree);
2157 /* In tree-vect-loop.c. */
2158 extern tree neutral_op_for_reduction (tree, tree_code, tree);
2159 extern widest_int vect_iv_limit_for_partial_vectors (loop_vec_info loop_vinfo);
2160 bool vect_rgroup_iv_might_wrap_p (loop_vec_info, rgroup_controls *);
2161 /* Used in tree-vect-loop-manip.c */
2162 extern opt_result vect_determine_partial_vectors_and_peeling (loop_vec_info,
2163 bool);
2164 /* Used in gimple-loop-interchange.c and tree-parloops.c. */
2165 extern bool check_reduction_path (dump_user_location_t, loop_p, gphi *, tree,
2166 enum tree_code);
2167 extern bool needs_fold_left_reduction_p (tree, tree_code);
2168 /* Drive for loop analysis stage. */
2169 extern opt_loop_vec_info vect_analyze_loop (class loop *, vec_info_shared *);
2170 extern tree vect_build_loop_niters (loop_vec_info, bool * = NULL);
2171 extern void vect_gen_vector_loop_niters (loop_vec_info, tree, tree *,
2172 tree *, bool);
2173 extern tree vect_halve_mask_nunits (tree, machine_mode);
2174 extern tree vect_double_mask_nunits (tree, machine_mode);
2175 extern void vect_record_loop_mask (loop_vec_info, vec_loop_masks *,
2176 unsigned int, tree, tree);
2177 extern tree vect_get_loop_mask (gimple_stmt_iterator *, vec_loop_masks *,
2178 unsigned int, tree, unsigned int);
2179 extern void vect_record_loop_len (loop_vec_info, vec_loop_lens *, unsigned int,
2180 tree, unsigned int);
2181 extern tree vect_get_loop_len (loop_vec_info, vec_loop_lens *, unsigned int,
2182 unsigned int);
2183 extern gimple_seq vect_gen_len (tree, tree, tree, tree);
2184 extern stmt_vec_info info_for_reduction (vec_info *, stmt_vec_info);
2185 extern bool reduction_fn_for_scalar_code (enum tree_code, internal_fn *);
2187 /* Drive for loop transformation stage. */
2188 extern class loop *vect_transform_loop (loop_vec_info, gimple *);
2189 struct vect_loop_form_info
2191 tree number_of_iterations;
2192 tree number_of_iterationsm1;
2193 tree assumptions;
2194 gcond *loop_cond;
2195 gcond *inner_loop_cond;
2197 extern opt_result vect_analyze_loop_form (class loop *, vect_loop_form_info *);
2198 extern loop_vec_info vect_create_loop_vinfo (class loop *, vec_info_shared *,
2199 const vect_loop_form_info *,
2200 loop_vec_info = nullptr);
2201 extern bool vectorizable_live_operation (vec_info *,
2202 stmt_vec_info, gimple_stmt_iterator *,
2203 slp_tree, slp_instance, int,
2204 bool, stmt_vector_for_cost *);
2205 extern bool vectorizable_reduction (loop_vec_info, stmt_vec_info,
2206 slp_tree, slp_instance,
2207 stmt_vector_for_cost *);
2208 extern bool vectorizable_induction (loop_vec_info, stmt_vec_info,
2209 gimple **, slp_tree,
2210 stmt_vector_for_cost *);
2211 extern bool vect_transform_reduction (loop_vec_info, stmt_vec_info,
2212 gimple_stmt_iterator *,
2213 gimple **, slp_tree);
2214 extern bool vect_transform_cycle_phi (loop_vec_info, stmt_vec_info,
2215 gimple **,
2216 slp_tree, slp_instance);
2217 extern bool vectorizable_lc_phi (loop_vec_info, stmt_vec_info,
2218 gimple **, slp_tree);
2219 extern bool vectorizable_phi (vec_info *, stmt_vec_info, gimple **, slp_tree,
2220 stmt_vector_for_cost *);
2221 extern bool vect_emulated_vector_p (tree);
2222 extern bool vect_can_vectorize_without_simd_p (tree_code);
2223 extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
2224 stmt_vector_for_cost *,
2225 stmt_vector_for_cost *,
2226 stmt_vector_for_cost *);
2227 extern tree cse_and_gimplify_to_preheader (loop_vec_info, tree);
2229 /* In tree-vect-slp.c. */
2230 extern void vect_slp_init (void);
2231 extern void vect_slp_fini (void);
2232 extern void vect_free_slp_instance (slp_instance);
2233 extern bool vect_transform_slp_perm_load (vec_info *, slp_tree, const vec<tree> &,
2234 gimple_stmt_iterator *, poly_uint64,
2235 bool, unsigned *,
2236 unsigned * = nullptr, bool = false);
2237 extern bool vect_slp_analyze_operations (vec_info *);
2238 extern void vect_schedule_slp (vec_info *, const vec<slp_instance> &);
2239 extern opt_result vect_analyze_slp (vec_info *, unsigned);
2240 extern bool vect_make_slp_decision (loop_vec_info);
2241 extern void vect_detect_hybrid_slp (loop_vec_info);
2242 extern void vect_optimize_slp (vec_info *);
2243 extern void vect_gather_slp_loads (vec_info *);
2244 extern void vect_get_slp_defs (slp_tree, vec<tree> *);
2245 extern void vect_get_slp_defs (vec_info *, slp_tree, vec<vec<tree> > *,
2246 unsigned n = -1U);
2247 extern bool vect_slp_if_converted_bb (basic_block bb, loop_p orig_loop);
2248 extern bool vect_slp_function (function *);
2249 extern stmt_vec_info vect_find_last_scalar_stmt_in_slp (slp_tree);
2250 extern stmt_vec_info vect_find_first_scalar_stmt_in_slp (slp_tree);
2251 extern bool is_simple_and_all_uses_invariant (stmt_vec_info, loop_vec_info);
2252 extern bool can_duplicate_and_interleave_p (vec_info *, unsigned int, tree,
2253 unsigned int * = NULL,
2254 tree * = NULL, tree * = NULL);
2255 extern void duplicate_and_interleave (vec_info *, gimple_seq *, tree,
2256 const vec<tree> &, unsigned int, vec<tree> &);
2257 extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
2258 extern slp_tree vect_create_new_slp_node (unsigned, tree_code);
2259 extern void vect_free_slp_tree (slp_tree);
2261 /* In tree-vect-patterns.c. */
2262 extern void
2263 vect_mark_pattern_stmts (vec_info *, stmt_vec_info, gimple *, tree);
2265 /* Pattern recognition functions.
2266 Additional pattern recognition functions can (and will) be added
2267 in the future. */
2268 void vect_pattern_recog (vec_info *);
2270 /* In tree-vectorizer.c. */
2271 unsigned vectorize_loops (void);
2272 void vect_free_loop_info_assumptions (class loop *);
2273 gimple *vect_loop_vectorized_call (class loop *, gcond **cond = NULL);
2274 bool vect_stmt_dominates_stmt_p (gimple *, gimple *);
2276 /* SLP Pattern matcher types, tree-vect-slp-patterns.c. */
2278 /* Forward declaration of possible two operands operation that can be matched
2279 by the complex numbers pattern matchers. */
2280 enum _complex_operation : unsigned;
2282 /* All possible load permute values that could result from the partial data-flow
2283 analysis. */
2284 typedef enum _complex_perm_kinds {
2285 PERM_UNKNOWN,
2286 PERM_EVENODD,
2287 PERM_ODDEVEN,
2288 PERM_ODDODD,
2289 PERM_EVENEVEN,
2290 /* Can be combined with any other PERM values. */
2291 PERM_TOP
2292 } complex_perm_kinds_t;
2294 /* Cache from nodes to the load permutation they represent. */
2295 typedef hash_map <slp_tree, complex_perm_kinds_t>
2296 slp_tree_to_load_perm_map_t;
2298 /* Vector pattern matcher base class. All SLP pattern matchers must inherit
2299 from this type. */
2301 class vect_pattern
2303 protected:
2304 /* The number of arguments that the IFN requires. */
2305 unsigned m_num_args;
2307 /* The internal function that will be used when a pattern is created. */
2308 internal_fn m_ifn;
2310 /* The current node being inspected. */
2311 slp_tree *m_node;
2313 /* The list of operands to be the children for the node produced when the
2314 internal function is created. */
2315 vec<slp_tree> m_ops;
2317 /* Default constructor where NODE is the root of the tree to inspect. */
2318 vect_pattern (slp_tree *node, vec<slp_tree> *m_ops, internal_fn ifn)
2320 this->m_ifn = ifn;
2321 this->m_node = node;
2322 this->m_ops.create (0);
2323 if (m_ops)
2324 this->m_ops.safe_splice (*m_ops);
2327 public:
2329 /* Create a new instance of the pattern matcher class of the given type. */
2330 static vect_pattern* recognize (slp_tree_to_load_perm_map_t *, slp_tree *);
2332 /* Build the pattern from the data collected so far. */
2333 virtual void build (vec_info *) = 0;
2335 /* Default destructor. */
2336 virtual ~vect_pattern ()
2338 this->m_ops.release ();
2342 /* Function pointer to create a new pattern matcher from a generic type. */
2343 typedef vect_pattern* (*vect_pattern_decl_t) (slp_tree_to_load_perm_map_t *,
2344 slp_tree *);
2346 /* List of supported pattern matchers. */
2347 extern vect_pattern_decl_t slp_patterns[];
2349 /* Number of supported pattern matchers. */
2350 extern size_t num__slp_patterns;
2352 /* ----------------------------------------------------------------------
2353 Target support routines
2354 -----------------------------------------------------------------------
2355 The following routines are provided to simplify costing decisions in
2356 target code. Please add more as needed. */
2358 /* Return true if an operaton of kind KIND for STMT_INFO represents
2359 the extraction of an element from a vector in preparation for
2360 storing the element to memory. */
2361 inline bool
2362 vect_is_store_elt_extraction (vect_cost_for_stmt kind, stmt_vec_info stmt_info)
2364 return (kind == vec_to_scalar
2365 && STMT_VINFO_DATA_REF (stmt_info)
2366 && DR_IS_WRITE (STMT_VINFO_DATA_REF (stmt_info)));
2369 /* Return true if STMT_INFO represents part of a reduction. */
2370 inline bool
2371 vect_is_reduction (stmt_vec_info stmt_info)
2373 return (STMT_VINFO_REDUC_DEF (stmt_info)
2374 || VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info)));
2377 /* If STMT_INFO describes a reduction, return the vect_reduction_type
2378 of the reduction it describes, otherwise return -1. */
2379 inline int
2380 vect_reduc_type (vec_info *vinfo, stmt_vec_info stmt_info)
2382 if (loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo))
2383 if (STMT_VINFO_REDUC_DEF (stmt_info))
2385 stmt_vec_info reduc_info = info_for_reduction (loop_vinfo, stmt_info);
2386 return int (STMT_VINFO_REDUC_TYPE (reduc_info));
2388 return -1;
2391 /* If STMT_INFO is a COND_EXPR that includes an embedded comparison, return the
2392 scalar type of the values being compared. Return null otherwise. */
2393 inline tree
2394 vect_embedded_comparison_type (stmt_vec_info stmt_info)
2396 if (auto *assign = dyn_cast<gassign *> (stmt_info->stmt))
2397 if (gimple_assign_rhs_code (assign) == COND_EXPR)
2399 tree cond = gimple_assign_rhs1 (assign);
2400 if (COMPARISON_CLASS_P (cond))
2401 return TREE_TYPE (TREE_OPERAND (cond, 0));
2403 return NULL_TREE;
2406 /* If STMT_INFO is a comparison or contains an embedded comparison, return the
2407 scalar type of the values being compared. Return null otherwise. */
2408 inline tree
2409 vect_comparison_type (stmt_vec_info stmt_info)
2411 if (auto *assign = dyn_cast<gassign *> (stmt_info->stmt))
2412 if (TREE_CODE_CLASS (gimple_assign_rhs_code (assign)) == tcc_comparison)
2413 return TREE_TYPE (gimple_assign_rhs1 (assign));
2414 return vect_embedded_comparison_type (stmt_info);
2417 /* Return true if STMT_INFO extends the result of a load. */
2418 inline bool
2419 vect_is_extending_load (class vec_info *vinfo, stmt_vec_info stmt_info)
2421 /* Although this is quite large for an inline function, this part
2422 at least should be inline. */
2423 gassign *assign = dyn_cast <gassign *> (stmt_info->stmt);
2424 if (!assign || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (assign)))
2425 return false;
2427 tree rhs = gimple_assign_rhs1 (stmt_info->stmt);
2428 tree lhs_type = TREE_TYPE (gimple_assign_lhs (assign));
2429 tree rhs_type = TREE_TYPE (rhs);
2430 if (!INTEGRAL_TYPE_P (lhs_type)
2431 || !INTEGRAL_TYPE_P (rhs_type)
2432 || TYPE_PRECISION (lhs_type) <= TYPE_PRECISION (rhs_type))
2433 return false;
2435 stmt_vec_info def_stmt_info = vinfo->lookup_def (rhs);
2436 return (def_stmt_info
2437 && STMT_VINFO_DATA_REF (def_stmt_info)
2438 && DR_IS_READ (STMT_VINFO_DATA_REF (def_stmt_info)));
2441 /* Return true if STMT_INFO is an integer truncation. */
2442 inline bool
2443 vect_is_integer_truncation (stmt_vec_info stmt_info)
2445 gassign *assign = dyn_cast <gassign *> (stmt_info->stmt);
2446 if (!assign || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (assign)))
2447 return false;
2449 tree lhs_type = TREE_TYPE (gimple_assign_lhs (assign));
2450 tree rhs_type = TREE_TYPE (gimple_assign_rhs1 (assign));
2451 return (INTEGRAL_TYPE_P (lhs_type)
2452 && INTEGRAL_TYPE_P (rhs_type)
2453 && TYPE_PRECISION (lhs_type) < TYPE_PRECISION (rhs_type));
2456 #endif /* GCC_TREE_VECTORIZER_H */