1 /* Analysis Utilities for Loop Vectorization.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3 Contributed by Dorit Nuzman <dorit@il.ibm.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "coretypes.h"
30 #include "basic-block.h"
31 #include "diagnostic.h"
32 #include "tree-flow.h"
33 #include "tree-dump.h"
39 #include "tree-data-ref.h"
40 #include "tree-vectorizer.h"
44 /* Function prototypes */
45 static void vect_pattern_recog_1
46 (tree (* ) (tree
, tree
*, tree
*), block_stmt_iterator
);
47 static bool widened_name_p (tree
, tree
, tree
*, tree
*);
49 /* Pattern recognition functions */
50 static tree
vect_recog_widen_sum_pattern (tree
, tree
*, tree
*);
51 static tree
vect_recog_widen_mult_pattern (tree
, tree
*, tree
*);
52 static tree
vect_recog_dot_prod_pattern (tree
, tree
*, tree
*);
53 static tree
vect_recog_pow_pattern (tree
, tree
*, tree
*);
54 static vect_recog_func_ptr vect_vect_recog_func_ptrs
[NUM_PATTERNS
] = {
55 vect_recog_widen_mult_pattern
,
56 vect_recog_widen_sum_pattern
,
57 vect_recog_dot_prod_pattern
,
58 vect_recog_pow_pattern
};
61 /* Function widened_name_p
63 Check whether NAME, an ssa-name used in USE_STMT,
64 is a result of a type-promotion, such that:
65 DEF_STMT: NAME = NOP (name0)
66 where the type of name0 (HALF_TYPE) is smaller than the type of NAME.
70 widened_name_p (tree name
, tree use_stmt
, tree
*half_type
, tree
*def_stmt
)
73 loop_vec_info loop_vinfo
;
74 stmt_vec_info stmt_vinfo
;
76 tree type
= TREE_TYPE (name
);
78 enum vect_def_type dt
;
81 stmt_vinfo
= vinfo_for_stmt (use_stmt
);
82 loop_vinfo
= STMT_VINFO_LOOP_VINFO (stmt_vinfo
);
84 if (!vect_is_simple_use (name
, loop_vinfo
, def_stmt
, &def
, &dt
))
87 if (dt
!= vect_loop_def
88 && dt
!= vect_invariant_def
&& dt
!= vect_constant_def
)
94 if (TREE_CODE (*def_stmt
) != GIMPLE_MODIFY_STMT
)
97 expr
= GIMPLE_STMT_OPERAND (*def_stmt
, 1);
98 if (TREE_CODE (expr
) != NOP_EXPR
)
101 oprnd0
= TREE_OPERAND (expr
, 0);
103 *half_type
= TREE_TYPE (oprnd0
);
104 if (!INTEGRAL_TYPE_P (type
) || !INTEGRAL_TYPE_P (*half_type
)
105 || (TYPE_UNSIGNED (type
) != TYPE_UNSIGNED (*half_type
))
106 || (TYPE_PRECISION (type
) < (TYPE_PRECISION (*half_type
) * 2)))
109 if (!vect_is_simple_use (oprnd0
, loop_vinfo
, &dummy
, &dummy
, &dt
))
112 if (dt
!= vect_invariant_def
&& dt
!= vect_constant_def
113 && dt
!= vect_loop_def
)
120 /* Function vect_recog_dot_prod_pattern
122 Try to find the following pattern:
128 sum_0 = phi <init, sum_1>
131 S3 x_T = (TYPE1) x_t;
132 S4 y_T = (TYPE1) y_t;
134 [S6 prod = (TYPE2) prod; #optional]
135 S7 sum_1 = prod + sum_0;
137 where 'TYPE1' is exactly double the size of type 'type', and 'TYPE2' is the
138 same size of 'TYPE1' or bigger. This is a special case of a reduction
143 * LAST_STMT: A stmt from which the pattern search begins. In the example,
144 when this function is called with S7, the pattern {S3,S4,S5,S6,S7} will be
149 * TYPE_IN: The type of the input arguments to the pattern.
151 * TYPE_OUT: The type of the output of this pattern.
153 * Return value: A new stmt that will be used to replace the sequence of
154 stmts that constitute the pattern. In this case it will be:
155 WIDEN_DOT_PRODUCT <x_t, y_t, sum_0>
159 vect_recog_dot_prod_pattern (tree last_stmt
, tree
*type_in
, tree
*type_out
)
163 tree oprnd00
, oprnd01
;
164 stmt_vec_info stmt_vinfo
= vinfo_for_stmt (last_stmt
);
165 tree type
, half_type
;
169 if (TREE_CODE (last_stmt
) != GIMPLE_MODIFY_STMT
)
172 expr
= GIMPLE_STMT_OPERAND (last_stmt
, 1);
173 type
= TREE_TYPE (expr
);
175 /* Look for the following pattern
179 DDPROD = (TYPE2) DPROD;
180 sum_1 = DDPROD + sum_0;
182 - DX is double the size of X
183 - DY is double the size of Y
184 - DX, DY, DPROD all have the same type
185 - sum is the same size of DPROD or bigger
186 - sum has been recognized as a reduction variable.
188 This is equivalent to:
189 DPROD = X w* Y; #widen mult
190 sum_1 = DPROD w+ sum_0; #widen summation
192 DPROD = X w* Y; #widen mult
193 sum_1 = DPROD + sum_0; #summation
196 /* Starting from LAST_STMT, follow the defs of its uses in search
197 of the above pattern. */
199 if (TREE_CODE (expr
) != PLUS_EXPR
)
202 if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo
))
204 /* Has been detected as widening-summation? */
206 stmt
= STMT_VINFO_RELATED_STMT (stmt_vinfo
);
207 expr
= GIMPLE_STMT_OPERAND (stmt
, 1);
208 type
= TREE_TYPE (expr
);
209 if (TREE_CODE (expr
) != WIDEN_SUM_EXPR
)
211 oprnd0
= TREE_OPERAND (expr
, 0);
212 oprnd1
= TREE_OPERAND (expr
, 1);
213 half_type
= TREE_TYPE (oprnd0
);
219 if (STMT_VINFO_DEF_TYPE (stmt_vinfo
) != vect_reduction_def
)
221 oprnd0
= TREE_OPERAND (expr
, 0);
222 oprnd1
= TREE_OPERAND (expr
, 1);
223 if (TYPE_MAIN_VARIANT (TREE_TYPE (oprnd0
)) != TYPE_MAIN_VARIANT (type
)
224 || TYPE_MAIN_VARIANT (TREE_TYPE (oprnd1
)) != TYPE_MAIN_VARIANT (type
))
228 if (widened_name_p (oprnd0
, stmt
, &half_type
, &def_stmt
))
231 expr
= GIMPLE_STMT_OPERAND (stmt
, 1);
232 oprnd0
= TREE_OPERAND (expr
, 0);
238 /* So far so good. Since last_stmt was detected as a (summation) reduction,
239 we know that oprnd1 is the reduction variable (defined by a loop-header
240 phi), and oprnd0 is an ssa-name defined by a stmt in the loop body.
241 Left to check that oprnd0 is defined by a (widen_)mult_expr */
243 prod_type
= half_type
;
244 stmt
= SSA_NAME_DEF_STMT (oprnd0
);
246 stmt_vinfo
= vinfo_for_stmt (stmt
);
247 gcc_assert (stmt_vinfo
);
248 if (STMT_VINFO_DEF_TYPE (stmt_vinfo
) != vect_loop_def
)
250 expr
= GIMPLE_STMT_OPERAND (stmt
, 1);
251 if (TREE_CODE (expr
) != MULT_EXPR
)
253 if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo
))
255 /* Has been detected as a widening multiplication? */
257 stmt
= STMT_VINFO_RELATED_STMT (stmt_vinfo
);
258 expr
= GIMPLE_STMT_OPERAND (stmt
, 1);
259 if (TREE_CODE (expr
) != WIDEN_MULT_EXPR
)
261 stmt_vinfo
= vinfo_for_stmt (stmt
);
262 gcc_assert (stmt_vinfo
);
263 gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo
) == vect_loop_def
);
264 oprnd00
= TREE_OPERAND (expr
, 0);
265 oprnd01
= TREE_OPERAND (expr
, 1);
269 tree half_type0
, half_type1
;
273 oprnd0
= TREE_OPERAND (expr
, 0);
274 oprnd1
= TREE_OPERAND (expr
, 1);
275 if (TYPE_MAIN_VARIANT (TREE_TYPE (oprnd0
))
276 != TYPE_MAIN_VARIANT (prod_type
)
277 || TYPE_MAIN_VARIANT (TREE_TYPE (oprnd1
))
278 != TYPE_MAIN_VARIANT (prod_type
))
280 if (!widened_name_p (oprnd0
, stmt
, &half_type0
, &def_stmt
))
282 oprnd00
= TREE_OPERAND (GIMPLE_STMT_OPERAND (def_stmt
, 1), 0);
283 if (!widened_name_p (oprnd1
, stmt
, &half_type1
, &def_stmt
))
285 oprnd01
= TREE_OPERAND (GIMPLE_STMT_OPERAND (def_stmt
, 1), 0);
286 if (TYPE_MAIN_VARIANT (half_type0
) != TYPE_MAIN_VARIANT (half_type1
))
288 if (TYPE_PRECISION (prod_type
) != TYPE_PRECISION (half_type0
) * 2)
292 half_type
= TREE_TYPE (oprnd00
);
293 *type_in
= half_type
;
296 /* Pattern detected. Create a stmt to be used to replace the pattern: */
297 pattern_expr
= build3 (DOT_PROD_EXPR
, type
, oprnd00
, oprnd01
, oprnd1
);
298 if (vect_print_dump_info (REPORT_DETAILS
))
300 fprintf (vect_dump
, "vect_recog_dot_prod_pattern: detected: ");
301 print_generic_expr (vect_dump
, pattern_expr
, TDF_SLIM
);
307 /* Function vect_recog_widen_mult_pattern
309 Try to find the following pattern:
312 TYPE a_T, b_T, prod_T;
318 S5 prod_T = a_T * b_T;
320 where type 'TYPE' is at least double the size of type 'type'.
324 * LAST_STMT: A stmt from which the pattern search begins. In the example,
325 when this function is called with S5, the pattern {S3,S4,S5} is be detected.
329 * TYPE_IN: The type of the input arguments to the pattern.
331 * TYPE_OUT: The type of the output of this pattern.
333 * Return value: A new stmt that will be used to replace the sequence of
334 stmts that constitute the pattern. In this case it will be:
335 WIDEN_MULT <a_t, b_t>
339 vect_recog_widen_mult_pattern (tree last_stmt
,
344 tree def_stmt0
, def_stmt1
;
346 tree type
, half_type0
, half_type1
;
350 enum tree_code dummy_code
;
352 if (TREE_CODE (last_stmt
) != GIMPLE_MODIFY_STMT
)
355 expr
= GIMPLE_STMT_OPERAND (last_stmt
, 1);
356 type
= TREE_TYPE (expr
);
358 /* Starting from LAST_STMT, follow the defs of its uses in search
359 of the above pattern. */
361 if (TREE_CODE (expr
) != MULT_EXPR
)
364 oprnd0
= TREE_OPERAND (expr
, 0);
365 oprnd1
= TREE_OPERAND (expr
, 1);
366 if (TYPE_MAIN_VARIANT (TREE_TYPE (oprnd0
)) != TYPE_MAIN_VARIANT (type
)
367 || TYPE_MAIN_VARIANT (TREE_TYPE (oprnd1
)) != TYPE_MAIN_VARIANT (type
))
370 /* Check argument 0 */
371 if (!widened_name_p (oprnd0
, last_stmt
, &half_type0
, &def_stmt0
))
373 oprnd0
= TREE_OPERAND (GIMPLE_STMT_OPERAND (def_stmt0
, 1), 0);
375 /* Check argument 1 */
376 if (!widened_name_p (oprnd1
, last_stmt
, &half_type1
, &def_stmt1
))
378 oprnd1
= TREE_OPERAND (GIMPLE_STMT_OPERAND (def_stmt1
, 1), 0);
380 if (TYPE_MAIN_VARIANT (half_type0
) != TYPE_MAIN_VARIANT (half_type1
))
383 /* Pattern detected. */
384 if (vect_print_dump_info (REPORT_DETAILS
))
385 fprintf (vect_dump
, "vect_recog_widen_mult_pattern: detected: ");
387 /* Check target support */
388 vectype
= get_vectype_for_scalar_type (half_type0
);
390 || !supportable_widening_operation (WIDEN_MULT_EXPR
, last_stmt
, vectype
,
391 &dummy
, &dummy
, &dummy_code
,
396 *type_out
= NULL_TREE
;
398 /* Pattern supported. Create a stmt to be used to replace the pattern: */
399 pattern_expr
= build2 (WIDEN_MULT_EXPR
, type
, oprnd0
, oprnd1
);
400 if (vect_print_dump_info (REPORT_DETAILS
))
401 print_generic_expr (vect_dump
, pattern_expr
, TDF_SLIM
);
406 /* Function vect_recog_pow_pattern
408 Try to find the following pattern:
412 with POW being one of pow, powf, powi, powif and N being
417 * LAST_STMT: A stmt from which the pattern search begins.
421 * TYPE_IN: The type of the input arguments to the pattern.
423 * TYPE_OUT: The type of the output of this pattern.
425 * Return value: A new stmt that will be used to replace the sequence of
426 stmts that constitute the pattern. In this case it will be:
433 vect_recog_pow_pattern (tree last_stmt
, tree
*type_in
, tree
*type_out
)
437 tree fn
, arglist
, base
, exp
;
439 if (TREE_CODE (last_stmt
) != GIMPLE_MODIFY_STMT
)
442 expr
= GIMPLE_STMT_OPERAND (last_stmt
, 1);
443 type
= TREE_TYPE (expr
);
445 if (TREE_CODE (expr
) != CALL_EXPR
)
448 fn
= get_callee_fndecl (expr
);
449 arglist
= TREE_OPERAND (expr
, 1);
450 switch (DECL_FUNCTION_CODE (fn
))
456 base
= TREE_VALUE (arglist
);
457 exp
= TREE_VALUE (TREE_CHAIN (arglist
));
458 if (TREE_CODE (exp
) != REAL_CST
459 && TREE_CODE (exp
) != INTEGER_CST
)
467 /* We now have a pow or powi builtin function call with a constant
470 *type_out
= NULL_TREE
;
472 /* Catch squaring. */
473 if ((host_integerp (exp
, 0)
474 && tree_low_cst (exp
, 0) == 2)
475 || (TREE_CODE (exp
) == REAL_CST
476 && REAL_VALUES_EQUAL (TREE_REAL_CST (exp
), dconst2
)))
478 *type_in
= TREE_TYPE (base
);
479 return build2 (MULT_EXPR
, TREE_TYPE (base
), base
, base
);
482 /* Catch square root. */
483 if (TREE_CODE (exp
) == REAL_CST
484 && REAL_VALUES_EQUAL (TREE_REAL_CST (exp
), dconsthalf
))
486 tree newfn
= mathfn_built_in (TREE_TYPE (base
), BUILT_IN_SQRT
);
487 tree newarglist
= build_tree_list (NULL_TREE
, base
);
488 *type_in
= get_vectype_for_scalar_type (TREE_TYPE (base
));
491 newfn
= build_function_call_expr (newfn
, newarglist
);
492 if (vectorizable_function (newfn
, *type_in
, *type_in
) != NULL_TREE
)
501 /* Function vect_recog_widen_sum_pattern
503 Try to find the following pattern:
506 TYPE x_T, sum = init;
508 sum_0 = phi <init, sum_1>
511 S3 sum_1 = x_T + sum_0;
513 where type 'TYPE' is at least double the size of type 'type', i.e - we're
514 summing elements of type 'type' into an accumulator of type 'TYPE'. This is
515 a special case of a reduction computation.
519 * LAST_STMT: A stmt from which the pattern search begins. In the example,
520 when this function is called with S3, the pattern {S2,S3} will be detected.
524 * TYPE_IN: The type of the input arguments to the pattern.
526 * TYPE_OUT: The type of the output of this pattern.
528 * Return value: A new stmt that will be used to replace the sequence of
529 stmts that constitute the pattern. In this case it will be:
530 WIDEN_SUM <x_t, sum_0>
534 vect_recog_widen_sum_pattern (tree last_stmt
, tree
*type_in
, tree
*type_out
)
538 stmt_vec_info stmt_vinfo
= vinfo_for_stmt (last_stmt
);
539 tree type
, half_type
;
542 if (TREE_CODE (last_stmt
) != GIMPLE_MODIFY_STMT
)
545 expr
= GIMPLE_STMT_OPERAND (last_stmt
, 1);
546 type
= TREE_TYPE (expr
);
548 /* Look for the following pattern
551 In which DX is at least double the size of X, and sum_1 has been
552 recognized as a reduction variable.
555 /* Starting from LAST_STMT, follow the defs of its uses in search
556 of the above pattern. */
558 if (TREE_CODE (expr
) != PLUS_EXPR
)
561 if (STMT_VINFO_DEF_TYPE (stmt_vinfo
) != vect_reduction_def
)
564 oprnd0
= TREE_OPERAND (expr
, 0);
565 oprnd1
= TREE_OPERAND (expr
, 1);
566 if (TYPE_MAIN_VARIANT (TREE_TYPE (oprnd0
)) != TYPE_MAIN_VARIANT (type
)
567 || TYPE_MAIN_VARIANT (TREE_TYPE (oprnd1
)) != TYPE_MAIN_VARIANT (type
))
570 /* So far so good. Since last_stmt was detected as a (summation) reduction,
571 we know that oprnd1 is the reduction variable (defined by a loop-header
572 phi), and oprnd0 is an ssa-name defined by a stmt in the loop body.
573 Left to check that oprnd0 is defined by a cast from type 'type' to type
576 if (!widened_name_p (oprnd0
, last_stmt
, &half_type
, &stmt
))
579 oprnd0
= TREE_OPERAND (GIMPLE_STMT_OPERAND (stmt
, 1), 0);
580 *type_in
= half_type
;
583 /* Pattern detected. Create a stmt to be used to replace the pattern: */
584 pattern_expr
= build2 (WIDEN_SUM_EXPR
, type
, oprnd0
, oprnd1
);
585 if (vect_print_dump_info (REPORT_DETAILS
))
587 fprintf (vect_dump
, "vect_recog_widen_sum_pattern: detected: ");
588 print_generic_expr (vect_dump
, pattern_expr
, TDF_SLIM
);
594 /* Function vect_pattern_recog_1
597 PATTERN_RECOG_FUNC: A pointer to a function that detects a certain
599 STMT: A stmt from which the pattern search should start.
601 If PATTERN_RECOG_FUNC successfully detected the pattern, it creates an
602 expression that computes the same functionality and can be used to
603 replace the sequence of stmts that are involved in the pattern.
606 This function checks if the expression returned by PATTERN_RECOG_FUNC is
607 supported in vector form by the target. We use 'TYPE_IN' to obtain the
608 relevant vector type. If 'TYPE_IN' is already a vector type, then this
609 indicates that target support had already been checked by PATTERN_RECOG_FUNC.
610 If 'TYPE_OUT' is also returned by PATTERN_RECOG_FUNC, we check that it fits
611 to the available target pattern.
613 This function also does some bookkeeping, as explained in the documentation
614 for vect_recog_pattern. */
617 vect_pattern_recog_1 (
618 tree (* vect_recog_func
) (tree
, tree
*, tree
*),
619 block_stmt_iterator si
)
621 tree stmt
= bsi_stmt (si
);
622 stmt_vec_info stmt_info
= vinfo_for_stmt (stmt
);
623 stmt_vec_info pattern_stmt_info
;
624 loop_vec_info loop_vinfo
= STMT_VINFO_LOOP_VINFO (stmt_info
);
626 tree pattern_vectype
;
627 tree type_in
, type_out
;
633 pattern_expr
= (* vect_recog_func
) (stmt
, &type_in
, &type_out
);
637 if (VECTOR_MODE_P (TYPE_MODE (type_in
)))
639 /* No need to check target support (already checked by the pattern
640 recognition function). */
641 pattern_vectype
= type_in
;
645 enum tree_code vec_mode
;
646 enum insn_code icode
;
649 /* Check target support */
650 pattern_vectype
= get_vectype_for_scalar_type (type_in
);
651 if (!pattern_vectype
)
654 optab
= optab_for_tree_code (TREE_CODE (pattern_expr
), pattern_vectype
);
655 vec_mode
= TYPE_MODE (pattern_vectype
);
657 || (icode
= optab
->handlers
[(int) vec_mode
].insn_code
) ==
660 && (insn_data
[icode
].operand
[0].mode
!=
661 TYPE_MODE (get_vectype_for_scalar_type (type_out
)))))
665 /* Found a vectorizable pattern. */
666 if (vect_print_dump_info (REPORT_DETAILS
))
668 fprintf (vect_dump
, "pattern recognized: ");
669 print_generic_expr (vect_dump
, pattern_expr
, TDF_SLIM
);
672 /* Mark the stmts that are involved in the pattern,
673 create a new stmt to express the pattern and insert it. */
674 code
= TREE_CODE (pattern_expr
);
675 pattern_type
= TREE_TYPE (pattern_expr
);
676 var
= create_tmp_var (pattern_type
, "patt");
677 add_referenced_var (var
);
678 var_name
= make_ssa_name (var
, NULL_TREE
);
679 pattern_expr
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, var_name
,
681 SSA_NAME_DEF_STMT (var_name
) = pattern_expr
;
682 bsi_insert_before (&si
, pattern_expr
, BSI_SAME_STMT
);
683 ann
= stmt_ann (pattern_expr
);
684 set_stmt_info (ann
, new_stmt_vec_info (pattern_expr
, loop_vinfo
));
685 pattern_stmt_info
= vinfo_for_stmt (pattern_expr
);
687 STMT_VINFO_RELATED_STMT (pattern_stmt_info
) = stmt
;
688 STMT_VINFO_DEF_TYPE (pattern_stmt_info
) = STMT_VINFO_DEF_TYPE (stmt_info
);
689 STMT_VINFO_VECTYPE (pattern_stmt_info
) = pattern_vectype
;
690 STMT_VINFO_IN_PATTERN_P (stmt_info
) = true;
691 STMT_VINFO_RELATED_STMT (stmt_info
) = pattern_expr
;
697 /* Function vect_pattern_recog
700 LOOP_VINFO - a struct_loop_info of a loop in which we want to look for
703 Output - for each computation idiom that is detected we insert a new stmt
704 that provides the same functionality and that can be vectorized. We
705 also record some information in the struct_stmt_info of the relevant
706 stmts, as explained below:
708 At the entry to this function we have the following stmts, with the
709 following initial value in the STMT_VINFO fields:
711 stmt in_pattern_p related_stmt vec_stmt
713 S2: a_2 = ..use(a_i).. - - -
714 S3: a_1 = ..use(a_2).. - - -
715 S4: a_0 = ..use(a_1).. - - -
716 S5: ... = ..use(a_0).. - - -
718 Say the sequence {S1,S2,S3,S4} was detected as a pattern that can be
719 represented by a single stmt. We then:
720 - create a new stmt S6 that will replace the pattern.
721 - insert the new stmt S6 before the last stmt in the pattern
722 - fill in the STMT_VINFO fields as follows:
724 in_pattern_p related_stmt vec_stmt
726 S2: a_2 = ..use(a_i).. - - -
727 S3: a_1 = ..use(a_2).. - - -
728 > S6: a_new = .... - S4 -
729 S4: a_0 = ..use(a_1).. true S6 -
730 S5: ... = ..use(a_0).. - - -
732 (the last stmt in the pattern (S4) and the new pattern stmt (S6) point
733 to each other through the RELATED_STMT field).
735 S6 will be marked as relevant in vect_mark_stmts_to_be_vectorized instead
736 of S4 because it will replace all its uses. Stmts {S1,S2,S3} will
737 remain irrelevant unless used by stmts other than S4.
739 If vectorization succeeds, vect_transform_stmt will skip over {S1,S2,S3}
740 (because they are marked as irrelevant). It will vectorize S6, and record
741 a pointer to the new vector stmt VS6 both from S6 (as usual), and also
742 from S4. We do that so that when we get to vectorizing stmts that use the
743 def of S4 (like S5 that uses a_0), we'll know where to take the relevant
744 vector-def from. S4 will be skipped, and S5 will be vectorized as usual:
746 in_pattern_p related_stmt vec_stmt
748 S2: a_2 = ..use(a_i).. - - -
749 S3: a_1 = ..use(a_2).. - - -
750 > VS6: va_new = .... - - -
751 S6: a_new = .... - S4 VS6
752 S4: a_0 = ..use(a_1).. true S6 VS6
753 > VS5: ... = ..vuse(va_new).. - - -
754 S5: ... = ..use(a_0).. - - -
756 DCE could then get rid of {S1,S2,S3,S4,S5,S6} (if their defs are not used
757 elsewhere), and we'll end up with:
760 VS5: ... = ..vuse(va_new)..
762 If vectorization does not succeed, DCE will clean S6 away (its def is
763 not used), and we'll end up with the original sequence.
767 vect_pattern_recog (loop_vec_info loop_vinfo
)
769 struct loop
*loop
= LOOP_VINFO_LOOP (loop_vinfo
);
770 basic_block
*bbs
= LOOP_VINFO_BBS (loop_vinfo
);
771 unsigned int nbbs
= loop
->num_nodes
;
772 block_stmt_iterator si
;
775 tree (* vect_recog_func_ptr
) (tree
, tree
*, tree
*);
777 if (vect_print_dump_info (REPORT_DETAILS
))
778 fprintf (vect_dump
, "=== vect_pattern_recog ===");
780 /* Scan through the loop stmts, applying the pattern recognition
781 functions starting at each stmt visited: */
782 for (i
= 0; i
< nbbs
; i
++)
784 basic_block bb
= bbs
[i
];
785 for (si
= bsi_start (bb
); !bsi_end_p (si
); bsi_next (&si
))
787 stmt
= bsi_stmt (si
);
789 /* Scan over all generic vect_recog_xxx_pattern functions. */
790 for (j
= 0; j
< NUM_PATTERNS
; j
++)
792 vect_recog_func_ptr
= vect_vect_recog_func_ptrs
[j
];
793 vect_pattern_recog_1 (vect_recog_func_ptr
, si
);