1 /* SLP - Basic Block Vectorization
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
4 and Ira Rosen <irar@il.ibm.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
32 #include "fold-const.h"
33 #include "stor-layout.h"
35 #include "gimple-pretty-print.h"
36 #include "internal-fn.h"
37 #include "gimple-iterator.h"
38 #include "tree-pass.h"
41 #include "insn-config.h"
50 #include "recog.h" /* FIXME: for insn_data */
51 #include "insn-codes.h"
53 #include "tree-vectorizer.h"
54 #include "langhooks.h"
55 #include "gimple-walk.h"
57 /* Extract the location of the basic block in the source code.
58 Return the basic block location if succeed and NULL if not. */
61 find_bb_location (basic_block bb
)
64 gimple_stmt_iterator si
;
67 return UNKNOWN_LOCATION
;
69 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
72 if (gimple_location (stmt
) != UNKNOWN_LOCATION
)
73 return gimple_location (stmt
);
76 return UNKNOWN_LOCATION
;
80 /* Recursively free the memory allocated for the SLP tree rooted at NODE. */
83 vect_free_slp_tree (slp_tree node
)
91 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
92 vect_free_slp_tree (child
);
94 SLP_TREE_CHILDREN (node
).release ();
95 SLP_TREE_SCALAR_STMTS (node
).release ();
96 SLP_TREE_VEC_STMTS (node
).release ();
97 SLP_TREE_LOAD_PERMUTATION (node
).release ();
103 /* Free the memory allocated for the SLP instance. */
106 vect_free_slp_instance (slp_instance instance
)
108 vect_free_slp_tree (SLP_INSTANCE_TREE (instance
));
109 SLP_INSTANCE_LOADS (instance
).release ();
114 /* Create an SLP node for SCALAR_STMTS. */
117 vect_create_new_slp_node (vec
<gimple
> scalar_stmts
)
120 gimple stmt
= scalar_stmts
[0];
123 if (is_gimple_call (stmt
))
124 nops
= gimple_call_num_args (stmt
);
125 else if (is_gimple_assign (stmt
))
127 nops
= gimple_num_ops (stmt
) - 1;
128 if (gimple_assign_rhs_code (stmt
) == COND_EXPR
)
134 node
= XNEW (struct _slp_tree
);
135 SLP_TREE_SCALAR_STMTS (node
) = scalar_stmts
;
136 SLP_TREE_VEC_STMTS (node
).create (0);
137 SLP_TREE_CHILDREN (node
).create (nops
);
138 SLP_TREE_LOAD_PERMUTATION (node
) = vNULL
;
139 SLP_TREE_TWO_OPERATORS (node
) = false;
145 /* Allocate operands info for NOPS operands, and GROUP_SIZE def-stmts for each
147 static vec
<slp_oprnd_info
>
148 vect_create_oprnd_info (int nops
, int group_size
)
151 slp_oprnd_info oprnd_info
;
152 vec
<slp_oprnd_info
> oprnds_info
;
154 oprnds_info
.create (nops
);
155 for (i
= 0; i
< nops
; i
++)
157 oprnd_info
= XNEW (struct _slp_oprnd_info
);
158 oprnd_info
->def_stmts
.create (group_size
);
159 oprnd_info
->first_dt
= vect_uninitialized_def
;
160 oprnd_info
->first_op_type
= NULL_TREE
;
161 oprnd_info
->first_pattern
= false;
162 oprnd_info
->second_pattern
= false;
163 oprnds_info
.quick_push (oprnd_info
);
170 /* Free operands info. */
173 vect_free_oprnd_info (vec
<slp_oprnd_info
> &oprnds_info
)
176 slp_oprnd_info oprnd_info
;
178 FOR_EACH_VEC_ELT (oprnds_info
, i
, oprnd_info
)
180 oprnd_info
->def_stmts
.release ();
181 XDELETE (oprnd_info
);
184 oprnds_info
.release ();
188 /* Find the place of the data-ref in STMT in the interleaving chain that starts
189 from FIRST_STMT. Return -1 if the data-ref is not a part of the chain. */
192 vect_get_place_in_interleaving_chain (gimple stmt
, gimple first_stmt
)
194 gimple next_stmt
= first_stmt
;
197 if (first_stmt
!= GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
)))
202 if (next_stmt
== stmt
)
204 next_stmt
= GROUP_NEXT_ELEMENT (vinfo_for_stmt (next_stmt
));
206 result
+= GROUP_GAP (vinfo_for_stmt (next_stmt
));
214 /* Get the defs for the rhs of STMT (collect them in OPRNDS_INFO), check that
215 they are of a valid type and that they match the defs of the first stmt of
216 the SLP group (stored in OPRNDS_INFO). If there was a fatal error
217 return -1, if the error could be corrected by swapping operands of the
218 operation return 1, if everything is ok return 0. */
221 vect_get_and_check_slp_defs (loop_vec_info loop_vinfo
, bb_vec_info bb_vinfo
,
222 gimple stmt
, unsigned stmt_num
,
223 vec
<slp_oprnd_info
> *oprnds_info
)
226 unsigned int i
, number_of_oprnds
;
229 enum vect_def_type dt
= vect_uninitialized_def
;
230 struct loop
*loop
= NULL
;
231 bool pattern
= false;
232 slp_oprnd_info oprnd_info
;
233 int first_op_idx
= 1;
234 bool commutative
= false;
235 bool first_op_cond
= false;
236 bool first
= stmt_num
== 0;
237 bool second
= stmt_num
== 1;
240 loop
= LOOP_VINFO_LOOP (loop_vinfo
);
242 if (is_gimple_call (stmt
))
244 number_of_oprnds
= gimple_call_num_args (stmt
);
247 else if (is_gimple_assign (stmt
))
249 enum tree_code code
= gimple_assign_rhs_code (stmt
);
250 number_of_oprnds
= gimple_num_ops (stmt
) - 1;
251 if (gimple_assign_rhs_code (stmt
) == COND_EXPR
)
253 first_op_cond
= true;
258 commutative
= commutative_tree_code (code
);
263 bool swapped
= false;
264 for (i
= 0; i
< number_of_oprnds
; i
++)
269 if (i
== 0 || i
== 1)
270 oprnd
= TREE_OPERAND (gimple_op (stmt
, first_op_idx
),
273 oprnd
= gimple_op (stmt
, first_op_idx
+ i
- 1);
276 oprnd
= gimple_op (stmt
, first_op_idx
+ (swapped
? !i
: i
));
278 oprnd_info
= (*oprnds_info
)[i
];
280 if (!vect_is_simple_use (oprnd
, NULL
, loop_vinfo
, bb_vinfo
, &def_stmt
,
283 if (dump_enabled_p ())
285 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
286 "Build SLP failed: can't analyze def for ");
287 dump_generic_expr (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, oprnd
);
288 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
294 /* Check if DEF_STMT is a part of a pattern in LOOP and get the def stmt
295 from the pattern. Check that all the stmts of the node are in the
297 if (def_stmt
&& gimple_bb (def_stmt
)
298 && ((loop
&& flow_bb_inside_loop_p (loop
, gimple_bb (def_stmt
)))
299 || (!loop
&& gimple_bb (def_stmt
) == BB_VINFO_BB (bb_vinfo
)
300 && gimple_code (def_stmt
) != GIMPLE_PHI
))
301 && vinfo_for_stmt (def_stmt
)
302 && STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (def_stmt
))
303 && !STMT_VINFO_RELEVANT (vinfo_for_stmt (def_stmt
))
304 && !STMT_VINFO_LIVE_P (vinfo_for_stmt (def_stmt
)))
307 if (!first
&& !oprnd_info
->first_pattern
308 /* Allow different pattern state for the defs of the
309 first stmt in reduction chains. */
310 && (oprnd_info
->first_dt
!= vect_reduction_def
311 || (!second
&& !oprnd_info
->second_pattern
)))
321 if (dump_enabled_p ())
323 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
324 "Build SLP failed: some of the stmts"
325 " are in a pattern, and others are not ");
326 dump_generic_expr (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, oprnd
);
327 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
333 def_stmt
= STMT_VINFO_RELATED_STMT (vinfo_for_stmt (def_stmt
));
334 dt
= STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def_stmt
));
336 if (dt
== vect_unknown_def_type
)
338 if (dump_enabled_p ())
339 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
340 "Unsupported pattern.\n");
344 switch (gimple_code (def_stmt
))
347 def
= gimple_phi_result (def_stmt
);
351 def
= gimple_assign_lhs (def_stmt
);
355 if (dump_enabled_p ())
356 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
357 "unsupported defining stmt:\n");
363 oprnd_info
->second_pattern
= pattern
;
367 oprnd_info
->first_dt
= dt
;
368 oprnd_info
->first_pattern
= pattern
;
369 oprnd_info
->first_op_type
= TREE_TYPE (oprnd
);
373 /* Not first stmt of the group, check that the def-stmt/s match
374 the def-stmt/s of the first stmt. Allow different definition
375 types for reduction chains: the first stmt must be a
376 vect_reduction_def (a phi node), and the rest
377 vect_internal_def. */
378 if (((oprnd_info
->first_dt
!= dt
379 && !(oprnd_info
->first_dt
== vect_reduction_def
380 && dt
== vect_internal_def
)
381 && !((oprnd_info
->first_dt
== vect_external_def
382 || oprnd_info
->first_dt
== vect_constant_def
)
383 && (dt
== vect_external_def
384 || dt
== vect_constant_def
)))
385 || !types_compatible_p (oprnd_info
->first_op_type
,
388 /* Try swapping operands if we got a mismatch. */
397 if (dump_enabled_p ())
398 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
399 "Build SLP failed: different types\n");
405 /* Check the types of the definitions. */
408 case vect_constant_def
:
409 case vect_external_def
:
410 case vect_reduction_def
:
413 case vect_internal_def
:
414 oprnd_info
->def_stmts
.quick_push (def_stmt
);
418 /* FORNOW: Not supported. */
419 if (dump_enabled_p ())
421 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
422 "Build SLP failed: illegal type of def ");
423 dump_generic_expr (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, def
);
424 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
436 tree cond
= gimple_assign_rhs1 (stmt
);
437 swap_ssa_operands (stmt
, &TREE_OPERAND (cond
, 0),
438 &TREE_OPERAND (cond
, 1));
439 TREE_SET_CODE (cond
, swap_tree_comparison (TREE_CODE (cond
)));
442 swap_ssa_operands (stmt
, gimple_assign_rhs1_ptr (stmt
),
443 gimple_assign_rhs2_ptr (stmt
));
450 /* Verify if the scalar stmts STMTS are isomorphic, require data
451 permutation or are of unsupported types of operation. Return
452 true if they are, otherwise return false and indicate in *MATCHES
453 which stmts are not isomorphic to the first one. If MATCHES[0]
454 is false then this indicates the comparison could not be
455 carried out or the stmts will never be vectorized by SLP. */
458 vect_build_slp_tree_1 (loop_vec_info loop_vinfo
, bb_vec_info bb_vinfo
,
459 vec
<gimple
> stmts
, unsigned int group_size
,
460 unsigned nops
, unsigned int *max_nunits
,
461 unsigned int vectorization_factor
, bool *matches
,
465 gimple first_stmt
= stmts
[0], stmt
= stmts
[0];
466 enum tree_code first_stmt_code
= ERROR_MARK
;
467 enum tree_code alt_stmt_code
= ERROR_MARK
;
468 enum tree_code rhs_code
= ERROR_MARK
;
469 enum tree_code first_cond_code
= ERROR_MARK
;
471 bool need_same_oprnds
= false;
472 tree vectype
= NULL_TREE
, scalar_type
, first_op1
= NULL_TREE
;
475 machine_mode optab_op2_mode
;
476 machine_mode vec_mode
;
478 gimple first_load
= NULL
, prev_first_load
= NULL
;
481 /* For every stmt in NODE find its def stmt/s. */
482 FOR_EACH_VEC_ELT (stmts
, i
, stmt
)
486 if (dump_enabled_p ())
488 dump_printf_loc (MSG_NOTE
, vect_location
, "Build SLP for ");
489 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
, stmt
, 0);
490 dump_printf (MSG_NOTE
, "\n");
493 /* Fail to vectorize statements marked as unvectorizable. */
494 if (!STMT_VINFO_VECTORIZABLE (vinfo_for_stmt (stmt
)))
496 if (dump_enabled_p ())
498 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
499 "Build SLP failed: unvectorizable statement ");
500 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
501 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
503 /* Fatal mismatch. */
508 lhs
= gimple_get_lhs (stmt
);
509 if (lhs
== NULL_TREE
)
511 if (dump_enabled_p ())
513 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
514 "Build SLP failed: not GIMPLE_ASSIGN nor "
516 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
517 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
519 /* Fatal mismatch. */
524 if (is_gimple_assign (stmt
)
525 && gimple_assign_rhs_code (stmt
) == COND_EXPR
526 && (cond
= gimple_assign_rhs1 (stmt
))
527 && !COMPARISON_CLASS_P (cond
))
529 if (dump_enabled_p ())
531 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
532 "Build SLP failed: condition is not "
534 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
535 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
537 /* Fatal mismatch. */
542 scalar_type
= vect_get_smallest_scalar_type (stmt
, &dummy
, &dummy
);
543 vectype
= get_vectype_for_scalar_type (scalar_type
);
546 if (dump_enabled_p ())
548 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
549 "Build SLP failed: unsupported data-type ");
550 dump_generic_expr (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
552 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
554 /* Fatal mismatch. */
559 /* If populating the vector type requires unrolling then fail
560 before adjusting *max_nunits for basic-block vectorization. */
562 && TYPE_VECTOR_SUBPARTS (vectype
) > group_size
)
564 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
565 "Build SLP failed: unrolling required "
566 "in basic block SLP\n");
567 /* Fatal mismatch. */
572 /* In case of multiple types we need to detect the smallest type. */
573 if (*max_nunits
< TYPE_VECTOR_SUBPARTS (vectype
))
575 *max_nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
577 vectorization_factor
= *max_nunits
;
580 if (gcall
*call_stmt
= dyn_cast
<gcall
*> (stmt
))
582 rhs_code
= CALL_EXPR
;
583 if (gimple_call_internal_p (call_stmt
)
584 || gimple_call_tail_p (call_stmt
)
585 || gimple_call_noreturn_p (call_stmt
)
586 || !gimple_call_nothrow_p (call_stmt
)
587 || gimple_call_chain (call_stmt
))
589 if (dump_enabled_p ())
591 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
592 "Build SLP failed: unsupported call type ");
593 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
595 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
597 /* Fatal mismatch. */
603 rhs_code
= gimple_assign_rhs_code (stmt
);
605 /* Check the operation. */
608 first_stmt_code
= rhs_code
;
610 /* Shift arguments should be equal in all the packed stmts for a
611 vector shift with scalar shift operand. */
612 if (rhs_code
== LSHIFT_EXPR
|| rhs_code
== RSHIFT_EXPR
613 || rhs_code
== LROTATE_EXPR
614 || rhs_code
== RROTATE_EXPR
)
616 vec_mode
= TYPE_MODE (vectype
);
618 /* First see if we have a vector/vector shift. */
619 optab
= optab_for_tree_code (rhs_code
, vectype
,
623 || optab_handler (optab
, vec_mode
) == CODE_FOR_nothing
)
625 /* No vector/vector shift, try for a vector/scalar shift. */
626 optab
= optab_for_tree_code (rhs_code
, vectype
,
631 if (dump_enabled_p ())
632 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
633 "Build SLP failed: no optab.\n");
634 /* Fatal mismatch. */
638 icode
= (int) optab_handler (optab
, vec_mode
);
639 if (icode
== CODE_FOR_nothing
)
641 if (dump_enabled_p ())
642 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
644 "op not supported by target.\n");
645 /* Fatal mismatch. */
649 optab_op2_mode
= insn_data
[icode
].operand
[2].mode
;
650 if (!VECTOR_MODE_P (optab_op2_mode
))
652 need_same_oprnds
= true;
653 first_op1
= gimple_assign_rhs2 (stmt
);
657 else if (rhs_code
== WIDEN_LSHIFT_EXPR
)
659 need_same_oprnds
= true;
660 first_op1
= gimple_assign_rhs2 (stmt
);
665 if (first_stmt_code
!= rhs_code
666 && alt_stmt_code
== ERROR_MARK
)
667 alt_stmt_code
= rhs_code
;
668 if (first_stmt_code
!= rhs_code
669 && (first_stmt_code
!= IMAGPART_EXPR
670 || rhs_code
!= REALPART_EXPR
)
671 && (first_stmt_code
!= REALPART_EXPR
672 || rhs_code
!= IMAGPART_EXPR
)
673 /* Handle mismatches in plus/minus by computing both
674 and merging the results. */
675 && !((first_stmt_code
== PLUS_EXPR
676 || first_stmt_code
== MINUS_EXPR
)
677 && (alt_stmt_code
== PLUS_EXPR
678 || alt_stmt_code
== MINUS_EXPR
)
679 && rhs_code
== alt_stmt_code
)
680 && !(STMT_VINFO_GROUPED_ACCESS (vinfo_for_stmt (stmt
))
681 && (first_stmt_code
== ARRAY_REF
682 || first_stmt_code
== BIT_FIELD_REF
683 || first_stmt_code
== INDIRECT_REF
684 || first_stmt_code
== COMPONENT_REF
685 || first_stmt_code
== MEM_REF
)))
687 if (dump_enabled_p ())
689 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
690 "Build SLP failed: different operation "
692 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
693 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
695 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
703 && !operand_equal_p (first_op1
, gimple_assign_rhs2 (stmt
), 0))
705 if (dump_enabled_p ())
707 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
708 "Build SLP failed: different shift "
710 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
711 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
717 if (rhs_code
== CALL_EXPR
)
719 gimple first_stmt
= stmts
[0];
720 if (gimple_call_num_args (stmt
) != nops
721 || !operand_equal_p (gimple_call_fn (first_stmt
),
722 gimple_call_fn (stmt
), 0)
723 || gimple_call_fntype (first_stmt
)
724 != gimple_call_fntype (stmt
))
726 if (dump_enabled_p ())
728 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
729 "Build SLP failed: different calls in ");
730 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
732 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
740 /* Grouped store or load. */
741 if (STMT_VINFO_GROUPED_ACCESS (vinfo_for_stmt (stmt
)))
743 if (REFERENCE_CLASS_P (lhs
))
751 /* Check that the size of interleaved loads group is not
752 greater than the SLP group size. */
754 = vectorization_factor
/ TYPE_VECTOR_SUBPARTS (vectype
);
756 && GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
)) == stmt
757 && ((GROUP_SIZE (vinfo_for_stmt (stmt
))
758 - GROUP_GAP (vinfo_for_stmt (stmt
)))
759 > ncopies
* group_size
))
761 if (dump_enabled_p ())
763 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
764 "Build SLP failed: the number "
765 "of interleaved loads is greater than "
766 "the SLP group size ");
767 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
769 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
771 /* Fatal mismatch. */
776 first_load
= GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
));
779 /* Check that there are no loads from different interleaving
780 chains in the same node. */
781 if (prev_first_load
!= first_load
)
783 if (dump_enabled_p ())
785 dump_printf_loc (MSG_MISSED_OPTIMIZATION
,
787 "Build SLP failed: different "
788 "interleaving chains in one node ");
789 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
791 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
798 prev_first_load
= first_load
;
800 } /* Grouped access. */
803 if (TREE_CODE_CLASS (rhs_code
) == tcc_reference
)
805 /* Not grouped load. */
806 if (dump_enabled_p ())
808 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
809 "Build SLP failed: not grouped load ");
810 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
811 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
814 /* FORNOW: Not grouped loads are not supported. */
815 /* Fatal mismatch. */
820 /* Not memory operation. */
821 if (TREE_CODE_CLASS (rhs_code
) != tcc_binary
822 && TREE_CODE_CLASS (rhs_code
) != tcc_unary
823 && TREE_CODE_CLASS (rhs_code
) != tcc_expression
824 && rhs_code
!= CALL_EXPR
)
826 if (dump_enabled_p ())
828 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
829 "Build SLP failed: operation");
830 dump_printf (MSG_MISSED_OPTIMIZATION
, " unsupported ");
831 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
832 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
834 /* Fatal mismatch. */
839 if (rhs_code
== COND_EXPR
)
841 tree cond_expr
= gimple_assign_rhs1 (stmt
);
844 first_cond_code
= TREE_CODE (cond_expr
);
845 else if (first_cond_code
!= TREE_CODE (cond_expr
))
847 if (dump_enabled_p ())
849 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
850 "Build SLP failed: different"
852 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
854 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
865 for (i
= 0; i
< group_size
; ++i
)
869 /* If we allowed a two-operation SLP node verify the target can cope
870 with the permute we are going to use. */
871 if (alt_stmt_code
!= ERROR_MARK
872 && TREE_CODE_CLASS (alt_stmt_code
) != tcc_reference
)
875 = XALLOCAVEC (unsigned char, TYPE_VECTOR_SUBPARTS (vectype
));
876 for (i
= 0; i
< TYPE_VECTOR_SUBPARTS (vectype
); ++i
)
879 if (gimple_assign_rhs_code (stmts
[i
% group_size
]) == alt_stmt_code
)
880 sel
[i
] += TYPE_VECTOR_SUBPARTS (vectype
);
882 if (!can_vec_perm_p (TYPE_MODE (vectype
), false, sel
))
884 for (i
= 0; i
< group_size
; ++i
)
885 if (gimple_assign_rhs_code (stmts
[i
]) == alt_stmt_code
)
888 if (dump_enabled_p ())
890 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
891 "Build SLP failed: different operation "
893 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
895 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
897 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
903 *two_operators
= true;
909 /* Recursively build an SLP tree starting from NODE.
910 Fail (and return a value not equal to zero) if def-stmts are not
911 isomorphic, require data permutation or are of unsupported types of
912 operation. Otherwise, return 0.
913 The value returned is the depth in the SLP tree where a mismatch
917 vect_build_slp_tree (loop_vec_info loop_vinfo
, bb_vec_info bb_vinfo
,
918 slp_tree
*node
, unsigned int group_size
,
919 unsigned int *max_nunits
,
920 vec
<slp_tree
> *loads
,
921 unsigned int vectorization_factor
,
922 bool *matches
, unsigned *npermutes
, unsigned *tree_size
,
923 unsigned max_tree_size
)
925 unsigned nops
, i
, this_tree_size
= 0;
930 stmt
= SLP_TREE_SCALAR_STMTS (*node
)[0];
931 if (is_gimple_call (stmt
))
932 nops
= gimple_call_num_args (stmt
);
933 else if (is_gimple_assign (stmt
))
935 nops
= gimple_num_ops (stmt
) - 1;
936 if (gimple_assign_rhs_code (stmt
) == COND_EXPR
)
942 bool two_operators
= false;
943 if (!vect_build_slp_tree_1 (loop_vinfo
, bb_vinfo
,
944 SLP_TREE_SCALAR_STMTS (*node
), group_size
, nops
,
945 max_nunits
, vectorization_factor
, matches
,
948 SLP_TREE_TWO_OPERATORS (*node
) = two_operators
;
950 /* If the SLP node is a load, terminate the recursion. */
951 if (STMT_VINFO_GROUPED_ACCESS (vinfo_for_stmt (stmt
))
952 && DR_IS_READ (STMT_VINFO_DATA_REF (vinfo_for_stmt (stmt
))))
954 loads
->safe_push (*node
);
958 /* Get at the operands, verifying they are compatible. */
959 vec
<slp_oprnd_info
> oprnds_info
= vect_create_oprnd_info (nops
, group_size
);
960 slp_oprnd_info oprnd_info
;
961 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (*node
), i
, stmt
)
963 switch (vect_get_and_check_slp_defs (loop_vinfo
, bb_vinfo
,
964 stmt
, i
, &oprnds_info
))
970 vect_free_oprnd_info (oprnds_info
);
977 for (i
= 0; i
< group_size
; ++i
)
980 vect_free_oprnd_info (oprnds_info
);
984 stmt
= SLP_TREE_SCALAR_STMTS (*node
)[0];
986 /* Create SLP_TREE nodes for the definition node/s. */
987 FOR_EACH_VEC_ELT (oprnds_info
, i
, oprnd_info
)
990 unsigned old_nloads
= loads
->length ();
991 unsigned old_max_nunits
= *max_nunits
;
993 if (oprnd_info
->first_dt
!= vect_internal_def
)
996 if (++this_tree_size
> max_tree_size
)
998 vect_free_oprnd_info (oprnds_info
);
1002 child
= vect_create_new_slp_node (oprnd_info
->def_stmts
);
1005 vect_free_oprnd_info (oprnds_info
);
1009 if (vect_build_slp_tree (loop_vinfo
, bb_vinfo
, &child
,
1010 group_size
, max_nunits
, loads
,
1011 vectorization_factor
, matches
,
1012 npermutes
, &this_tree_size
, max_tree_size
))
1014 /* If we have all children of child built up from scalars then just
1015 throw that away and build it up this node from scalars. */
1016 if (!SLP_TREE_CHILDREN (child
).is_empty ())
1019 slp_tree grandchild
;
1021 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child
), j
, grandchild
)
1022 if (grandchild
!= NULL
)
1027 *max_nunits
= old_max_nunits
;
1028 loads
->truncate (old_nloads
);
1029 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child
), j
, grandchild
)
1030 vect_free_slp_tree (grandchild
);
1031 SLP_TREE_CHILDREN (child
).truncate (0);
1033 dump_printf_loc (MSG_NOTE
, vect_location
,
1034 "Building parent vector operands from "
1035 "scalars instead\n");
1036 oprnd_info
->def_stmts
= vNULL
;
1037 vect_free_slp_tree (child
);
1038 SLP_TREE_CHILDREN (*node
).quick_push (NULL
);
1043 oprnd_info
->def_stmts
= vNULL
;
1044 SLP_TREE_CHILDREN (*node
).quick_push (child
);
1048 /* If the SLP build failed fatally and we analyze a basic-block
1049 simply treat nodes we fail to build as externally defined
1050 (and thus build vectors from the scalar defs).
1051 The cost model will reject outright expensive cases.
1052 ??? This doesn't treat cases where permutation ultimatively
1053 fails (or we don't try permutation below). Ideally we'd
1054 even compute a permutation that will end up with the maximum
1058 /* ??? Rejecting patterns this way doesn't work. We'd have to
1059 do extra work to cancel the pattern so the uses see the
1061 && !is_pattern_stmt_p (vinfo_for_stmt (stmt
)))
1064 slp_tree grandchild
;
1067 *max_nunits
= old_max_nunits
;
1068 loads
->truncate (old_nloads
);
1069 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child
), j
, grandchild
)
1070 vect_free_slp_tree (grandchild
);
1071 SLP_TREE_CHILDREN (child
).truncate (0);
1073 dump_printf_loc (MSG_NOTE
, vect_location
,
1074 "Building vector operands from scalars\n");
1075 oprnd_info
->def_stmts
= vNULL
;
1076 vect_free_slp_tree (child
);
1077 SLP_TREE_CHILDREN (*node
).quick_push (NULL
);
1081 /* If the SLP build for operand zero failed and operand zero
1082 and one can be commutated try that for the scalar stmts
1083 that failed the match. */
1085 /* A first scalar stmt mismatch signals a fatal mismatch. */
1087 /* ??? For COND_EXPRs we can swap the comparison operands
1088 as well as the arms under some constraints. */
1090 && oprnds_info
[1]->first_dt
== vect_internal_def
1091 && is_gimple_assign (stmt
)
1092 && commutative_tree_code (gimple_assign_rhs_code (stmt
))
1093 && !SLP_TREE_TWO_OPERATORS (*node
)
1094 /* Do so only if the number of not successful permutes was nor more
1095 than a cut-ff as re-trying the recursive match on
1096 possibly each level of the tree would expose exponential
1101 slp_tree grandchild
;
1104 *max_nunits
= old_max_nunits
;
1105 loads
->truncate (old_nloads
);
1106 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child
), j
, grandchild
)
1107 vect_free_slp_tree (grandchild
);
1108 SLP_TREE_CHILDREN (child
).truncate (0);
1110 /* Swap mismatched definition stmts. */
1111 dump_printf_loc (MSG_NOTE
, vect_location
,
1112 "Re-trying with swapped operands of stmts ");
1113 for (j
= 0; j
< group_size
; ++j
)
1116 std::swap (oprnds_info
[0]->def_stmts
[j
],
1117 oprnds_info
[1]->def_stmts
[j
]);
1118 dump_printf (MSG_NOTE
, "%d ", j
);
1120 dump_printf (MSG_NOTE
, "\n");
1121 /* And try again with scratch 'matches' ... */
1122 bool *tem
= XALLOCAVEC (bool, group_size
);
1123 if (vect_build_slp_tree (loop_vinfo
, bb_vinfo
, &child
,
1124 group_size
, max_nunits
, loads
,
1125 vectorization_factor
,
1126 tem
, npermutes
, &this_tree_size
,
1129 /* ... so if successful we can apply the operand swapping
1130 to the GIMPLE IL. This is necessary because for example
1131 vect_get_slp_defs uses operand indexes and thus expects
1132 canonical operand order. */
1133 for (j
= 0; j
< group_size
; ++j
)
1136 gimple stmt
= SLP_TREE_SCALAR_STMTS (*node
)[j
];
1137 swap_ssa_operands (stmt
, gimple_assign_rhs1_ptr (stmt
),
1138 gimple_assign_rhs2_ptr (stmt
));
1140 oprnd_info
->def_stmts
= vNULL
;
1141 SLP_TREE_CHILDREN (*node
).quick_push (child
);
1148 oprnd_info
->def_stmts
= vNULL
;
1149 vect_free_slp_tree (child
);
1150 vect_free_oprnd_info (oprnds_info
);
1155 *tree_size
+= this_tree_size
;
1157 vect_free_oprnd_info (oprnds_info
);
1161 /* Dump a slp tree NODE using flags specified in DUMP_KIND. */
1164 vect_print_slp_tree (int dump_kind
, slp_tree node
)
1173 dump_printf (dump_kind
, "node ");
1174 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
1176 dump_printf (dump_kind
, "\n\tstmt %d ", i
);
1177 dump_gimple_stmt (dump_kind
, TDF_SLIM
, stmt
, 0);
1179 dump_printf (dump_kind
, "\n");
1181 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
1182 vect_print_slp_tree (dump_kind
, child
);
1186 /* Mark the tree rooted at NODE with MARK (PURE_SLP or HYBRID).
1187 If MARK is HYBRID, it refers to a specific stmt in NODE (the stmt at index
1188 J). Otherwise, MARK is PURE_SLP and J is -1, which indicates that all the
1189 stmts in NODE are to be marked. */
1192 vect_mark_slp_stmts (slp_tree node
, enum slp_vect_type mark
, int j
)
1201 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
1202 if (j
< 0 || i
== j
)
1203 STMT_SLP_TYPE (vinfo_for_stmt (stmt
)) = mark
;
1205 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
1206 vect_mark_slp_stmts (child
, mark
, j
);
1210 /* Mark the statements of the tree rooted at NODE as relevant (vect_used). */
1213 vect_mark_slp_stmts_relevant (slp_tree node
)
1217 stmt_vec_info stmt_info
;
1223 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
1225 stmt_info
= vinfo_for_stmt (stmt
);
1226 gcc_assert (!STMT_VINFO_RELEVANT (stmt_info
)
1227 || STMT_VINFO_RELEVANT (stmt_info
) == vect_used_in_scope
);
1228 STMT_VINFO_RELEVANT (stmt_info
) = vect_used_in_scope
;
1231 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
1232 vect_mark_slp_stmts_relevant (child
);
1236 /* Rearrange the statements of NODE according to PERMUTATION. */
1239 vect_slp_rearrange_stmts (slp_tree node
, unsigned int group_size
,
1240 vec
<unsigned> permutation
)
1243 vec
<gimple
> tmp_stmts
;
1247 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
1248 vect_slp_rearrange_stmts (child
, group_size
, permutation
);
1250 gcc_assert (group_size
== SLP_TREE_SCALAR_STMTS (node
).length ());
1251 tmp_stmts
.create (group_size
);
1252 tmp_stmts
.quick_grow_cleared (group_size
);
1254 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
1255 tmp_stmts
[permutation
[i
]] = stmt
;
1257 SLP_TREE_SCALAR_STMTS (node
).release ();
1258 SLP_TREE_SCALAR_STMTS (node
) = tmp_stmts
;
1262 /* Attempt to reorder stmts in a reduction chain so that we don't
1263 require any load permutation. Return true if that was possible,
1264 otherwise return false. */
1267 vect_attempt_slp_rearrange_stmts (slp_instance slp_instn
)
1269 unsigned int group_size
= SLP_INSTANCE_GROUP_SIZE (slp_instn
);
1273 slp_tree node
, load
;
1275 /* Compare all the permutation sequences to the first one. We know
1276 that at least one load is permuted. */
1277 node
= SLP_INSTANCE_LOADS (slp_instn
)[0];
1278 if (!node
->load_permutation
.exists ())
1280 for (i
= 1; SLP_INSTANCE_LOADS (slp_instn
).iterate (i
, &load
); ++i
)
1282 if (!load
->load_permutation
.exists ())
1284 FOR_EACH_VEC_ELT (load
->load_permutation
, j
, lidx
)
1285 if (lidx
!= node
->load_permutation
[j
])
1289 /* Check that the loads in the first sequence are different and there
1290 are no gaps between them. */
1291 load_index
= sbitmap_alloc (group_size
);
1292 bitmap_clear (load_index
);
1293 FOR_EACH_VEC_ELT (node
->load_permutation
, i
, lidx
)
1295 if (bitmap_bit_p (load_index
, lidx
))
1297 sbitmap_free (load_index
);
1300 bitmap_set_bit (load_index
, lidx
);
1302 for (i
= 0; i
< group_size
; i
++)
1303 if (!bitmap_bit_p (load_index
, i
))
1305 sbitmap_free (load_index
);
1308 sbitmap_free (load_index
);
1310 /* This permutation is valid for reduction. Since the order of the
1311 statements in the nodes is not important unless they are memory
1312 accesses, we can rearrange the statements in all the nodes
1313 according to the order of the loads. */
1314 vect_slp_rearrange_stmts (SLP_INSTANCE_TREE (slp_instn
), group_size
,
1315 node
->load_permutation
);
1317 /* We are done, no actual permutations need to be generated. */
1318 FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn
), i
, node
)
1319 SLP_TREE_LOAD_PERMUTATION (node
).release ();
1323 /* Check if the required load permutations in the SLP instance
1324 SLP_INSTN are supported. */
1327 vect_supported_load_permutation_p (slp_instance slp_instn
)
1329 unsigned int group_size
= SLP_INSTANCE_GROUP_SIZE (slp_instn
);
1330 unsigned int i
, j
, k
, next
;
1332 gimple stmt
, load
, next_load
, first_load
;
1333 struct data_reference
*dr
;
1335 if (dump_enabled_p ())
1337 dump_printf_loc (MSG_NOTE
, vect_location
, "Load permutation ");
1338 FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn
), i
, node
)
1339 if (node
->load_permutation
.exists ())
1340 FOR_EACH_VEC_ELT (node
->load_permutation
, j
, next
)
1341 dump_printf (MSG_NOTE
, "%d ", next
);
1343 for (k
= 0; k
< group_size
; ++k
)
1344 dump_printf (MSG_NOTE
, "%d ", k
);
1345 dump_printf (MSG_NOTE
, "\n");
1348 /* In case of reduction every load permutation is allowed, since the order
1349 of the reduction statements is not important (as opposed to the case of
1350 grouped stores). The only condition we need to check is that all the
1351 load nodes are of the same size and have the same permutation (and then
1352 rearrange all the nodes of the SLP instance according to this
1355 /* Check that all the load nodes are of the same size. */
1356 /* ??? Can't we assert this? */
1357 FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn
), i
, node
)
1358 if (SLP_TREE_SCALAR_STMTS (node
).length () != (unsigned) group_size
)
1361 node
= SLP_INSTANCE_TREE (slp_instn
);
1362 stmt
= SLP_TREE_SCALAR_STMTS (node
)[0];
1364 /* Reduction (there are no data-refs in the root).
1365 In reduction chain the order of the loads is not important. */
1366 if (!STMT_VINFO_DATA_REF (vinfo_for_stmt (stmt
))
1367 && !GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
)))
1369 if (vect_attempt_slp_rearrange_stmts (slp_instn
))
1372 /* Fallthru to general load permutation handling. */
1375 /* In basic block vectorization we allow any subchain of an interleaving
1377 FORNOW: not supported in loop SLP because of realignment compications. */
1378 if (STMT_VINFO_BB_VINFO (vinfo_for_stmt (stmt
)))
1380 /* Check whether the loads in an instance form a subchain and thus
1381 no permutation is necessary. */
1382 FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn
), i
, node
)
1384 if (!SLP_TREE_LOAD_PERMUTATION (node
).exists ())
1386 bool subchain_p
= true;
1388 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), j
, load
)
1391 && (next_load
!= load
1392 || GROUP_GAP (vinfo_for_stmt (load
)) != 1))
1397 next_load
= GROUP_NEXT_ELEMENT (vinfo_for_stmt (load
));
1400 SLP_TREE_LOAD_PERMUTATION (node
).release ();
1403 /* Verify the permutation can be generated. */
1405 if (!vect_transform_slp_perm_load (node
, tem
, NULL
,
1406 1, slp_instn
, true))
1408 dump_printf_loc (MSG_MISSED_OPTIMIZATION
,
1410 "unsupported load permutation\n");
1416 /* Check that the alignment of the first load in every subchain, i.e.,
1417 the first statement in every load node, is supported.
1418 ??? This belongs in alignment checking. */
1419 FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn
), i
, node
)
1421 first_load
= SLP_TREE_SCALAR_STMTS (node
)[0];
1422 if (first_load
!= GROUP_FIRST_ELEMENT (vinfo_for_stmt (first_load
)))
1424 dr
= STMT_VINFO_DATA_REF (vinfo_for_stmt (first_load
));
1425 if (vect_supportable_dr_alignment (dr
, false)
1426 == dr_unaligned_unsupported
)
1428 if (dump_enabled_p ())
1430 dump_printf_loc (MSG_MISSED_OPTIMIZATION
,
1432 "unsupported unaligned load ");
1433 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
,
1435 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
1445 /* For loop vectorization verify we can generate the permutation. */
1446 FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (slp_instn
), i
, node
)
1447 if (node
->load_permutation
.exists ()
1448 && !vect_transform_slp_perm_load
1450 SLP_INSTANCE_UNROLLING_FACTOR (slp_instn
), slp_instn
, true))
1457 /* Find the last store in SLP INSTANCE. */
1460 vect_find_last_scalar_stmt_in_slp (slp_tree node
)
1462 gimple last
= NULL
, stmt
;
1464 for (int i
= 0; SLP_TREE_SCALAR_STMTS (node
).iterate (i
, &stmt
); i
++)
1466 stmt_vec_info stmt_vinfo
= vinfo_for_stmt (stmt
);
1467 if (is_pattern_stmt_p (stmt_vinfo
))
1468 last
= get_later_stmt (STMT_VINFO_RELATED_STMT (stmt_vinfo
), last
);
1470 last
= get_later_stmt (stmt
, last
);
1476 /* Compute the cost for the SLP node NODE in the SLP instance INSTANCE. */
1479 vect_analyze_slp_cost_1 (slp_instance instance
, slp_tree node
,
1480 stmt_vector_for_cost
*prologue_cost_vec
,
1481 stmt_vector_for_cost
*body_cost_vec
,
1482 unsigned ncopies_for_cost
)
1487 stmt_vec_info stmt_info
;
1489 unsigned group_size
= SLP_INSTANCE_GROUP_SIZE (instance
);
1491 /* Recurse down the SLP tree. */
1492 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
1494 vect_analyze_slp_cost_1 (instance
, child
, prologue_cost_vec
,
1495 body_cost_vec
, ncopies_for_cost
);
1497 /* Look at the first scalar stmt to determine the cost. */
1498 stmt
= SLP_TREE_SCALAR_STMTS (node
)[0];
1499 stmt_info
= vinfo_for_stmt (stmt
);
1500 if (STMT_VINFO_GROUPED_ACCESS (stmt_info
))
1502 if (DR_IS_WRITE (STMT_VINFO_DATA_REF (stmt_info
)))
1503 vect_model_store_cost (stmt_info
, ncopies_for_cost
, false,
1504 vect_uninitialized_def
,
1505 node
, prologue_cost_vec
, body_cost_vec
);
1509 gcc_checking_assert (DR_IS_READ (STMT_VINFO_DATA_REF (stmt_info
)));
1510 vect_model_load_cost (stmt_info
, ncopies_for_cost
, false,
1511 node
, prologue_cost_vec
, body_cost_vec
);
1512 /* If the load is permuted record the cost for the permutation.
1513 ??? Loads from multiple chains are let through here only
1514 for a single special case involving complex numbers where
1515 in the end no permutation is necessary. */
1516 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, s
)
1517 if ((STMT_VINFO_GROUP_FIRST_ELEMENT (vinfo_for_stmt (s
))
1518 == STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_info
))
1519 && vect_get_place_in_interleaving_chain
1520 (s
, STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_info
)) != i
)
1522 record_stmt_cost (body_cost_vec
, group_size
, vec_perm
,
1523 stmt_info
, 0, vect_body
);
1530 record_stmt_cost (body_cost_vec
, ncopies_for_cost
, vector_stmt
,
1531 stmt_info
, 0, vect_body
);
1532 if (SLP_TREE_TWO_OPERATORS (node
))
1534 record_stmt_cost (body_cost_vec
, ncopies_for_cost
, vector_stmt
,
1535 stmt_info
, 0, vect_body
);
1536 record_stmt_cost (body_cost_vec
, ncopies_for_cost
, vec_perm
,
1537 stmt_info
, 0, vect_body
);
1541 /* Scan operands and account for prologue cost of constants/externals.
1542 ??? This over-estimates cost for multiple uses and should be
1544 lhs
= gimple_get_lhs (stmt
);
1545 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
1547 tree def
, op
= gimple_op (stmt
, i
);
1549 enum vect_def_type dt
;
1550 if (!op
|| op
== lhs
)
1552 if (vect_is_simple_use (op
, NULL
, STMT_VINFO_LOOP_VINFO (stmt_info
),
1553 STMT_VINFO_BB_VINFO (stmt_info
),
1554 &def_stmt
, &def
, &dt
))
1556 /* Without looking at the actual initializer a vector of
1557 constants can be implemented as load from the constant pool.
1558 ??? We need to pass down stmt_info for a vector type
1559 even if it points to the wrong stmt. */
1560 if (dt
== vect_constant_def
)
1561 record_stmt_cost (prologue_cost_vec
, 1, vector_load
,
1562 stmt_info
, 0, vect_prologue
);
1563 else if (dt
== vect_external_def
)
1564 record_stmt_cost (prologue_cost_vec
, 1, vec_construct
,
1565 stmt_info
, 0, vect_prologue
);
1570 /* Compute the cost for the SLP instance INSTANCE. */
1573 vect_analyze_slp_cost (slp_instance instance
, void *data
)
1575 stmt_vector_for_cost body_cost_vec
, prologue_cost_vec
;
1576 unsigned ncopies_for_cost
;
1577 stmt_info_for_cost
*si
;
1580 /* Calculate the number of vector stmts to create based on the unrolling
1581 factor (number of vectors is 1 if NUNITS >= GROUP_SIZE, and is
1582 GROUP_SIZE / NUNITS otherwise. */
1583 unsigned group_size
= SLP_INSTANCE_GROUP_SIZE (instance
);
1584 slp_tree node
= SLP_INSTANCE_TREE (instance
);
1585 stmt_vec_info stmt_info
= vinfo_for_stmt (SLP_TREE_SCALAR_STMTS (node
)[0]);
1586 /* Adjust the group_size by the vectorization factor which is always one
1587 for basic-block vectorization. */
1588 if (STMT_VINFO_LOOP_VINFO (stmt_info
))
1589 group_size
*= LOOP_VINFO_VECT_FACTOR (STMT_VINFO_LOOP_VINFO (stmt_info
));
1590 unsigned nunits
= TYPE_VECTOR_SUBPARTS (STMT_VINFO_VECTYPE (stmt_info
));
1591 /* For reductions look at a reduction operand in case the reduction
1592 operation is widening like DOT_PROD or SAD. */
1593 if (!STMT_VINFO_GROUPED_ACCESS (stmt_info
))
1595 gimple stmt
= SLP_TREE_SCALAR_STMTS (node
)[0];
1596 switch (gimple_assign_rhs_code (stmt
))
1600 nunits
= TYPE_VECTOR_SUBPARTS (get_vectype_for_scalar_type
1601 (TREE_TYPE (gimple_assign_rhs1 (stmt
))));
1606 ncopies_for_cost
= least_common_multiple (nunits
, group_size
) / nunits
;
1608 prologue_cost_vec
.create (10);
1609 body_cost_vec
.create (10);
1610 vect_analyze_slp_cost_1 (instance
, SLP_INSTANCE_TREE (instance
),
1611 &prologue_cost_vec
, &body_cost_vec
,
1614 /* Record the prologue costs, which were delayed until we were
1615 sure that SLP was successful. */
1616 FOR_EACH_VEC_ELT (prologue_cost_vec
, i
, si
)
1618 struct _stmt_vec_info
*stmt_info
1619 = si
->stmt
? vinfo_for_stmt (si
->stmt
) : NULL
;
1620 (void) add_stmt_cost (data
, si
->count
, si
->kind
, stmt_info
,
1621 si
->misalign
, vect_prologue
);
1624 /* Record the instance's instructions in the target cost model. */
1625 FOR_EACH_VEC_ELT (body_cost_vec
, i
, si
)
1627 struct _stmt_vec_info
*stmt_info
1628 = si
->stmt
? vinfo_for_stmt (si
->stmt
) : NULL
;
1629 (void) add_stmt_cost (data
, si
->count
, si
->kind
, stmt_info
,
1630 si
->misalign
, vect_body
);
1633 prologue_cost_vec
.release ();
1634 body_cost_vec
.release ();
1637 /* Analyze an SLP instance starting from a group of grouped stores. Call
1638 vect_build_slp_tree to build a tree of packed stmts if possible.
1639 Return FALSE if it's impossible to SLP any stmt in the loop. */
1642 vect_analyze_slp_instance (loop_vec_info loop_vinfo
, bb_vec_info bb_vinfo
,
1643 gimple stmt
, unsigned max_tree_size
)
1645 slp_instance new_instance
;
1647 unsigned int group_size
= GROUP_SIZE (vinfo_for_stmt (stmt
));
1648 unsigned int unrolling_factor
= 1, nunits
;
1649 tree vectype
, scalar_type
= NULL_TREE
;
1651 unsigned int vectorization_factor
= 0;
1653 unsigned int max_nunits
= 0;
1654 vec
<slp_tree
> loads
;
1655 struct data_reference
*dr
= STMT_VINFO_DATA_REF (vinfo_for_stmt (stmt
));
1656 vec
<gimple
> scalar_stmts
;
1658 if (GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
)))
1662 scalar_type
= TREE_TYPE (DR_REF (dr
));
1663 vectype
= get_vectype_for_scalar_type (scalar_type
);
1667 gcc_assert (loop_vinfo
);
1668 vectype
= STMT_VINFO_VECTYPE (vinfo_for_stmt (stmt
));
1671 group_size
= GROUP_SIZE (vinfo_for_stmt (stmt
));
1675 gcc_assert (loop_vinfo
);
1676 vectype
= STMT_VINFO_VECTYPE (vinfo_for_stmt (stmt
));
1677 group_size
= LOOP_VINFO_REDUCTIONS (loop_vinfo
).length ();
1682 if (dump_enabled_p ())
1684 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
1685 "Build SLP failed: unsupported data-type ");
1686 dump_generic_expr (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, scalar_type
);
1687 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
1693 nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1695 vectorization_factor
= LOOP_VINFO_VECT_FACTOR (loop_vinfo
);
1697 vectorization_factor
= nunits
;
1699 /* Calculate the unrolling factor. */
1700 unrolling_factor
= least_common_multiple (nunits
, group_size
) / group_size
;
1701 if (unrolling_factor
!= 1 && !loop_vinfo
)
1703 if (dump_enabled_p ())
1704 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
1705 "Build SLP failed: unrolling required in basic"
1711 /* Create a node (a root of the SLP tree) for the packed grouped stores. */
1712 scalar_stmts
.create (group_size
);
1714 if (GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
)))
1716 /* Collect the stores and store them in SLP_TREE_SCALAR_STMTS. */
1719 if (STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (next
))
1720 && STMT_VINFO_RELATED_STMT (vinfo_for_stmt (next
)))
1721 scalar_stmts
.safe_push (
1722 STMT_VINFO_RELATED_STMT (vinfo_for_stmt (next
)));
1724 scalar_stmts
.safe_push (next
);
1725 next
= GROUP_NEXT_ELEMENT (vinfo_for_stmt (next
));
1727 /* Mark the first element of the reduction chain as reduction to properly
1728 transform the node. In the reduction analysis phase only the last
1729 element of the chain is marked as reduction. */
1730 if (!STMT_VINFO_GROUPED_ACCESS (vinfo_for_stmt (stmt
)))
1731 STMT_VINFO_DEF_TYPE (vinfo_for_stmt (stmt
)) = vect_reduction_def
;
1735 /* Collect reduction statements. */
1736 vec
<gimple
> reductions
= LOOP_VINFO_REDUCTIONS (loop_vinfo
);
1737 for (i
= 0; reductions
.iterate (i
, &next
); i
++)
1738 scalar_stmts
.safe_push (next
);
1741 node
= vect_create_new_slp_node (scalar_stmts
);
1743 loads
.create (group_size
);
1745 /* Build the tree for the SLP instance. */
1746 bool *matches
= XALLOCAVEC (bool, group_size
);
1747 unsigned npermutes
= 0;
1748 if (vect_build_slp_tree (loop_vinfo
, bb_vinfo
, &node
, group_size
,
1749 &max_nunits
, &loads
,
1750 vectorization_factor
, matches
, &npermutes
, NULL
,
1753 /* Calculate the unrolling factor based on the smallest type. */
1754 if (max_nunits
> nunits
)
1755 unrolling_factor
= least_common_multiple (max_nunits
, group_size
)
1758 if (unrolling_factor
!= 1 && !loop_vinfo
)
1760 if (dump_enabled_p ())
1761 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
1762 "Build SLP failed: unrolling required in basic"
1764 vect_free_slp_tree (node
);
1769 /* Create a new SLP instance. */
1770 new_instance
= XNEW (struct _slp_instance
);
1771 SLP_INSTANCE_TREE (new_instance
) = node
;
1772 SLP_INSTANCE_GROUP_SIZE (new_instance
) = group_size
;
1773 SLP_INSTANCE_UNROLLING_FACTOR (new_instance
) = unrolling_factor
;
1774 SLP_INSTANCE_LOADS (new_instance
) = loads
;
1776 /* Compute the load permutation. */
1778 bool loads_permuted
= false;
1779 FOR_EACH_VEC_ELT (loads
, i
, load_node
)
1781 vec
<unsigned> load_permutation
;
1783 gimple load
, first_stmt
;
1784 bool this_load_permuted
= false;
1785 load_permutation
.create (group_size
);
1786 first_stmt
= GROUP_FIRST_ELEMENT
1787 (vinfo_for_stmt (SLP_TREE_SCALAR_STMTS (load_node
)[0]));
1788 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (load_node
), j
, load
)
1791 = vect_get_place_in_interleaving_chain (load
, first_stmt
);
1792 gcc_assert (load_place
!= -1);
1793 if (load_place
!= j
)
1794 this_load_permuted
= true;
1795 load_permutation
.safe_push (load_place
);
1797 if (!this_load_permuted
1798 /* The load requires permutation when unrolling exposes
1799 a gap either because the group is larger than the SLP
1800 group-size or because there is a gap between the groups. */
1801 && (unrolling_factor
== 1
1802 || (group_size
== GROUP_SIZE (vinfo_for_stmt (first_stmt
))
1803 && GROUP_GAP (vinfo_for_stmt (first_stmt
)) == 0)))
1805 load_permutation
.release ();
1808 SLP_TREE_LOAD_PERMUTATION (load_node
) = load_permutation
;
1809 loads_permuted
= true;
1814 if (!vect_supported_load_permutation_p (new_instance
))
1816 if (dump_enabled_p ())
1818 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
1819 "Build SLP failed: unsupported load "
1821 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
1822 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
1824 vect_free_slp_instance (new_instance
);
1831 LOOP_VINFO_SLP_INSTANCES (loop_vinfo
).safe_push (new_instance
);
1833 BB_VINFO_SLP_INSTANCES (bb_vinfo
).safe_push (new_instance
);
1835 if (dump_enabled_p ())
1836 vect_print_slp_tree (MSG_NOTE
, node
);
1841 /* Failed to SLP. */
1842 /* Free the allocated memory. */
1843 vect_free_slp_tree (node
);
1850 /* Check if there are stmts in the loop can be vectorized using SLP. Build SLP
1851 trees of packed scalar stmts if SLP is possible. */
1854 vect_analyze_slp (loop_vec_info loop_vinfo
, bb_vec_info bb_vinfo
,
1855 unsigned max_tree_size
)
1858 vec
<gimple
> grouped_stores
;
1859 vec
<gimple
> reductions
= vNULL
;
1860 vec
<gimple
> reduc_chains
= vNULL
;
1861 gimple first_element
;
1864 if (dump_enabled_p ())
1865 dump_printf_loc (MSG_NOTE
, vect_location
, "=== vect_analyze_slp ===\n");
1869 grouped_stores
= LOOP_VINFO_GROUPED_STORES (loop_vinfo
);
1870 reduc_chains
= LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo
);
1871 reductions
= LOOP_VINFO_REDUCTIONS (loop_vinfo
);
1874 grouped_stores
= BB_VINFO_GROUPED_STORES (bb_vinfo
);
1876 /* Find SLP sequences starting from groups of grouped stores. */
1877 FOR_EACH_VEC_ELT (grouped_stores
, i
, first_element
)
1878 if (vect_analyze_slp_instance (loop_vinfo
, bb_vinfo
, first_element
,
1882 if (reduc_chains
.length () > 0)
1884 /* Find SLP sequences starting from reduction chains. */
1885 FOR_EACH_VEC_ELT (reduc_chains
, i
, first_element
)
1886 if (vect_analyze_slp_instance (loop_vinfo
, bb_vinfo
, first_element
,
1892 /* Don't try to vectorize SLP reductions if reduction chain was
1897 /* Find SLP sequences starting from groups of reductions. */
1898 if (reductions
.length () > 1
1899 && vect_analyze_slp_instance (loop_vinfo
, bb_vinfo
, reductions
[0],
1907 /* For each possible SLP instance decide whether to SLP it and calculate overall
1908 unrolling factor needed to SLP the loop. Return TRUE if decided to SLP at
1909 least one instance. */
1912 vect_make_slp_decision (loop_vec_info loop_vinfo
)
1914 unsigned int i
, unrolling_factor
= 1;
1915 vec
<slp_instance
> slp_instances
= LOOP_VINFO_SLP_INSTANCES (loop_vinfo
);
1916 slp_instance instance
;
1917 int decided_to_slp
= 0;
1919 if (dump_enabled_p ())
1920 dump_printf_loc (MSG_NOTE
, vect_location
, "=== vect_make_slp_decision ==="
1923 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
1925 /* FORNOW: SLP if you can. */
1926 if (unrolling_factor
< SLP_INSTANCE_UNROLLING_FACTOR (instance
))
1927 unrolling_factor
= SLP_INSTANCE_UNROLLING_FACTOR (instance
);
1929 /* Mark all the stmts that belong to INSTANCE as PURE_SLP stmts. Later we
1930 call vect_detect_hybrid_slp () to find stmts that need hybrid SLP and
1931 loop-based vectorization. Such stmts will be marked as HYBRID. */
1932 vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance
), pure_slp
, -1);
1936 LOOP_VINFO_SLP_UNROLLING_FACTOR (loop_vinfo
) = unrolling_factor
;
1938 if (decided_to_slp
&& dump_enabled_p ())
1939 dump_printf_loc (MSG_NOTE
, vect_location
,
1940 "Decided to SLP %d instances. Unrolling factor %d\n",
1941 decided_to_slp
, unrolling_factor
);
1943 return (decided_to_slp
> 0);
1947 /* Find stmts that must be both vectorized and SLPed (since they feed stmts that
1948 can't be SLPed) in the tree rooted at NODE. Mark such stmts as HYBRID. */
1951 vect_detect_hybrid_slp_stmts (slp_tree node
, unsigned i
, slp_vect_type stype
)
1953 gimple stmt
= SLP_TREE_SCALAR_STMTS (node
)[i
];
1954 imm_use_iterator imm_iter
;
1956 stmt_vec_info use_vinfo
, stmt_vinfo
= vinfo_for_stmt (stmt
);
1958 loop_vec_info loop_vinfo
= STMT_VINFO_LOOP_VINFO (stmt_vinfo
);
1959 struct loop
*loop
= LOOP_VINFO_LOOP (loop_vinfo
);
1962 /* Propagate hybrid down the SLP tree. */
1963 if (stype
== hybrid
)
1965 else if (HYBRID_SLP_STMT (stmt_vinfo
))
1969 /* Check if a pure SLP stmt has uses in non-SLP stmts. */
1970 gcc_checking_assert (PURE_SLP_STMT (stmt_vinfo
));
1971 /* We always get the pattern stmt here, but for immediate
1972 uses we have to use the LHS of the original stmt. */
1973 gcc_checking_assert (!STMT_VINFO_IN_PATTERN_P (stmt_vinfo
));
1974 if (STMT_VINFO_RELATED_STMT (stmt_vinfo
))
1975 stmt
= STMT_VINFO_RELATED_STMT (stmt_vinfo
);
1976 if (TREE_CODE (gimple_op (stmt
, 0)) == SSA_NAME
)
1977 FOR_EACH_IMM_USE_STMT (use_stmt
, imm_iter
, gimple_op (stmt
, 0))
1979 if (!flow_bb_inside_loop_p (loop
, gimple_bb (use_stmt
)))
1981 use_vinfo
= vinfo_for_stmt (use_stmt
);
1982 if (STMT_VINFO_IN_PATTERN_P (use_vinfo
)
1983 && STMT_VINFO_RELATED_STMT (use_vinfo
))
1984 use_vinfo
= vinfo_for_stmt (STMT_VINFO_RELATED_STMT (use_vinfo
));
1985 if (!STMT_SLP_TYPE (use_vinfo
)
1986 && (STMT_VINFO_RELEVANT (use_vinfo
)
1987 || VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (use_vinfo
)))
1988 && !(gimple_code (use_stmt
) == GIMPLE_PHI
1989 && STMT_VINFO_DEF_TYPE (use_vinfo
) == vect_reduction_def
))
1991 if (dump_enabled_p ())
1993 dump_printf_loc (MSG_NOTE
, vect_location
, "use of SLP "
1994 "def in non-SLP stmt: ");
1995 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
, use_stmt
, 0);
2003 && !HYBRID_SLP_STMT (stmt_vinfo
))
2005 if (dump_enabled_p ())
2007 dump_printf_loc (MSG_NOTE
, vect_location
, "marking hybrid: ");
2008 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
, stmt
, 0);
2010 STMT_SLP_TYPE (stmt_vinfo
) = hybrid
;
2013 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), j
, child
)
2015 vect_detect_hybrid_slp_stmts (child
, i
, stype
);
2018 /* Helpers for vect_detect_hybrid_slp walking pattern stmt uses. */
2021 vect_detect_hybrid_slp_1 (tree
*tp
, int *, void *data
)
2023 walk_stmt_info
*wi
= (walk_stmt_info
*)data
;
2024 struct loop
*loopp
= (struct loop
*)wi
->info
;
2029 if (TREE_CODE (*tp
) == SSA_NAME
2030 && !SSA_NAME_IS_DEFAULT_DEF (*tp
))
2032 gimple def_stmt
= SSA_NAME_DEF_STMT (*tp
);
2033 if (flow_bb_inside_loop_p (loopp
, gimple_bb (def_stmt
))
2034 && PURE_SLP_STMT (vinfo_for_stmt (def_stmt
)))
2036 if (dump_enabled_p ())
2038 dump_printf_loc (MSG_NOTE
, vect_location
, "marking hybrid: ");
2039 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
, def_stmt
, 0);
2041 STMT_SLP_TYPE (vinfo_for_stmt (def_stmt
)) = hybrid
;
2049 vect_detect_hybrid_slp_2 (gimple_stmt_iterator
*gsi
, bool *handled
,
2052 /* If the stmt is in a SLP instance then this isn't a reason
2053 to mark use definitions in other SLP instances as hybrid. */
2054 if (STMT_SLP_TYPE (vinfo_for_stmt (gsi_stmt (*gsi
))) != loop_vect
)
2059 /* Find stmts that must be both vectorized and SLPed. */
2062 vect_detect_hybrid_slp (loop_vec_info loop_vinfo
)
2065 vec
<slp_instance
> slp_instances
= LOOP_VINFO_SLP_INSTANCES (loop_vinfo
);
2066 slp_instance instance
;
2068 if (dump_enabled_p ())
2069 dump_printf_loc (MSG_NOTE
, vect_location
, "=== vect_detect_hybrid_slp ==="
2072 /* First walk all pattern stmt in the loop and mark defs of uses as
2073 hybrid because immediate uses in them are not recorded. */
2074 for (i
= 0; i
< LOOP_VINFO_LOOP (loop_vinfo
)->num_nodes
; ++i
)
2076 basic_block bb
= LOOP_VINFO_BBS (loop_vinfo
)[i
];
2077 for (gimple_stmt_iterator gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
);
2080 gimple stmt
= gsi_stmt (gsi
);
2081 stmt_vec_info stmt_info
= vinfo_for_stmt (stmt
);
2082 if (STMT_VINFO_IN_PATTERN_P (stmt_info
))
2085 memset (&wi
, 0, sizeof (wi
));
2086 wi
.info
= LOOP_VINFO_LOOP (loop_vinfo
);
2087 gimple_stmt_iterator gsi2
2088 = gsi_for_stmt (STMT_VINFO_RELATED_STMT (stmt_info
));
2089 walk_gimple_stmt (&gsi2
, vect_detect_hybrid_slp_2
,
2090 vect_detect_hybrid_slp_1
, &wi
);
2091 walk_gimple_seq (STMT_VINFO_PATTERN_DEF_SEQ (stmt_info
),
2092 vect_detect_hybrid_slp_2
,
2093 vect_detect_hybrid_slp_1
, &wi
);
2098 /* Then walk the SLP instance trees marking stmts with uses in
2099 non-SLP stmts as hybrid, also propagating hybrid down the
2100 SLP tree, collecting the above info on-the-fly. */
2101 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
2103 for (unsigned i
= 0; i
< SLP_INSTANCE_GROUP_SIZE (instance
); ++i
)
2104 vect_detect_hybrid_slp_stmts (SLP_INSTANCE_TREE (instance
),
2110 /* Create and initialize a new bb_vec_info struct for BB, as well as
2111 stmt_vec_info structs for all the stmts in it. */
2114 new_bb_vec_info (basic_block bb
)
2116 bb_vec_info res
= NULL
;
2117 gimple_stmt_iterator gsi
;
2119 res
= (bb_vec_info
) xcalloc (1, sizeof (struct _bb_vec_info
));
2120 BB_VINFO_BB (res
) = bb
;
2122 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
2124 gimple stmt
= gsi_stmt (gsi
);
2125 gimple_set_uid (stmt
, 0);
2126 set_vinfo_for_stmt (stmt
, new_stmt_vec_info (stmt
, NULL
, res
));
2129 BB_VINFO_GROUPED_STORES (res
).create (10);
2130 BB_VINFO_SLP_INSTANCES (res
).create (2);
2131 BB_VINFO_TARGET_COST_DATA (res
) = init_cost (NULL
);
2138 /* Free BB_VINFO struct, as well as all the stmt_vec_info structs of all the
2139 stmts in the basic block. */
2142 destroy_bb_vec_info (bb_vec_info bb_vinfo
)
2144 vec
<slp_instance
> slp_instances
;
2145 slp_instance instance
;
2147 gimple_stmt_iterator si
;
2153 bb
= BB_VINFO_BB (bb_vinfo
);
2155 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
2157 gimple stmt
= gsi_stmt (si
);
2158 stmt_vec_info stmt_info
= vinfo_for_stmt (stmt
);
2161 /* Free stmt_vec_info. */
2162 free_stmt_vec_info (stmt
);
2165 vect_destroy_datarefs (NULL
, bb_vinfo
);
2166 free_dependence_relations (BB_VINFO_DDRS (bb_vinfo
));
2167 BB_VINFO_GROUPED_STORES (bb_vinfo
).release ();
2168 slp_instances
= BB_VINFO_SLP_INSTANCES (bb_vinfo
);
2169 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
2170 vect_free_slp_instance (instance
);
2171 BB_VINFO_SLP_INSTANCES (bb_vinfo
).release ();
2172 destroy_cost_data (BB_VINFO_TARGET_COST_DATA (bb_vinfo
));
2178 /* Analyze statements contained in SLP tree node after recursively analyzing
2179 the subtree. Return TRUE if the operations are supported. */
2182 vect_slp_analyze_node_operations (slp_tree node
)
2192 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
2193 if (!vect_slp_analyze_node_operations (child
))
2196 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
2198 stmt_vec_info stmt_info
= vinfo_for_stmt (stmt
);
2199 gcc_assert (stmt_info
);
2200 gcc_assert (STMT_SLP_TYPE (stmt_info
) != loop_vect
);
2202 if (!vect_analyze_stmt (stmt
, &dummy
, node
))
2210 /* Analyze statements in SLP instances of the basic block. Return TRUE if the
2211 operations are supported. */
2214 vect_slp_analyze_operations (vec
<slp_instance
> slp_instances
, void *data
)
2216 slp_instance instance
;
2219 if (dump_enabled_p ())
2220 dump_printf_loc (MSG_NOTE
, vect_location
,
2221 "=== vect_slp_analyze_operations ===\n");
2223 for (i
= 0; slp_instances
.iterate (i
, &instance
); )
2225 if (!vect_slp_analyze_node_operations (SLP_INSTANCE_TREE (instance
)))
2227 dump_printf_loc (MSG_NOTE
, vect_location
,
2228 "removing SLP instance operations starting from: ");
2229 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
,
2230 SLP_TREE_SCALAR_STMTS
2231 (SLP_INSTANCE_TREE (instance
))[0], 0);
2232 vect_free_slp_instance (instance
);
2233 slp_instances
.ordered_remove (i
);
2237 /* Compute the costs of the SLP instance. */
2238 vect_analyze_slp_cost (instance
, data
);
2243 if (!slp_instances
.length ())
2250 /* Compute the scalar cost of the SLP node NODE and its children
2251 and return it. Do not account defs that are marked in LIFE and
2252 update LIFE according to uses of NODE. */
2255 vect_bb_slp_scalar_cost (basic_block bb
,
2256 slp_tree node
, vec
<bool, va_heap
> *life
)
2258 unsigned scalar_cost
= 0;
2263 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
2266 ssa_op_iter op_iter
;
2267 def_operand_p def_p
;
2268 stmt_vec_info stmt_info
;
2273 /* If there is a non-vectorized use of the defs then the scalar
2274 stmt is kept live in which case we do not account it or any
2275 required defs in the SLP children in the scalar cost. This
2276 way we make the vectorization more costly when compared to
2278 FOR_EACH_SSA_DEF_OPERAND (def_p
, stmt
, op_iter
, SSA_OP_DEF
)
2280 imm_use_iterator use_iter
;
2282 FOR_EACH_IMM_USE_STMT (use_stmt
, use_iter
, DEF_FROM_PTR (def_p
))
2283 if (!is_gimple_debug (use_stmt
)
2284 && (gimple_code (use_stmt
) == GIMPLE_PHI
2285 || gimple_bb (use_stmt
) != bb
2286 || !STMT_VINFO_VECTORIZABLE (vinfo_for_stmt (use_stmt
))))
2289 BREAK_FROM_IMM_USE_STMT (use_iter
);
2295 stmt_info
= vinfo_for_stmt (stmt
);
2296 if (STMT_VINFO_DATA_REF (stmt_info
))
2298 if (DR_IS_READ (STMT_VINFO_DATA_REF (stmt_info
)))
2299 stmt_cost
= vect_get_stmt_cost (scalar_load
);
2301 stmt_cost
= vect_get_stmt_cost (scalar_store
);
2304 stmt_cost
= vect_get_stmt_cost (scalar_stmt
);
2306 scalar_cost
+= stmt_cost
;
2309 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
2311 scalar_cost
+= vect_bb_slp_scalar_cost (bb
, child
, life
);
2316 /* Check if vectorization of the basic block is profitable. */
2319 vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo
)
2321 vec
<slp_instance
> slp_instances
= BB_VINFO_SLP_INSTANCES (bb_vinfo
);
2322 slp_instance instance
;
2324 unsigned int vec_inside_cost
= 0, vec_outside_cost
= 0, scalar_cost
= 0;
2325 unsigned int vec_prologue_cost
= 0, vec_epilogue_cost
= 0;
2327 /* Calculate scalar cost. */
2328 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
2330 auto_vec
<bool, 20> life
;
2331 life
.safe_grow_cleared (SLP_INSTANCE_GROUP_SIZE (instance
));
2332 scalar_cost
+= vect_bb_slp_scalar_cost (BB_VINFO_BB (bb_vinfo
),
2333 SLP_INSTANCE_TREE (instance
),
2337 /* Complete the target-specific cost calculation. */
2338 finish_cost (BB_VINFO_TARGET_COST_DATA (bb_vinfo
), &vec_prologue_cost
,
2339 &vec_inside_cost
, &vec_epilogue_cost
);
2341 vec_outside_cost
= vec_prologue_cost
+ vec_epilogue_cost
;
2343 if (dump_enabled_p ())
2345 dump_printf_loc (MSG_NOTE
, vect_location
, "Cost model analysis: \n");
2346 dump_printf (MSG_NOTE
, " Vector inside of basic block cost: %d\n",
2348 dump_printf (MSG_NOTE
, " Vector prologue cost: %d\n", vec_prologue_cost
);
2349 dump_printf (MSG_NOTE
, " Vector epilogue cost: %d\n", vec_epilogue_cost
);
2350 dump_printf (MSG_NOTE
, " Scalar cost of basic block: %d\n", scalar_cost
);
2353 /* Vectorization is profitable if its cost is less than the cost of scalar
2355 if (vec_outside_cost
+ vec_inside_cost
>= scalar_cost
)
2361 /* Check if the basic block can be vectorized. */
2364 vect_slp_analyze_bb_1 (basic_block bb
)
2366 bb_vec_info bb_vinfo
;
2367 vec
<slp_instance
> slp_instances
;
2368 slp_instance instance
;
2371 unsigned n_stmts
= 0;
2373 bb_vinfo
= new_bb_vec_info (bb
);
2377 if (!vect_analyze_data_refs (NULL
, bb_vinfo
, &min_vf
, &n_stmts
))
2379 if (dump_enabled_p ())
2380 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2381 "not vectorized: unhandled data-ref in basic "
2384 destroy_bb_vec_info (bb_vinfo
);
2388 if (BB_VINFO_DATAREFS (bb_vinfo
).length () < 2)
2390 if (dump_enabled_p ())
2391 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2392 "not vectorized: not enough data-refs in "
2395 destroy_bb_vec_info (bb_vinfo
);
2399 if (!vect_analyze_data_ref_accesses (NULL
, bb_vinfo
))
2401 if (dump_enabled_p ())
2402 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2403 "not vectorized: unhandled data access in "
2406 destroy_bb_vec_info (bb_vinfo
);
2410 vect_pattern_recog (NULL
, bb_vinfo
);
2412 if (!vect_analyze_data_refs_alignment (NULL
, bb_vinfo
))
2414 if (dump_enabled_p ())
2415 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2416 "not vectorized: bad data alignment in basic "
2419 destroy_bb_vec_info (bb_vinfo
);
2423 /* Check the SLP opportunities in the basic block, analyze and build SLP
2425 if (!vect_analyze_slp (NULL
, bb_vinfo
, n_stmts
))
2427 if (dump_enabled_p ())
2429 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2430 "Failed to SLP the basic block.\n");
2431 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2432 "not vectorized: failed to find SLP opportunities "
2433 "in basic block.\n");
2436 destroy_bb_vec_info (bb_vinfo
);
2440 slp_instances
= BB_VINFO_SLP_INSTANCES (bb_vinfo
);
2442 /* Mark all the statements that we want to vectorize as pure SLP and
2444 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
2446 vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance
), pure_slp
, -1);
2447 vect_mark_slp_stmts_relevant (SLP_INSTANCE_TREE (instance
));
2450 /* Mark all the statements that we do not want to vectorize. */
2451 for (gimple_stmt_iterator gsi
= gsi_start_bb (BB_VINFO_BB (bb_vinfo
));
2452 !gsi_end_p (gsi
); gsi_next (&gsi
))
2454 stmt_vec_info vinfo
= vinfo_for_stmt (gsi_stmt (gsi
));
2455 if (STMT_SLP_TYPE (vinfo
) != pure_slp
)
2456 STMT_VINFO_VECTORIZABLE (vinfo
) = false;
2459 /* Analyze dependences. At this point all stmts not participating in
2460 vectorization have to be marked. Dependence analysis assumes
2461 that we either vectorize all SLP instances or none at all. */
2462 if (!vect_slp_analyze_data_ref_dependences (bb_vinfo
))
2464 if (dump_enabled_p ())
2465 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2466 "not vectorized: unhandled data dependence "
2467 "in basic block.\n");
2469 destroy_bb_vec_info (bb_vinfo
);
2473 if (!vect_verify_datarefs_alignment (NULL
, bb_vinfo
))
2475 if (dump_enabled_p ())
2476 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2477 "not vectorized: unsupported alignment in basic "
2479 destroy_bb_vec_info (bb_vinfo
);
2483 if (!vect_slp_analyze_operations (BB_VINFO_SLP_INSTANCES (bb_vinfo
),
2484 BB_VINFO_TARGET_COST_DATA (bb_vinfo
)))
2486 if (dump_enabled_p ())
2487 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2488 "not vectorized: bad operation in basic block.\n");
2490 destroy_bb_vec_info (bb_vinfo
);
2494 /* Cost model: check if the vectorization is worthwhile. */
2495 if (!unlimited_cost_model (NULL
)
2496 && !vect_bb_vectorization_profitable_p (bb_vinfo
))
2498 if (dump_enabled_p ())
2499 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2500 "not vectorized: vectorization is not "
2503 destroy_bb_vec_info (bb_vinfo
);
2507 if (dump_enabled_p ())
2508 dump_printf_loc (MSG_NOTE
, vect_location
,
2509 "Basic block will be vectorized using SLP\n");
2516 vect_slp_analyze_bb (basic_block bb
)
2518 bb_vec_info bb_vinfo
;
2520 gimple_stmt_iterator gsi
;
2521 unsigned int vector_sizes
;
2523 if (dump_enabled_p ())
2524 dump_printf_loc (MSG_NOTE
, vect_location
, "===vect_slp_analyze_bb===\n");
2526 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
2528 gimple stmt
= gsi_stmt (gsi
);
2529 if (!is_gimple_debug (stmt
)
2530 && !gimple_nop_p (stmt
)
2531 && gimple_code (stmt
) != GIMPLE_LABEL
)
2535 if (insns
> PARAM_VALUE (PARAM_SLP_MAX_INSNS_IN_BB
))
2537 if (dump_enabled_p ())
2538 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
2539 "not vectorized: too many instructions in "
2545 /* Autodetect first vector size we try. */
2546 current_vector_size
= 0;
2547 vector_sizes
= targetm
.vectorize
.autovectorize_vector_sizes ();
2551 bb_vinfo
= vect_slp_analyze_bb_1 (bb
);
2555 destroy_bb_vec_info (bb_vinfo
);
2557 vector_sizes
&= ~current_vector_size
;
2558 if (vector_sizes
== 0
2559 || current_vector_size
== 0)
2562 /* Try the next biggest vector size. */
2563 current_vector_size
= 1 << floor_log2 (vector_sizes
);
2564 if (dump_enabled_p ())
2565 dump_printf_loc (MSG_NOTE
, vect_location
,
2566 "***** Re-trying analysis with "
2567 "vector size %d\n", current_vector_size
);
2572 /* For constant and loop invariant defs of SLP_NODE this function returns
2573 (vector) defs (VEC_OPRNDS) that will be used in the vectorized stmts.
2574 OP_NUM determines if we gather defs for operand 0 or operand 1 of the RHS of
2575 scalar stmts. NUMBER_OF_VECTORS is the number of vector defs to create.
2576 REDUC_INDEX is the index of the reduction operand in the statements, unless
2580 vect_get_constant_vectors (tree op
, slp_tree slp_node
,
2581 vec
<tree
> *vec_oprnds
,
2582 unsigned int op_num
, unsigned int number_of_vectors
,
2585 vec
<gimple
> stmts
= SLP_TREE_SCALAR_STMTS (slp_node
);
2586 gimple stmt
= stmts
[0];
2587 stmt_vec_info stmt_vinfo
= vinfo_for_stmt (stmt
);
2591 unsigned j
, number_of_places_left_in_vector
;
2594 int group_size
= stmts
.length ();
2595 unsigned int vec_num
, i
;
2596 unsigned number_of_copies
= 1;
2598 voprnds
.create (number_of_vectors
);
2599 bool constant_p
, is_store
;
2600 tree neutral_op
= NULL
;
2601 enum tree_code code
= gimple_expr_code (stmt
);
2604 gimple_seq ctor_seq
= NULL
;
2606 vector_type
= get_vectype_for_scalar_type (TREE_TYPE (op
));
2607 nunits
= TYPE_VECTOR_SUBPARTS (vector_type
);
2609 if (STMT_VINFO_DEF_TYPE (stmt_vinfo
) == vect_reduction_def
2610 && reduc_index
!= -1)
2612 op_num
= reduc_index
;
2613 op
= gimple_op (stmt
, op_num
+ 1);
2614 /* For additional copies (see the explanation of NUMBER_OF_COPIES below)
2615 we need either neutral operands or the original operands. See
2616 get_initial_def_for_reduction() for details. */
2619 case WIDEN_SUM_EXPR
:
2626 if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (op
)))
2627 neutral_op
= build_real (TREE_TYPE (op
), dconst0
);
2629 neutral_op
= build_int_cst (TREE_TYPE (op
), 0);
2634 if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (op
)))
2635 neutral_op
= build_real (TREE_TYPE (op
), dconst1
);
2637 neutral_op
= build_int_cst (TREE_TYPE (op
), 1);
2642 neutral_op
= build_int_cst (TREE_TYPE (op
), -1);
2645 /* For MIN/MAX we don't have an easy neutral operand but
2646 the initial values can be used fine here. Only for
2647 a reduction chain we have to force a neutral element. */
2650 if (!GROUP_FIRST_ELEMENT (stmt_vinfo
))
2654 def_stmt
= SSA_NAME_DEF_STMT (op
);
2655 loop
= (gimple_bb (stmt
))->loop_father
;
2656 neutral_op
= PHI_ARG_DEF_FROM_EDGE (def_stmt
,
2657 loop_preheader_edge (loop
));
2662 gcc_assert (!GROUP_FIRST_ELEMENT (stmt_vinfo
));
2667 if (STMT_VINFO_DATA_REF (stmt_vinfo
))
2670 op
= gimple_assign_rhs1 (stmt
);
2677 if (CONSTANT_CLASS_P (op
))
2682 /* NUMBER_OF_COPIES is the number of times we need to use the same values in
2683 created vectors. It is greater than 1 if unrolling is performed.
2685 For example, we have two scalar operands, s1 and s2 (e.g., group of
2686 strided accesses of size two), while NUNITS is four (i.e., four scalars
2687 of this type can be packed in a vector). The output vector will contain
2688 two copies of each scalar operand: {s1, s2, s1, s2}. (NUMBER_OF_COPIES
2691 If GROUP_SIZE > NUNITS, the scalars will be split into several vectors
2692 containing the operands.
2694 For example, NUNITS is four as before, and the group size is 8
2695 (s1, s2, ..., s8). We will create two vectors {s1, s2, s3, s4} and
2696 {s5, s6, s7, s8}. */
2698 number_of_copies
= nunits
* number_of_vectors
/ group_size
;
2700 number_of_places_left_in_vector
= nunits
;
2701 elts
= XALLOCAVEC (tree
, nunits
);
2702 bool place_after_defs
= false;
2703 for (j
= 0; j
< number_of_copies
; j
++)
2705 for (i
= group_size
- 1; stmts
.iterate (i
, &stmt
); i
--)
2708 op
= gimple_assign_rhs1 (stmt
);
2714 if (op_num
== 0 || op_num
== 1)
2716 tree cond
= gimple_assign_rhs1 (stmt
);
2717 op
= TREE_OPERAND (cond
, op_num
);
2722 op
= gimple_assign_rhs2 (stmt
);
2724 op
= gimple_assign_rhs3 (stmt
);
2729 op
= gimple_call_arg (stmt
, op_num
);
2736 op
= gimple_op (stmt
, op_num
+ 1);
2737 /* Unlike the other binary operators, shifts/rotates have
2738 the shift count being int, instead of the same type as
2739 the lhs, so make sure the scalar is the right type if
2740 we are dealing with vectors of
2741 long long/long/short/char. */
2742 if (op_num
== 1 && TREE_CODE (op
) == INTEGER_CST
)
2743 op
= fold_convert (TREE_TYPE (vector_type
), op
);
2747 op
= gimple_op (stmt
, op_num
+ 1);
2752 if (reduc_index
!= -1)
2754 loop
= (gimple_bb (stmt
))->loop_father
;
2755 def_stmt
= SSA_NAME_DEF_STMT (op
);
2759 /* Get the def before the loop. In reduction chain we have only
2760 one initial value. */
2761 if ((j
!= (number_of_copies
- 1)
2762 || (GROUP_FIRST_ELEMENT (vinfo_for_stmt (stmt
))
2767 op
= PHI_ARG_DEF_FROM_EDGE (def_stmt
,
2768 loop_preheader_edge (loop
));
2771 /* Create 'vect_ = {op0,op1,...,opn}'. */
2772 number_of_places_left_in_vector
--;
2774 if (!types_compatible_p (TREE_TYPE (vector_type
), TREE_TYPE (op
)))
2776 if (CONSTANT_CLASS_P (op
))
2778 op
= fold_unary (VIEW_CONVERT_EXPR
,
2779 TREE_TYPE (vector_type
), op
);
2780 gcc_assert (op
&& CONSTANT_CLASS_P (op
));
2784 tree new_temp
= make_ssa_name (TREE_TYPE (vector_type
));
2786 op
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (vector_type
), op
);
2788 = gimple_build_assign (new_temp
, VIEW_CONVERT_EXPR
, op
);
2789 gimple_seq_add_stmt (&ctor_seq
, init_stmt
);
2793 elts
[number_of_places_left_in_vector
] = op
;
2794 if (!CONSTANT_CLASS_P (op
))
2796 if (TREE_CODE (orig_op
) == SSA_NAME
2797 && !SSA_NAME_IS_DEFAULT_DEF (orig_op
)
2798 && STMT_VINFO_BB_VINFO (stmt_vinfo
)
2799 && (STMT_VINFO_BB_VINFO (stmt_vinfo
)->bb
2800 == gimple_bb (SSA_NAME_DEF_STMT (orig_op
))))
2801 place_after_defs
= true;
2803 if (number_of_places_left_in_vector
== 0)
2805 number_of_places_left_in_vector
= nunits
;
2808 vec_cst
= build_vector (vector_type
, elts
);
2811 vec
<constructor_elt
, va_gc
> *v
;
2813 vec_alloc (v
, nunits
);
2814 for (k
= 0; k
< nunits
; ++k
)
2815 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, elts
[k
]);
2816 vec_cst
= build_constructor (vector_type
, v
);
2819 gimple_stmt_iterator gsi
;
2820 if (place_after_defs
)
2823 (vect_find_last_scalar_stmt_in_slp (slp_node
));
2824 init
= vect_init_vector (stmt
, vec_cst
, vector_type
, &gsi
);
2827 init
= vect_init_vector (stmt
, vec_cst
, vector_type
, NULL
);
2828 if (ctor_seq
!= NULL
)
2830 gsi
= gsi_for_stmt (SSA_NAME_DEF_STMT (init
));
2831 gsi_insert_seq_before_without_update (&gsi
, ctor_seq
,
2835 voprnds
.quick_push (init
);
2836 place_after_defs
= false;
2841 /* Since the vectors are created in the reverse order, we should invert
2843 vec_num
= voprnds
.length ();
2844 for (j
= vec_num
; j
!= 0; j
--)
2846 vop
= voprnds
[j
- 1];
2847 vec_oprnds
->quick_push (vop
);
2852 /* In case that VF is greater than the unrolling factor needed for the SLP
2853 group of stmts, NUMBER_OF_VECTORS to be created is greater than
2854 NUMBER_OF_SCALARS/NUNITS or NUNITS/NUMBER_OF_SCALARS, and hence we have
2855 to replicate the vectors. */
2856 while (number_of_vectors
> vec_oprnds
->length ())
2858 tree neutral_vec
= NULL
;
2863 neutral_vec
= build_vector_from_val (vector_type
, neutral_op
);
2865 vec_oprnds
->quick_push (neutral_vec
);
2869 for (i
= 0; vec_oprnds
->iterate (i
, &vop
) && i
< vec_num
; i
++)
2870 vec_oprnds
->quick_push (vop
);
2876 /* Get vectorized definitions from SLP_NODE that contains corresponding
2877 vectorized def-stmts. */
2880 vect_get_slp_vect_defs (slp_tree slp_node
, vec
<tree
> *vec_oprnds
)
2883 gimple vec_def_stmt
;
2886 gcc_assert (SLP_TREE_VEC_STMTS (slp_node
).exists ());
2888 FOR_EACH_VEC_ELT (SLP_TREE_VEC_STMTS (slp_node
), i
, vec_def_stmt
)
2890 gcc_assert (vec_def_stmt
);
2891 vec_oprnd
= gimple_get_lhs (vec_def_stmt
);
2892 vec_oprnds
->quick_push (vec_oprnd
);
2897 /* Get vectorized definitions for SLP_NODE.
2898 If the scalar definitions are loop invariants or constants, collect them and
2899 call vect_get_constant_vectors() to create vector stmts.
2900 Otherwise, the def-stmts must be already vectorized and the vectorized stmts
2901 must be stored in the corresponding child of SLP_NODE, and we call
2902 vect_get_slp_vect_defs () to retrieve them. */
2905 vect_get_slp_defs (vec
<tree
> ops
, slp_tree slp_node
,
2906 vec
<vec
<tree
> > *vec_oprnds
, int reduc_index
)
2909 int number_of_vects
= 0, i
;
2910 unsigned int child_index
= 0;
2911 HOST_WIDE_INT lhs_size_unit
, rhs_size_unit
;
2912 slp_tree child
= NULL
;
2915 bool vectorized_defs
;
2917 first_stmt
= SLP_TREE_SCALAR_STMTS (slp_node
)[0];
2918 FOR_EACH_VEC_ELT (ops
, i
, oprnd
)
2920 /* For each operand we check if it has vectorized definitions in a child
2921 node or we need to create them (for invariants and constants). We
2922 check if the LHS of the first stmt of the next child matches OPRND.
2923 If it does, we found the correct child. Otherwise, we call
2924 vect_get_constant_vectors (), and not advance CHILD_INDEX in order
2925 to check this child node for the next operand. */
2926 vectorized_defs
= false;
2927 if (SLP_TREE_CHILDREN (slp_node
).length () > child_index
)
2929 child
= SLP_TREE_CHILDREN (slp_node
)[child_index
];
2931 /* We have to check both pattern and original def, if available. */
2934 gimple first_def
= SLP_TREE_SCALAR_STMTS (child
)[0];
2936 = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (first_def
));
2938 if (operand_equal_p (oprnd
, gimple_get_lhs (first_def
), 0)
2940 && operand_equal_p (oprnd
, gimple_get_lhs (related
), 0)))
2942 /* The number of vector defs is determined by the number of
2943 vector statements in the node from which we get those
2945 number_of_vects
= SLP_TREE_NUMBER_OF_VEC_STMTS (child
);
2946 vectorized_defs
= true;
2954 if (!vectorized_defs
)
2958 number_of_vects
= SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node
);
2959 /* Number of vector stmts was calculated according to LHS in
2960 vect_schedule_slp_instance (), fix it by replacing LHS with
2961 RHS, if necessary. See vect_get_smallest_scalar_type () for
2963 vect_get_smallest_scalar_type (first_stmt
, &lhs_size_unit
,
2965 if (rhs_size_unit
!= lhs_size_unit
)
2967 number_of_vects
*= rhs_size_unit
;
2968 number_of_vects
/= lhs_size_unit
;
2973 /* Allocate memory for vectorized defs. */
2975 vec_defs
.create (number_of_vects
);
2977 /* For reduction defs we call vect_get_constant_vectors (), since we are
2978 looking for initial loop invariant values. */
2979 if (vectorized_defs
&& reduc_index
== -1)
2980 /* The defs are already vectorized. */
2981 vect_get_slp_vect_defs (child
, &vec_defs
);
2983 /* Build vectors from scalar defs. */
2984 vect_get_constant_vectors (oprnd
, slp_node
, &vec_defs
, i
,
2985 number_of_vects
, reduc_index
);
2987 vec_oprnds
->quick_push (vec_defs
);
2989 /* For reductions, we only need initial values. */
2990 if (reduc_index
!= -1)
2996 /* Create NCOPIES permutation statements using the mask MASK_BYTES (by
2997 building a vector of type MASK_TYPE from it) and two input vectors placed in
2998 DR_CHAIN at FIRST_VEC_INDX and SECOND_VEC_INDX for the first copy and
2999 shifting by STRIDE elements of DR_CHAIN for every copy.
3000 (STRIDE is the number of vectorized stmts for NODE divided by the number of
3002 VECT_STMTS_COUNTER specifies the index in the vectorized stmts of NODE, where
3003 the created stmts must be inserted. */
3006 vect_create_mask_and_perm (gimple stmt
,
3007 tree mask
, int first_vec_indx
, int second_vec_indx
,
3008 gimple_stmt_iterator
*gsi
, slp_tree node
,
3009 tree vectype
, vec
<tree
> dr_chain
,
3010 int ncopies
, int vect_stmts_counter
)
3013 gimple perm_stmt
= NULL
;
3015 tree first_vec
, second_vec
, data_ref
;
3017 stride
= SLP_TREE_NUMBER_OF_VEC_STMTS (node
) / ncopies
;
3019 /* Initialize the vect stmts of NODE to properly insert the generated
3021 for (i
= SLP_TREE_VEC_STMTS (node
).length ();
3022 i
< (int) SLP_TREE_NUMBER_OF_VEC_STMTS (node
); i
++)
3023 SLP_TREE_VEC_STMTS (node
).quick_push (NULL
);
3025 perm_dest
= vect_create_destination_var (gimple_assign_lhs (stmt
), vectype
);
3026 for (i
= 0; i
< ncopies
; i
++)
3028 first_vec
= dr_chain
[first_vec_indx
];
3029 second_vec
= dr_chain
[second_vec_indx
];
3031 /* Generate the permute statement. */
3032 perm_stmt
= gimple_build_assign (perm_dest
, VEC_PERM_EXPR
,
3033 first_vec
, second_vec
, mask
);
3034 data_ref
= make_ssa_name (perm_dest
, perm_stmt
);
3035 gimple_set_lhs (perm_stmt
, data_ref
);
3036 vect_finish_stmt_generation (stmt
, perm_stmt
, gsi
);
3038 /* Store the vector statement in NODE. */
3039 SLP_TREE_VEC_STMTS (node
)[stride
* i
+ vect_stmts_counter
] = perm_stmt
;
3041 first_vec_indx
+= stride
;
3042 second_vec_indx
+= stride
;
3047 /* Given FIRST_MASK_ELEMENT - the mask element in element representation,
3048 return in CURRENT_MASK_ELEMENT its equivalent in target specific
3049 representation. Check that the mask is valid and return FALSE if not.
3050 Return TRUE in NEED_NEXT_VECTOR if the permutation requires to move to
3051 the next vector, i.e., the current first vector is not needed. */
3054 vect_get_mask_element (gimple stmt
, int first_mask_element
, int m
,
3055 int mask_nunits
, bool only_one_vec
, int index
,
3056 unsigned char *mask
, int *current_mask_element
,
3057 bool *need_next_vector
, int *number_of_mask_fixes
,
3058 bool *mask_fixed
, bool *needs_first_vector
)
3062 /* Convert to target specific representation. */
3063 *current_mask_element
= first_mask_element
+ m
;
3064 /* Adjust the value in case it's a mask for second and third vectors. */
3065 *current_mask_element
-= mask_nunits
* (*number_of_mask_fixes
- 1);
3067 if (*current_mask_element
< 0)
3069 if (dump_enabled_p ())
3071 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
3072 "permutation requires past vector ");
3073 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
3074 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
3079 if (*current_mask_element
< mask_nunits
)
3080 *needs_first_vector
= true;
3082 /* We have only one input vector to permute but the mask accesses values in
3083 the next vector as well. */
3084 if (only_one_vec
&& *current_mask_element
>= mask_nunits
)
3086 if (dump_enabled_p ())
3088 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
3089 "permutation requires at least two vectors ");
3090 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
3091 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
3097 /* The mask requires the next vector. */
3098 while (*current_mask_element
>= mask_nunits
* 2)
3100 if (*needs_first_vector
|| *mask_fixed
)
3102 /* We either need the first vector too or have already moved to the
3103 next vector. In both cases, this permutation needs three
3105 if (dump_enabled_p ())
3107 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
3108 "permutation requires at "
3109 "least three vectors ");
3110 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
3111 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
3117 /* We move to the next vector, dropping the first one and working with
3118 the second and the third - we need to adjust the values of the mask
3120 *current_mask_element
-= mask_nunits
* *number_of_mask_fixes
;
3122 for (i
= 0; i
< index
; i
++)
3123 mask
[i
] -= mask_nunits
* *number_of_mask_fixes
;
3125 (*number_of_mask_fixes
)++;
3129 *need_next_vector
= *mask_fixed
;
3131 /* This was the last element of this mask. Start a new one. */
3132 if (index
== mask_nunits
- 1)
3134 *number_of_mask_fixes
= 1;
3135 *mask_fixed
= false;
3136 *needs_first_vector
= false;
3143 /* Generate vector permute statements from a list of loads in DR_CHAIN.
3144 If ANALYZE_ONLY is TRUE, only check that it is possible to create valid
3145 permute statements for the SLP node NODE of the SLP instance
3146 SLP_NODE_INSTANCE. */
3149 vect_transform_slp_perm_load (slp_tree node
, vec
<tree
> dr_chain
,
3150 gimple_stmt_iterator
*gsi
, int vf
,
3151 slp_instance slp_node_instance
, bool analyze_only
)
3153 gimple stmt
= SLP_TREE_SCALAR_STMTS (node
)[0];
3154 stmt_vec_info stmt_info
= vinfo_for_stmt (stmt
);
3155 tree mask_element_type
= NULL_TREE
, mask_type
;
3156 int i
, j
, k
, nunits
, vec_index
= 0;
3157 tree vectype
= STMT_VINFO_VECTYPE (stmt_info
);
3158 int group_size
= SLP_INSTANCE_GROUP_SIZE (slp_node_instance
);
3159 int first_mask_element
;
3160 int index
, unroll_factor
, current_mask_element
, ncopies
;
3161 unsigned char *mask
;
3162 bool only_one_vec
= false, need_next_vector
= false;
3163 int first_vec_index
, second_vec_index
, orig_vec_stmts_num
, vect_stmts_counter
;
3164 int number_of_mask_fixes
= 1;
3165 bool mask_fixed
= false;
3166 bool needs_first_vector
= false;
3169 if (!STMT_VINFO_GROUPED_ACCESS (stmt_info
))
3172 stmt_info
= vinfo_for_stmt (GROUP_FIRST_ELEMENT (stmt_info
));
3174 mode
= TYPE_MODE (vectype
);
3176 if (!can_vec_perm_p (mode
, false, NULL
))
3178 if (dump_enabled_p ())
3180 dump_printf_loc (MSG_MISSED_OPTIMIZATION
, vect_location
,
3181 "no vect permute for ");
3182 dump_gimple_stmt (MSG_MISSED_OPTIMIZATION
, TDF_SLIM
, stmt
, 0);
3183 dump_printf (MSG_MISSED_OPTIMIZATION
, "\n");
3188 /* The generic VEC_PERM_EXPR code always uses an integral type of the
3189 same size as the vector element being permuted. */
3190 mask_element_type
= lang_hooks
.types
.type_for_mode
3191 (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype
))), 1);
3192 mask_type
= get_vectype_for_scalar_type (mask_element_type
);
3193 nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
3194 mask
= XALLOCAVEC (unsigned char, nunits
);
3195 unroll_factor
= SLP_INSTANCE_UNROLLING_FACTOR (slp_node_instance
);
3197 /* The number of vector stmts to generate based only on SLP_NODE_INSTANCE
3198 unrolling factor. */
3200 = (STMT_VINFO_GROUP_SIZE (stmt_info
)
3201 * SLP_INSTANCE_UNROLLING_FACTOR (slp_node_instance
)
3202 + nunits
- 1) / nunits
;
3203 if (orig_vec_stmts_num
== 1)
3204 only_one_vec
= true;
3206 /* Number of copies is determined by the final vectorization factor
3207 relatively to SLP_NODE_INSTANCE unrolling factor. */
3208 ncopies
= vf
/ SLP_INSTANCE_UNROLLING_FACTOR (slp_node_instance
);
3210 /* Generate permutation masks for every NODE. Number of masks for each NODE
3211 is equal to GROUP_SIZE.
3212 E.g., we have a group of three nodes with three loads from the same
3213 location in each node, and the vector size is 4. I.e., we have a
3214 a0b0c0a1b1c1... sequence and we need to create the following vectors:
3215 for a's: a0a0a0a1 a1a1a2a2 a2a3a3a3
3216 for b's: b0b0b0b1 b1b1b2b2 b2b3b3b3
3219 The masks for a's should be: {0,0,0,3} {3,3,6,6} {6,9,9,9}.
3220 The last mask is illegal since we assume two operands for permute
3221 operation, and the mask element values can't be outside that range.
3222 Hence, the last mask must be converted into {2,5,5,5}.
3223 For the first two permutations we need the first and the second input
3224 vectors: {a0,b0,c0,a1} and {b1,c1,a2,b2}, and for the last permutation
3225 we need the second and the third vectors: {b1,c1,a2,b2} and
3230 vect_stmts_counter
= 0;
3232 first_vec_index
= vec_index
++;
3234 second_vec_index
= first_vec_index
;
3236 second_vec_index
= vec_index
++;
3238 for (j
= 0; j
< unroll_factor
; j
++)
3240 for (k
= 0; k
< group_size
; k
++)
3242 i
= SLP_TREE_LOAD_PERMUTATION (node
)[k
];
3243 first_mask_element
= i
+ j
* STMT_VINFO_GROUP_SIZE (stmt_info
);
3244 if (!vect_get_mask_element (stmt
, first_mask_element
, 0,
3245 nunits
, only_one_vec
, index
,
3246 mask
, ¤t_mask_element
,
3248 &number_of_mask_fixes
, &mask_fixed
,
3249 &needs_first_vector
))
3251 gcc_assert (current_mask_element
>= 0
3252 && current_mask_element
< 2 * nunits
);
3253 mask
[index
++] = current_mask_element
;
3255 if (index
== nunits
)
3258 if (!can_vec_perm_p (mode
, false, mask
))
3260 if (dump_enabled_p ())
3262 dump_printf_loc (MSG_MISSED_OPTIMIZATION
,
3264 "unsupported vect permute { ");
3265 for (i
= 0; i
< nunits
; ++i
)
3266 dump_printf (MSG_MISSED_OPTIMIZATION
, "%d ",
3268 dump_printf (MSG_MISSED_OPTIMIZATION
, "}\n");
3276 tree mask_vec
, *mask_elts
;
3277 mask_elts
= XALLOCAVEC (tree
, nunits
);
3278 for (l
= 0; l
< nunits
; ++l
)
3279 mask_elts
[l
] = build_int_cst (mask_element_type
,
3281 mask_vec
= build_vector (mask_type
, mask_elts
);
3283 if (need_next_vector
)
3285 first_vec_index
= second_vec_index
;
3286 second_vec_index
= vec_index
;
3289 vect_create_mask_and_perm (stmt
,
3290 mask_vec
, first_vec_index
, second_vec_index
,
3291 gsi
, node
, vectype
, dr_chain
,
3292 ncopies
, vect_stmts_counter
++);
3304 /* Vectorize SLP instance tree in postorder. */
3307 vect_schedule_slp_instance (slp_tree node
, slp_instance instance
,
3308 unsigned int vectorization_factor
)
3311 bool grouped_store
, is_store
;
3312 gimple_stmt_iterator si
;
3313 stmt_vec_info stmt_info
;
3314 unsigned int vec_stmts_size
, nunits
, group_size
;
3322 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
3323 vect_schedule_slp_instance (child
, instance
, vectorization_factor
);
3325 stmt
= SLP_TREE_SCALAR_STMTS (node
)[0];
3326 stmt_info
= vinfo_for_stmt (stmt
);
3328 /* VECTYPE is the type of the destination. */
3329 vectype
= STMT_VINFO_VECTYPE (stmt_info
);
3330 nunits
= (unsigned int) TYPE_VECTOR_SUBPARTS (vectype
);
3331 group_size
= SLP_INSTANCE_GROUP_SIZE (instance
);
3333 /* For each SLP instance calculate number of vector stmts to be created
3334 for the scalar stmts in each node of the SLP tree. Number of vector
3335 elements in one vector iteration is the number of scalar elements in
3336 one scalar iteration (GROUP_SIZE) multiplied by VF divided by vector
3338 Unless this is a SLP reduction in which case the number of vector
3339 stmts is equal to the number of vector stmts of the children. */
3340 if (GROUP_FIRST_ELEMENT (stmt_info
)
3341 && !STMT_VINFO_GROUPED_ACCESS (stmt_info
))
3342 vec_stmts_size
= SLP_TREE_NUMBER_OF_VEC_STMTS (SLP_TREE_CHILDREN (node
)[0]);
3344 vec_stmts_size
= (vectorization_factor
* group_size
) / nunits
;
3346 if (!SLP_TREE_VEC_STMTS (node
).exists ())
3348 SLP_TREE_VEC_STMTS (node
).create (vec_stmts_size
);
3349 SLP_TREE_NUMBER_OF_VEC_STMTS (node
) = vec_stmts_size
;
3352 if (dump_enabled_p ())
3354 dump_printf_loc (MSG_NOTE
,vect_location
,
3355 "------>vectorizing SLP node starting from: ");
3356 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
, stmt
, 0);
3357 dump_printf (MSG_NOTE
, "\n");
3360 /* Vectorized stmts go before the last scalar stmt which is where
3361 all uses are ready. */
3362 si
= gsi_for_stmt (vect_find_last_scalar_stmt_in_slp (node
));
3364 /* Mark the first element of the reduction chain as reduction to properly
3365 transform the node. In the analysis phase only the last element of the
3366 chain is marked as reduction. */
3367 if (GROUP_FIRST_ELEMENT (stmt_info
) && !STMT_VINFO_GROUPED_ACCESS (stmt_info
)
3368 && GROUP_FIRST_ELEMENT (stmt_info
) == stmt
)
3370 STMT_VINFO_DEF_TYPE (stmt_info
) = vect_reduction_def
;
3371 STMT_VINFO_TYPE (stmt_info
) = reduc_vec_info_type
;
3374 /* Handle two-operation SLP nodes by vectorizing the group with
3375 both operations and then performing a merge. */
3376 if (SLP_TREE_TWO_OPERATORS (node
))
3378 enum tree_code code0
= gimple_assign_rhs_code (stmt
);
3379 enum tree_code ocode
;
3381 unsigned char *mask
= XALLOCAVEC (unsigned char, group_size
);
3382 bool allsame
= true;
3383 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, ostmt
)
3384 if (gimple_assign_rhs_code (ostmt
) != code0
)
3388 ocode
= gimple_assign_rhs_code (ostmt
);
3397 tree tmask
= NULL_TREE
;
3398 vect_transform_stmt (stmt
, &si
, &grouped_store
, node
, instance
);
3399 v0
= SLP_TREE_VEC_STMTS (node
).copy ();
3400 SLP_TREE_VEC_STMTS (node
).truncate (0);
3401 gimple_assign_set_rhs_code (stmt
, ocode
);
3402 vect_transform_stmt (stmt
, &si
, &grouped_store
, node
, instance
);
3403 gimple_assign_set_rhs_code (stmt
, code0
);
3404 v1
= SLP_TREE_VEC_STMTS (node
).copy ();
3405 SLP_TREE_VEC_STMTS (node
).truncate (0);
3406 tree meltype
= build_nonstandard_integer_type
3407 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (vectype
))), 1);
3408 tree mvectype
= get_same_sized_vectype (meltype
, vectype
);
3410 for (j
= 0; j
< v0
.length (); ++j
)
3412 tree
*melts
= XALLOCAVEC (tree
, TYPE_VECTOR_SUBPARTS (vectype
));
3413 for (l
= 0; l
< TYPE_VECTOR_SUBPARTS (vectype
); ++l
)
3415 if (k
>= group_size
)
3417 melts
[l
] = build_int_cst
3418 (meltype
, mask
[k
++] * TYPE_VECTOR_SUBPARTS (vectype
) + l
);
3420 tmask
= build_vector (mvectype
, melts
);
3422 /* ??? Not all targets support a VEC_PERM_EXPR with a
3423 constant mask that would translate to a vec_merge RTX
3424 (with their vec_perm_const_ok). We can either not
3425 vectorize in that case or let veclower do its job.
3426 Unfortunately that isn't too great and at least for
3427 plus/minus we'd eventually like to match targets
3428 vector addsub instructions. */
3430 vstmt
= gimple_build_assign (make_ssa_name (vectype
),
3432 gimple_assign_lhs (v0
[j
]),
3433 gimple_assign_lhs (v1
[j
]), tmask
);
3434 vect_finish_stmt_generation (stmt
, vstmt
, &si
);
3435 SLP_TREE_VEC_STMTS (node
).quick_push (vstmt
);
3442 is_store
= vect_transform_stmt (stmt
, &si
, &grouped_store
, node
, instance
);
3446 /* Replace scalar calls from SLP node NODE with setting of their lhs to zero.
3447 For loop vectorization this is done in vectorizable_call, but for SLP
3448 it needs to be deferred until end of vect_schedule_slp, because multiple
3449 SLP instances may refer to the same scalar stmt. */
3452 vect_remove_slp_scalar_calls (slp_tree node
)
3454 gimple stmt
, new_stmt
;
3455 gimple_stmt_iterator gsi
;
3459 stmt_vec_info stmt_info
;
3464 FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node
), i
, child
)
3465 vect_remove_slp_scalar_calls (child
);
3467 FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node
), i
, stmt
)
3469 if (!is_gimple_call (stmt
) || gimple_bb (stmt
) == NULL
)
3471 stmt_info
= vinfo_for_stmt (stmt
);
3472 if (stmt_info
== NULL
3473 || is_pattern_stmt_p (stmt_info
)
3474 || !PURE_SLP_STMT (stmt_info
))
3476 lhs
= gimple_call_lhs (stmt
);
3477 new_stmt
= gimple_build_assign (lhs
, build_zero_cst (TREE_TYPE (lhs
)));
3478 set_vinfo_for_stmt (new_stmt
, stmt_info
);
3479 set_vinfo_for_stmt (stmt
, NULL
);
3480 STMT_VINFO_STMT (stmt_info
) = new_stmt
;
3481 gsi
= gsi_for_stmt (stmt
);
3482 gsi_replace (&gsi
, new_stmt
, false);
3483 SSA_NAME_DEF_STMT (gimple_assign_lhs (new_stmt
)) = new_stmt
;
3487 /* Generate vector code for all SLP instances in the loop/basic block. */
3490 vect_schedule_slp (loop_vec_info loop_vinfo
, bb_vec_info bb_vinfo
)
3492 vec
<slp_instance
> slp_instances
;
3493 slp_instance instance
;
3495 bool is_store
= false;
3499 slp_instances
= LOOP_VINFO_SLP_INSTANCES (loop_vinfo
);
3500 vf
= LOOP_VINFO_VECT_FACTOR (loop_vinfo
);
3504 slp_instances
= BB_VINFO_SLP_INSTANCES (bb_vinfo
);
3508 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
3510 /* Schedule the tree of INSTANCE. */
3511 is_store
= vect_schedule_slp_instance (SLP_INSTANCE_TREE (instance
),
3513 if (dump_enabled_p ())
3514 dump_printf_loc (MSG_NOTE
, vect_location
,
3515 "vectorizing stmts using SLP.\n");
3518 FOR_EACH_VEC_ELT (slp_instances
, i
, instance
)
3520 slp_tree root
= SLP_INSTANCE_TREE (instance
);
3523 gimple_stmt_iterator gsi
;
3525 /* Remove scalar call stmts. Do not do this for basic-block
3526 vectorization as not all uses may be vectorized.
3527 ??? Why should this be necessary? DCE should be able to
3528 remove the stmts itself.
3529 ??? For BB vectorization we can as well remove scalar
3530 stmts starting from the SLP tree root if they have no
3533 vect_remove_slp_scalar_calls (root
);
3535 for (j
= 0; SLP_TREE_SCALAR_STMTS (root
).iterate (j
, &store
)
3536 && j
< SLP_INSTANCE_GROUP_SIZE (instance
); j
++)
3538 if (!STMT_VINFO_DATA_REF (vinfo_for_stmt (store
)))
3541 if (is_pattern_stmt_p (vinfo_for_stmt (store
)))
3542 store
= STMT_VINFO_RELATED_STMT (vinfo_for_stmt (store
));
3543 /* Free the attached stmt_vec_info and remove the stmt. */
3544 gsi
= gsi_for_stmt (store
);
3545 unlink_stmt_vdef (store
);
3546 gsi_remove (&gsi
, true);
3547 release_defs (store
);
3548 free_stmt_vec_info (store
);
3556 /* Vectorize the basic block. */
3559 vect_slp_transform_bb (basic_block bb
)
3561 bb_vec_info bb_vinfo
= vec_info_for_bb (bb
);
3562 gimple_stmt_iterator si
;
3564 gcc_assert (bb_vinfo
);
3566 if (dump_enabled_p ())
3567 dump_printf_loc (MSG_NOTE
, vect_location
, "SLPing BB\n");
3569 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
3571 gimple stmt
= gsi_stmt (si
);
3572 stmt_vec_info stmt_info
;
3574 if (dump_enabled_p ())
3576 dump_printf_loc (MSG_NOTE
, vect_location
,
3577 "------>SLPing statement: ");
3578 dump_gimple_stmt (MSG_NOTE
, TDF_SLIM
, stmt
, 0);
3579 dump_printf (MSG_NOTE
, "\n");
3582 stmt_info
= vinfo_for_stmt (stmt
);
3583 gcc_assert (stmt_info
);
3585 /* Schedule all the SLP instances when the first SLP stmt is reached. */
3586 if (STMT_SLP_TYPE (stmt_info
))
3588 vect_schedule_slp (NULL
, bb_vinfo
);
3593 if (dump_enabled_p ())
3594 dump_printf_loc (MSG_NOTE
, vect_location
,
3595 "BASIC BLOCK VECTORIZED\n");
3597 destroy_bb_vec_info (bb_vinfo
);