annotate gcc/tree-vect-generic.c @ 138:fc828634a951

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:17:14 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Lower vector operations to scalar operations.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
5
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Free Software Foundation; either version 3, or (at your option) any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 later version.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
10
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
15
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
111
kono
parents: 67
diff changeset
23 #include "backend.h"
kono
parents: 67
diff changeset
24 #include "rtl.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "tree.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "gimple.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "tree-pass.h"
111
kono
parents: 67
diff changeset
28 #include "ssa.h"
kono
parents: 67
diff changeset
29 #include "expmed.h"
kono
parents: 67
diff changeset
30 #include "optabs-tree.h"
kono
parents: 67
diff changeset
31 #include "diagnostic.h"
kono
parents: 67
diff changeset
32 #include "fold-const.h"
kono
parents: 67
diff changeset
33 #include "stor-layout.h"
kono
parents: 67
diff changeset
34 #include "langhooks.h"
kono
parents: 67
diff changeset
35 #include "tree-eh.h"
kono
parents: 67
diff changeset
36 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
37 #include "gimplify-me.h"
kono
parents: 67
diff changeset
38 #include "gimplify.h"
kono
parents: 67
diff changeset
39 #include "tree-cfg.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
40 #include "tree-vector-builder.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41 #include "vec-perm-indices.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
111
kono
parents: 67
diff changeset
43
kono
parents: 67
diff changeset
44 static void expand_vector_operations_1 (gimple_stmt_iterator *);
kono
parents: 67
diff changeset
45
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
46 /* Return the number of elements in a vector type TYPE that we have
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 already decided needs to be expanded piecewise. We don't support
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
48 this kind of expansion for variable-length vectors, since we should
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
49 always check for target support before introducing uses of those. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
50 static unsigned int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 nunits_for_known_piecewise_op (const_tree type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 return TYPE_VECTOR_SUBPARTS (type).to_constant ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 /* Return true if TYPE1 has more elements than TYPE2, where either
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 type may be a vector or a scalar. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 static inline bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 subparts_gt (tree type1, tree type2)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
61 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
62 poly_uint64 n1 = VECTOR_TYPE_P (type1) ? TYPE_VECTOR_SUBPARTS (type1) : 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
63 poly_uint64 n2 = VECTOR_TYPE_P (type2) ? TYPE_VECTOR_SUBPARTS (type2) : 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64 return known_gt (n1, n2);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 /* Build a constant of type TYPE, made of VALUE's bits replicated
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 every TYPE_SIZE (INNER_TYPE) bits to fit TYPE's precision. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 build_replicated_const (tree type, tree inner_type, HOST_WIDE_INT value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 {
111
kono
parents: 67
diff changeset
72 int width = tree_to_uhwi (TYPE_SIZE (inner_type));
kono
parents: 67
diff changeset
73 int n = (TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
kono
parents: 67
diff changeset
74 / HOST_BITS_PER_WIDE_INT;
kono
parents: 67
diff changeset
75 unsigned HOST_WIDE_INT low, mask;
kono
parents: 67
diff changeset
76 HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
kono
parents: 67
diff changeset
77 int i;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
111
kono
parents: 67
diff changeset
79 gcc_assert (n && n <= WIDE_INT_MAX_ELTS);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 if (width == HOST_BITS_PER_WIDE_INT)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 low = value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 mask = ((HOST_WIDE_INT)1 << width) - 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
111
kono
parents: 67
diff changeset
89 for (i = 0; i < n; i++)
kono
parents: 67
diff changeset
90 a[i] = low;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
111
kono
parents: 67
diff changeset
92 gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
kono
parents: 67
diff changeset
93 return wide_int_to_tree
kono
parents: 67
diff changeset
94 (type, wide_int::from_array (a, n, TYPE_PRECISION (type)));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 static GTY(()) tree vector_inner_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 static GTY(()) tree vector_last_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 static GTY(()) int vector_last_nunits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 /* Return a suitable vector types made of SUBPARTS units each of mode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 "word_mode" (the global variable). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 build_word_mode_vector_type (int nunits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 if (!vector_inner_type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 vector_inner_type = lang_hooks.types.type_for_mode (word_mode, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 else if (vector_last_nunits == nunits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 gcc_assert (TREE_CODE (vector_last_type) == VECTOR_TYPE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 return vector_last_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 vector_last_nunits = nunits;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
115 vector_last_type = build_vector_type (vector_inner_type, nunits);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 return vector_last_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 typedef tree (*elem_op_func) (gimple_stmt_iterator *,
111
kono
parents: 67
diff changeset
120 tree, tree, tree, tree, tree, enum tree_code,
kono
parents: 67
diff changeset
121 tree);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
123 tree
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 tree_vec_extract (gimple_stmt_iterator *gsi, tree type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 tree t, tree bitsize, tree bitpos)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 {
111
kono
parents: 67
diff changeset
127 if (TREE_CODE (t) == SSA_NAME)
kono
parents: 67
diff changeset
128 {
kono
parents: 67
diff changeset
129 gimple *def_stmt = SSA_NAME_DEF_STMT (t);
kono
parents: 67
diff changeset
130 if (is_gimple_assign (def_stmt)
kono
parents: 67
diff changeset
131 && (gimple_assign_rhs_code (def_stmt) == VECTOR_CST
kono
parents: 67
diff changeset
132 || (bitpos
kono
parents: 67
diff changeset
133 && gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR)))
kono
parents: 67
diff changeset
134 t = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
135 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 if (bitpos)
111
kono
parents: 67
diff changeset
137 {
kono
parents: 67
diff changeset
138 if (TREE_CODE (type) == BOOLEAN_TYPE)
kono
parents: 67
diff changeset
139 {
kono
parents: 67
diff changeset
140 tree itype
kono
parents: 67
diff changeset
141 = build_nonstandard_integer_type (tree_to_uhwi (bitsize), 0);
kono
parents: 67
diff changeset
142 tree field = gimplify_build3 (gsi, BIT_FIELD_REF, itype, t,
kono
parents: 67
diff changeset
143 bitsize, bitpos);
kono
parents: 67
diff changeset
144 return gimplify_build2 (gsi, NE_EXPR, type, field,
kono
parents: 67
diff changeset
145 build_zero_cst (itype));
kono
parents: 67
diff changeset
146 }
kono
parents: 67
diff changeset
147 else
kono
parents: 67
diff changeset
148 return gimplify_build3 (gsi, BIT_FIELD_REF, type, t, bitsize, bitpos);
kono
parents: 67
diff changeset
149 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 return gimplify_build1 (gsi, VIEW_CONVERT_EXPR, type, t);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 do_unop (gimple_stmt_iterator *gsi, tree inner_type, tree a,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 tree b ATTRIBUTE_UNUSED, tree bitpos, tree bitsize,
111
kono
parents: 67
diff changeset
157 enum tree_code code, tree type ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 return gimplify_build1 (gsi, code, inner_type, a);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 do_binop (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b,
111
kono
parents: 67
diff changeset
165 tree bitpos, tree bitsize, enum tree_code code,
kono
parents: 67
diff changeset
166 tree type ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 {
111
kono
parents: 67
diff changeset
168 if (TREE_CODE (TREE_TYPE (a)) == VECTOR_TYPE)
kono
parents: 67
diff changeset
169 a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
kono
parents: 67
diff changeset
170 if (TREE_CODE (TREE_TYPE (b)) == VECTOR_TYPE)
kono
parents: 67
diff changeset
171 b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
kono
parents: 67
diff changeset
172 return gimplify_build2 (gsi, code, inner_type, a, b);
kono
parents: 67
diff changeset
173 }
kono
parents: 67
diff changeset
174
kono
parents: 67
diff changeset
175 /* Construct expression (A[BITPOS] code B[BITPOS]) ? -1 : 0
kono
parents: 67
diff changeset
176
kono
parents: 67
diff changeset
177 INNER_TYPE is the type of A and B elements
kono
parents: 67
diff changeset
178
kono
parents: 67
diff changeset
179 returned expression is of signed integer type with the
kono
parents: 67
diff changeset
180 size equal to the size of INNER_TYPE. */
kono
parents: 67
diff changeset
181 static tree
kono
parents: 67
diff changeset
182 do_compare (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b,
kono
parents: 67
diff changeset
183 tree bitpos, tree bitsize, enum tree_code code, tree type)
kono
parents: 67
diff changeset
184 {
kono
parents: 67
diff changeset
185 tree stype = TREE_TYPE (type);
kono
parents: 67
diff changeset
186 tree cst_false = build_zero_cst (stype);
kono
parents: 67
diff changeset
187 tree cst_true = build_all_ones_cst (stype);
kono
parents: 67
diff changeset
188 tree cmp;
kono
parents: 67
diff changeset
189
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
111
kono
parents: 67
diff changeset
192
kono
parents: 67
diff changeset
193 cmp = build2 (code, boolean_type_node, a, b);
kono
parents: 67
diff changeset
194 return gimplify_build3 (gsi, COND_EXPR, stype, cmp, cst_true, cst_false);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 /* Expand vector addition to scalars. This does bit twiddling
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 in order to increase parallelism:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 a + b = (((int) a & 0x7f7f7f7f) + ((int) b & 0x7f7f7f7f)) ^
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 (a ^ b) & 0x80808080
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 a - b = (((int) a | 0x80808080) - ((int) b & 0x7f7f7f7f)) ^
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 (a ^ ~b) & 0x80808080
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 -b = (0x80808080 - ((int) b & 0x7f7f7f7f)) ^ (~b & 0x80808080)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 This optimization should be done only if 4 vector items or more
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 fit into a word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 do_plus_minus (gimple_stmt_iterator *gsi, tree word_type, tree a, tree b,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 tree bitpos ATTRIBUTE_UNUSED, tree bitsize ATTRIBUTE_UNUSED,
111
kono
parents: 67
diff changeset
213 enum tree_code code, tree type ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 tree inner_type = TREE_TYPE (TREE_TYPE (a));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 unsigned HOST_WIDE_INT max;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 tree low_bits, high_bits, a_low, b_low, result_low, signs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 max = GET_MODE_MASK (TYPE_MODE (inner_type));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 low_bits = build_replicated_const (word_type, inner_type, max >> 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 high_bits = build_replicated_const (word_type, inner_type, max & ~(max >> 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 a = tree_vec_extract (gsi, word_type, a, bitsize, bitpos);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 b = tree_vec_extract (gsi, word_type, b, bitsize, bitpos);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 signs = gimplify_build2 (gsi, BIT_XOR_EXPR, word_type, a, b);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 b_low = gimplify_build2 (gsi, BIT_AND_EXPR, word_type, b, low_bits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 if (code == PLUS_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 a_low = gimplify_build2 (gsi, BIT_AND_EXPR, word_type, a, low_bits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 a_low = gimplify_build2 (gsi, BIT_IOR_EXPR, word_type, a, high_bits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 signs = gimplify_build1 (gsi, BIT_NOT_EXPR, word_type, signs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 signs = gimplify_build2 (gsi, BIT_AND_EXPR, word_type, signs, high_bits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 result_low = gimplify_build2 (gsi, code, word_type, a_low, b_low);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 return gimplify_build2 (gsi, BIT_XOR_EXPR, word_type, result_low, signs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 do_negate (gimple_stmt_iterator *gsi, tree word_type, tree b,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 tree unused ATTRIBUTE_UNUSED, tree bitpos ATTRIBUTE_UNUSED,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 tree bitsize ATTRIBUTE_UNUSED,
111
kono
parents: 67
diff changeset
245 enum tree_code code ATTRIBUTE_UNUSED,
kono
parents: 67
diff changeset
246 tree type ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 tree inner_type = TREE_TYPE (TREE_TYPE (b));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 HOST_WIDE_INT max;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 tree low_bits, high_bits, b_low, result_low, signs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 max = GET_MODE_MASK (TYPE_MODE (inner_type));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 low_bits = build_replicated_const (word_type, inner_type, max >> 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 high_bits = build_replicated_const (word_type, inner_type, max & ~(max >> 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 b = tree_vec_extract (gsi, word_type, b, bitsize, bitpos);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 b_low = gimplify_build2 (gsi, BIT_AND_EXPR, word_type, b, low_bits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 signs = gimplify_build1 (gsi, BIT_NOT_EXPR, word_type, b);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 signs = gimplify_build2 (gsi, BIT_AND_EXPR, word_type, signs, high_bits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 result_low = gimplify_build2 (gsi, MINUS_EXPR, word_type, high_bits, b_low);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 return gimplify_build2 (gsi, BIT_XOR_EXPR, word_type, result_low, signs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 /* Expand a vector operation to scalars, by using many operations
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 whose type is the vector type's inner type. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 expand_vector_piecewise (gimple_stmt_iterator *gsi, elem_op_func f,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 tree type, tree inner_type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 tree a, tree b, enum tree_code code)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 {
111
kono
parents: 67
diff changeset
272 vec<constructor_elt, va_gc> *v;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 tree part_width = TYPE_SIZE (inner_type);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 tree index = bitsize_int (0);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
275 int nunits = nunits_for_known_piecewise_op (type);
111
kono
parents: 67
diff changeset
276 int delta = tree_to_uhwi (part_width)
kono
parents: 67
diff changeset
277 / tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 int i;
111
kono
parents: 67
diff changeset
279 location_t loc = gimple_location (gsi_stmt (*gsi));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280
111
kono
parents: 67
diff changeset
281 if (types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
kono
parents: 67
diff changeset
282 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 67
diff changeset
283 "vector operation will be expanded piecewise");
kono
parents: 67
diff changeset
284 else
kono
parents: 67
diff changeset
285 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 67
diff changeset
286 "vector operation will be expanded in parallel");
kono
parents: 67
diff changeset
287
kono
parents: 67
diff changeset
288 vec_alloc (v, (nunits + delta - 1) / delta);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 for (i = 0; i < nunits;
111
kono
parents: 67
diff changeset
290 i += delta, index = int_const_binop (PLUS_EXPR, index, part_width))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 {
111
kono
parents: 67
diff changeset
292 tree result = f (gsi, inner_type, a, b, index, part_width, code, type);
kono
parents: 67
diff changeset
293 constructor_elt ce = {NULL_TREE, result};
kono
parents: 67
diff changeset
294 v->quick_push (ce);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 return build_constructor (type, v);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 /* Expand a vector operation to scalars with the freedom to use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 a scalar integer type, or to use a different size for the items
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 in the vector type. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 expand_vector_parallel (gimple_stmt_iterator *gsi, elem_op_func f, tree type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 tree a, tree b,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 enum tree_code code)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 tree result, compute_type;
111
kono
parents: 67
diff changeset
309 int n_words = tree_to_uhwi (TYPE_SIZE_UNIT (type)) / UNITS_PER_WORD;
kono
parents: 67
diff changeset
310 location_t loc = gimple_location (gsi_stmt (*gsi));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 /* We have three strategies. If the type is already correct, just do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 the operation an element at a time. Else, if the vector is wider than
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 one word, do it a word at a time; finally, if the vector is smaller
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 than one word, do it as a scalar. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 if (TYPE_MODE (TREE_TYPE (type)) == word_mode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 return expand_vector_piecewise (gsi, f,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 type, TREE_TYPE (type),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 a, b, code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 else if (n_words > 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 tree word_type = build_word_mode_vector_type (n_words);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 result = expand_vector_piecewise (gsi, f,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 word_type, TREE_TYPE (word_type),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 a, b, code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 result = force_gimple_operand_gsi (gsi, result, true, NULL, true,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 /* Use a single scalar operation with a mode no wider than word_mode. */
111
kono
parents: 67
diff changeset
332 scalar_int_mode mode
kono
parents: 67
diff changeset
333 = int_mode_for_size (tree_to_uhwi (TYPE_SIZE (type)), 0).require ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 compute_type = lang_hooks.types.type_for_mode (mode, 1);
111
kono
parents: 67
diff changeset
335 result = f (gsi, compute_type, a, b, NULL_TREE, NULL_TREE, code, type);
kono
parents: 67
diff changeset
336 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 67
diff changeset
337 "vector operation will be expanded with a "
kono
parents: 67
diff changeset
338 "single scalar operation");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 /* Expand a vector operation to scalars; for integer types we can use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 special bit twiddling tricks to do the sums a word at a time, using
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 function F_PARALLEL instead of F. These tricks are done only if
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 they can process at least four items, that is, only if the vector
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 holds at least four items and if a word can hold four items. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 expand_vector_addition (gimple_stmt_iterator *gsi,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 elem_op_func f, elem_op_func f_parallel,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 tree type, tree a, tree b, enum tree_code code)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 int parts_per_word = UNITS_PER_WORD
111
kono
parents: 67
diff changeset
355 / tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 if (INTEGRAL_TYPE_P (TREE_TYPE (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 && parts_per_word >= 4
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
359 && nunits_for_known_piecewise_op (type) >= 4)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 return expand_vector_parallel (gsi, f_parallel,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 type, a, b, code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 return expand_vector_piecewise (gsi, f,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 type, TREE_TYPE (type),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 a, b, code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
111
kono
parents: 67
diff changeset
368 /* Try to expand vector comparison expression OP0 CODE OP1 by
kono
parents: 67
diff changeset
369 querying optab if the following expression:
kono
parents: 67
diff changeset
370 VEC_COND_EXPR< OP0 CODE OP1, {-1,...}, {0,...}>
kono
parents: 67
diff changeset
371 can be expanded. */
kono
parents: 67
diff changeset
372 static tree
kono
parents: 67
diff changeset
373 expand_vector_comparison (gimple_stmt_iterator *gsi, tree type, tree op0,
kono
parents: 67
diff changeset
374 tree op1, enum tree_code code)
kono
parents: 67
diff changeset
375 {
kono
parents: 67
diff changeset
376 tree t;
kono
parents: 67
diff changeset
377 if (!expand_vec_cmp_expr_p (TREE_TYPE (op0), type, code)
kono
parents: 67
diff changeset
378 && !expand_vec_cond_expr_p (type, TREE_TYPE (op0), code))
kono
parents: 67
diff changeset
379 t = expand_vector_piecewise (gsi, do_compare, type,
kono
parents: 67
diff changeset
380 TREE_TYPE (TREE_TYPE (op0)), op0, op1, code);
kono
parents: 67
diff changeset
381 else
kono
parents: 67
diff changeset
382 t = NULL_TREE;
kono
parents: 67
diff changeset
383
kono
parents: 67
diff changeset
384 return t;
kono
parents: 67
diff changeset
385 }
kono
parents: 67
diff changeset
386
kono
parents: 67
diff changeset
387 /* Helper function of expand_vector_divmod. Gimplify a RSHIFT_EXPR in type
kono
parents: 67
diff changeset
388 of OP0 with shift counts in SHIFTCNTS array and return the temporary holding
kono
parents: 67
diff changeset
389 the result if successful, otherwise return NULL_TREE. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
390 static tree
111
kono
parents: 67
diff changeset
391 add_rshift (gimple_stmt_iterator *gsi, tree type, tree op0, int *shiftcnts)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
392 {
111
kono
parents: 67
diff changeset
393 optab op;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
394 unsigned int i, nunits = nunits_for_known_piecewise_op (type);
111
kono
parents: 67
diff changeset
395 bool scalar_shift = true;
kono
parents: 67
diff changeset
396
kono
parents: 67
diff changeset
397 for (i = 1; i < nunits; i++)
kono
parents: 67
diff changeset
398 {
kono
parents: 67
diff changeset
399 if (shiftcnts[i] != shiftcnts[0])
kono
parents: 67
diff changeset
400 scalar_shift = false;
kono
parents: 67
diff changeset
401 }
kono
parents: 67
diff changeset
402
kono
parents: 67
diff changeset
403 if (scalar_shift && shiftcnts[0] == 0)
kono
parents: 67
diff changeset
404 return op0;
kono
parents: 67
diff changeset
405
kono
parents: 67
diff changeset
406 if (scalar_shift)
kono
parents: 67
diff changeset
407 {
kono
parents: 67
diff changeset
408 op = optab_for_tree_code (RSHIFT_EXPR, type, optab_scalar);
kono
parents: 67
diff changeset
409 if (op != unknown_optab
kono
parents: 67
diff changeset
410 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 67
diff changeset
411 return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0,
kono
parents: 67
diff changeset
412 build_int_cst (NULL_TREE, shiftcnts[0]));
kono
parents: 67
diff changeset
413 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
414
111
kono
parents: 67
diff changeset
415 op = optab_for_tree_code (RSHIFT_EXPR, type, optab_vector);
kono
parents: 67
diff changeset
416 if (op != unknown_optab
kono
parents: 67
diff changeset
417 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 67
diff changeset
418 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
419 tree_vector_builder vec (type, nunits, 1);
111
kono
parents: 67
diff changeset
420 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
421 vec.quick_push (build_int_cst (TREE_TYPE (type), shiftcnts[i]));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
422 return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0, vec.build ());
111
kono
parents: 67
diff changeset
423 }
kono
parents: 67
diff changeset
424
kono
parents: 67
diff changeset
425 return NULL_TREE;
kono
parents: 67
diff changeset
426 }
kono
parents: 67
diff changeset
427
kono
parents: 67
diff changeset
428 /* Try to expand integer vector division by constant using
kono
parents: 67
diff changeset
429 widening multiply, shifts and additions. */
kono
parents: 67
diff changeset
430 static tree
kono
parents: 67
diff changeset
431 expand_vector_divmod (gimple_stmt_iterator *gsi, tree type, tree op0,
kono
parents: 67
diff changeset
432 tree op1, enum tree_code code)
kono
parents: 67
diff changeset
433 {
kono
parents: 67
diff changeset
434 bool use_pow2 = true;
kono
parents: 67
diff changeset
435 bool has_vector_shift = true;
kono
parents: 67
diff changeset
436 int mode = -1, this_mode;
kono
parents: 67
diff changeset
437 int pre_shift = -1, post_shift;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
438 unsigned int nunits = nunits_for_known_piecewise_op (type);
111
kono
parents: 67
diff changeset
439 int *shifts = XALLOCAVEC (int, nunits * 4);
kono
parents: 67
diff changeset
440 int *pre_shifts = shifts + nunits;
kono
parents: 67
diff changeset
441 int *post_shifts = pre_shifts + nunits;
kono
parents: 67
diff changeset
442 int *shift_temps = post_shifts + nunits;
kono
parents: 67
diff changeset
443 unsigned HOST_WIDE_INT *mulc = XALLOCAVEC (unsigned HOST_WIDE_INT, nunits);
kono
parents: 67
diff changeset
444 int prec = TYPE_PRECISION (TREE_TYPE (type));
kono
parents: 67
diff changeset
445 int dummy_int;
kono
parents: 67
diff changeset
446 unsigned int i;
kono
parents: 67
diff changeset
447 signop sign_p = TYPE_SIGN (TREE_TYPE (type));
kono
parents: 67
diff changeset
448 unsigned HOST_WIDE_INT mask = GET_MODE_MASK (TYPE_MODE (TREE_TYPE (type)));
kono
parents: 67
diff changeset
449 tree cur_op, mulcst, tem;
kono
parents: 67
diff changeset
450 optab op;
kono
parents: 67
diff changeset
451
kono
parents: 67
diff changeset
452 if (prec > HOST_BITS_PER_WIDE_INT)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
453 return NULL_TREE;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
454
111
kono
parents: 67
diff changeset
455 op = optab_for_tree_code (RSHIFT_EXPR, type, optab_vector);
kono
parents: 67
diff changeset
456 if (op == unknown_optab
kono
parents: 67
diff changeset
457 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 67
diff changeset
458 has_vector_shift = false;
kono
parents: 67
diff changeset
459
kono
parents: 67
diff changeset
460 /* Analysis phase. Determine if all op1 elements are either power
kono
parents: 67
diff changeset
461 of two and it is possible to expand it using shifts (or for remainder
kono
parents: 67
diff changeset
462 using masking). Additionally compute the multiplicative constants
kono
parents: 67
diff changeset
463 and pre and post shifts if the division is to be expanded using
kono
parents: 67
diff changeset
464 widening or high part multiplication plus shifts. */
kono
parents: 67
diff changeset
465 for (i = 0; i < nunits; i++)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
466 {
111
kono
parents: 67
diff changeset
467 tree cst = VECTOR_CST_ELT (op1, i);
kono
parents: 67
diff changeset
468 unsigned HOST_WIDE_INT ml;
kono
parents: 67
diff changeset
469
kono
parents: 67
diff changeset
470 if (TREE_CODE (cst) != INTEGER_CST || integer_zerop (cst))
kono
parents: 67
diff changeset
471 return NULL_TREE;
kono
parents: 67
diff changeset
472 pre_shifts[i] = 0;
kono
parents: 67
diff changeset
473 post_shifts[i] = 0;
kono
parents: 67
diff changeset
474 mulc[i] = 0;
kono
parents: 67
diff changeset
475 if (use_pow2
kono
parents: 67
diff changeset
476 && (!integer_pow2p (cst) || tree_int_cst_sgn (cst) != 1))
kono
parents: 67
diff changeset
477 use_pow2 = false;
kono
parents: 67
diff changeset
478 if (use_pow2)
kono
parents: 67
diff changeset
479 {
kono
parents: 67
diff changeset
480 shifts[i] = tree_log2 (cst);
kono
parents: 67
diff changeset
481 if (shifts[i] != shifts[0]
kono
parents: 67
diff changeset
482 && code == TRUNC_DIV_EXPR
kono
parents: 67
diff changeset
483 && !has_vector_shift)
kono
parents: 67
diff changeset
484 use_pow2 = false;
kono
parents: 67
diff changeset
485 }
kono
parents: 67
diff changeset
486 if (mode == -2)
kono
parents: 67
diff changeset
487 continue;
kono
parents: 67
diff changeset
488 if (sign_p == UNSIGNED)
kono
parents: 67
diff changeset
489 {
kono
parents: 67
diff changeset
490 unsigned HOST_WIDE_INT mh;
kono
parents: 67
diff changeset
491 unsigned HOST_WIDE_INT d = TREE_INT_CST_LOW (cst) & mask;
kono
parents: 67
diff changeset
492
kono
parents: 67
diff changeset
493 if (d >= (HOST_WIDE_INT_1U << (prec - 1)))
kono
parents: 67
diff changeset
494 /* FIXME: Can transform this into op0 >= op1 ? 1 : 0. */
kono
parents: 67
diff changeset
495 return NULL_TREE;
kono
parents: 67
diff changeset
496
kono
parents: 67
diff changeset
497 if (d <= 1)
kono
parents: 67
diff changeset
498 {
kono
parents: 67
diff changeset
499 mode = -2;
kono
parents: 67
diff changeset
500 continue;
kono
parents: 67
diff changeset
501 }
kono
parents: 67
diff changeset
502
kono
parents: 67
diff changeset
503 /* Find a suitable multiplier and right shift count
kono
parents: 67
diff changeset
504 instead of multiplying with D. */
kono
parents: 67
diff changeset
505 mh = choose_multiplier (d, prec, prec, &ml, &post_shift, &dummy_int);
kono
parents: 67
diff changeset
506
kono
parents: 67
diff changeset
507 /* If the suggested multiplier is more than SIZE bits, we can
kono
parents: 67
diff changeset
508 do better for even divisors, using an initial right shift. */
kono
parents: 67
diff changeset
509 if ((mh != 0 && (d & 1) == 0)
kono
parents: 67
diff changeset
510 || (!has_vector_shift && pre_shift != -1))
kono
parents: 67
diff changeset
511 {
kono
parents: 67
diff changeset
512 if (has_vector_shift)
kono
parents: 67
diff changeset
513 pre_shift = ctz_or_zero (d);
kono
parents: 67
diff changeset
514 else if (pre_shift == -1)
kono
parents: 67
diff changeset
515 {
kono
parents: 67
diff changeset
516 unsigned int j;
kono
parents: 67
diff changeset
517 for (j = 0; j < nunits; j++)
kono
parents: 67
diff changeset
518 {
kono
parents: 67
diff changeset
519 tree cst2 = VECTOR_CST_ELT (op1, j);
kono
parents: 67
diff changeset
520 unsigned HOST_WIDE_INT d2;
kono
parents: 67
diff changeset
521 int this_pre_shift;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
522
111
kono
parents: 67
diff changeset
523 if (!tree_fits_uhwi_p (cst2))
kono
parents: 67
diff changeset
524 return NULL_TREE;
kono
parents: 67
diff changeset
525 d2 = tree_to_uhwi (cst2) & mask;
kono
parents: 67
diff changeset
526 if (d2 == 0)
kono
parents: 67
diff changeset
527 return NULL_TREE;
kono
parents: 67
diff changeset
528 this_pre_shift = floor_log2 (d2 & -d2);
kono
parents: 67
diff changeset
529 if (pre_shift == -1 || this_pre_shift < pre_shift)
kono
parents: 67
diff changeset
530 pre_shift = this_pre_shift;
kono
parents: 67
diff changeset
531 }
kono
parents: 67
diff changeset
532 if (i != 0 && pre_shift != 0)
kono
parents: 67
diff changeset
533 {
kono
parents: 67
diff changeset
534 /* Restart. */
kono
parents: 67
diff changeset
535 i = -1U;
kono
parents: 67
diff changeset
536 mode = -1;
kono
parents: 67
diff changeset
537 continue;
kono
parents: 67
diff changeset
538 }
kono
parents: 67
diff changeset
539 }
kono
parents: 67
diff changeset
540 if (pre_shift != 0)
kono
parents: 67
diff changeset
541 {
kono
parents: 67
diff changeset
542 if ((d >> pre_shift) <= 1)
kono
parents: 67
diff changeset
543 {
kono
parents: 67
diff changeset
544 mode = -2;
kono
parents: 67
diff changeset
545 continue;
kono
parents: 67
diff changeset
546 }
kono
parents: 67
diff changeset
547 mh = choose_multiplier (d >> pre_shift, prec,
kono
parents: 67
diff changeset
548 prec - pre_shift,
kono
parents: 67
diff changeset
549 &ml, &post_shift, &dummy_int);
kono
parents: 67
diff changeset
550 gcc_assert (!mh);
kono
parents: 67
diff changeset
551 pre_shifts[i] = pre_shift;
kono
parents: 67
diff changeset
552 }
kono
parents: 67
diff changeset
553 }
kono
parents: 67
diff changeset
554 if (!mh)
kono
parents: 67
diff changeset
555 this_mode = 0;
kono
parents: 67
diff changeset
556 else
kono
parents: 67
diff changeset
557 this_mode = 1;
kono
parents: 67
diff changeset
558 }
kono
parents: 67
diff changeset
559 else
kono
parents: 67
diff changeset
560 {
kono
parents: 67
diff changeset
561 HOST_WIDE_INT d = TREE_INT_CST_LOW (cst);
kono
parents: 67
diff changeset
562 unsigned HOST_WIDE_INT abs_d;
kono
parents: 67
diff changeset
563
kono
parents: 67
diff changeset
564 if (d == -1)
kono
parents: 67
diff changeset
565 return NULL_TREE;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
566
111
kono
parents: 67
diff changeset
567 /* Since d might be INT_MIN, we have to cast to
kono
parents: 67
diff changeset
568 unsigned HOST_WIDE_INT before negating to avoid
kono
parents: 67
diff changeset
569 undefined signed overflow. */
kono
parents: 67
diff changeset
570 abs_d = (d >= 0
kono
parents: 67
diff changeset
571 ? (unsigned HOST_WIDE_INT) d
kono
parents: 67
diff changeset
572 : - (unsigned HOST_WIDE_INT) d);
kono
parents: 67
diff changeset
573
kono
parents: 67
diff changeset
574 /* n rem d = n rem -d */
kono
parents: 67
diff changeset
575 if (code == TRUNC_MOD_EXPR && d < 0)
kono
parents: 67
diff changeset
576 d = abs_d;
kono
parents: 67
diff changeset
577 else if (abs_d == HOST_WIDE_INT_1U << (prec - 1))
kono
parents: 67
diff changeset
578 {
kono
parents: 67
diff changeset
579 /* This case is not handled correctly below. */
kono
parents: 67
diff changeset
580 mode = -2;
kono
parents: 67
diff changeset
581 continue;
kono
parents: 67
diff changeset
582 }
kono
parents: 67
diff changeset
583 if (abs_d <= 1)
kono
parents: 67
diff changeset
584 {
kono
parents: 67
diff changeset
585 mode = -2;
kono
parents: 67
diff changeset
586 continue;
kono
parents: 67
diff changeset
587 }
kono
parents: 67
diff changeset
588
kono
parents: 67
diff changeset
589 choose_multiplier (abs_d, prec, prec - 1, &ml,
kono
parents: 67
diff changeset
590 &post_shift, &dummy_int);
kono
parents: 67
diff changeset
591 if (ml >= HOST_WIDE_INT_1U << (prec - 1))
kono
parents: 67
diff changeset
592 {
kono
parents: 67
diff changeset
593 this_mode = 4 + (d < 0);
kono
parents: 67
diff changeset
594 ml |= HOST_WIDE_INT_M1U << (prec - 1);
kono
parents: 67
diff changeset
595 }
kono
parents: 67
diff changeset
596 else
kono
parents: 67
diff changeset
597 this_mode = 2 + (d < 0);
kono
parents: 67
diff changeset
598 }
kono
parents: 67
diff changeset
599 mulc[i] = ml;
kono
parents: 67
diff changeset
600 post_shifts[i] = post_shift;
kono
parents: 67
diff changeset
601 if ((i && !has_vector_shift && post_shifts[0] != post_shift)
kono
parents: 67
diff changeset
602 || post_shift >= prec
kono
parents: 67
diff changeset
603 || pre_shifts[i] >= prec)
kono
parents: 67
diff changeset
604 this_mode = -2;
kono
parents: 67
diff changeset
605
kono
parents: 67
diff changeset
606 if (i == 0)
kono
parents: 67
diff changeset
607 mode = this_mode;
kono
parents: 67
diff changeset
608 else if (mode != this_mode)
kono
parents: 67
diff changeset
609 mode = -2;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
610 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
611
111
kono
parents: 67
diff changeset
612 if (use_pow2)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
613 {
111
kono
parents: 67
diff changeset
614 tree addend = NULL_TREE;
kono
parents: 67
diff changeset
615 if (sign_p == SIGNED)
kono
parents: 67
diff changeset
616 {
kono
parents: 67
diff changeset
617 tree uns_type;
kono
parents: 67
diff changeset
618
kono
parents: 67
diff changeset
619 /* Both division and remainder sequences need
kono
parents: 67
diff changeset
620 op0 < 0 ? mask : 0 computed. It can be either computed as
kono
parents: 67
diff changeset
621 (type) (((uns_type) (op0 >> (prec - 1))) >> (prec - shifts[i]))
kono
parents: 67
diff changeset
622 if none of the shifts is 0, or as the conditional. */
kono
parents: 67
diff changeset
623 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
624 if (shifts[i] == 0)
kono
parents: 67
diff changeset
625 break;
kono
parents: 67
diff changeset
626 uns_type
kono
parents: 67
diff changeset
627 = build_vector_type (build_nonstandard_integer_type (prec, 1),
kono
parents: 67
diff changeset
628 nunits);
kono
parents: 67
diff changeset
629 if (i == nunits && TYPE_MODE (uns_type) == TYPE_MODE (type))
kono
parents: 67
diff changeset
630 {
kono
parents: 67
diff changeset
631 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
632 shift_temps[i] = prec - 1;
kono
parents: 67
diff changeset
633 cur_op = add_rshift (gsi, type, op0, shift_temps);
kono
parents: 67
diff changeset
634 if (cur_op != NULL_TREE)
kono
parents: 67
diff changeset
635 {
kono
parents: 67
diff changeset
636 cur_op = gimplify_build1 (gsi, VIEW_CONVERT_EXPR,
kono
parents: 67
diff changeset
637 uns_type, cur_op);
kono
parents: 67
diff changeset
638 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
639 shift_temps[i] = prec - shifts[i];
kono
parents: 67
diff changeset
640 cur_op = add_rshift (gsi, uns_type, cur_op, shift_temps);
kono
parents: 67
diff changeset
641 if (cur_op != NULL_TREE)
kono
parents: 67
diff changeset
642 addend = gimplify_build1 (gsi, VIEW_CONVERT_EXPR,
kono
parents: 67
diff changeset
643 type, cur_op);
kono
parents: 67
diff changeset
644 }
kono
parents: 67
diff changeset
645 }
kono
parents: 67
diff changeset
646 if (addend == NULL_TREE
kono
parents: 67
diff changeset
647 && expand_vec_cond_expr_p (type, type, LT_EXPR))
kono
parents: 67
diff changeset
648 {
kono
parents: 67
diff changeset
649 tree zero, cst, cond, mask_type;
kono
parents: 67
diff changeset
650 gimple *stmt;
kono
parents: 67
diff changeset
651
kono
parents: 67
diff changeset
652 mask_type = build_same_sized_truth_vector_type (type);
kono
parents: 67
diff changeset
653 zero = build_zero_cst (type);
kono
parents: 67
diff changeset
654 cond = build2 (LT_EXPR, mask_type, op0, zero);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
655 tree_vector_builder vec (type, nunits, 1);
111
kono
parents: 67
diff changeset
656 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
657 vec.quick_push (build_int_cst (TREE_TYPE (type),
kono
parents: 67
diff changeset
658 (HOST_WIDE_INT_1U
kono
parents: 67
diff changeset
659 << shifts[i]) - 1));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
660 cst = vec.build ();
111
kono
parents: 67
diff changeset
661 addend = make_ssa_name (type);
kono
parents: 67
diff changeset
662 stmt = gimple_build_assign (addend, VEC_COND_EXPR, cond,
kono
parents: 67
diff changeset
663 cst, zero);
kono
parents: 67
diff changeset
664 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
kono
parents: 67
diff changeset
665 }
kono
parents: 67
diff changeset
666 }
kono
parents: 67
diff changeset
667 if (code == TRUNC_DIV_EXPR)
kono
parents: 67
diff changeset
668 {
kono
parents: 67
diff changeset
669 if (sign_p == UNSIGNED)
kono
parents: 67
diff changeset
670 {
kono
parents: 67
diff changeset
671 /* q = op0 >> shift; */
kono
parents: 67
diff changeset
672 cur_op = add_rshift (gsi, type, op0, shifts);
kono
parents: 67
diff changeset
673 if (cur_op != NULL_TREE)
kono
parents: 67
diff changeset
674 return cur_op;
kono
parents: 67
diff changeset
675 }
kono
parents: 67
diff changeset
676 else if (addend != NULL_TREE)
kono
parents: 67
diff changeset
677 {
kono
parents: 67
diff changeset
678 /* t1 = op0 + addend;
kono
parents: 67
diff changeset
679 q = t1 >> shift; */
kono
parents: 67
diff changeset
680 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
681 if (op != unknown_optab
kono
parents: 67
diff changeset
682 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 67
diff changeset
683 {
kono
parents: 67
diff changeset
684 cur_op = gimplify_build2 (gsi, PLUS_EXPR, type, op0, addend);
kono
parents: 67
diff changeset
685 cur_op = add_rshift (gsi, type, cur_op, shifts);
kono
parents: 67
diff changeset
686 if (cur_op != NULL_TREE)
kono
parents: 67
diff changeset
687 return cur_op;
kono
parents: 67
diff changeset
688 }
kono
parents: 67
diff changeset
689 }
kono
parents: 67
diff changeset
690 }
kono
parents: 67
diff changeset
691 else
kono
parents: 67
diff changeset
692 {
kono
parents: 67
diff changeset
693 tree mask;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
694 tree_vector_builder vec (type, nunits, 1);
111
kono
parents: 67
diff changeset
695 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
696 vec.quick_push (build_int_cst (TREE_TYPE (type),
kono
parents: 67
diff changeset
697 (HOST_WIDE_INT_1U
kono
parents: 67
diff changeset
698 << shifts[i]) - 1));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
699 mask = vec.build ();
111
kono
parents: 67
diff changeset
700 op = optab_for_tree_code (BIT_AND_EXPR, type, optab_default);
kono
parents: 67
diff changeset
701 if (op != unknown_optab
kono
parents: 67
diff changeset
702 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 67
diff changeset
703 {
kono
parents: 67
diff changeset
704 if (sign_p == UNSIGNED)
kono
parents: 67
diff changeset
705 /* r = op0 & mask; */
kono
parents: 67
diff changeset
706 return gimplify_build2 (gsi, BIT_AND_EXPR, type, op0, mask);
kono
parents: 67
diff changeset
707 else if (addend != NULL_TREE)
kono
parents: 67
diff changeset
708 {
kono
parents: 67
diff changeset
709 /* t1 = op0 + addend;
kono
parents: 67
diff changeset
710 t2 = t1 & mask;
kono
parents: 67
diff changeset
711 r = t2 - addend; */
kono
parents: 67
diff changeset
712 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
713 if (op != unknown_optab
kono
parents: 67
diff changeset
714 && optab_handler (op, TYPE_MODE (type))
kono
parents: 67
diff changeset
715 != CODE_FOR_nothing)
kono
parents: 67
diff changeset
716 {
kono
parents: 67
diff changeset
717 cur_op = gimplify_build2 (gsi, PLUS_EXPR, type, op0,
kono
parents: 67
diff changeset
718 addend);
kono
parents: 67
diff changeset
719 cur_op = gimplify_build2 (gsi, BIT_AND_EXPR, type,
kono
parents: 67
diff changeset
720 cur_op, mask);
kono
parents: 67
diff changeset
721 op = optab_for_tree_code (MINUS_EXPR, type,
kono
parents: 67
diff changeset
722 optab_default);
kono
parents: 67
diff changeset
723 if (op != unknown_optab
kono
parents: 67
diff changeset
724 && optab_handler (op, TYPE_MODE (type))
kono
parents: 67
diff changeset
725 != CODE_FOR_nothing)
kono
parents: 67
diff changeset
726 return gimplify_build2 (gsi, MINUS_EXPR, type,
kono
parents: 67
diff changeset
727 cur_op, addend);
kono
parents: 67
diff changeset
728 }
kono
parents: 67
diff changeset
729 }
kono
parents: 67
diff changeset
730 }
kono
parents: 67
diff changeset
731 }
kono
parents: 67
diff changeset
732 }
kono
parents: 67
diff changeset
733
kono
parents: 67
diff changeset
734 if (mode == -2 || BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
kono
parents: 67
diff changeset
735 return NULL_TREE;
kono
parents: 67
diff changeset
736
kono
parents: 67
diff changeset
737 if (!can_mult_highpart_p (TYPE_MODE (type), TYPE_UNSIGNED (type)))
kono
parents: 67
diff changeset
738 return NULL_TREE;
kono
parents: 67
diff changeset
739
kono
parents: 67
diff changeset
740 cur_op = op0;
kono
parents: 67
diff changeset
741
kono
parents: 67
diff changeset
742 switch (mode)
kono
parents: 67
diff changeset
743 {
kono
parents: 67
diff changeset
744 case 0:
kono
parents: 67
diff changeset
745 gcc_assert (sign_p == UNSIGNED);
kono
parents: 67
diff changeset
746 /* t1 = oprnd0 >> pre_shift;
kono
parents: 67
diff changeset
747 t2 = t1 h* ml;
kono
parents: 67
diff changeset
748 q = t2 >> post_shift; */
kono
parents: 67
diff changeset
749 cur_op = add_rshift (gsi, type, cur_op, pre_shifts);
kono
parents: 67
diff changeset
750 if (cur_op == NULL_TREE)
kono
parents: 67
diff changeset
751 return NULL_TREE;
kono
parents: 67
diff changeset
752 break;
kono
parents: 67
diff changeset
753 case 1:
kono
parents: 67
diff changeset
754 gcc_assert (sign_p == UNSIGNED);
kono
parents: 67
diff changeset
755 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
756 {
kono
parents: 67
diff changeset
757 shift_temps[i] = 1;
kono
parents: 67
diff changeset
758 post_shifts[i]--;
kono
parents: 67
diff changeset
759 }
kono
parents: 67
diff changeset
760 break;
kono
parents: 67
diff changeset
761 case 2:
kono
parents: 67
diff changeset
762 case 3:
kono
parents: 67
diff changeset
763 case 4:
kono
parents: 67
diff changeset
764 case 5:
kono
parents: 67
diff changeset
765 gcc_assert (sign_p == SIGNED);
kono
parents: 67
diff changeset
766 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
767 shift_temps[i] = prec - 1;
kono
parents: 67
diff changeset
768 break;
kono
parents: 67
diff changeset
769 default:
kono
parents: 67
diff changeset
770 return NULL_TREE;
kono
parents: 67
diff changeset
771 }
kono
parents: 67
diff changeset
772
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
773 tree_vector_builder vec (type, nunits, 1);
111
kono
parents: 67
diff changeset
774 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
775 vec.quick_push (build_int_cst (TREE_TYPE (type), mulc[i]));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
776 mulcst = vec.build ();
111
kono
parents: 67
diff changeset
777
kono
parents: 67
diff changeset
778 cur_op = gimplify_build2 (gsi, MULT_HIGHPART_EXPR, type, cur_op, mulcst);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
779
111
kono
parents: 67
diff changeset
780 switch (mode)
kono
parents: 67
diff changeset
781 {
kono
parents: 67
diff changeset
782 case 0:
kono
parents: 67
diff changeset
783 /* t1 = oprnd0 >> pre_shift;
kono
parents: 67
diff changeset
784 t2 = t1 h* ml;
kono
parents: 67
diff changeset
785 q = t2 >> post_shift; */
kono
parents: 67
diff changeset
786 cur_op = add_rshift (gsi, type, cur_op, post_shifts);
kono
parents: 67
diff changeset
787 break;
kono
parents: 67
diff changeset
788 case 1:
kono
parents: 67
diff changeset
789 /* t1 = oprnd0 h* ml;
kono
parents: 67
diff changeset
790 t2 = oprnd0 - t1;
kono
parents: 67
diff changeset
791 t3 = t2 >> 1;
kono
parents: 67
diff changeset
792 t4 = t1 + t3;
kono
parents: 67
diff changeset
793 q = t4 >> (post_shift - 1); */
kono
parents: 67
diff changeset
794 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
795 if (op == unknown_optab
kono
parents: 67
diff changeset
796 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 67
diff changeset
797 return NULL_TREE;
kono
parents: 67
diff changeset
798 tem = gimplify_build2 (gsi, MINUS_EXPR, type, op0, cur_op);
kono
parents: 67
diff changeset
799 tem = add_rshift (gsi, type, tem, shift_temps);
kono
parents: 67
diff changeset
800 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
801 if (op == unknown_optab
kono
parents: 67
diff changeset
802 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 67
diff changeset
803 return NULL_TREE;
kono
parents: 67
diff changeset
804 tem = gimplify_build2 (gsi, PLUS_EXPR, type, cur_op, tem);
kono
parents: 67
diff changeset
805 cur_op = add_rshift (gsi, type, tem, post_shifts);
kono
parents: 67
diff changeset
806 if (cur_op == NULL_TREE)
kono
parents: 67
diff changeset
807 return NULL_TREE;
kono
parents: 67
diff changeset
808 break;
kono
parents: 67
diff changeset
809 case 2:
kono
parents: 67
diff changeset
810 case 3:
kono
parents: 67
diff changeset
811 case 4:
kono
parents: 67
diff changeset
812 case 5:
kono
parents: 67
diff changeset
813 /* t1 = oprnd0 h* ml;
kono
parents: 67
diff changeset
814 t2 = t1; [ iff (mode & 2) != 0 ]
kono
parents: 67
diff changeset
815 t2 = t1 + oprnd0; [ iff (mode & 2) == 0 ]
kono
parents: 67
diff changeset
816 t3 = t2 >> post_shift;
kono
parents: 67
diff changeset
817 t4 = oprnd0 >> (prec - 1);
kono
parents: 67
diff changeset
818 q = t3 - t4; [ iff (mode & 1) == 0 ]
kono
parents: 67
diff changeset
819 q = t4 - t3; [ iff (mode & 1) != 0 ] */
kono
parents: 67
diff changeset
820 if ((mode & 2) == 0)
kono
parents: 67
diff changeset
821 {
kono
parents: 67
diff changeset
822 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
823 if (op == unknown_optab
kono
parents: 67
diff changeset
824 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
825 return NULL_TREE;
111
kono
parents: 67
diff changeset
826 cur_op = gimplify_build2 (gsi, PLUS_EXPR, type, cur_op, op0);
kono
parents: 67
diff changeset
827 }
kono
parents: 67
diff changeset
828 cur_op = add_rshift (gsi, type, cur_op, post_shifts);
kono
parents: 67
diff changeset
829 if (cur_op == NULL_TREE)
kono
parents: 67
diff changeset
830 return NULL_TREE;
kono
parents: 67
diff changeset
831 tem = add_rshift (gsi, type, op0, shift_temps);
kono
parents: 67
diff changeset
832 if (tem == NULL_TREE)
kono
parents: 67
diff changeset
833 return NULL_TREE;
kono
parents: 67
diff changeset
834 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
835 if (op == unknown_optab
kono
parents: 67
diff changeset
836 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
837 return NULL_TREE;
111
kono
parents: 67
diff changeset
838 if ((mode & 1) == 0)
kono
parents: 67
diff changeset
839 cur_op = gimplify_build2 (gsi, MINUS_EXPR, type, cur_op, tem);
kono
parents: 67
diff changeset
840 else
kono
parents: 67
diff changeset
841 cur_op = gimplify_build2 (gsi, MINUS_EXPR, type, tem, cur_op);
kono
parents: 67
diff changeset
842 break;
kono
parents: 67
diff changeset
843 default:
kono
parents: 67
diff changeset
844 gcc_unreachable ();
kono
parents: 67
diff changeset
845 }
kono
parents: 67
diff changeset
846
kono
parents: 67
diff changeset
847 if (code == TRUNC_DIV_EXPR)
kono
parents: 67
diff changeset
848 return cur_op;
kono
parents: 67
diff changeset
849
kono
parents: 67
diff changeset
850 /* We divided. Now finish by:
kono
parents: 67
diff changeset
851 t1 = q * oprnd1;
kono
parents: 67
diff changeset
852 r = oprnd0 - t1; */
kono
parents: 67
diff changeset
853 op = optab_for_tree_code (MULT_EXPR, type, optab_default);
kono
parents: 67
diff changeset
854 if (op == unknown_optab
kono
parents: 67
diff changeset
855 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 67
diff changeset
856 return NULL_TREE;
kono
parents: 67
diff changeset
857 tem = gimplify_build2 (gsi, MULT_EXPR, type, cur_op, op1);
kono
parents: 67
diff changeset
858 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
859 if (op == unknown_optab
kono
parents: 67
diff changeset
860 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 67
diff changeset
861 return NULL_TREE;
kono
parents: 67
diff changeset
862 return gimplify_build2 (gsi, MINUS_EXPR, type, op0, tem);
kono
parents: 67
diff changeset
863 }
kono
parents: 67
diff changeset
864
kono
parents: 67
diff changeset
865 /* Expand a vector condition to scalars, by using many conditions
kono
parents: 67
diff changeset
866 on the vector's elements. */
kono
parents: 67
diff changeset
867 static void
kono
parents: 67
diff changeset
868 expand_vector_condition (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
869 {
kono
parents: 67
diff changeset
870 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
871 tree type = gimple_expr_type (stmt);
kono
parents: 67
diff changeset
872 tree a = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
873 tree a1 = a;
kono
parents: 67
diff changeset
874 tree a2 = NULL_TREE;
kono
parents: 67
diff changeset
875 bool a_is_comparison = false;
kono
parents: 67
diff changeset
876 tree b = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
877 tree c = gimple_assign_rhs3 (stmt);
kono
parents: 67
diff changeset
878 vec<constructor_elt, va_gc> *v;
kono
parents: 67
diff changeset
879 tree constr;
kono
parents: 67
diff changeset
880 tree inner_type = TREE_TYPE (type);
kono
parents: 67
diff changeset
881 tree cond_type = TREE_TYPE (TREE_TYPE (a));
kono
parents: 67
diff changeset
882 tree comp_inner_type = cond_type;
kono
parents: 67
diff changeset
883 tree width = TYPE_SIZE (inner_type);
kono
parents: 67
diff changeset
884 tree index = bitsize_int (0);
kono
parents: 67
diff changeset
885 tree comp_width = width;
kono
parents: 67
diff changeset
886 tree comp_index = index;
kono
parents: 67
diff changeset
887 int i;
kono
parents: 67
diff changeset
888 location_t loc = gimple_location (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
889
kono
parents: 67
diff changeset
890 if (!is_gimple_val (a))
kono
parents: 67
diff changeset
891 {
kono
parents: 67
diff changeset
892 gcc_assert (COMPARISON_CLASS_P (a));
kono
parents: 67
diff changeset
893 a_is_comparison = true;
kono
parents: 67
diff changeset
894 a1 = TREE_OPERAND (a, 0);
kono
parents: 67
diff changeset
895 a2 = TREE_OPERAND (a, 1);
kono
parents: 67
diff changeset
896 comp_inner_type = TREE_TYPE (TREE_TYPE (a1));
kono
parents: 67
diff changeset
897 comp_width = TYPE_SIZE (comp_inner_type);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
898 }
111
kono
parents: 67
diff changeset
899
kono
parents: 67
diff changeset
900 if (expand_vec_cond_expr_p (type, TREE_TYPE (a1), TREE_CODE (a)))
kono
parents: 67
diff changeset
901 return;
kono
parents: 67
diff changeset
902
kono
parents: 67
diff changeset
903 /* Handle vector boolean types with bitmasks. If there is a comparison
kono
parents: 67
diff changeset
904 and we can expand the comparison into the vector boolean bitmask,
kono
parents: 67
diff changeset
905 or otherwise if it is compatible with type, we can transform
kono
parents: 67
diff changeset
906 vbfld_1 = x_2 < y_3 ? vbfld_4 : vbfld_5;
kono
parents: 67
diff changeset
907 into
kono
parents: 67
diff changeset
908 tmp_6 = x_2 < y_3;
kono
parents: 67
diff changeset
909 tmp_7 = tmp_6 & vbfld_4;
kono
parents: 67
diff changeset
910 tmp_8 = ~tmp_6;
kono
parents: 67
diff changeset
911 tmp_9 = tmp_8 & vbfld_5;
kono
parents: 67
diff changeset
912 vbfld_1 = tmp_7 | tmp_9;
kono
parents: 67
diff changeset
913 Similarly for vbfld_10 instead of x_2 < y_3. */
kono
parents: 67
diff changeset
914 if (VECTOR_BOOLEAN_TYPE_P (type)
kono
parents: 67
diff changeset
915 && SCALAR_INT_MODE_P (TYPE_MODE (type))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
916 && known_lt (GET_MODE_BITSIZE (TYPE_MODE (type)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
917 TYPE_VECTOR_SUBPARTS (type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
918 * GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (type))))
111
kono
parents: 67
diff changeset
919 && (a_is_comparison
kono
parents: 67
diff changeset
920 ? useless_type_conversion_p (type, TREE_TYPE (a))
kono
parents: 67
diff changeset
921 : expand_vec_cmp_expr_p (TREE_TYPE (a1), type, TREE_CODE (a))))
kono
parents: 67
diff changeset
922 {
kono
parents: 67
diff changeset
923 if (a_is_comparison)
kono
parents: 67
diff changeset
924 a = gimplify_build2 (gsi, TREE_CODE (a), type, a1, a2);
kono
parents: 67
diff changeset
925 a1 = gimplify_build2 (gsi, BIT_AND_EXPR, type, a, b);
kono
parents: 67
diff changeset
926 a2 = gimplify_build1 (gsi, BIT_NOT_EXPR, type, a);
kono
parents: 67
diff changeset
927 a2 = gimplify_build2 (gsi, BIT_AND_EXPR, type, a2, c);
kono
parents: 67
diff changeset
928 a = gimplify_build2 (gsi, BIT_IOR_EXPR, type, a1, a2);
kono
parents: 67
diff changeset
929 gimple_assign_set_rhs_from_tree (gsi, a);
kono
parents: 67
diff changeset
930 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
931 return;
kono
parents: 67
diff changeset
932 }
kono
parents: 67
diff changeset
933
kono
parents: 67
diff changeset
934 /* TODO: try and find a smaller vector type. */
kono
parents: 67
diff changeset
935
kono
parents: 67
diff changeset
936 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 67
diff changeset
937 "vector condition will be expanded piecewise");
kono
parents: 67
diff changeset
938
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
939 int nunits = nunits_for_known_piecewise_op (type);
111
kono
parents: 67
diff changeset
940 vec_alloc (v, nunits);
kono
parents: 67
diff changeset
941 for (i = 0; i < nunits; i++)
kono
parents: 67
diff changeset
942 {
kono
parents: 67
diff changeset
943 tree aa, result;
kono
parents: 67
diff changeset
944 tree bb = tree_vec_extract (gsi, inner_type, b, width, index);
kono
parents: 67
diff changeset
945 tree cc = tree_vec_extract (gsi, inner_type, c, width, index);
kono
parents: 67
diff changeset
946 if (a_is_comparison)
kono
parents: 67
diff changeset
947 {
kono
parents: 67
diff changeset
948 tree aa1 = tree_vec_extract (gsi, comp_inner_type, a1,
kono
parents: 67
diff changeset
949 comp_width, comp_index);
kono
parents: 67
diff changeset
950 tree aa2 = tree_vec_extract (gsi, comp_inner_type, a2,
kono
parents: 67
diff changeset
951 comp_width, comp_index);
kono
parents: 67
diff changeset
952 aa = fold_build2 (TREE_CODE (a), cond_type, aa1, aa2);
kono
parents: 67
diff changeset
953 }
kono
parents: 67
diff changeset
954 else
kono
parents: 67
diff changeset
955 aa = tree_vec_extract (gsi, cond_type, a, width, index);
kono
parents: 67
diff changeset
956 result = gimplify_build3 (gsi, COND_EXPR, inner_type, aa, bb, cc);
kono
parents: 67
diff changeset
957 constructor_elt ce = {NULL_TREE, result};
kono
parents: 67
diff changeset
958 v->quick_push (ce);
kono
parents: 67
diff changeset
959 index = int_const_binop (PLUS_EXPR, index, width);
kono
parents: 67
diff changeset
960 if (width == comp_width)
kono
parents: 67
diff changeset
961 comp_index = index;
kono
parents: 67
diff changeset
962 else
kono
parents: 67
diff changeset
963 comp_index = int_const_binop (PLUS_EXPR, comp_index, comp_width);
kono
parents: 67
diff changeset
964 }
kono
parents: 67
diff changeset
965
kono
parents: 67
diff changeset
966 constr = build_constructor (type, v);
kono
parents: 67
diff changeset
967 gimple_assign_set_rhs_from_tree (gsi, constr);
kono
parents: 67
diff changeset
968 update_stmt (gsi_stmt (*gsi));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
969 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
970
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 expand_vector_operation (gimple_stmt_iterator *gsi, tree type, tree compute_type,
111
kono
parents: 67
diff changeset
973 gassign *assign, enum tree_code code)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 {
111
kono
parents: 67
diff changeset
975 machine_mode compute_mode = TYPE_MODE (compute_type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 /* If the compute mode is not a vector mode (hence we are not decomposing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978 a BLKmode vector to smaller, hardware-supported vectors), we may want
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 to expand the operations in parallel. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
980 if (!VECTOR_MODE_P (compute_mode))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981 switch (code)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 case PLUS_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 case MINUS_EXPR:
111
kono
parents: 67
diff changeset
985 if (ANY_INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_TRAPS (type))
kono
parents: 67
diff changeset
986 return expand_vector_addition (gsi, do_binop, do_plus_minus, type,
kono
parents: 67
diff changeset
987 gimple_assign_rhs1 (assign),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 gimple_assign_rhs2 (assign), code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 case NEGATE_EXPR:
111
kono
parents: 67
diff changeset
992 if (ANY_INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_TRAPS (type))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 return expand_vector_addition (gsi, do_unop, do_negate, type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 gimple_assign_rhs1 (assign),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 NULL_TREE, code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 case BIT_AND_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 case BIT_IOR_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 case BIT_XOR_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 return expand_vector_parallel (gsi, do_binop, type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 gimple_assign_rhs1 (assign),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 gimple_assign_rhs2 (assign), code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 case BIT_NOT_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 return expand_vector_parallel (gsi, do_unop, type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 gimple_assign_rhs1 (assign),
111
kono
parents: 67
diff changeset
1008 NULL_TREE, code);
kono
parents: 67
diff changeset
1009 case EQ_EXPR:
kono
parents: 67
diff changeset
1010 case NE_EXPR:
kono
parents: 67
diff changeset
1011 case GT_EXPR:
kono
parents: 67
diff changeset
1012 case LT_EXPR:
kono
parents: 67
diff changeset
1013 case GE_EXPR:
kono
parents: 67
diff changeset
1014 case LE_EXPR:
kono
parents: 67
diff changeset
1015 case UNEQ_EXPR:
kono
parents: 67
diff changeset
1016 case UNGT_EXPR:
kono
parents: 67
diff changeset
1017 case UNLT_EXPR:
kono
parents: 67
diff changeset
1018 case UNGE_EXPR:
kono
parents: 67
diff changeset
1019 case UNLE_EXPR:
kono
parents: 67
diff changeset
1020 case LTGT_EXPR:
kono
parents: 67
diff changeset
1021 case ORDERED_EXPR:
kono
parents: 67
diff changeset
1022 case UNORDERED_EXPR:
kono
parents: 67
diff changeset
1023 {
kono
parents: 67
diff changeset
1024 tree rhs1 = gimple_assign_rhs1 (assign);
kono
parents: 67
diff changeset
1025 tree rhs2 = gimple_assign_rhs2 (assign);
kono
parents: 67
diff changeset
1026
kono
parents: 67
diff changeset
1027 return expand_vector_comparison (gsi, type, rhs1, rhs2, code);
kono
parents: 67
diff changeset
1028 }
kono
parents: 67
diff changeset
1029
kono
parents: 67
diff changeset
1030 case TRUNC_DIV_EXPR:
kono
parents: 67
diff changeset
1031 case TRUNC_MOD_EXPR:
kono
parents: 67
diff changeset
1032 {
kono
parents: 67
diff changeset
1033 tree rhs1 = gimple_assign_rhs1 (assign);
kono
parents: 67
diff changeset
1034 tree rhs2 = gimple_assign_rhs2 (assign);
kono
parents: 67
diff changeset
1035 tree ret;
kono
parents: 67
diff changeset
1036
kono
parents: 67
diff changeset
1037 if (!optimize
kono
parents: 67
diff changeset
1038 || !VECTOR_INTEGER_TYPE_P (type)
kono
parents: 67
diff changeset
1039 || TREE_CODE (rhs2) != VECTOR_CST
kono
parents: 67
diff changeset
1040 || !VECTOR_MODE_P (TYPE_MODE (type)))
kono
parents: 67
diff changeset
1041 break;
kono
parents: 67
diff changeset
1042
kono
parents: 67
diff changeset
1043 ret = expand_vector_divmod (gsi, type, rhs1, rhs2, code);
kono
parents: 67
diff changeset
1044 if (ret != NULL_TREE)
kono
parents: 67
diff changeset
1045 return ret;
kono
parents: 67
diff changeset
1046 break;
kono
parents: 67
diff changeset
1047 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 if (TREE_CODE_CLASS (code) == tcc_unary)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 return expand_vector_piecewise (gsi, do_unop, type, compute_type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 gimple_assign_rhs1 (assign),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 NULL_TREE, code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 return expand_vector_piecewise (gsi, do_binop, type, compute_type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059 gimple_assign_rhs1 (assign),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 gimple_assign_rhs2 (assign), code);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 }
111
kono
parents: 67
diff changeset
1062
kono
parents: 67
diff changeset
1063 /* Try to optimize
kono
parents: 67
diff changeset
1064 a_5 = { b_7, b_7 + 3, b_7 + 6, b_7 + 9 };
kono
parents: 67
diff changeset
1065 style stmts into:
kono
parents: 67
diff changeset
1066 _9 = { b_7, b_7, b_7, b_7 };
kono
parents: 67
diff changeset
1067 a_5 = _9 + { 0, 3, 6, 9 };
kono
parents: 67
diff changeset
1068 because vector splat operation is usually more efficient
kono
parents: 67
diff changeset
1069 than piecewise initialization of the vector. */
kono
parents: 67
diff changeset
1070
kono
parents: 67
diff changeset
1071 static void
kono
parents: 67
diff changeset
1072 optimize_vector_constructor (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
1073 {
kono
parents: 67
diff changeset
1074 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1075 tree lhs = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
1076 tree rhs = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1077 tree type = TREE_TYPE (rhs);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1078 unsigned int i, j;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1079 unsigned HOST_WIDE_INT nelts;
111
kono
parents: 67
diff changeset
1080 bool all_same = true;
kono
parents: 67
diff changeset
1081 constructor_elt *elt;
kono
parents: 67
diff changeset
1082 gimple *g;
kono
parents: 67
diff changeset
1083 tree base = NULL_TREE;
kono
parents: 67
diff changeset
1084 optab op;
kono
parents: 67
diff changeset
1085
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1086 if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1087 || nelts <= 2
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1088 || CONSTRUCTOR_NELTS (rhs) != nelts)
111
kono
parents: 67
diff changeset
1089 return;
kono
parents: 67
diff changeset
1090 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 67
diff changeset
1091 if (op == unknown_optab
kono
parents: 67
diff changeset
1092 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 67
diff changeset
1093 return;
kono
parents: 67
diff changeset
1094 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (rhs), i, elt)
kono
parents: 67
diff changeset
1095 if (TREE_CODE (elt->value) != SSA_NAME
kono
parents: 67
diff changeset
1096 || TREE_CODE (TREE_TYPE (elt->value)) == VECTOR_TYPE)
kono
parents: 67
diff changeset
1097 return;
kono
parents: 67
diff changeset
1098 else
kono
parents: 67
diff changeset
1099 {
kono
parents: 67
diff changeset
1100 tree this_base = elt->value;
kono
parents: 67
diff changeset
1101 if (this_base != CONSTRUCTOR_ELT (rhs, 0)->value)
kono
parents: 67
diff changeset
1102 all_same = false;
kono
parents: 67
diff changeset
1103 for (j = 0; j < nelts + 1; j++)
kono
parents: 67
diff changeset
1104 {
kono
parents: 67
diff changeset
1105 g = SSA_NAME_DEF_STMT (this_base);
kono
parents: 67
diff changeset
1106 if (is_gimple_assign (g)
kono
parents: 67
diff changeset
1107 && gimple_assign_rhs_code (g) == PLUS_EXPR
kono
parents: 67
diff changeset
1108 && TREE_CODE (gimple_assign_rhs2 (g)) == INTEGER_CST
kono
parents: 67
diff changeset
1109 && TREE_CODE (gimple_assign_rhs1 (g)) == SSA_NAME
kono
parents: 67
diff changeset
1110 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (gimple_assign_rhs1 (g)))
kono
parents: 67
diff changeset
1111 this_base = gimple_assign_rhs1 (g);
kono
parents: 67
diff changeset
1112 else
kono
parents: 67
diff changeset
1113 break;
kono
parents: 67
diff changeset
1114 }
kono
parents: 67
diff changeset
1115 if (i == 0)
kono
parents: 67
diff changeset
1116 base = this_base;
kono
parents: 67
diff changeset
1117 else if (this_base != base)
kono
parents: 67
diff changeset
1118 return;
kono
parents: 67
diff changeset
1119 }
kono
parents: 67
diff changeset
1120 if (all_same)
kono
parents: 67
diff changeset
1121 return;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1122 tree_vector_builder cst (type, nelts, 1);
111
kono
parents: 67
diff changeset
1123 for (i = 0; i < nelts; i++)
kono
parents: 67
diff changeset
1124 {
kono
parents: 67
diff changeset
1125 tree this_base = CONSTRUCTOR_ELT (rhs, i)->value;
kono
parents: 67
diff changeset
1126 tree elt = build_zero_cst (TREE_TYPE (base));
kono
parents: 67
diff changeset
1127 while (this_base != base)
kono
parents: 67
diff changeset
1128 {
kono
parents: 67
diff changeset
1129 g = SSA_NAME_DEF_STMT (this_base);
kono
parents: 67
diff changeset
1130 elt = fold_binary (PLUS_EXPR, TREE_TYPE (base),
kono
parents: 67
diff changeset
1131 elt, gimple_assign_rhs2 (g));
kono
parents: 67
diff changeset
1132 if (elt == NULL_TREE
kono
parents: 67
diff changeset
1133 || TREE_CODE (elt) != INTEGER_CST
kono
parents: 67
diff changeset
1134 || TREE_OVERFLOW (elt))
kono
parents: 67
diff changeset
1135 return;
kono
parents: 67
diff changeset
1136 this_base = gimple_assign_rhs1 (g);
kono
parents: 67
diff changeset
1137 }
kono
parents: 67
diff changeset
1138 cst.quick_push (elt);
kono
parents: 67
diff changeset
1139 }
kono
parents: 67
diff changeset
1140 for (i = 0; i < nelts; i++)
kono
parents: 67
diff changeset
1141 CONSTRUCTOR_ELT (rhs, i)->value = base;
kono
parents: 67
diff changeset
1142 g = gimple_build_assign (make_ssa_name (type), rhs);
kono
parents: 67
diff changeset
1143 gsi_insert_before (gsi, g, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1144 g = gimple_build_assign (lhs, PLUS_EXPR, gimple_assign_lhs (g),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1145 cst.build ());
111
kono
parents: 67
diff changeset
1146 gsi_replace (gsi, g, false);
kono
parents: 67
diff changeset
1147 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148
111
kono
parents: 67
diff changeset
1149 /* Return a type for the widest vector mode whose components are of type
kono
parents: 67
diff changeset
1150 TYPE, or NULL_TREE if none is found. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 static tree
111
kono
parents: 67
diff changeset
1153 type_for_widest_vector_mode (tree type, optab op)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 {
111
kono
parents: 67
diff changeset
1155 machine_mode inner_mode = TYPE_MODE (type);
kono
parents: 67
diff changeset
1156 machine_mode best_mode = VOIDmode, mode;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1157 poly_int64 best_nunits = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 if (SCALAR_FLOAT_MODE_P (inner_mode))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 mode = MIN_MODE_VECTOR_FLOAT;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 else if (SCALAR_FRACT_MODE_P (inner_mode))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 mode = MIN_MODE_VECTOR_FRACT;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 else if (SCALAR_UFRACT_MODE_P (inner_mode))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 mode = MIN_MODE_VECTOR_UFRACT;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 else if (SCALAR_ACCUM_MODE_P (inner_mode))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 mode = MIN_MODE_VECTOR_ACCUM;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 else if (SCALAR_UACCUM_MODE_P (inner_mode))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 mode = MIN_MODE_VECTOR_UACCUM;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1169 else if (inner_mode == BImode)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1170 mode = MIN_MODE_VECTOR_BOOL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 mode = MIN_MODE_VECTOR_INT;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173
111
kono
parents: 67
diff changeset
1174 FOR_EACH_MODE_FROM (mode, mode)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 if (GET_MODE_INNER (mode) == inner_mode
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1176 && maybe_gt (GET_MODE_NUNITS (mode), best_nunits)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1177 && optab_handler (op, mode) != CODE_FOR_nothing)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 best_mode = mode, best_nunits = GET_MODE_NUNITS (mode);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 if (best_mode == VOIDmode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 return NULL_TREE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 else
111
kono
parents: 67
diff changeset
1183 return build_vector_type_for_mode (type, best_mode);
kono
parents: 67
diff changeset
1184 }
kono
parents: 67
diff changeset
1185
kono
parents: 67
diff changeset
1186
kono
parents: 67
diff changeset
1187 /* Build a reference to the element of the vector VECT. Function
kono
parents: 67
diff changeset
1188 returns either the element itself, either BIT_FIELD_REF, or an
kono
parents: 67
diff changeset
1189 ARRAY_REF expression.
kono
parents: 67
diff changeset
1190
kono
parents: 67
diff changeset
1191 GSI is required to insert temporary variables while building a
kono
parents: 67
diff changeset
1192 refernece to the element of the vector VECT.
kono
parents: 67
diff changeset
1193
kono
parents: 67
diff changeset
1194 PTMPVEC is a pointer to the temporary variable for caching
kono
parents: 67
diff changeset
1195 purposes. In case when PTMPVEC is NULL new temporary variable
kono
parents: 67
diff changeset
1196 will be created. */
kono
parents: 67
diff changeset
1197 static tree
kono
parents: 67
diff changeset
1198 vector_element (gimple_stmt_iterator *gsi, tree vect, tree idx, tree *ptmpvec)
kono
parents: 67
diff changeset
1199 {
kono
parents: 67
diff changeset
1200 tree vect_type, vect_elt_type;
kono
parents: 67
diff changeset
1201 gimple *asgn;
kono
parents: 67
diff changeset
1202 tree tmpvec;
kono
parents: 67
diff changeset
1203 tree arraytype;
kono
parents: 67
diff changeset
1204 bool need_asgn = true;
kono
parents: 67
diff changeset
1205 unsigned int elements;
kono
parents: 67
diff changeset
1206
kono
parents: 67
diff changeset
1207 vect_type = TREE_TYPE (vect);
kono
parents: 67
diff changeset
1208 vect_elt_type = TREE_TYPE (vect_type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1209 elements = nunits_for_known_piecewise_op (vect_type);
111
kono
parents: 67
diff changeset
1210
kono
parents: 67
diff changeset
1211 if (TREE_CODE (idx) == INTEGER_CST)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 {
111
kono
parents: 67
diff changeset
1213 unsigned HOST_WIDE_INT index;
kono
parents: 67
diff changeset
1214
kono
parents: 67
diff changeset
1215 /* Given that we're about to compute a binary modulus,
kono
parents: 67
diff changeset
1216 we don't care about the high bits of the value. */
kono
parents: 67
diff changeset
1217 index = TREE_INT_CST_LOW (idx);
kono
parents: 67
diff changeset
1218 if (!tree_fits_uhwi_p (idx) || index >= elements)
kono
parents: 67
diff changeset
1219 {
kono
parents: 67
diff changeset
1220 index &= elements - 1;
kono
parents: 67
diff changeset
1221 idx = build_int_cst (TREE_TYPE (idx), index);
kono
parents: 67
diff changeset
1222 }
kono
parents: 67
diff changeset
1223
kono
parents: 67
diff changeset
1224 /* When lowering a vector statement sequence do some easy
kono
parents: 67
diff changeset
1225 simplification by looking through intermediate vector results. */
kono
parents: 67
diff changeset
1226 if (TREE_CODE (vect) == SSA_NAME)
kono
parents: 67
diff changeset
1227 {
kono
parents: 67
diff changeset
1228 gimple *def_stmt = SSA_NAME_DEF_STMT (vect);
kono
parents: 67
diff changeset
1229 if (is_gimple_assign (def_stmt)
kono
parents: 67
diff changeset
1230 && (gimple_assign_rhs_code (def_stmt) == VECTOR_CST
kono
parents: 67
diff changeset
1231 || gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR))
kono
parents: 67
diff changeset
1232 vect = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
1233 }
kono
parents: 67
diff changeset
1234
kono
parents: 67
diff changeset
1235 if (TREE_CODE (vect) == VECTOR_CST)
kono
parents: 67
diff changeset
1236 return VECTOR_CST_ELT (vect, index);
kono
parents: 67
diff changeset
1237 else if (TREE_CODE (vect) == CONSTRUCTOR
kono
parents: 67
diff changeset
1238 && (CONSTRUCTOR_NELTS (vect) == 0
kono
parents: 67
diff changeset
1239 || TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (vect, 0)->value))
kono
parents: 67
diff changeset
1240 != VECTOR_TYPE))
kono
parents: 67
diff changeset
1241 {
kono
parents: 67
diff changeset
1242 if (index < CONSTRUCTOR_NELTS (vect))
kono
parents: 67
diff changeset
1243 return CONSTRUCTOR_ELT (vect, index)->value;
kono
parents: 67
diff changeset
1244 return build_zero_cst (vect_elt_type);
kono
parents: 67
diff changeset
1245 }
kono
parents: 67
diff changeset
1246 else
kono
parents: 67
diff changeset
1247 {
kono
parents: 67
diff changeset
1248 tree size = TYPE_SIZE (vect_elt_type);
kono
parents: 67
diff changeset
1249 tree pos = fold_build2 (MULT_EXPR, bitsizetype, bitsize_int (index),
kono
parents: 67
diff changeset
1250 size);
kono
parents: 67
diff changeset
1251 return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
kono
parents: 67
diff changeset
1252 }
kono
parents: 67
diff changeset
1253 }
kono
parents: 67
diff changeset
1254
kono
parents: 67
diff changeset
1255 if (!ptmpvec)
kono
parents: 67
diff changeset
1256 tmpvec = create_tmp_var (vect_type, "vectmp");
kono
parents: 67
diff changeset
1257 else if (!*ptmpvec)
kono
parents: 67
diff changeset
1258 tmpvec = *ptmpvec = create_tmp_var (vect_type, "vectmp");
kono
parents: 67
diff changeset
1259 else
kono
parents: 67
diff changeset
1260 {
kono
parents: 67
diff changeset
1261 tmpvec = *ptmpvec;
kono
parents: 67
diff changeset
1262 need_asgn = false;
kono
parents: 67
diff changeset
1263 }
kono
parents: 67
diff changeset
1264
kono
parents: 67
diff changeset
1265 if (need_asgn)
kono
parents: 67
diff changeset
1266 {
kono
parents: 67
diff changeset
1267 TREE_ADDRESSABLE (tmpvec) = 1;
kono
parents: 67
diff changeset
1268 asgn = gimple_build_assign (tmpvec, vect);
kono
parents: 67
diff changeset
1269 gsi_insert_before (gsi, asgn, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1270 }
kono
parents: 67
diff changeset
1271
kono
parents: 67
diff changeset
1272 arraytype = build_array_type_nelts (vect_elt_type, elements);
kono
parents: 67
diff changeset
1273 return build4 (ARRAY_REF, vect_elt_type,
kono
parents: 67
diff changeset
1274 build1 (VIEW_CONVERT_EXPR, arraytype, tmpvec),
kono
parents: 67
diff changeset
1275 idx, NULL_TREE, NULL_TREE);
kono
parents: 67
diff changeset
1276 }
kono
parents: 67
diff changeset
1277
kono
parents: 67
diff changeset
1278 /* Check if VEC_PERM_EXPR within the given setting is supported
kono
parents: 67
diff changeset
1279 by hardware, or lower it piecewise.
kono
parents: 67
diff changeset
1280
kono
parents: 67
diff changeset
1281 When VEC_PERM_EXPR has the same first and second operands:
kono
parents: 67
diff changeset
1282 VEC_PERM_EXPR <v0, v0, mask> the lowered version would be
kono
parents: 67
diff changeset
1283 {v0[mask[0]], v0[mask[1]], ...}
kono
parents: 67
diff changeset
1284 MASK and V0 must have the same number of elements.
kono
parents: 67
diff changeset
1285
kono
parents: 67
diff changeset
1286 Otherwise VEC_PERM_EXPR <v0, v1, mask> is lowered to
kono
parents: 67
diff changeset
1287 {mask[0] < len(v0) ? v0[mask[0]] : v1[mask[0]], ...}
kono
parents: 67
diff changeset
1288 V0 and V1 must have the same type. MASK, V0, V1 must have the
kono
parents: 67
diff changeset
1289 same number of arguments. */
kono
parents: 67
diff changeset
1290
kono
parents: 67
diff changeset
1291 static void
kono
parents: 67
diff changeset
1292 lower_vec_perm (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
1293 {
kono
parents: 67
diff changeset
1294 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1295 tree mask = gimple_assign_rhs3 (stmt);
kono
parents: 67
diff changeset
1296 tree vec0 = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1297 tree vec1 = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
1298 tree vect_type = TREE_TYPE (vec0);
kono
parents: 67
diff changeset
1299 tree mask_type = TREE_TYPE (mask);
kono
parents: 67
diff changeset
1300 tree vect_elt_type = TREE_TYPE (vect_type);
kono
parents: 67
diff changeset
1301 tree mask_elt_type = TREE_TYPE (mask_type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1302 unsigned HOST_WIDE_INT elements;
111
kono
parents: 67
diff changeset
1303 vec<constructor_elt, va_gc> *v;
kono
parents: 67
diff changeset
1304 tree constr, t, si, i_val;
kono
parents: 67
diff changeset
1305 tree vec0tmp = NULL_TREE, vec1tmp = NULL_TREE, masktmp = NULL_TREE;
kono
parents: 67
diff changeset
1306 bool two_operand_p = !operand_equal_p (vec0, vec1, 0);
kono
parents: 67
diff changeset
1307 location_t loc = gimple_location (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1308 unsigned i;
kono
parents: 67
diff changeset
1309
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1310 if (!TYPE_VECTOR_SUBPARTS (vect_type).is_constant (&elements))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1311 return;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1312
111
kono
parents: 67
diff changeset
1313 if (TREE_CODE (mask) == SSA_NAME)
kono
parents: 67
diff changeset
1314 {
kono
parents: 67
diff changeset
1315 gimple *def_stmt = SSA_NAME_DEF_STMT (mask);
kono
parents: 67
diff changeset
1316 if (is_gimple_assign (def_stmt)
kono
parents: 67
diff changeset
1317 && gimple_assign_rhs_code (def_stmt) == VECTOR_CST)
kono
parents: 67
diff changeset
1318 mask = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
1319 }
kono
parents: 67
diff changeset
1320
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1321 vec_perm_builder sel_int;
111
kono
parents: 67
diff changeset
1322
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1323 if (TREE_CODE (mask) == VECTOR_CST
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1324 && tree_to_vec_perm_builder (&sel_int, mask))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1325 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1326 vec_perm_indices indices (sel_int, 2, elements);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1327 if (can_vec_perm_const_p (TYPE_MODE (vect_type), indices))
111
kono
parents: 67
diff changeset
1328 {
kono
parents: 67
diff changeset
1329 gimple_assign_set_rhs3 (stmt, mask);
kono
parents: 67
diff changeset
1330 update_stmt (stmt);
kono
parents: 67
diff changeset
1331 return;
kono
parents: 67
diff changeset
1332 }
kono
parents: 67
diff changeset
1333 /* Also detect vec_shr pattern - VEC_PERM_EXPR with zero
kono
parents: 67
diff changeset
1334 vector as VEC1 and a right element shift MASK. */
kono
parents: 67
diff changeset
1335 if (optab_handler (vec_shr_optab, TYPE_MODE (vect_type))
kono
parents: 67
diff changeset
1336 != CODE_FOR_nothing
kono
parents: 67
diff changeset
1337 && TREE_CODE (vec1) == VECTOR_CST
kono
parents: 67
diff changeset
1338 && initializer_zerop (vec1)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1339 && maybe_ne (indices[0], 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1340 && known_lt (poly_uint64 (indices[0]), elements))
111
kono
parents: 67
diff changeset
1341 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1342 bool ok_p = indices.series_p (0, 1, indices[0], 1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1343 if (!ok_p)
111
kono
parents: 67
diff changeset
1344 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1345 for (i = 1; i < elements; ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1346 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1347 poly_uint64 actual = indices[i];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1348 poly_uint64 expected = i + indices[0];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1349 /* Indices into the second vector are all equivalent. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1350 if (maybe_lt (actual, elements)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1351 ? maybe_ne (actual, expected)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1352 : maybe_lt (expected, elements))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1353 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1354 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1355 ok_p = i == elements;
111
kono
parents: 67
diff changeset
1356 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1357 if (ok_p)
111
kono
parents: 67
diff changeset
1358 {
kono
parents: 67
diff changeset
1359 gimple_assign_set_rhs3 (stmt, mask);
kono
parents: 67
diff changeset
1360 update_stmt (stmt);
kono
parents: 67
diff changeset
1361 return;
kono
parents: 67
diff changeset
1362 }
kono
parents: 67
diff changeset
1363 }
kono
parents: 67
diff changeset
1364 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1365 else if (can_vec_perm_var_p (TYPE_MODE (vect_type)))
111
kono
parents: 67
diff changeset
1366 return;
kono
parents: 67
diff changeset
1367
kono
parents: 67
diff changeset
1368 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 67
diff changeset
1369 "vector shuffling operation will be expanded piecewise");
kono
parents: 67
diff changeset
1370
kono
parents: 67
diff changeset
1371 vec_alloc (v, elements);
kono
parents: 67
diff changeset
1372 for (i = 0; i < elements; i++)
kono
parents: 67
diff changeset
1373 {
kono
parents: 67
diff changeset
1374 si = size_int (i);
kono
parents: 67
diff changeset
1375 i_val = vector_element (gsi, mask, si, &masktmp);
kono
parents: 67
diff changeset
1376
kono
parents: 67
diff changeset
1377 if (TREE_CODE (i_val) == INTEGER_CST)
kono
parents: 67
diff changeset
1378 {
kono
parents: 67
diff changeset
1379 unsigned HOST_WIDE_INT index;
kono
parents: 67
diff changeset
1380
kono
parents: 67
diff changeset
1381 index = TREE_INT_CST_LOW (i_val);
kono
parents: 67
diff changeset
1382 if (!tree_fits_uhwi_p (i_val) || index >= elements)
kono
parents: 67
diff changeset
1383 i_val = build_int_cst (mask_elt_type, index & (elements - 1));
kono
parents: 67
diff changeset
1384
kono
parents: 67
diff changeset
1385 if (two_operand_p && (index & elements) != 0)
kono
parents: 67
diff changeset
1386 t = vector_element (gsi, vec1, i_val, &vec1tmp);
kono
parents: 67
diff changeset
1387 else
kono
parents: 67
diff changeset
1388 t = vector_element (gsi, vec0, i_val, &vec0tmp);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389
111
kono
parents: 67
diff changeset
1390 t = force_gimple_operand_gsi (gsi, t, true, NULL_TREE,
kono
parents: 67
diff changeset
1391 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1392 }
kono
parents: 67
diff changeset
1393 else
kono
parents: 67
diff changeset
1394 {
kono
parents: 67
diff changeset
1395 tree cond = NULL_TREE, v0_val;
kono
parents: 67
diff changeset
1396
kono
parents: 67
diff changeset
1397 if (two_operand_p)
kono
parents: 67
diff changeset
1398 {
kono
parents: 67
diff changeset
1399 cond = fold_build2 (BIT_AND_EXPR, mask_elt_type, i_val,
kono
parents: 67
diff changeset
1400 build_int_cst (mask_elt_type, elements));
kono
parents: 67
diff changeset
1401 cond = force_gimple_operand_gsi (gsi, cond, true, NULL_TREE,
kono
parents: 67
diff changeset
1402 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1403 }
kono
parents: 67
diff changeset
1404
kono
parents: 67
diff changeset
1405 i_val = fold_build2 (BIT_AND_EXPR, mask_elt_type, i_val,
kono
parents: 67
diff changeset
1406 build_int_cst (mask_elt_type, elements - 1));
kono
parents: 67
diff changeset
1407 i_val = force_gimple_operand_gsi (gsi, i_val, true, NULL_TREE,
kono
parents: 67
diff changeset
1408 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1409
kono
parents: 67
diff changeset
1410 v0_val = vector_element (gsi, vec0, i_val, &vec0tmp);
kono
parents: 67
diff changeset
1411 v0_val = force_gimple_operand_gsi (gsi, v0_val, true, NULL_TREE,
kono
parents: 67
diff changeset
1412 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1413
kono
parents: 67
diff changeset
1414 if (two_operand_p)
kono
parents: 67
diff changeset
1415 {
kono
parents: 67
diff changeset
1416 tree v1_val;
kono
parents: 67
diff changeset
1417
kono
parents: 67
diff changeset
1418 v1_val = vector_element (gsi, vec1, i_val, &vec1tmp);
kono
parents: 67
diff changeset
1419 v1_val = force_gimple_operand_gsi (gsi, v1_val, true, NULL_TREE,
kono
parents: 67
diff changeset
1420 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1421
kono
parents: 67
diff changeset
1422 cond = fold_build2 (EQ_EXPR, boolean_type_node,
kono
parents: 67
diff changeset
1423 cond, build_zero_cst (mask_elt_type));
kono
parents: 67
diff changeset
1424 cond = fold_build3 (COND_EXPR, vect_elt_type,
kono
parents: 67
diff changeset
1425 cond, v0_val, v1_val);
kono
parents: 67
diff changeset
1426 t = force_gimple_operand_gsi (gsi, cond, true, NULL_TREE,
kono
parents: 67
diff changeset
1427 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1428 }
kono
parents: 67
diff changeset
1429 else
kono
parents: 67
diff changeset
1430 t = v0_val;
kono
parents: 67
diff changeset
1431 }
kono
parents: 67
diff changeset
1432
kono
parents: 67
diff changeset
1433 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
kono
parents: 67
diff changeset
1434 }
kono
parents: 67
diff changeset
1435
kono
parents: 67
diff changeset
1436 constr = build_constructor (vect_type, v);
kono
parents: 67
diff changeset
1437 gimple_assign_set_rhs_from_tree (gsi, constr);
kono
parents: 67
diff changeset
1438 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1439 }
kono
parents: 67
diff changeset
1440
kono
parents: 67
diff changeset
1441 /* If OP is a uniform vector return the element it is a splat from. */
kono
parents: 67
diff changeset
1442
kono
parents: 67
diff changeset
1443 static tree
kono
parents: 67
diff changeset
1444 ssa_uniform_vector_p (tree op)
kono
parents: 67
diff changeset
1445 {
kono
parents: 67
diff changeset
1446 if (TREE_CODE (op) == VECTOR_CST
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1447 || TREE_CODE (op) == VEC_DUPLICATE_EXPR
111
kono
parents: 67
diff changeset
1448 || TREE_CODE (op) == CONSTRUCTOR)
kono
parents: 67
diff changeset
1449 return uniform_vector_p (op);
kono
parents: 67
diff changeset
1450 if (TREE_CODE (op) == SSA_NAME)
kono
parents: 67
diff changeset
1451 {
kono
parents: 67
diff changeset
1452 gimple *def_stmt = SSA_NAME_DEF_STMT (op);
kono
parents: 67
diff changeset
1453 if (gimple_assign_single_p (def_stmt))
kono
parents: 67
diff changeset
1454 return uniform_vector_p (gimple_assign_rhs1 (def_stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1455 }
111
kono
parents: 67
diff changeset
1456 return NULL_TREE;
kono
parents: 67
diff changeset
1457 }
kono
parents: 67
diff changeset
1458
kono
parents: 67
diff changeset
1459 /* Return type in which CODE operation with optab OP can be
kono
parents: 67
diff changeset
1460 computed. */
kono
parents: 67
diff changeset
1461
kono
parents: 67
diff changeset
1462 static tree
kono
parents: 67
diff changeset
1463 get_compute_type (enum tree_code code, optab op, tree type)
kono
parents: 67
diff changeset
1464 {
kono
parents: 67
diff changeset
1465 /* For very wide vectors, try using a smaller vector mode. */
kono
parents: 67
diff changeset
1466 tree compute_type = type;
kono
parents: 67
diff changeset
1467 if (op
kono
parents: 67
diff changeset
1468 && (!VECTOR_MODE_P (TYPE_MODE (type))
kono
parents: 67
diff changeset
1469 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing))
kono
parents: 67
diff changeset
1470 {
kono
parents: 67
diff changeset
1471 tree vector_compute_type
kono
parents: 67
diff changeset
1472 = type_for_widest_vector_mode (TREE_TYPE (type), op);
kono
parents: 67
diff changeset
1473 if (vector_compute_type != NULL_TREE
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1474 && subparts_gt (compute_type, vector_compute_type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1475 && maybe_ne (TYPE_VECTOR_SUBPARTS (vector_compute_type), 1U)
111
kono
parents: 67
diff changeset
1476 && (optab_handler (op, TYPE_MODE (vector_compute_type))
kono
parents: 67
diff changeset
1477 != CODE_FOR_nothing))
kono
parents: 67
diff changeset
1478 compute_type = vector_compute_type;
kono
parents: 67
diff changeset
1479 }
kono
parents: 67
diff changeset
1480
kono
parents: 67
diff changeset
1481 /* If we are breaking a BLKmode vector into smaller pieces,
kono
parents: 67
diff changeset
1482 type_for_widest_vector_mode has already looked into the optab,
kono
parents: 67
diff changeset
1483 so skip these checks. */
kono
parents: 67
diff changeset
1484 if (compute_type == type)
kono
parents: 67
diff changeset
1485 {
kono
parents: 67
diff changeset
1486 machine_mode compute_mode = TYPE_MODE (compute_type);
kono
parents: 67
diff changeset
1487 if (VECTOR_MODE_P (compute_mode))
kono
parents: 67
diff changeset
1488 {
kono
parents: 67
diff changeset
1489 if (op && optab_handler (op, compute_mode) != CODE_FOR_nothing)
kono
parents: 67
diff changeset
1490 return compute_type;
kono
parents: 67
diff changeset
1491 if (code == MULT_HIGHPART_EXPR
kono
parents: 67
diff changeset
1492 && can_mult_highpart_p (compute_mode,
kono
parents: 67
diff changeset
1493 TYPE_UNSIGNED (compute_type)))
kono
parents: 67
diff changeset
1494 return compute_type;
kono
parents: 67
diff changeset
1495 }
kono
parents: 67
diff changeset
1496 /* There is no operation in hardware, so fall back to scalars. */
kono
parents: 67
diff changeset
1497 compute_type = TREE_TYPE (type);
kono
parents: 67
diff changeset
1498 }
kono
parents: 67
diff changeset
1499
kono
parents: 67
diff changeset
1500 return compute_type;
kono
parents: 67
diff changeset
1501 }
kono
parents: 67
diff changeset
1502
kono
parents: 67
diff changeset
1503 static tree
kono
parents: 67
diff changeset
1504 do_cond (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b,
kono
parents: 67
diff changeset
1505 tree bitpos, tree bitsize, enum tree_code code,
kono
parents: 67
diff changeset
1506 tree type ATTRIBUTE_UNUSED)
kono
parents: 67
diff changeset
1507 {
kono
parents: 67
diff changeset
1508 if (TREE_CODE (TREE_TYPE (a)) == VECTOR_TYPE)
kono
parents: 67
diff changeset
1509 a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
kono
parents: 67
diff changeset
1510 if (TREE_CODE (TREE_TYPE (b)) == VECTOR_TYPE)
kono
parents: 67
diff changeset
1511 b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
kono
parents: 67
diff changeset
1512 tree cond = gimple_assign_rhs1 (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1513 return gimplify_build3 (gsi, code, inner_type, unshare_expr (cond), a, b);
kono
parents: 67
diff changeset
1514 }
kono
parents: 67
diff changeset
1515
kono
parents: 67
diff changeset
1516 /* Expand a vector COND_EXPR to scalars, piecewise. */
kono
parents: 67
diff changeset
1517 static void
kono
parents: 67
diff changeset
1518 expand_vector_scalar_condition (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
1519 {
kono
parents: 67
diff changeset
1520 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1521 tree type = gimple_expr_type (stmt);
kono
parents: 67
diff changeset
1522 tree compute_type = get_compute_type (COND_EXPR, mov_optab, type);
kono
parents: 67
diff changeset
1523 machine_mode compute_mode = TYPE_MODE (compute_type);
kono
parents: 67
diff changeset
1524 gcc_assert (compute_mode != BLKmode);
kono
parents: 67
diff changeset
1525 tree lhs = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
1526 tree rhs2 = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
1527 tree rhs3 = gimple_assign_rhs3 (stmt);
kono
parents: 67
diff changeset
1528 tree new_rhs;
kono
parents: 67
diff changeset
1529
kono
parents: 67
diff changeset
1530 /* If the compute mode is not a vector mode (hence we are not decomposing
kono
parents: 67
diff changeset
1531 a BLKmode vector to smaller, hardware-supported vectors), we may want
kono
parents: 67
diff changeset
1532 to expand the operations in parallel. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1533 if (!VECTOR_MODE_P (compute_mode))
111
kono
parents: 67
diff changeset
1534 new_rhs = expand_vector_parallel (gsi, do_cond, type, rhs2, rhs3,
kono
parents: 67
diff changeset
1535 COND_EXPR);
kono
parents: 67
diff changeset
1536 else
kono
parents: 67
diff changeset
1537 new_rhs = expand_vector_piecewise (gsi, do_cond, type, compute_type,
kono
parents: 67
diff changeset
1538 rhs2, rhs3, COND_EXPR);
kono
parents: 67
diff changeset
1539 if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (new_rhs)))
kono
parents: 67
diff changeset
1540 new_rhs = gimplify_build1 (gsi, VIEW_CONVERT_EXPR, TREE_TYPE (lhs),
kono
parents: 67
diff changeset
1541 new_rhs);
kono
parents: 67
diff changeset
1542
kono
parents: 67
diff changeset
1543 /* NOTE: We should avoid using gimple_assign_set_rhs_from_tree. One
kono
parents: 67
diff changeset
1544 way to do it is change expand_vector_operation and its callees to
kono
parents: 67
diff changeset
1545 return a tree_code, RHS1 and RHS2 instead of a tree. */
kono
parents: 67
diff changeset
1546 gimple_assign_set_rhs_from_tree (gsi, new_rhs);
kono
parents: 67
diff changeset
1547 update_stmt (gsi_stmt (*gsi));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1548 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1549
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1550 /* Process one statement. If we identify a vector operation, expand it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1551
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1552 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1553 expand_vector_operations_1 (gimple_stmt_iterator *gsi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1554 {
111
kono
parents: 67
diff changeset
1555 tree lhs, rhs1, rhs2 = NULL, type, compute_type = NULL_TREE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1556 enum tree_code code;
111
kono
parents: 67
diff changeset
1557 optab op = unknown_optab;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1558 enum gimple_rhs_class rhs_class;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1559 tree new_rhs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1560
111
kono
parents: 67
diff changeset
1561 /* Only consider code == GIMPLE_ASSIGN. */
kono
parents: 67
diff changeset
1562 gassign *stmt = dyn_cast <gassign *> (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1563 if (!stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1564 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1565
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1566 code = gimple_assign_rhs_code (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1567 rhs_class = get_gimple_rhs_class (code);
111
kono
parents: 67
diff changeset
1568 lhs = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
1569
kono
parents: 67
diff changeset
1570 if (code == VEC_PERM_EXPR)
kono
parents: 67
diff changeset
1571 {
kono
parents: 67
diff changeset
1572 lower_vec_perm (gsi);
kono
parents: 67
diff changeset
1573 return;
kono
parents: 67
diff changeset
1574 }
kono
parents: 67
diff changeset
1575
kono
parents: 67
diff changeset
1576 if (code == VEC_COND_EXPR)
kono
parents: 67
diff changeset
1577 {
kono
parents: 67
diff changeset
1578 expand_vector_condition (gsi);
kono
parents: 67
diff changeset
1579 return;
kono
parents: 67
diff changeset
1580 }
kono
parents: 67
diff changeset
1581
kono
parents: 67
diff changeset
1582 if (code == COND_EXPR
kono
parents: 67
diff changeset
1583 && TREE_CODE (TREE_TYPE (gimple_assign_lhs (stmt))) == VECTOR_TYPE
kono
parents: 67
diff changeset
1584 && TYPE_MODE (TREE_TYPE (gimple_assign_lhs (stmt))) == BLKmode)
kono
parents: 67
diff changeset
1585 {
kono
parents: 67
diff changeset
1586 expand_vector_scalar_condition (gsi);
kono
parents: 67
diff changeset
1587 return;
kono
parents: 67
diff changeset
1588 }
kono
parents: 67
diff changeset
1589
kono
parents: 67
diff changeset
1590 if (code == CONSTRUCTOR
kono
parents: 67
diff changeset
1591 && TREE_CODE (lhs) == SSA_NAME
kono
parents: 67
diff changeset
1592 && VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (lhs)))
kono
parents: 67
diff changeset
1593 && !gimple_clobber_p (stmt)
kono
parents: 67
diff changeset
1594 && optimize)
kono
parents: 67
diff changeset
1595 {
kono
parents: 67
diff changeset
1596 optimize_vector_constructor (gsi);
kono
parents: 67
diff changeset
1597 return;
kono
parents: 67
diff changeset
1598 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1599
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1600 if (rhs_class != GIMPLE_UNARY_RHS && rhs_class != GIMPLE_BINARY_RHS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1601 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1602
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1603 rhs1 = gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1604 type = gimple_expr_type (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1605 if (rhs_class == GIMPLE_BINARY_RHS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1606 rhs2 = gimple_assign_rhs2 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1607
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1608 if (!VECTOR_TYPE_P (type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1609 || !VECTOR_TYPE_P (TREE_TYPE (rhs1)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1610 return;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1611
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1612 /* A scalar operation pretending to be a vector one. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1613 if (VECTOR_BOOLEAN_TYPE_P (type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1614 && !VECTOR_MODE_P (TYPE_MODE (type))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1615 && TYPE_MODE (type) != BLKmode)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1616 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1617
111
kono
parents: 67
diff changeset
1618 /* If the vector operation is operating on all same vector elements
kono
parents: 67
diff changeset
1619 implement it with a scalar operation and a splat if the target
kono
parents: 67
diff changeset
1620 supports the scalar operation. */
kono
parents: 67
diff changeset
1621 tree srhs1, srhs2 = NULL_TREE;
kono
parents: 67
diff changeset
1622 if ((srhs1 = ssa_uniform_vector_p (rhs1)) != NULL_TREE
kono
parents: 67
diff changeset
1623 && (rhs2 == NULL_TREE
kono
parents: 67
diff changeset
1624 || (! VECTOR_TYPE_P (TREE_TYPE (rhs2))
kono
parents: 67
diff changeset
1625 && (srhs2 = rhs2))
kono
parents: 67
diff changeset
1626 || (srhs2 = ssa_uniform_vector_p (rhs2)) != NULL_TREE)
kono
parents: 67
diff changeset
1627 /* As we query direct optabs restrict to non-convert operations. */
kono
parents: 67
diff changeset
1628 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (TREE_TYPE (srhs1)))
kono
parents: 67
diff changeset
1629 {
kono
parents: 67
diff changeset
1630 op = optab_for_tree_code (code, TREE_TYPE (type), optab_scalar);
kono
parents: 67
diff changeset
1631 if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB
kono
parents: 67
diff changeset
1632 && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != CODE_FOR_nothing)
kono
parents: 67
diff changeset
1633 {
kono
parents: 67
diff changeset
1634 tree slhs = make_ssa_name (TREE_TYPE (srhs1));
kono
parents: 67
diff changeset
1635 gimple *repl = gimple_build_assign (slhs, code, srhs1, srhs2);
kono
parents: 67
diff changeset
1636 gsi_insert_before (gsi, repl, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1637 gimple_assign_set_rhs_from_tree (gsi,
kono
parents: 67
diff changeset
1638 build_vector_from_val (type, slhs));
kono
parents: 67
diff changeset
1639 update_stmt (stmt);
kono
parents: 67
diff changeset
1640 return;
kono
parents: 67
diff changeset
1641 }
kono
parents: 67
diff changeset
1642 }
kono
parents: 67
diff changeset
1643
kono
parents: 67
diff changeset
1644 if (CONVERT_EXPR_CODE_P (code)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1645 || code == FLOAT_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1646 || code == FIX_TRUNC_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1647 || code == VIEW_CONVERT_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1648 return;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1649
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1650 /* The signedness is determined from input argument. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1651 if (code == VEC_UNPACK_FLOAT_HI_EXPR
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1652 || code == VEC_UNPACK_FLOAT_LO_EXPR
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1653 || code == VEC_PACK_FLOAT_EXPR)
111
kono
parents: 67
diff changeset
1654 {
kono
parents: 67
diff changeset
1655 type = TREE_TYPE (rhs1);
kono
parents: 67
diff changeset
1656 /* We do not know how to scalarize those. */
kono
parents: 67
diff changeset
1657 return;
kono
parents: 67
diff changeset
1658 }
kono
parents: 67
diff changeset
1659
kono
parents: 67
diff changeset
1660 /* For widening/narrowing vector operations, the relevant type is of the
kono
parents: 67
diff changeset
1661 arguments, not the widened result. VEC_UNPACK_FLOAT_*_EXPR is
kono
parents: 67
diff changeset
1662 calculated in the same way above. */
kono
parents: 67
diff changeset
1663 if (code == WIDEN_SUM_EXPR
kono
parents: 67
diff changeset
1664 || code == VEC_WIDEN_MULT_HI_EXPR
kono
parents: 67
diff changeset
1665 || code == VEC_WIDEN_MULT_LO_EXPR
kono
parents: 67
diff changeset
1666 || code == VEC_WIDEN_MULT_EVEN_EXPR
kono
parents: 67
diff changeset
1667 || code == VEC_WIDEN_MULT_ODD_EXPR
kono
parents: 67
diff changeset
1668 || code == VEC_UNPACK_HI_EXPR
kono
parents: 67
diff changeset
1669 || code == VEC_UNPACK_LO_EXPR
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1670 || code == VEC_UNPACK_FIX_TRUNC_HI_EXPR
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1671 || code == VEC_UNPACK_FIX_TRUNC_LO_EXPR
111
kono
parents: 67
diff changeset
1672 || code == VEC_PACK_TRUNC_EXPR
kono
parents: 67
diff changeset
1673 || code == VEC_PACK_SAT_EXPR
kono
parents: 67
diff changeset
1674 || code == VEC_PACK_FIX_TRUNC_EXPR
kono
parents: 67
diff changeset
1675 || code == VEC_WIDEN_LSHIFT_HI_EXPR
kono
parents: 67
diff changeset
1676 || code == VEC_WIDEN_LSHIFT_LO_EXPR)
kono
parents: 67
diff changeset
1677 {
kono
parents: 67
diff changeset
1678 type = TREE_TYPE (rhs1);
kono
parents: 67
diff changeset
1679 /* We do not know how to scalarize those. */
kono
parents: 67
diff changeset
1680 return;
kono
parents: 67
diff changeset
1681 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1682
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1683 /* Choose between vector shift/rotate by vector and vector shift/rotate by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1684 scalar */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1685 if (code == LSHIFT_EXPR
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1686 || code == RSHIFT_EXPR
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1687 || code == LROTATE_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1688 || code == RROTATE_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1689 {
111
kono
parents: 67
diff changeset
1690 optab opv;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1691
111
kono
parents: 67
diff changeset
1692 /* Check whether we have vector <op> {x,x,x,x} where x
kono
parents: 67
diff changeset
1693 could be a scalar variable or a constant. Transform
kono
parents: 67
diff changeset
1694 vector <op> {x,x,x,x} ==> vector <op> scalar. */
kono
parents: 67
diff changeset
1695 if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (rhs2)))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1696 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1697 tree first;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1698
111
kono
parents: 67
diff changeset
1699 if ((first = ssa_uniform_vector_p (rhs2)) != NULL_TREE)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1700 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1701 gimple_assign_set_rhs2 (stmt, first);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1702 update_stmt (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1703 rhs2 = first;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1704 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1705 }
111
kono
parents: 67
diff changeset
1706
kono
parents: 67
diff changeset
1707 opv = optab_for_tree_code (code, type, optab_vector);
kono
parents: 67
diff changeset
1708 if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (rhs2)))
kono
parents: 67
diff changeset
1709 op = opv;
kono
parents: 67
diff changeset
1710 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1711 {
111
kono
parents: 67
diff changeset
1712 op = optab_for_tree_code (code, type, optab_scalar);
kono
parents: 67
diff changeset
1713
kono
parents: 67
diff changeset
1714 compute_type = get_compute_type (code, op, type);
kono
parents: 67
diff changeset
1715 if (compute_type == type)
kono
parents: 67
diff changeset
1716 return;
kono
parents: 67
diff changeset
1717 /* The rtl expander will expand vector/scalar as vector/vector
kono
parents: 67
diff changeset
1718 if necessary. Pick one with wider vector type. */
kono
parents: 67
diff changeset
1719 tree compute_vtype = get_compute_type (code, opv, type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1720 if (subparts_gt (compute_vtype, compute_type))
111
kono
parents: 67
diff changeset
1721 {
kono
parents: 67
diff changeset
1722 compute_type = compute_vtype;
kono
parents: 67
diff changeset
1723 op = opv;
kono
parents: 67
diff changeset
1724 }
kono
parents: 67
diff changeset
1725 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1726
111
kono
parents: 67
diff changeset
1727 if (code == LROTATE_EXPR || code == RROTATE_EXPR)
kono
parents: 67
diff changeset
1728 {
kono
parents: 67
diff changeset
1729 if (compute_type == NULL_TREE)
kono
parents: 67
diff changeset
1730 compute_type = get_compute_type (code, op, type);
kono
parents: 67
diff changeset
1731 if (compute_type == type)
kono
parents: 67
diff changeset
1732 return;
kono
parents: 67
diff changeset
1733 /* Before splitting vector rotates into scalar rotates,
kono
parents: 67
diff changeset
1734 see if we can't use vector shifts and BIT_IOR_EXPR
kono
parents: 67
diff changeset
1735 instead. For vector by vector rotates we'd also
kono
parents: 67
diff changeset
1736 need to check BIT_AND_EXPR and NEGATE_EXPR, punt there
kono
parents: 67
diff changeset
1737 for now, fold doesn't seem to create such rotates anyway. */
kono
parents: 67
diff changeset
1738 if (compute_type == TREE_TYPE (type)
kono
parents: 67
diff changeset
1739 && !VECTOR_INTEGER_TYPE_P (TREE_TYPE (rhs2)))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1740 {
111
kono
parents: 67
diff changeset
1741 optab oplv = vashl_optab, opl = ashl_optab;
kono
parents: 67
diff changeset
1742 optab oprv = vlshr_optab, opr = lshr_optab, opo = ior_optab;
kono
parents: 67
diff changeset
1743 tree compute_lvtype = get_compute_type (LSHIFT_EXPR, oplv, type);
kono
parents: 67
diff changeset
1744 tree compute_rvtype = get_compute_type (RSHIFT_EXPR, oprv, type);
kono
parents: 67
diff changeset
1745 tree compute_otype = get_compute_type (BIT_IOR_EXPR, opo, type);
kono
parents: 67
diff changeset
1746 tree compute_ltype = get_compute_type (LSHIFT_EXPR, opl, type);
kono
parents: 67
diff changeset
1747 tree compute_rtype = get_compute_type (RSHIFT_EXPR, opr, type);
kono
parents: 67
diff changeset
1748 /* The rtl expander will expand vector/scalar as vector/vector
kono
parents: 67
diff changeset
1749 if necessary. Pick one with wider vector type. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1750 if (subparts_gt (compute_lvtype, compute_ltype))
111
kono
parents: 67
diff changeset
1751 {
kono
parents: 67
diff changeset
1752 compute_ltype = compute_lvtype;
kono
parents: 67
diff changeset
1753 opl = oplv;
kono
parents: 67
diff changeset
1754 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1755 if (subparts_gt (compute_rvtype, compute_rtype))
111
kono
parents: 67
diff changeset
1756 {
kono
parents: 67
diff changeset
1757 compute_rtype = compute_rvtype;
kono
parents: 67
diff changeset
1758 opr = oprv;
kono
parents: 67
diff changeset
1759 }
kono
parents: 67
diff changeset
1760 /* Pick the narrowest type from LSHIFT_EXPR, RSHIFT_EXPR and
kono
parents: 67
diff changeset
1761 BIT_IOR_EXPR. */
kono
parents: 67
diff changeset
1762 compute_type = compute_ltype;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1763 if (subparts_gt (compute_type, compute_rtype))
111
kono
parents: 67
diff changeset
1764 compute_type = compute_rtype;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1765 if (subparts_gt (compute_type, compute_otype))
111
kono
parents: 67
diff changeset
1766 compute_type = compute_otype;
kono
parents: 67
diff changeset
1767 /* Verify all 3 operations can be performed in that type. */
kono
parents: 67
diff changeset
1768 if (compute_type != TREE_TYPE (type))
kono
parents: 67
diff changeset
1769 {
kono
parents: 67
diff changeset
1770 if (optab_handler (opl, TYPE_MODE (compute_type))
kono
parents: 67
diff changeset
1771 == CODE_FOR_nothing
kono
parents: 67
diff changeset
1772 || optab_handler (opr, TYPE_MODE (compute_type))
kono
parents: 67
diff changeset
1773 == CODE_FOR_nothing
kono
parents: 67
diff changeset
1774 || optab_handler (opo, TYPE_MODE (compute_type))
kono
parents: 67
diff changeset
1775 == CODE_FOR_nothing)
kono
parents: 67
diff changeset
1776 compute_type = TREE_TYPE (type);
kono
parents: 67
diff changeset
1777 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1778 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1779 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1780 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1781 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1782 op = optab_for_tree_code (code, type, optab_default);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1783
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1784 /* Optabs will try converting a negation into a subtraction, so
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1785 look for it as well. TODO: negation of floating-point vectors
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1786 might be turned into an exclusive OR toggling the sign bit. */
111
kono
parents: 67
diff changeset
1787 if (op == unknown_optab
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1788 && code == NEGATE_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1789 && INTEGRAL_TYPE_P (TREE_TYPE (type)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1790 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1791
111
kono
parents: 67
diff changeset
1792 if (compute_type == NULL_TREE)
kono
parents: 67
diff changeset
1793 compute_type = get_compute_type (code, op, type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1794 if (compute_type == type)
111
kono
parents: 67
diff changeset
1795 return;
kono
parents: 67
diff changeset
1796
kono
parents: 67
diff changeset
1797 new_rhs = expand_vector_operation (gsi, type, compute_type, stmt, code);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1798
111
kono
parents: 67
diff changeset
1799 /* Leave expression untouched for later expansion. */
kono
parents: 67
diff changeset
1800 if (new_rhs == NULL_TREE)
kono
parents: 67
diff changeset
1801 return;
kono
parents: 67
diff changeset
1802
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1803 if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (new_rhs)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1804 new_rhs = gimplify_build1 (gsi, VIEW_CONVERT_EXPR, TREE_TYPE (lhs),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1805 new_rhs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1806
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1807 /* NOTE: We should avoid using gimple_assign_set_rhs_from_tree. One
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1808 way to do it is change expand_vector_operation and its callees to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1809 return a tree_code, RHS1 and RHS2 instead of a tree. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1810 gimple_assign_set_rhs_from_tree (gsi, new_rhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1811 update_stmt (gsi_stmt (*gsi));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1812 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1813
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1814 /* Use this to lower vector operations introduced by the vectorizer,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1815 if it may need the bit-twiddling tricks implemented in this file. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1816
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1817 static unsigned int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1818 expand_vector_operations (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1819 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1820 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1821 basic_block bb;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1822 bool cfg_changed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1823
111
kono
parents: 67
diff changeset
1824 FOR_EACH_BB_FN (bb, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1825 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1826 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1827 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1828 expand_vector_operations_1 (&gsi);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1829 /* ??? If we do not cleanup EH then we will ICE in
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1830 verification. But in reality we have created wrong-code
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1831 as we did not properly transition EH info and edges to
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1832 the piecewise computations. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1833 if (maybe_clean_eh_stmt (gsi_stmt (gsi))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1834 && gimple_purge_dead_eh_edges (bb))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1835 cfg_changed = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1836 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1837 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1838
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1839 return cfg_changed ? TODO_cleanup_cfg : 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1840 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1841
111
kono
parents: 67
diff changeset
1842 namespace {
kono
parents: 67
diff changeset
1843
kono
parents: 67
diff changeset
1844 const pass_data pass_data_lower_vector =
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1845 {
111
kono
parents: 67
diff changeset
1846 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
1847 "veclower", /* name */
kono
parents: 67
diff changeset
1848 OPTGROUP_VEC, /* optinfo_flags */
kono
parents: 67
diff changeset
1849 TV_NONE, /* tv_id */
kono
parents: 67
diff changeset
1850 PROP_cfg, /* properties_required */
kono
parents: 67
diff changeset
1851 PROP_gimple_lvec, /* properties_provided */
kono
parents: 67
diff changeset
1852 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1853 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1854 TODO_update_ssa, /* todo_flags_finish */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1855 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1856
111
kono
parents: 67
diff changeset
1857 class pass_lower_vector : public gimple_opt_pass
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1858 {
111
kono
parents: 67
diff changeset
1859 public:
kono
parents: 67
diff changeset
1860 pass_lower_vector (gcc::context *ctxt)
kono
parents: 67
diff changeset
1861 : gimple_opt_pass (pass_data_lower_vector, ctxt)
kono
parents: 67
diff changeset
1862 {}
kono
parents: 67
diff changeset
1863
kono
parents: 67
diff changeset
1864 /* opt_pass methods: */
kono
parents: 67
diff changeset
1865 virtual bool gate (function *fun)
kono
parents: 67
diff changeset
1866 {
kono
parents: 67
diff changeset
1867 return !(fun->curr_properties & PROP_gimple_lvec);
kono
parents: 67
diff changeset
1868 }
kono
parents: 67
diff changeset
1869
kono
parents: 67
diff changeset
1870 virtual unsigned int execute (function *)
kono
parents: 67
diff changeset
1871 {
kono
parents: 67
diff changeset
1872 return expand_vector_operations ();
kono
parents: 67
diff changeset
1873 }
kono
parents: 67
diff changeset
1874
kono
parents: 67
diff changeset
1875 }; // class pass_lower_vector
kono
parents: 67
diff changeset
1876
kono
parents: 67
diff changeset
1877 } // anon namespace
kono
parents: 67
diff changeset
1878
kono
parents: 67
diff changeset
1879 gimple_opt_pass *
kono
parents: 67
diff changeset
1880 make_pass_lower_vector (gcc::context *ctxt)
kono
parents: 67
diff changeset
1881 {
kono
parents: 67
diff changeset
1882 return new pass_lower_vector (ctxt);
kono
parents: 67
diff changeset
1883 }
kono
parents: 67
diff changeset
1884
kono
parents: 67
diff changeset
1885 namespace {
kono
parents: 67
diff changeset
1886
kono
parents: 67
diff changeset
1887 const pass_data pass_data_lower_vector_ssa =
kono
parents: 67
diff changeset
1888 {
kono
parents: 67
diff changeset
1889 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
1890 "veclower2", /* name */
kono
parents: 67
diff changeset
1891 OPTGROUP_VEC, /* optinfo_flags */
kono
parents: 67
diff changeset
1892 TV_NONE, /* tv_id */
kono
parents: 67
diff changeset
1893 PROP_cfg, /* properties_required */
kono
parents: 67
diff changeset
1894 PROP_gimple_lvec, /* properties_provided */
kono
parents: 67
diff changeset
1895 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1896 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1897 ( TODO_update_ssa
kono
parents: 67
diff changeset
1898 | TODO_cleanup_cfg ), /* todo_flags_finish */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1899 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1900
111
kono
parents: 67
diff changeset
1901 class pass_lower_vector_ssa : public gimple_opt_pass
kono
parents: 67
diff changeset
1902 {
kono
parents: 67
diff changeset
1903 public:
kono
parents: 67
diff changeset
1904 pass_lower_vector_ssa (gcc::context *ctxt)
kono
parents: 67
diff changeset
1905 : gimple_opt_pass (pass_data_lower_vector_ssa, ctxt)
kono
parents: 67
diff changeset
1906 {}
kono
parents: 67
diff changeset
1907
kono
parents: 67
diff changeset
1908 /* opt_pass methods: */
kono
parents: 67
diff changeset
1909 opt_pass * clone () { return new pass_lower_vector_ssa (m_ctxt); }
kono
parents: 67
diff changeset
1910 virtual unsigned int execute (function *)
kono
parents: 67
diff changeset
1911 {
kono
parents: 67
diff changeset
1912 return expand_vector_operations ();
kono
parents: 67
diff changeset
1913 }
kono
parents: 67
diff changeset
1914
kono
parents: 67
diff changeset
1915 }; // class pass_lower_vector_ssa
kono
parents: 67
diff changeset
1916
kono
parents: 67
diff changeset
1917 } // anon namespace
kono
parents: 67
diff changeset
1918
kono
parents: 67
diff changeset
1919 gimple_opt_pass *
kono
parents: 67
diff changeset
1920 make_pass_lower_vector_ssa (gcc::context *ctxt)
kono
parents: 67
diff changeset
1921 {
kono
parents: 67
diff changeset
1922 return new pass_lower_vector_ssa (ctxt);
kono
parents: 67
diff changeset
1923 }
kono
parents: 67
diff changeset
1924
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1925 #include "gt-tree-vect-generic.h"