1 /* Lower vector operations to scalar operations.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
26 #include "langhooks.h"
27 #include "tree-flow.h"
29 #include "tree-iterator.h"
30 #include "tree-pass.h"
34 /* Need to include rtl.h, expr.h, etc. for optabs. */
39 static void expand_vector_operations_1 (gimple_stmt_iterator
*);
42 /* Build a constant of type TYPE, made of VALUE's bits replicated
43 every TYPE_SIZE (INNER_TYPE) bits to fit TYPE's precision. */
45 build_replicated_const (tree type
, tree inner_type
, HOST_WIDE_INT value
)
47 int width
= tree_low_cst (TYPE_SIZE (inner_type
), 1);
48 int n
= HOST_BITS_PER_WIDE_INT
/ width
;
49 unsigned HOST_WIDE_INT low
, high
, mask
;
54 if (width
== HOST_BITS_PER_WIDE_INT
)
58 mask
= ((HOST_WIDE_INT
)1 << width
) - 1;
59 low
= (unsigned HOST_WIDE_INT
) ~0 / mask
* (value
& mask
);
62 if (TYPE_PRECISION (type
) < HOST_BITS_PER_WIDE_INT
)
63 low
&= ((HOST_WIDE_INT
)1 << TYPE_PRECISION (type
)) - 1, high
= 0;
64 else if (TYPE_PRECISION (type
) == HOST_BITS_PER_WIDE_INT
)
66 else if (TYPE_PRECISION (type
) == 2 * HOST_BITS_PER_WIDE_INT
)
71 ret
= build_int_cst_wide (type
, low
, high
);
75 static GTY(()) tree vector_inner_type
;
76 static GTY(()) tree vector_last_type
;
77 static GTY(()) int vector_last_nunits
;
79 /* Return a suitable vector types made of SUBPARTS units each of mode
80 "word_mode" (the global variable). */
82 build_word_mode_vector_type (int nunits
)
84 if (!vector_inner_type
)
85 vector_inner_type
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
86 else if (vector_last_nunits
== nunits
)
88 gcc_assert (TREE_CODE (vector_last_type
) == VECTOR_TYPE
);
89 return vector_last_type
;
92 /* We build a new type, but we canonicalize it nevertheless,
93 because it still saves some memory. */
94 vector_last_nunits
= nunits
;
95 vector_last_type
= type_hash_canon (nunits
,
96 build_vector_type (vector_inner_type
,
98 return vector_last_type
;
101 typedef tree (*elem_op_func
) (gimple_stmt_iterator
*,
102 tree
, tree
, tree
, tree
, tree
, enum tree_code
);
105 tree_vec_extract (gimple_stmt_iterator
*gsi
, tree type
,
106 tree t
, tree bitsize
, tree bitpos
)
109 return gimplify_build3 (gsi
, BIT_FIELD_REF
, type
, t
, bitsize
, bitpos
);
111 return gimplify_build1 (gsi
, VIEW_CONVERT_EXPR
, type
, t
);
115 do_unop (gimple_stmt_iterator
*gsi
, tree inner_type
, tree a
,
116 tree b ATTRIBUTE_UNUSED
, tree bitpos
, tree bitsize
,
119 a
= tree_vec_extract (gsi
, inner_type
, a
, bitsize
, bitpos
);
120 return gimplify_build1 (gsi
, code
, inner_type
, a
);
124 do_binop (gimple_stmt_iterator
*gsi
, tree inner_type
, tree a
, tree b
,
125 tree bitpos
, tree bitsize
, enum tree_code code
)
127 a
= tree_vec_extract (gsi
, inner_type
, a
, bitsize
, bitpos
);
128 b
= tree_vec_extract (gsi
, inner_type
, b
, bitsize
, bitpos
);
129 return gimplify_build2 (gsi
, code
, inner_type
, a
, b
);
133 /* Construct expression (A[BITPOS] code B[BITPOS]) ? -1 : 0
135 INNER_TYPE is the type of A and B elements
137 returned expression is of signed integer type with the
138 size equal to the size of INNER_TYPE. */
140 do_compare (gimple_stmt_iterator
*gsi
, tree inner_type
, tree a
, tree b
,
141 tree bitpos
, tree bitsize
, enum tree_code code
)
145 a
= tree_vec_extract (gsi
, inner_type
, a
, bitsize
, bitpos
);
146 b
= tree_vec_extract (gsi
, inner_type
, b
, bitsize
, bitpos
);
148 comp_type
= build_nonstandard_integer_type
149 (GET_MODE_BITSIZE (TYPE_MODE (inner_type
)), 0);
151 return gimplify_build3 (gsi
, COND_EXPR
, comp_type
,
152 fold_build2 (code
, boolean_type_node
, a
, b
),
153 build_int_cst (comp_type
, -1),
154 build_int_cst (comp_type
, 0));
157 /* Expand vector addition to scalars. This does bit twiddling
158 in order to increase parallelism:
160 a + b = (((int) a & 0x7f7f7f7f) + ((int) b & 0x7f7f7f7f)) ^
163 a - b = (((int) a | 0x80808080) - ((int) b & 0x7f7f7f7f)) ^
164 (a ^ ~b) & 0x80808080
166 -b = (0x80808080 - ((int) b & 0x7f7f7f7f)) ^ (~b & 0x80808080)
168 This optimization should be done only if 4 vector items or more
171 do_plus_minus (gimple_stmt_iterator
*gsi
, tree word_type
, tree a
, tree b
,
172 tree bitpos ATTRIBUTE_UNUSED
, tree bitsize ATTRIBUTE_UNUSED
,
175 tree inner_type
= TREE_TYPE (TREE_TYPE (a
));
176 unsigned HOST_WIDE_INT max
;
177 tree low_bits
, high_bits
, a_low
, b_low
, result_low
, signs
;
179 max
= GET_MODE_MASK (TYPE_MODE (inner_type
));
180 low_bits
= build_replicated_const (word_type
, inner_type
, max
>> 1);
181 high_bits
= build_replicated_const (word_type
, inner_type
, max
& ~(max
>> 1));
183 a
= tree_vec_extract (gsi
, word_type
, a
, bitsize
, bitpos
);
184 b
= tree_vec_extract (gsi
, word_type
, b
, bitsize
, bitpos
);
186 signs
= gimplify_build2 (gsi
, BIT_XOR_EXPR
, word_type
, a
, b
);
187 b_low
= gimplify_build2 (gsi
, BIT_AND_EXPR
, word_type
, b
, low_bits
);
188 if (code
== PLUS_EXPR
)
189 a_low
= gimplify_build2 (gsi
, BIT_AND_EXPR
, word_type
, a
, low_bits
);
192 a_low
= gimplify_build2 (gsi
, BIT_IOR_EXPR
, word_type
, a
, high_bits
);
193 signs
= gimplify_build1 (gsi
, BIT_NOT_EXPR
, word_type
, signs
);
196 signs
= gimplify_build2 (gsi
, BIT_AND_EXPR
, word_type
, signs
, high_bits
);
197 result_low
= gimplify_build2 (gsi
, code
, word_type
, a_low
, b_low
);
198 return gimplify_build2 (gsi
, BIT_XOR_EXPR
, word_type
, result_low
, signs
);
202 do_negate (gimple_stmt_iterator
*gsi
, tree word_type
, tree b
,
203 tree unused ATTRIBUTE_UNUSED
, tree bitpos ATTRIBUTE_UNUSED
,
204 tree bitsize ATTRIBUTE_UNUSED
,
205 enum tree_code code ATTRIBUTE_UNUSED
)
207 tree inner_type
= TREE_TYPE (TREE_TYPE (b
));
209 tree low_bits
, high_bits
, b_low
, result_low
, signs
;
211 max
= GET_MODE_MASK (TYPE_MODE (inner_type
));
212 low_bits
= build_replicated_const (word_type
, inner_type
, max
>> 1);
213 high_bits
= build_replicated_const (word_type
, inner_type
, max
& ~(max
>> 1));
215 b
= tree_vec_extract (gsi
, word_type
, b
, bitsize
, bitpos
);
217 b_low
= gimplify_build2 (gsi
, BIT_AND_EXPR
, word_type
, b
, low_bits
);
218 signs
= gimplify_build1 (gsi
, BIT_NOT_EXPR
, word_type
, b
);
219 signs
= gimplify_build2 (gsi
, BIT_AND_EXPR
, word_type
, signs
, high_bits
);
220 result_low
= gimplify_build2 (gsi
, MINUS_EXPR
, word_type
, high_bits
, b_low
);
221 return gimplify_build2 (gsi
, BIT_XOR_EXPR
, word_type
, result_low
, signs
);
224 /* Expand a vector operation to scalars, by using many operations
225 whose type is the vector type's inner type. */
227 expand_vector_piecewise (gimple_stmt_iterator
*gsi
, elem_op_func f
,
228 tree type
, tree inner_type
,
229 tree a
, tree b
, enum tree_code code
)
231 VEC(constructor_elt
,gc
) *v
;
232 tree part_width
= TYPE_SIZE (inner_type
);
233 tree index
= bitsize_int (0);
234 int nunits
= TYPE_VECTOR_SUBPARTS (type
);
235 int delta
= tree_low_cst (part_width
, 1)
236 / tree_low_cst (TYPE_SIZE (TREE_TYPE (type
)), 1);
239 v
= VEC_alloc(constructor_elt
, gc
, (nunits
+ delta
- 1) / delta
);
240 for (i
= 0; i
< nunits
;
241 i
+= delta
, index
= int_const_binop (PLUS_EXPR
, index
, part_width
))
243 tree result
= f (gsi
, inner_type
, a
, b
, index
, part_width
, code
);
244 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
245 ce
->index
= NULL_TREE
;
249 return build_constructor (type
, v
);
252 /* Expand a vector operation to scalars with the freedom to use
253 a scalar integer type, or to use a different size for the items
254 in the vector type. */
256 expand_vector_parallel (gimple_stmt_iterator
*gsi
, elem_op_func f
, tree type
,
260 tree result
, compute_type
;
261 enum machine_mode mode
;
262 int n_words
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1) / UNITS_PER_WORD
;
264 /* We have three strategies. If the type is already correct, just do
265 the operation an element at a time. Else, if the vector is wider than
266 one word, do it a word at a time; finally, if the vector is smaller
267 than one word, do it as a scalar. */
268 if (TYPE_MODE (TREE_TYPE (type
)) == word_mode
)
269 return expand_vector_piecewise (gsi
, f
,
270 type
, TREE_TYPE (type
),
272 else if (n_words
> 1)
274 tree word_type
= build_word_mode_vector_type (n_words
);
275 result
= expand_vector_piecewise (gsi
, f
,
276 word_type
, TREE_TYPE (word_type
),
278 result
= force_gimple_operand_gsi (gsi
, result
, true, NULL
, true,
283 /* Use a single scalar operation with a mode no wider than word_mode. */
284 mode
= mode_for_size (tree_low_cst (TYPE_SIZE (type
), 1), MODE_INT
, 0);
285 compute_type
= lang_hooks
.types
.type_for_mode (mode
, 1);
286 result
= f (gsi
, compute_type
, a
, b
, NULL_TREE
, NULL_TREE
, code
);
292 /* Expand a vector operation to scalars; for integer types we can use
293 special bit twiddling tricks to do the sums a word at a time, using
294 function F_PARALLEL instead of F. These tricks are done only if
295 they can process at least four items, that is, only if the vector
296 holds at least four items and if a word can hold four items. */
298 expand_vector_addition (gimple_stmt_iterator
*gsi
,
299 elem_op_func f
, elem_op_func f_parallel
,
300 tree type
, tree a
, tree b
, enum tree_code code
)
302 int parts_per_word
= UNITS_PER_WORD
303 / tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type
)), 1);
305 if (INTEGRAL_TYPE_P (TREE_TYPE (type
))
306 && parts_per_word
>= 4
307 && TYPE_VECTOR_SUBPARTS (type
) >= 4)
308 return expand_vector_parallel (gsi
, f_parallel
,
311 return expand_vector_piecewise (gsi
, f
,
312 type
, TREE_TYPE (type
),
316 /* Check if vector VEC consists of all the equal elements and
317 that the number of elements corresponds to the type of VEC.
318 The function returns first element of the vector
319 or NULL_TREE if the vector is not uniform. */
321 uniform_vector_p (tree vec
)
326 if (vec
== NULL_TREE
)
329 if (TREE_CODE (vec
) == VECTOR_CST
)
331 els
= TREE_VECTOR_CST_ELTS (vec
);
332 first
= TREE_VALUE (els
);
333 els
= TREE_CHAIN (els
);
335 for (t
= els
; t
; t
= TREE_CHAIN (t
))
336 if (!operand_equal_p (first
, TREE_VALUE (t
), 0))
342 else if (TREE_CODE (vec
) == CONSTRUCTOR
)
344 first
= error_mark_node
;
346 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
353 if (!operand_equal_p (first
, t
, 0))
356 if (i
!= TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)))
365 /* Try to expand vector comparison expression OP0 CODE OP1 by
366 querying optab if the following expression:
367 VEC_COND_EXPR< OP0 CODE OP1, {-1,...}, {0,...}>
370 expand_vector_comparison (gimple_stmt_iterator
*gsi
, tree type
, tree op0
,
371 tree op1
, enum tree_code code
)
374 if (! expand_vec_cond_expr_p (type
, TREE_TYPE (op0
)))
375 t
= expand_vector_piecewise (gsi
, do_compare
, type
,
376 TREE_TYPE (TREE_TYPE (op0
)), op0
, op1
, code
);
384 expand_vector_operation (gimple_stmt_iterator
*gsi
, tree type
, tree compute_type
,
385 gimple assign
, enum tree_code code
)
387 enum machine_mode compute_mode
= TYPE_MODE (compute_type
);
389 /* If the compute mode is not a vector mode (hence we are not decomposing
390 a BLKmode vector to smaller, hardware-supported vectors), we may want
391 to expand the operations in parallel. */
392 if (GET_MODE_CLASS (compute_mode
) != MODE_VECTOR_INT
393 && GET_MODE_CLASS (compute_mode
) != MODE_VECTOR_FLOAT
394 && GET_MODE_CLASS (compute_mode
) != MODE_VECTOR_FRACT
395 && GET_MODE_CLASS (compute_mode
) != MODE_VECTOR_UFRACT
396 && GET_MODE_CLASS (compute_mode
) != MODE_VECTOR_ACCUM
397 && GET_MODE_CLASS (compute_mode
) != MODE_VECTOR_UACCUM
)
402 if (!TYPE_OVERFLOW_TRAPS (type
))
403 return expand_vector_addition (gsi
, do_binop
, do_plus_minus
, type
,
404 gimple_assign_rhs1 (assign
),
405 gimple_assign_rhs2 (assign
), code
);
409 if (!TYPE_OVERFLOW_TRAPS (type
))
410 return expand_vector_addition (gsi
, do_unop
, do_negate
, type
,
411 gimple_assign_rhs1 (assign
),
418 return expand_vector_parallel (gsi
, do_binop
, type
,
419 gimple_assign_rhs1 (assign
),
420 gimple_assign_rhs2 (assign
), code
);
423 return expand_vector_parallel (gsi
, do_unop
, type
,
424 gimple_assign_rhs1 (assign
),
441 tree rhs1
= gimple_assign_rhs1 (assign
);
442 tree rhs2
= gimple_assign_rhs2 (assign
);
444 return expand_vector_comparison (gsi
, type
, rhs1
, rhs2
, code
);
450 if (TREE_CODE_CLASS (code
) == tcc_unary
)
451 return expand_vector_piecewise (gsi
, do_unop
, type
, compute_type
,
452 gimple_assign_rhs1 (assign
),
455 return expand_vector_piecewise (gsi
, do_binop
, type
, compute_type
,
456 gimple_assign_rhs1 (assign
),
457 gimple_assign_rhs2 (assign
), code
);
460 /* Return a type for the widest vector mode whose components are of mode
461 INNER_MODE, or NULL_TREE if none is found.
462 SATP is true for saturating fixed-point types. */
465 type_for_widest_vector_mode (enum machine_mode inner_mode
, optab op
, int satp
)
467 enum machine_mode best_mode
= VOIDmode
, mode
;
470 if (SCALAR_FLOAT_MODE_P (inner_mode
))
471 mode
= MIN_MODE_VECTOR_FLOAT
;
472 else if (SCALAR_FRACT_MODE_P (inner_mode
))
473 mode
= MIN_MODE_VECTOR_FRACT
;
474 else if (SCALAR_UFRACT_MODE_P (inner_mode
))
475 mode
= MIN_MODE_VECTOR_UFRACT
;
476 else if (SCALAR_ACCUM_MODE_P (inner_mode
))
477 mode
= MIN_MODE_VECTOR_ACCUM
;
478 else if (SCALAR_UACCUM_MODE_P (inner_mode
))
479 mode
= MIN_MODE_VECTOR_UACCUM
;
481 mode
= MIN_MODE_VECTOR_INT
;
483 for (; mode
!= VOIDmode
; mode
= GET_MODE_WIDER_MODE (mode
))
484 if (GET_MODE_INNER (mode
) == inner_mode
485 && GET_MODE_NUNITS (mode
) > best_nunits
486 && optab_handler (op
, mode
) != CODE_FOR_nothing
)
487 best_mode
= mode
, best_nunits
= GET_MODE_NUNITS (mode
);
489 if (best_mode
== VOIDmode
)
493 /* For fixed-point modes, we need to pass satp as the 2nd parameter. */
494 if (ALL_FIXED_POINT_MODE_P (best_mode
))
495 return lang_hooks
.types
.type_for_mode (best_mode
, satp
);
497 return lang_hooks
.types
.type_for_mode (best_mode
, 1);
501 /* Process one statement. If we identify a vector operation, expand it. */
504 expand_vector_operations_1 (gimple_stmt_iterator
*gsi
)
506 gimple stmt
= gsi_stmt (*gsi
);
507 tree lhs
, rhs1
, rhs2
= NULL
, type
, compute_type
;
509 enum machine_mode compute_mode
;
511 enum gimple_rhs_class rhs_class
;
514 if (gimple_code (stmt
) != GIMPLE_ASSIGN
)
517 code
= gimple_assign_rhs_code (stmt
);
518 rhs_class
= get_gimple_rhs_class (code
);
519 lhs
= gimple_assign_lhs (stmt
);
521 if (rhs_class
!= GIMPLE_UNARY_RHS
&& rhs_class
!= GIMPLE_BINARY_RHS
)
524 rhs1
= gimple_assign_rhs1 (stmt
);
525 type
= gimple_expr_type (stmt
);
526 if (rhs_class
== GIMPLE_BINARY_RHS
)
527 rhs2
= gimple_assign_rhs2 (stmt
);
529 if (TREE_CODE (type
) != VECTOR_TYPE
)
533 || code
== FLOAT_EXPR
534 || code
== FIX_TRUNC_EXPR
535 || code
== VIEW_CONVERT_EXPR
)
538 gcc_assert (code
!= CONVERT_EXPR
);
540 /* The signedness is determined from input argument. */
541 if (code
== VEC_UNPACK_FLOAT_HI_EXPR
542 || code
== VEC_UNPACK_FLOAT_LO_EXPR
)
543 type
= TREE_TYPE (rhs1
);
545 /* Choose between vector shift/rotate by vector and vector shift/rotate by
547 if (code
== LSHIFT_EXPR
548 || code
== RSHIFT_EXPR
549 || code
== LROTATE_EXPR
550 || code
== RROTATE_EXPR
)
552 bool vector_scalar_shift
;
553 op
= optab_for_tree_code (code
, type
, optab_scalar
);
555 /* Vector/Scalar shift is supported. */
556 vector_scalar_shift
= (op
&& (optab_handler (op
, TYPE_MODE (type
))
557 != CODE_FOR_nothing
));
559 /* If the 2nd argument is vector, we need a vector/vector shift.
560 Except all the elements in the second vector are the same. */
561 if (VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (rhs2
))))
566 /* Check whether we have vector <op> {x,x,x,x} where x
567 could be a scalar variable or a constant. Transform
568 vector <op> {x,x,x,x} ==> vector <op> scalar. */
569 if (vector_scalar_shift
570 && ((TREE_CODE (rhs2
) == VECTOR_CST
571 && (first
= uniform_vector_p (rhs2
)) != NULL_TREE
)
572 || (TREE_CODE (rhs2
) == SSA_NAME
573 && (def_stmt
= SSA_NAME_DEF_STMT (rhs2
))
574 && gimple_assign_single_p (def_stmt
)
575 && (first
= uniform_vector_p
576 (gimple_assign_rhs1 (def_stmt
))) != NULL_TREE
)))
578 gimple_assign_set_rhs2 (stmt
, first
);
583 op
= optab_for_tree_code (code
, type
, optab_vector
);
586 /* Try for a vector/scalar shift, and if we don't have one, see if we
587 have a vector/vector shift */
588 else if (!vector_scalar_shift
)
590 op
= optab_for_tree_code (code
, type
, optab_vector
);
592 if (op
&& (optab_handler (op
, TYPE_MODE (type
))
593 != CODE_FOR_nothing
))
595 /* Transform vector <op> scalar => vector <op> {x,x,x,x}. */
596 int n_parts
= TYPE_VECTOR_SUBPARTS (type
);
597 int part_size
= tree_low_cst (TYPE_SIZE (TREE_TYPE (type
)), 1);
598 tree part_type
= lang_hooks
.types
.type_for_size (part_size
, 1);
599 tree vect_type
= build_vector_type (part_type
, n_parts
);
601 rhs2
= fold_convert (part_type
, rhs2
);
602 rhs2
= build_vector_from_val (vect_type
, rhs2
);
603 gimple_assign_set_rhs2 (stmt
, rhs2
);
609 op
= optab_for_tree_code (code
, type
, optab_default
);
611 /* For widening/narrowing vector operations, the relevant type is of the
612 arguments, not the widened result. VEC_UNPACK_FLOAT_*_EXPR is
613 calculated in the same way above. */
614 if (code
== WIDEN_SUM_EXPR
615 || code
== VEC_WIDEN_MULT_HI_EXPR
616 || code
== VEC_WIDEN_MULT_LO_EXPR
617 || code
== VEC_UNPACK_HI_EXPR
618 || code
== VEC_UNPACK_LO_EXPR
619 || code
== VEC_PACK_TRUNC_EXPR
620 || code
== VEC_PACK_SAT_EXPR
621 || code
== VEC_PACK_FIX_TRUNC_EXPR
)
622 type
= TREE_TYPE (rhs1
);
624 /* Optabs will try converting a negation into a subtraction, so
625 look for it as well. TODO: negation of floating-point vectors
626 might be turned into an exclusive OR toggling the sign bit. */
628 && code
== NEGATE_EXPR
629 && INTEGRAL_TYPE_P (TREE_TYPE (type
)))
630 op
= optab_for_tree_code (MINUS_EXPR
, type
, optab_default
);
632 /* For very wide vectors, try using a smaller vector mode. */
634 if (TYPE_MODE (type
) == BLKmode
&& op
)
636 tree vector_compute_type
637 = type_for_widest_vector_mode (TYPE_MODE (TREE_TYPE (type
)), op
,
638 TYPE_SATURATING (TREE_TYPE (type
)));
639 if (vector_compute_type
!= NULL_TREE
640 && (TYPE_VECTOR_SUBPARTS (vector_compute_type
)
641 < TYPE_VECTOR_SUBPARTS (compute_type
)))
642 compute_type
= vector_compute_type
;
645 /* If we are breaking a BLKmode vector into smaller pieces,
646 type_for_widest_vector_mode has already looked into the optab,
647 so skip these checks. */
648 if (compute_type
== type
)
650 compute_mode
= TYPE_MODE (compute_type
);
651 if ((GET_MODE_CLASS (compute_mode
) == MODE_VECTOR_INT
652 || GET_MODE_CLASS (compute_mode
) == MODE_VECTOR_FLOAT
653 || GET_MODE_CLASS (compute_mode
) == MODE_VECTOR_FRACT
654 || GET_MODE_CLASS (compute_mode
) == MODE_VECTOR_UFRACT
655 || GET_MODE_CLASS (compute_mode
) == MODE_VECTOR_ACCUM
656 || GET_MODE_CLASS (compute_mode
) == MODE_VECTOR_UACCUM
)
658 && optab_handler (op
, compute_mode
) != CODE_FOR_nothing
)
661 /* There is no operation in hardware, so fall back to scalars. */
662 compute_type
= TREE_TYPE (type
);
665 gcc_assert (code
!= VEC_LSHIFT_EXPR
&& code
!= VEC_RSHIFT_EXPR
);
666 new_rhs
= expand_vector_operation (gsi
, type
, compute_type
, stmt
, code
);
668 /* Leave expression untouched for later expansion. */
669 if (new_rhs
== NULL_TREE
)
672 if (!useless_type_conversion_p (TREE_TYPE (lhs
), TREE_TYPE (new_rhs
)))
673 new_rhs
= gimplify_build1 (gsi
, VIEW_CONVERT_EXPR
, TREE_TYPE (lhs
),
676 /* NOTE: We should avoid using gimple_assign_set_rhs_from_tree. One
677 way to do it is change expand_vector_operation and its callees to
678 return a tree_code, RHS1 and RHS2 instead of a tree. */
679 gimple_assign_set_rhs_from_tree (gsi
, new_rhs
);
680 update_stmt (gsi_stmt (*gsi
));
683 /* Use this to lower vector operations introduced by the vectorizer,
684 if it may need the bit-twiddling tricks implemented in this file. */
687 gate_expand_vector_operations (void)
689 return flag_tree_vectorize
!= 0;
693 expand_vector_operations (void)
695 gimple_stmt_iterator gsi
;
697 bool cfg_changed
= false;
701 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
703 expand_vector_operations_1 (&gsi
);
704 /* ??? If we do not cleanup EH then we will ICE in
705 verification. But in reality we have created wrong-code
706 as we did not properly transition EH info and edges to
707 the piecewise computations. */
708 if (maybe_clean_eh_stmt (gsi_stmt (gsi
))
709 && gimple_purge_dead_eh_edges (bb
))
714 return cfg_changed
? TODO_cleanup_cfg
: 0;
717 struct gimple_opt_pass pass_lower_vector
=
721 "veclower", /* name */
723 expand_vector_operations
, /* execute */
726 0, /* static_pass_number */
728 PROP_cfg
, /* properties_required */
729 0, /* properties_provided */
730 0, /* properties_destroyed */
731 0, /* todo_flags_start */
732 TODO_update_ssa
/* todo_flags_finish */
734 | TODO_verify_stmts
| TODO_verify_flow
738 struct gimple_opt_pass pass_lower_vector_ssa
=
742 "veclower2", /* name */
743 gate_expand_vector_operations
, /* gate */
744 expand_vector_operations
, /* execute */
747 0, /* static_pass_number */
749 PROP_cfg
, /* properties_required */
750 0, /* properties_provided */
751 0, /* properties_destroyed */
752 0, /* todo_flags_start */
753 TODO_update_ssa
/* todo_flags_finish */
755 | TODO_verify_stmts
| TODO_verify_flow
759 #include "gt-tree-vect-generic.h"