annotate gcc/tree-vect-generic.c @ 118:fd00160c1b76

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