annotate gcc/tree-vect-generic.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
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.
16
kono
parents: 14
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.
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 2
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.
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 2
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.
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 2
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"
16
kono
parents: 14
diff changeset
23 #include "backend.h"
kono
parents: 14
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"
16
kono
parents: 14
diff changeset
28 #include "ssa.h"
kono
parents: 14
diff changeset
29 #include "expmed.h"
kono
parents: 14
diff changeset
30 #include "optabs-tree.h"
kono
parents: 14
diff changeset
31 #include "diagnostic.h"
kono
parents: 14
diff changeset
32 #include "fold-const.h"
kono
parents: 14
diff changeset
33 #include "stor-layout.h"
kono
parents: 14
diff changeset
34 #include "langhooks.h"
kono
parents: 14
diff changeset
35 #include "tree-eh.h"
kono
parents: 14
diff changeset
36 #include "gimple-iterator.h"
kono
parents: 14
diff changeset
37 #include "gimplify-me.h"
kono
parents: 14
diff changeset
38 #include "gimplify.h"
kono
parents: 14
diff changeset
39 #include "tree-cfg.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
16
kono
parents: 14
diff changeset
41
kono
parents: 14
diff changeset
42 static void expand_vector_operations_1 (gimple_stmt_iterator *);
kono
parents: 14
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 {
16
kono
parents: 14
diff changeset
50 int width = tree_to_uhwi (TYPE_SIZE (inner_type));
kono
parents: 14
diff changeset
51 int n = (TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
kono
parents: 14
diff changeset
52 / HOST_BITS_PER_WIDE_INT;
kono
parents: 14
diff changeset
53 unsigned HOST_WIDE_INT low, mask;
kono
parents: 14
diff changeset
54 HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
kono
parents: 14
diff changeset
55 int i;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
16
kono
parents: 14
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
16
kono
parents: 14
diff changeset
67 for (i = 0; i < n; i++)
kono
parents: 14
diff changeset
68 a[i] = low;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
16
kono
parents: 14
diff changeset
70 gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
kono
parents: 14
diff changeset
71 return wide_int_to_tree
kono
parents: 14
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 *,
16
kono
parents: 14
diff changeset
102 tree, tree, tree, tree, tree, enum tree_code,
kono
parents: 14
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 {
16
kono
parents: 14
diff changeset
109 if (TREE_CODE (t) == SSA_NAME)
kono
parents: 14
diff changeset
110 {
kono
parents: 14
diff changeset
111 gimple *def_stmt = SSA_NAME_DEF_STMT (t);
kono
parents: 14
diff changeset
112 if (is_gimple_assign (def_stmt)
kono
parents: 14
diff changeset
113 && (gimple_assign_rhs_code (def_stmt) == VECTOR_CST
kono
parents: 14
diff changeset
114 || (bitpos
kono
parents: 14
diff changeset
115 && gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR)))
kono
parents: 14
diff changeset
116 t = gimple_assign_rhs1 (def_stmt);
kono
parents: 14
diff changeset
117 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 if (bitpos)
16
kono
parents: 14
diff changeset
119 {
kono
parents: 14
diff changeset
120 if (TREE_CODE (type) == BOOLEAN_TYPE)
kono
parents: 14
diff changeset
121 {
kono
parents: 14
diff changeset
122 tree itype
kono
parents: 14
diff changeset
123 = build_nonstandard_integer_type (tree_to_uhwi (bitsize), 0);
kono
parents: 14
diff changeset
124 tree field = gimplify_build3 (gsi, BIT_FIELD_REF, itype, t,
kono
parents: 14
diff changeset
125 bitsize, bitpos);
kono
parents: 14
diff changeset
126 return gimplify_build2 (gsi, NE_EXPR, type, field,
kono
parents: 14
diff changeset
127 build_zero_cst (itype));
kono
parents: 14
diff changeset
128 }
kono
parents: 14
diff changeset
129 else
kono
parents: 14
diff changeset
130 return gimplify_build3 (gsi, BIT_FIELD_REF, type, t, bitsize, bitpos);
kono
parents: 14
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,
16
kono
parents: 14
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,
16
kono
parents: 14
diff changeset
147 tree bitpos, tree bitsize, enum tree_code code,
kono
parents: 14
diff changeset
148 tree type ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 {
16
kono
parents: 14
diff changeset
150 if (TREE_CODE (TREE_TYPE (a)) == VECTOR_TYPE)
kono
parents: 14
diff changeset
151 a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
kono
parents: 14
diff changeset
152 if (TREE_CODE (TREE_TYPE (b)) == VECTOR_TYPE)
kono
parents: 14
diff changeset
153 b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
kono
parents: 14
diff changeset
154 return gimplify_build2 (gsi, code, inner_type, a, b);
kono
parents: 14
diff changeset
155 }
kono
parents: 14
diff changeset
156
kono
parents: 14
diff changeset
157 /* Construct expression (A[BITPOS] code B[BITPOS]) ? -1 : 0
kono
parents: 14
diff changeset
158
kono
parents: 14
diff changeset
159 INNER_TYPE is the type of A and B elements
kono
parents: 14
diff changeset
160
kono
parents: 14
diff changeset
161 returned expression is of signed integer type with the
kono
parents: 14
diff changeset
162 size equal to the size of INNER_TYPE. */
kono
parents: 14
diff changeset
163 static tree
kono
parents: 14
diff changeset
164 do_compare (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b,
kono
parents: 14
diff changeset
165 tree bitpos, tree bitsize, enum tree_code code, tree type)
kono
parents: 14
diff changeset
166 {
kono
parents: 14
diff changeset
167 tree stype = TREE_TYPE (type);
kono
parents: 14
diff changeset
168 tree cst_false = build_zero_cst (stype);
kono
parents: 14
diff changeset
169 tree cst_true = build_all_ones_cst (stype);
kono
parents: 14
diff changeset
170 tree cmp;
kono
parents: 14
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);
16
kono
parents: 14
diff changeset
174
kono
parents: 14
diff changeset
175 cmp = build2 (code, boolean_type_node, a, b);
kono
parents: 14
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,
16
kono
parents: 14
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,
16
kono
parents: 14
diff changeset
227 enum tree_code code ATTRIBUTE_UNUSED,
kono
parents: 14
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 {
16
kono
parents: 14
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);
16
kono
parents: 14
diff changeset
258 int delta = tree_to_uhwi (part_width)
kono
parents: 14
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;
16
kono
parents: 14
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
16
kono
parents: 14
diff changeset
263 if (types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
kono
parents: 14
diff changeset
264 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 14
diff changeset
265 "vector operation will be expanded piecewise");
kono
parents: 14
diff changeset
266 else
kono
parents: 14
diff changeset
267 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 14
diff changeset
268 "vector operation will be expanded in parallel");
kono
parents: 14
diff changeset
269
kono
parents: 14
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;
16
kono
parents: 14
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 {
16
kono
parents: 14
diff changeset
274 tree result = f (gsi, inner_type, a, b, index, part_width, code, type);
kono
parents: 14
diff changeset
275 constructor_elt ce = {NULL_TREE, result};
kono
parents: 14
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;
16
kono
parents: 14
diff changeset
291 int n_words = tree_to_uhwi (TYPE_SIZE_UNIT (type)) / UNITS_PER_WORD;
kono
parents: 14
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. */
16
kono
parents: 14
diff changeset
314 scalar_int_mode mode
kono
parents: 14
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);
16
kono
parents: 14
diff changeset
317 result = f (gsi, compute_type, a, b, NULL_TREE, NULL_TREE, code, type);
kono
parents: 14
diff changeset
318 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 14
diff changeset
319 "vector operation will be expanded with a "
kono
parents: 14
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
16
kono
parents: 14
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
16
kono
parents: 14
diff changeset
350 /* Try to expand vector comparison expression OP0 CODE OP1 by
kono
parents: 14
diff changeset
351 querying optab if the following expression:
kono
parents: 14
diff changeset
352 VEC_COND_EXPR< OP0 CODE OP1, {-1,...}, {0,...}>
kono
parents: 14
diff changeset
353 can be expanded. */
kono
parents: 14
diff changeset
354 static tree
kono
parents: 14
diff changeset
355 expand_vector_comparison (gimple_stmt_iterator *gsi, tree type, tree op0,
kono
parents: 14
diff changeset
356 tree op1, enum tree_code code)
kono
parents: 14
diff changeset
357 {
kono
parents: 14
diff changeset
358 tree t;
kono
parents: 14
diff changeset
359 if (!expand_vec_cmp_expr_p (TREE_TYPE (op0), type, code)
kono
parents: 14
diff changeset
360 && !expand_vec_cond_expr_p (type, TREE_TYPE (op0), code))
kono
parents: 14
diff changeset
361 t = expand_vector_piecewise (gsi, do_compare, type,
kono
parents: 14
diff changeset
362 TREE_TYPE (TREE_TYPE (op0)), op0, op1, code);
kono
parents: 14
diff changeset
363 else
kono
parents: 14
diff changeset
364 t = NULL_TREE;
kono
parents: 14
diff changeset
365
kono
parents: 14
diff changeset
366 return t;
kono
parents: 14
diff changeset
367 }
kono
parents: 14
diff changeset
368
kono
parents: 14
diff changeset
369 /* Helper function of expand_vector_divmod. Gimplify a RSHIFT_EXPR in type
kono
parents: 14
diff changeset
370 of OP0 with shift counts in SHIFTCNTS array and return the temporary holding
kono
parents: 14
diff changeset
371 the result if successful, otherwise return NULL_TREE. */
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
372 static tree
16
kono
parents: 14
diff changeset
373 add_rshift (gimple_stmt_iterator *gsi, tree type, tree op0, int *shiftcnts)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
374 {
16
kono
parents: 14
diff changeset
375 optab op;
kono
parents: 14
diff changeset
376 unsigned int i, nunits = TYPE_VECTOR_SUBPARTS (type);
kono
parents: 14
diff changeset
377 bool scalar_shift = true;
kono
parents: 14
diff changeset
378
kono
parents: 14
diff changeset
379 for (i = 1; i < nunits; i++)
kono
parents: 14
diff changeset
380 {
kono
parents: 14
diff changeset
381 if (shiftcnts[i] != shiftcnts[0])
kono
parents: 14
diff changeset
382 scalar_shift = false;
kono
parents: 14
diff changeset
383 }
kono
parents: 14
diff changeset
384
kono
parents: 14
diff changeset
385 if (scalar_shift && shiftcnts[0] == 0)
kono
parents: 14
diff changeset
386 return op0;
kono
parents: 14
diff changeset
387
kono
parents: 14
diff changeset
388 if (scalar_shift)
kono
parents: 14
diff changeset
389 {
kono
parents: 14
diff changeset
390 op = optab_for_tree_code (RSHIFT_EXPR, type, optab_scalar);
kono
parents: 14
diff changeset
391 if (op != unknown_optab
kono
parents: 14
diff changeset
392 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 14
diff changeset
393 return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0,
kono
parents: 14
diff changeset
394 build_int_cst (NULL_TREE, shiftcnts[0]));
kono
parents: 14
diff changeset
395 }
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
396
16
kono
parents: 14
diff changeset
397 op = optab_for_tree_code (RSHIFT_EXPR, type, optab_vector);
kono
parents: 14
diff changeset
398 if (op != unknown_optab
kono
parents: 14
diff changeset
399 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 14
diff changeset
400 {
kono
parents: 14
diff changeset
401 auto_vec<tree, 32> vec (nunits);
kono
parents: 14
diff changeset
402 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
403 vec.quick_push (build_int_cst (TREE_TYPE (type), shiftcnts[i]));
kono
parents: 14
diff changeset
404 return gimplify_build2 (gsi, RSHIFT_EXPR, type, op0,
kono
parents: 14
diff changeset
405 build_vector (type, vec));
kono
parents: 14
diff changeset
406 }
kono
parents: 14
diff changeset
407
kono
parents: 14
diff changeset
408 return NULL_TREE;
kono
parents: 14
diff changeset
409 }
kono
parents: 14
diff changeset
410
kono
parents: 14
diff changeset
411 /* Try to expand integer vector division by constant using
kono
parents: 14
diff changeset
412 widening multiply, shifts and additions. */
kono
parents: 14
diff changeset
413 static tree
kono
parents: 14
diff changeset
414 expand_vector_divmod (gimple_stmt_iterator *gsi, tree type, tree op0,
kono
parents: 14
diff changeset
415 tree op1, enum tree_code code)
kono
parents: 14
diff changeset
416 {
kono
parents: 14
diff changeset
417 bool use_pow2 = true;
kono
parents: 14
diff changeset
418 bool has_vector_shift = true;
kono
parents: 14
diff changeset
419 int mode = -1, this_mode;
kono
parents: 14
diff changeset
420 int pre_shift = -1, post_shift;
kono
parents: 14
diff changeset
421 unsigned int nunits = TYPE_VECTOR_SUBPARTS (type);
kono
parents: 14
diff changeset
422 int *shifts = XALLOCAVEC (int, nunits * 4);
kono
parents: 14
diff changeset
423 int *pre_shifts = shifts + nunits;
kono
parents: 14
diff changeset
424 int *post_shifts = pre_shifts + nunits;
kono
parents: 14
diff changeset
425 int *shift_temps = post_shifts + nunits;
kono
parents: 14
diff changeset
426 unsigned HOST_WIDE_INT *mulc = XALLOCAVEC (unsigned HOST_WIDE_INT, nunits);
kono
parents: 14
diff changeset
427 int prec = TYPE_PRECISION (TREE_TYPE (type));
kono
parents: 14
diff changeset
428 int dummy_int;
kono
parents: 14
diff changeset
429 unsigned int i;
kono
parents: 14
diff changeset
430 signop sign_p = TYPE_SIGN (TREE_TYPE (type));
kono
parents: 14
diff changeset
431 unsigned HOST_WIDE_INT mask = GET_MODE_MASK (TYPE_MODE (TREE_TYPE (type)));
kono
parents: 14
diff changeset
432 tree cur_op, mulcst, tem;
kono
parents: 14
diff changeset
433 optab op;
kono
parents: 14
diff changeset
434
kono
parents: 14
diff changeset
435 if (prec > HOST_BITS_PER_WIDE_INT)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
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: 11
diff changeset
437
16
kono
parents: 14
diff changeset
438 op = optab_for_tree_code (RSHIFT_EXPR, type, optab_vector);
kono
parents: 14
diff changeset
439 if (op == unknown_optab
kono
parents: 14
diff changeset
440 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 14
diff changeset
441 has_vector_shift = false;
kono
parents: 14
diff changeset
442
kono
parents: 14
diff changeset
443 /* Analysis phase. Determine if all op1 elements are either power
kono
parents: 14
diff changeset
444 of two and it is possible to expand it using shifts (or for remainder
kono
parents: 14
diff changeset
445 using masking). Additionally compute the multiplicative constants
kono
parents: 14
diff changeset
446 and pre and post shifts if the division is to be expanded using
kono
parents: 14
diff changeset
447 widening or high part multiplication plus shifts. */
kono
parents: 14
diff changeset
448 for (i = 0; i < nunits; i++)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
449 {
16
kono
parents: 14
diff changeset
450 tree cst = VECTOR_CST_ELT (op1, i);
kono
parents: 14
diff changeset
451 unsigned HOST_WIDE_INT ml;
kono
parents: 14
diff changeset
452
kono
parents: 14
diff changeset
453 if (TREE_CODE (cst) != INTEGER_CST || integer_zerop (cst))
kono
parents: 14
diff changeset
454 return NULL_TREE;
kono
parents: 14
diff changeset
455 pre_shifts[i] = 0;
kono
parents: 14
diff changeset
456 post_shifts[i] = 0;
kono
parents: 14
diff changeset
457 mulc[i] = 0;
kono
parents: 14
diff changeset
458 if (use_pow2
kono
parents: 14
diff changeset
459 && (!integer_pow2p (cst) || tree_int_cst_sgn (cst) != 1))
kono
parents: 14
diff changeset
460 use_pow2 = false;
kono
parents: 14
diff changeset
461 if (use_pow2)
kono
parents: 14
diff changeset
462 {
kono
parents: 14
diff changeset
463 shifts[i] = tree_log2 (cst);
kono
parents: 14
diff changeset
464 if (shifts[i] != shifts[0]
kono
parents: 14
diff changeset
465 && code == TRUNC_DIV_EXPR
kono
parents: 14
diff changeset
466 && !has_vector_shift)
kono
parents: 14
diff changeset
467 use_pow2 = false;
kono
parents: 14
diff changeset
468 }
kono
parents: 14
diff changeset
469 if (mode == -2)
kono
parents: 14
diff changeset
470 continue;
kono
parents: 14
diff changeset
471 if (sign_p == UNSIGNED)
kono
parents: 14
diff changeset
472 {
kono
parents: 14
diff changeset
473 unsigned HOST_WIDE_INT mh;
kono
parents: 14
diff changeset
474 unsigned HOST_WIDE_INT d = TREE_INT_CST_LOW (cst) & mask;
kono
parents: 14
diff changeset
475
kono
parents: 14
diff changeset
476 if (d >= (HOST_WIDE_INT_1U << (prec - 1)))
kono
parents: 14
diff changeset
477 /* FIXME: Can transform this into op0 >= op1 ? 1 : 0. */
kono
parents: 14
diff changeset
478 return NULL_TREE;
kono
parents: 14
diff changeset
479
kono
parents: 14
diff changeset
480 if (d <= 1)
kono
parents: 14
diff changeset
481 {
kono
parents: 14
diff changeset
482 mode = -2;
kono
parents: 14
diff changeset
483 continue;
kono
parents: 14
diff changeset
484 }
kono
parents: 14
diff changeset
485
kono
parents: 14
diff changeset
486 /* Find a suitable multiplier and right shift count
kono
parents: 14
diff changeset
487 instead of multiplying with D. */
kono
parents: 14
diff changeset
488 mh = choose_multiplier (d, prec, prec, &ml, &post_shift, &dummy_int);
kono
parents: 14
diff changeset
489
kono
parents: 14
diff changeset
490 /* If the suggested multiplier is more than SIZE bits, we can
kono
parents: 14
diff changeset
491 do better for even divisors, using an initial right shift. */
kono
parents: 14
diff changeset
492 if ((mh != 0 && (d & 1) == 0)
kono
parents: 14
diff changeset
493 || (!has_vector_shift && pre_shift != -1))
kono
parents: 14
diff changeset
494 {
kono
parents: 14
diff changeset
495 if (has_vector_shift)
kono
parents: 14
diff changeset
496 pre_shift = ctz_or_zero (d);
kono
parents: 14
diff changeset
497 else if (pre_shift == -1)
kono
parents: 14
diff changeset
498 {
kono
parents: 14
diff changeset
499 unsigned int j;
kono
parents: 14
diff changeset
500 for (j = 0; j < nunits; j++)
kono
parents: 14
diff changeset
501 {
kono
parents: 14
diff changeset
502 tree cst2 = VECTOR_CST_ELT (op1, j);
kono
parents: 14
diff changeset
503 unsigned HOST_WIDE_INT d2;
kono
parents: 14
diff changeset
504 int this_pre_shift;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
505
16
kono
parents: 14
diff changeset
506 if (!tree_fits_uhwi_p (cst2))
kono
parents: 14
diff changeset
507 return NULL_TREE;
kono
parents: 14
diff changeset
508 d2 = tree_to_uhwi (cst2) & mask;
kono
parents: 14
diff changeset
509 if (d2 == 0)
kono
parents: 14
diff changeset
510 return NULL_TREE;
kono
parents: 14
diff changeset
511 this_pre_shift = floor_log2 (d2 & -d2);
kono
parents: 14
diff changeset
512 if (pre_shift == -1 || this_pre_shift < pre_shift)
kono
parents: 14
diff changeset
513 pre_shift = this_pre_shift;
kono
parents: 14
diff changeset
514 }
kono
parents: 14
diff changeset
515 if (i != 0 && pre_shift != 0)
kono
parents: 14
diff changeset
516 {
kono
parents: 14
diff changeset
517 /* Restart. */
kono
parents: 14
diff changeset
518 i = -1U;
kono
parents: 14
diff changeset
519 mode = -1;
kono
parents: 14
diff changeset
520 continue;
kono
parents: 14
diff changeset
521 }
kono
parents: 14
diff changeset
522 }
kono
parents: 14
diff changeset
523 if (pre_shift != 0)
kono
parents: 14
diff changeset
524 {
kono
parents: 14
diff changeset
525 if ((d >> pre_shift) <= 1)
kono
parents: 14
diff changeset
526 {
kono
parents: 14
diff changeset
527 mode = -2;
kono
parents: 14
diff changeset
528 continue;
kono
parents: 14
diff changeset
529 }
kono
parents: 14
diff changeset
530 mh = choose_multiplier (d >> pre_shift, prec,
kono
parents: 14
diff changeset
531 prec - pre_shift,
kono
parents: 14
diff changeset
532 &ml, &post_shift, &dummy_int);
kono
parents: 14
diff changeset
533 gcc_assert (!mh);
kono
parents: 14
diff changeset
534 pre_shifts[i] = pre_shift;
kono
parents: 14
diff changeset
535 }
kono
parents: 14
diff changeset
536 }
kono
parents: 14
diff changeset
537 if (!mh)
kono
parents: 14
diff changeset
538 this_mode = 0;
kono
parents: 14
diff changeset
539 else
kono
parents: 14
diff changeset
540 this_mode = 1;
kono
parents: 14
diff changeset
541 }
kono
parents: 14
diff changeset
542 else
kono
parents: 14
diff changeset
543 {
kono
parents: 14
diff changeset
544 HOST_WIDE_INT d = TREE_INT_CST_LOW (cst);
kono
parents: 14
diff changeset
545 unsigned HOST_WIDE_INT abs_d;
kono
parents: 14
diff changeset
546
kono
parents: 14
diff changeset
547 if (d == -1)
kono
parents: 14
diff changeset
548 return NULL_TREE;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
549
16
kono
parents: 14
diff changeset
550 /* Since d might be INT_MIN, we have to cast to
kono
parents: 14
diff changeset
551 unsigned HOST_WIDE_INT before negating to avoid
kono
parents: 14
diff changeset
552 undefined signed overflow. */
kono
parents: 14
diff changeset
553 abs_d = (d >= 0
kono
parents: 14
diff changeset
554 ? (unsigned HOST_WIDE_INT) d
kono
parents: 14
diff changeset
555 : - (unsigned HOST_WIDE_INT) d);
kono
parents: 14
diff changeset
556
kono
parents: 14
diff changeset
557 /* n rem d = n rem -d */
kono
parents: 14
diff changeset
558 if (code == TRUNC_MOD_EXPR && d < 0)
kono
parents: 14
diff changeset
559 d = abs_d;
kono
parents: 14
diff changeset
560 else if (abs_d == HOST_WIDE_INT_1U << (prec - 1))
kono
parents: 14
diff changeset
561 {
kono
parents: 14
diff changeset
562 /* This case is not handled correctly below. */
kono
parents: 14
diff changeset
563 mode = -2;
kono
parents: 14
diff changeset
564 continue;
kono
parents: 14
diff changeset
565 }
kono
parents: 14
diff changeset
566 if (abs_d <= 1)
kono
parents: 14
diff changeset
567 {
kono
parents: 14
diff changeset
568 mode = -2;
kono
parents: 14
diff changeset
569 continue;
kono
parents: 14
diff changeset
570 }
kono
parents: 14
diff changeset
571
kono
parents: 14
diff changeset
572 choose_multiplier (abs_d, prec, prec - 1, &ml,
kono
parents: 14
diff changeset
573 &post_shift, &dummy_int);
kono
parents: 14
diff changeset
574 if (ml >= HOST_WIDE_INT_1U << (prec - 1))
kono
parents: 14
diff changeset
575 {
kono
parents: 14
diff changeset
576 this_mode = 4 + (d < 0);
kono
parents: 14
diff changeset
577 ml |= HOST_WIDE_INT_M1U << (prec - 1);
kono
parents: 14
diff changeset
578 }
kono
parents: 14
diff changeset
579 else
kono
parents: 14
diff changeset
580 this_mode = 2 + (d < 0);
kono
parents: 14
diff changeset
581 }
kono
parents: 14
diff changeset
582 mulc[i] = ml;
kono
parents: 14
diff changeset
583 post_shifts[i] = post_shift;
kono
parents: 14
diff changeset
584 if ((i && !has_vector_shift && post_shifts[0] != post_shift)
kono
parents: 14
diff changeset
585 || post_shift >= prec
kono
parents: 14
diff changeset
586 || pre_shifts[i] >= prec)
kono
parents: 14
diff changeset
587 this_mode = -2;
kono
parents: 14
diff changeset
588
kono
parents: 14
diff changeset
589 if (i == 0)
kono
parents: 14
diff changeset
590 mode = this_mode;
kono
parents: 14
diff changeset
591 else if (mode != this_mode)
kono
parents: 14
diff changeset
592 mode = -2;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
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: 11
diff changeset
594
16
kono
parents: 14
diff changeset
595 if (use_pow2)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
596 {
16
kono
parents: 14
diff changeset
597 tree addend = NULL_TREE;
kono
parents: 14
diff changeset
598 if (sign_p == SIGNED)
kono
parents: 14
diff changeset
599 {
kono
parents: 14
diff changeset
600 tree uns_type;
kono
parents: 14
diff changeset
601
kono
parents: 14
diff changeset
602 /* Both division and remainder sequences need
kono
parents: 14
diff changeset
603 op0 < 0 ? mask : 0 computed. It can be either computed as
kono
parents: 14
diff changeset
604 (type) (((uns_type) (op0 >> (prec - 1))) >> (prec - shifts[i]))
kono
parents: 14
diff changeset
605 if none of the shifts is 0, or as the conditional. */
kono
parents: 14
diff changeset
606 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
607 if (shifts[i] == 0)
kono
parents: 14
diff changeset
608 break;
kono
parents: 14
diff changeset
609 uns_type
kono
parents: 14
diff changeset
610 = build_vector_type (build_nonstandard_integer_type (prec, 1),
kono
parents: 14
diff changeset
611 nunits);
kono
parents: 14
diff changeset
612 if (i == nunits && TYPE_MODE (uns_type) == TYPE_MODE (type))
kono
parents: 14
diff changeset
613 {
kono
parents: 14
diff changeset
614 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
615 shift_temps[i] = prec - 1;
kono
parents: 14
diff changeset
616 cur_op = add_rshift (gsi, type, op0, shift_temps);
kono
parents: 14
diff changeset
617 if (cur_op != NULL_TREE)
kono
parents: 14
diff changeset
618 {
kono
parents: 14
diff changeset
619 cur_op = gimplify_build1 (gsi, VIEW_CONVERT_EXPR,
kono
parents: 14
diff changeset
620 uns_type, cur_op);
kono
parents: 14
diff changeset
621 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
622 shift_temps[i] = prec - shifts[i];
kono
parents: 14
diff changeset
623 cur_op = add_rshift (gsi, uns_type, cur_op, shift_temps);
kono
parents: 14
diff changeset
624 if (cur_op != NULL_TREE)
kono
parents: 14
diff changeset
625 addend = gimplify_build1 (gsi, VIEW_CONVERT_EXPR,
kono
parents: 14
diff changeset
626 type, cur_op);
kono
parents: 14
diff changeset
627 }
kono
parents: 14
diff changeset
628 }
kono
parents: 14
diff changeset
629 if (addend == NULL_TREE
kono
parents: 14
diff changeset
630 && expand_vec_cond_expr_p (type, type, LT_EXPR))
kono
parents: 14
diff changeset
631 {
kono
parents: 14
diff changeset
632 tree zero, cst, cond, mask_type;
kono
parents: 14
diff changeset
633 gimple *stmt;
kono
parents: 14
diff changeset
634
kono
parents: 14
diff changeset
635 mask_type = build_same_sized_truth_vector_type (type);
kono
parents: 14
diff changeset
636 zero = build_zero_cst (type);
kono
parents: 14
diff changeset
637 cond = build2 (LT_EXPR, mask_type, op0, zero);
kono
parents: 14
diff changeset
638 auto_vec<tree, 32> vec (nunits);
kono
parents: 14
diff changeset
639 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
640 vec.quick_push (build_int_cst (TREE_TYPE (type),
kono
parents: 14
diff changeset
641 (HOST_WIDE_INT_1U
kono
parents: 14
diff changeset
642 << shifts[i]) - 1));
kono
parents: 14
diff changeset
643 cst = build_vector (type, vec);
kono
parents: 14
diff changeset
644 addend = make_ssa_name (type);
kono
parents: 14
diff changeset
645 stmt = gimple_build_assign (addend, VEC_COND_EXPR, cond,
kono
parents: 14
diff changeset
646 cst, zero);
kono
parents: 14
diff changeset
647 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
kono
parents: 14
diff changeset
648 }
kono
parents: 14
diff changeset
649 }
kono
parents: 14
diff changeset
650 if (code == TRUNC_DIV_EXPR)
kono
parents: 14
diff changeset
651 {
kono
parents: 14
diff changeset
652 if (sign_p == UNSIGNED)
kono
parents: 14
diff changeset
653 {
kono
parents: 14
diff changeset
654 /* q = op0 >> shift; */
kono
parents: 14
diff changeset
655 cur_op = add_rshift (gsi, type, op0, shifts);
kono
parents: 14
diff changeset
656 if (cur_op != NULL_TREE)
kono
parents: 14
diff changeset
657 return cur_op;
kono
parents: 14
diff changeset
658 }
kono
parents: 14
diff changeset
659 else if (addend != NULL_TREE)
kono
parents: 14
diff changeset
660 {
kono
parents: 14
diff changeset
661 /* t1 = op0 + addend;
kono
parents: 14
diff changeset
662 q = t1 >> shift; */
kono
parents: 14
diff changeset
663 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
664 if (op != unknown_optab
kono
parents: 14
diff changeset
665 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 14
diff changeset
666 {
kono
parents: 14
diff changeset
667 cur_op = gimplify_build2 (gsi, PLUS_EXPR, type, op0, addend);
kono
parents: 14
diff changeset
668 cur_op = add_rshift (gsi, type, cur_op, shifts);
kono
parents: 14
diff changeset
669 if (cur_op != NULL_TREE)
kono
parents: 14
diff changeset
670 return cur_op;
kono
parents: 14
diff changeset
671 }
kono
parents: 14
diff changeset
672 }
kono
parents: 14
diff changeset
673 }
kono
parents: 14
diff changeset
674 else
kono
parents: 14
diff changeset
675 {
kono
parents: 14
diff changeset
676 tree mask;
kono
parents: 14
diff changeset
677 auto_vec<tree, 32> vec (nunits);
kono
parents: 14
diff changeset
678 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
679 vec.quick_push (build_int_cst (TREE_TYPE (type),
kono
parents: 14
diff changeset
680 (HOST_WIDE_INT_1U
kono
parents: 14
diff changeset
681 << shifts[i]) - 1));
kono
parents: 14
diff changeset
682 mask = build_vector (type, vec);
kono
parents: 14
diff changeset
683 op = optab_for_tree_code (BIT_AND_EXPR, type, optab_default);
kono
parents: 14
diff changeset
684 if (op != unknown_optab
kono
parents: 14
diff changeset
685 && optab_handler (op, TYPE_MODE (type)) != CODE_FOR_nothing)
kono
parents: 14
diff changeset
686 {
kono
parents: 14
diff changeset
687 if (sign_p == UNSIGNED)
kono
parents: 14
diff changeset
688 /* r = op0 & mask; */
kono
parents: 14
diff changeset
689 return gimplify_build2 (gsi, BIT_AND_EXPR, type, op0, mask);
kono
parents: 14
diff changeset
690 else if (addend != NULL_TREE)
kono
parents: 14
diff changeset
691 {
kono
parents: 14
diff changeset
692 /* t1 = op0 + addend;
kono
parents: 14
diff changeset
693 t2 = t1 & mask;
kono
parents: 14
diff changeset
694 r = t2 - addend; */
kono
parents: 14
diff changeset
695 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
696 if (op != unknown_optab
kono
parents: 14
diff changeset
697 && optab_handler (op, TYPE_MODE (type))
kono
parents: 14
diff changeset
698 != CODE_FOR_nothing)
kono
parents: 14
diff changeset
699 {
kono
parents: 14
diff changeset
700 cur_op = gimplify_build2 (gsi, PLUS_EXPR, type, op0,
kono
parents: 14
diff changeset
701 addend);
kono
parents: 14
diff changeset
702 cur_op = gimplify_build2 (gsi, BIT_AND_EXPR, type,
kono
parents: 14
diff changeset
703 cur_op, mask);
kono
parents: 14
diff changeset
704 op = optab_for_tree_code (MINUS_EXPR, type,
kono
parents: 14
diff changeset
705 optab_default);
kono
parents: 14
diff changeset
706 if (op != unknown_optab
kono
parents: 14
diff changeset
707 && optab_handler (op, TYPE_MODE (type))
kono
parents: 14
diff changeset
708 != CODE_FOR_nothing)
kono
parents: 14
diff changeset
709 return gimplify_build2 (gsi, MINUS_EXPR, type,
kono
parents: 14
diff changeset
710 cur_op, addend);
kono
parents: 14
diff changeset
711 }
kono
parents: 14
diff changeset
712 }
kono
parents: 14
diff changeset
713 }
kono
parents: 14
diff changeset
714 }
kono
parents: 14
diff changeset
715 }
kono
parents: 14
diff changeset
716
kono
parents: 14
diff changeset
717 if (mode == -2 || BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
kono
parents: 14
diff changeset
718 return NULL_TREE;
kono
parents: 14
diff changeset
719
kono
parents: 14
diff changeset
720 if (!can_mult_highpart_p (TYPE_MODE (type), TYPE_UNSIGNED (type)))
kono
parents: 14
diff changeset
721 return NULL_TREE;
kono
parents: 14
diff changeset
722
kono
parents: 14
diff changeset
723 cur_op = op0;
kono
parents: 14
diff changeset
724
kono
parents: 14
diff changeset
725 switch (mode)
kono
parents: 14
diff changeset
726 {
kono
parents: 14
diff changeset
727 case 0:
kono
parents: 14
diff changeset
728 gcc_assert (sign_p == UNSIGNED);
kono
parents: 14
diff changeset
729 /* t1 = oprnd0 >> pre_shift;
kono
parents: 14
diff changeset
730 t2 = t1 h* ml;
kono
parents: 14
diff changeset
731 q = t2 >> post_shift; */
kono
parents: 14
diff changeset
732 cur_op = add_rshift (gsi, type, cur_op, pre_shifts);
kono
parents: 14
diff changeset
733 if (cur_op == NULL_TREE)
kono
parents: 14
diff changeset
734 return NULL_TREE;
kono
parents: 14
diff changeset
735 break;
kono
parents: 14
diff changeset
736 case 1:
kono
parents: 14
diff changeset
737 gcc_assert (sign_p == UNSIGNED);
kono
parents: 14
diff changeset
738 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
739 {
kono
parents: 14
diff changeset
740 shift_temps[i] = 1;
kono
parents: 14
diff changeset
741 post_shifts[i]--;
kono
parents: 14
diff changeset
742 }
kono
parents: 14
diff changeset
743 break;
kono
parents: 14
diff changeset
744 case 2:
kono
parents: 14
diff changeset
745 case 3:
kono
parents: 14
diff changeset
746 case 4:
kono
parents: 14
diff changeset
747 case 5:
kono
parents: 14
diff changeset
748 gcc_assert (sign_p == SIGNED);
kono
parents: 14
diff changeset
749 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
750 shift_temps[i] = prec - 1;
kono
parents: 14
diff changeset
751 break;
kono
parents: 14
diff changeset
752 default:
kono
parents: 14
diff changeset
753 return NULL_TREE;
kono
parents: 14
diff changeset
754 }
kono
parents: 14
diff changeset
755
kono
parents: 14
diff changeset
756 auto_vec<tree, 32> vec (nunits);
kono
parents: 14
diff changeset
757 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
758 vec.quick_push (build_int_cst (TREE_TYPE (type), mulc[i]));
kono
parents: 14
diff changeset
759 mulcst = build_vector (type, vec);
kono
parents: 14
diff changeset
760
kono
parents: 14
diff changeset
761 cur_op = gimplify_build2 (gsi, MULT_HIGHPART_EXPR, type, cur_op, mulcst);
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
762
16
kono
parents: 14
diff changeset
763 switch (mode)
kono
parents: 14
diff changeset
764 {
kono
parents: 14
diff changeset
765 case 0:
kono
parents: 14
diff changeset
766 /* t1 = oprnd0 >> pre_shift;
kono
parents: 14
diff changeset
767 t2 = t1 h* ml;
kono
parents: 14
diff changeset
768 q = t2 >> post_shift; */
kono
parents: 14
diff changeset
769 cur_op = add_rshift (gsi, type, cur_op, post_shifts);
kono
parents: 14
diff changeset
770 break;
kono
parents: 14
diff changeset
771 case 1:
kono
parents: 14
diff changeset
772 /* t1 = oprnd0 h* ml;
kono
parents: 14
diff changeset
773 t2 = oprnd0 - t1;
kono
parents: 14
diff changeset
774 t3 = t2 >> 1;
kono
parents: 14
diff changeset
775 t4 = t1 + t3;
kono
parents: 14
diff changeset
776 q = t4 >> (post_shift - 1); */
kono
parents: 14
diff changeset
777 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
778 if (op == unknown_optab
kono
parents: 14
diff changeset
779 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 14
diff changeset
780 return NULL_TREE;
kono
parents: 14
diff changeset
781 tem = gimplify_build2 (gsi, MINUS_EXPR, type, op0, cur_op);
kono
parents: 14
diff changeset
782 tem = add_rshift (gsi, type, tem, shift_temps);
kono
parents: 14
diff changeset
783 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
784 if (op == unknown_optab
kono
parents: 14
diff changeset
785 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 14
diff changeset
786 return NULL_TREE;
kono
parents: 14
diff changeset
787 tem = gimplify_build2 (gsi, PLUS_EXPR, type, cur_op, tem);
kono
parents: 14
diff changeset
788 cur_op = add_rshift (gsi, type, tem, post_shifts);
kono
parents: 14
diff changeset
789 if (cur_op == NULL_TREE)
kono
parents: 14
diff changeset
790 return NULL_TREE;
kono
parents: 14
diff changeset
791 break;
kono
parents: 14
diff changeset
792 case 2:
kono
parents: 14
diff changeset
793 case 3:
kono
parents: 14
diff changeset
794 case 4:
kono
parents: 14
diff changeset
795 case 5:
kono
parents: 14
diff changeset
796 /* t1 = oprnd0 h* ml;
kono
parents: 14
diff changeset
797 t2 = t1; [ iff (mode & 2) != 0 ]
kono
parents: 14
diff changeset
798 t2 = t1 + oprnd0; [ iff (mode & 2) == 0 ]
kono
parents: 14
diff changeset
799 t3 = t2 >> post_shift;
kono
parents: 14
diff changeset
800 t4 = oprnd0 >> (prec - 1);
kono
parents: 14
diff changeset
801 q = t3 - t4; [ iff (mode & 1) == 0 ]
kono
parents: 14
diff changeset
802 q = t4 - t3; [ iff (mode & 1) != 0 ] */
kono
parents: 14
diff changeset
803 if ((mode & 2) == 0)
kono
parents: 14
diff changeset
804 {
kono
parents: 14
diff changeset
805 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
806 if (op == unknown_optab
kono
parents: 14
diff changeset
807 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
808 return NULL_TREE;
16
kono
parents: 14
diff changeset
809 cur_op = gimplify_build2 (gsi, PLUS_EXPR, type, cur_op, op0);
kono
parents: 14
diff changeset
810 }
kono
parents: 14
diff changeset
811 cur_op = add_rshift (gsi, type, cur_op, post_shifts);
kono
parents: 14
diff changeset
812 if (cur_op == NULL_TREE)
kono
parents: 14
diff changeset
813 return NULL_TREE;
kono
parents: 14
diff changeset
814 tem = add_rshift (gsi, type, op0, shift_temps);
kono
parents: 14
diff changeset
815 if (tem == NULL_TREE)
kono
parents: 14
diff changeset
816 return NULL_TREE;
kono
parents: 14
diff changeset
817 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
818 if (op == unknown_optab
kono
parents: 14
diff changeset
819 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
820 return NULL_TREE;
16
kono
parents: 14
diff changeset
821 if ((mode & 1) == 0)
kono
parents: 14
diff changeset
822 cur_op = gimplify_build2 (gsi, MINUS_EXPR, type, cur_op, tem);
kono
parents: 14
diff changeset
823 else
kono
parents: 14
diff changeset
824 cur_op = gimplify_build2 (gsi, MINUS_EXPR, type, tem, cur_op);
kono
parents: 14
diff changeset
825 break;
kono
parents: 14
diff changeset
826 default:
kono
parents: 14
diff changeset
827 gcc_unreachable ();
kono
parents: 14
diff changeset
828 }
kono
parents: 14
diff changeset
829
kono
parents: 14
diff changeset
830 if (code == TRUNC_DIV_EXPR)
kono
parents: 14
diff changeset
831 return cur_op;
kono
parents: 14
diff changeset
832
kono
parents: 14
diff changeset
833 /* We divided. Now finish by:
kono
parents: 14
diff changeset
834 t1 = q * oprnd1;
kono
parents: 14
diff changeset
835 r = oprnd0 - t1; */
kono
parents: 14
diff changeset
836 op = optab_for_tree_code (MULT_EXPR, type, optab_default);
kono
parents: 14
diff changeset
837 if (op == unknown_optab
kono
parents: 14
diff changeset
838 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 14
diff changeset
839 return NULL_TREE;
kono
parents: 14
diff changeset
840 tem = gimplify_build2 (gsi, MULT_EXPR, type, cur_op, op1);
kono
parents: 14
diff changeset
841 op = optab_for_tree_code (MINUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
842 if (op == unknown_optab
kono
parents: 14
diff changeset
843 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 14
diff changeset
844 return NULL_TREE;
kono
parents: 14
diff changeset
845 return gimplify_build2 (gsi, MINUS_EXPR, type, op0, tem);
kono
parents: 14
diff changeset
846 }
kono
parents: 14
diff changeset
847
kono
parents: 14
diff changeset
848 /* Expand a vector condition to scalars, by using many conditions
kono
parents: 14
diff changeset
849 on the vector's elements. */
kono
parents: 14
diff changeset
850 static void
kono
parents: 14
diff changeset
851 expand_vector_condition (gimple_stmt_iterator *gsi)
kono
parents: 14
diff changeset
852 {
kono
parents: 14
diff changeset
853 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
854 tree type = gimple_expr_type (stmt);
kono
parents: 14
diff changeset
855 tree a = gimple_assign_rhs1 (stmt);
kono
parents: 14
diff changeset
856 tree a1 = a;
kono
parents: 14
diff changeset
857 tree a2 = NULL_TREE;
kono
parents: 14
diff changeset
858 bool a_is_comparison = false;
kono
parents: 14
diff changeset
859 tree b = gimple_assign_rhs2 (stmt);
kono
parents: 14
diff changeset
860 tree c = gimple_assign_rhs3 (stmt);
kono
parents: 14
diff changeset
861 vec<constructor_elt, va_gc> *v;
kono
parents: 14
diff changeset
862 tree constr;
kono
parents: 14
diff changeset
863 tree inner_type = TREE_TYPE (type);
kono
parents: 14
diff changeset
864 tree cond_type = TREE_TYPE (TREE_TYPE (a));
kono
parents: 14
diff changeset
865 tree comp_inner_type = cond_type;
kono
parents: 14
diff changeset
866 tree width = TYPE_SIZE (inner_type);
kono
parents: 14
diff changeset
867 tree index = bitsize_int (0);
kono
parents: 14
diff changeset
868 tree comp_width = width;
kono
parents: 14
diff changeset
869 tree comp_index = index;
kono
parents: 14
diff changeset
870 int nunits = TYPE_VECTOR_SUBPARTS (type);
kono
parents: 14
diff changeset
871 int i;
kono
parents: 14
diff changeset
872 location_t loc = gimple_location (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
873
kono
parents: 14
diff changeset
874 if (!is_gimple_val (a))
kono
parents: 14
diff changeset
875 {
kono
parents: 14
diff changeset
876 gcc_assert (COMPARISON_CLASS_P (a));
kono
parents: 14
diff changeset
877 a_is_comparison = true;
kono
parents: 14
diff changeset
878 a1 = TREE_OPERAND (a, 0);
kono
parents: 14
diff changeset
879 a2 = TREE_OPERAND (a, 1);
kono
parents: 14
diff changeset
880 comp_inner_type = TREE_TYPE (TREE_TYPE (a1));
kono
parents: 14
diff changeset
881 comp_width = TYPE_SIZE (comp_inner_type);
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
882 }
16
kono
parents: 14
diff changeset
883
kono
parents: 14
diff changeset
884 if (expand_vec_cond_expr_p (type, TREE_TYPE (a1), TREE_CODE (a)))
kono
parents: 14
diff changeset
885 return;
kono
parents: 14
diff changeset
886
kono
parents: 14
diff changeset
887 /* Handle vector boolean types with bitmasks. If there is a comparison
kono
parents: 14
diff changeset
888 and we can expand the comparison into the vector boolean bitmask,
kono
parents: 14
diff changeset
889 or otherwise if it is compatible with type, we can transform
kono
parents: 14
diff changeset
890 vbfld_1 = x_2 < y_3 ? vbfld_4 : vbfld_5;
kono
parents: 14
diff changeset
891 into
kono
parents: 14
diff changeset
892 tmp_6 = x_2 < y_3;
kono
parents: 14
diff changeset
893 tmp_7 = tmp_6 & vbfld_4;
kono
parents: 14
diff changeset
894 tmp_8 = ~tmp_6;
kono
parents: 14
diff changeset
895 tmp_9 = tmp_8 & vbfld_5;
kono
parents: 14
diff changeset
896 vbfld_1 = tmp_7 | tmp_9;
kono
parents: 14
diff changeset
897 Similarly for vbfld_10 instead of x_2 < y_3. */
kono
parents: 14
diff changeset
898 if (VECTOR_BOOLEAN_TYPE_P (type)
kono
parents: 14
diff changeset
899 && SCALAR_INT_MODE_P (TYPE_MODE (type))
kono
parents: 14
diff changeset
900 && (GET_MODE_BITSIZE (TYPE_MODE (type))
kono
parents: 14
diff changeset
901 < (TYPE_VECTOR_SUBPARTS (type)
kono
parents: 14
diff changeset
902 * GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type)))))
kono
parents: 14
diff changeset
903 && (a_is_comparison
kono
parents: 14
diff changeset
904 ? useless_type_conversion_p (type, TREE_TYPE (a))
kono
parents: 14
diff changeset
905 : expand_vec_cmp_expr_p (TREE_TYPE (a1), type, TREE_CODE (a))))
kono
parents: 14
diff changeset
906 {
kono
parents: 14
diff changeset
907 if (a_is_comparison)
kono
parents: 14
diff changeset
908 a = gimplify_build2 (gsi, TREE_CODE (a), type, a1, a2);
kono
parents: 14
diff changeset
909 a1 = gimplify_build2 (gsi, BIT_AND_EXPR, type, a, b);
kono
parents: 14
diff changeset
910 a2 = gimplify_build1 (gsi, BIT_NOT_EXPR, type, a);
kono
parents: 14
diff changeset
911 a2 = gimplify_build2 (gsi, BIT_AND_EXPR, type, a2, c);
kono
parents: 14
diff changeset
912 a = gimplify_build2 (gsi, BIT_IOR_EXPR, type, a1, a2);
kono
parents: 14
diff changeset
913 gimple_assign_set_rhs_from_tree (gsi, a);
kono
parents: 14
diff changeset
914 update_stmt (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
915 return;
kono
parents: 14
diff changeset
916 }
kono
parents: 14
diff changeset
917
kono
parents: 14
diff changeset
918 /* TODO: try and find a smaller vector type. */
kono
parents: 14
diff changeset
919
kono
parents: 14
diff changeset
920 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 14
diff changeset
921 "vector condition will be expanded piecewise");
kono
parents: 14
diff changeset
922
kono
parents: 14
diff changeset
923 vec_alloc (v, nunits);
kono
parents: 14
diff changeset
924 for (i = 0; i < nunits; i++)
kono
parents: 14
diff changeset
925 {
kono
parents: 14
diff changeset
926 tree aa, result;
kono
parents: 14
diff changeset
927 tree bb = tree_vec_extract (gsi, inner_type, b, width, index);
kono
parents: 14
diff changeset
928 tree cc = tree_vec_extract (gsi, inner_type, c, width, index);
kono
parents: 14
diff changeset
929 if (a_is_comparison)
kono
parents: 14
diff changeset
930 {
kono
parents: 14
diff changeset
931 tree aa1 = tree_vec_extract (gsi, comp_inner_type, a1,
kono
parents: 14
diff changeset
932 comp_width, comp_index);
kono
parents: 14
diff changeset
933 tree aa2 = tree_vec_extract (gsi, comp_inner_type, a2,
kono
parents: 14
diff changeset
934 comp_width, comp_index);
kono
parents: 14
diff changeset
935 aa = fold_build2 (TREE_CODE (a), cond_type, aa1, aa2);
kono
parents: 14
diff changeset
936 }
kono
parents: 14
diff changeset
937 else
kono
parents: 14
diff changeset
938 aa = tree_vec_extract (gsi, cond_type, a, width, index);
kono
parents: 14
diff changeset
939 result = gimplify_build3 (gsi, COND_EXPR, inner_type, aa, bb, cc);
kono
parents: 14
diff changeset
940 constructor_elt ce = {NULL_TREE, result};
kono
parents: 14
diff changeset
941 v->quick_push (ce);
kono
parents: 14
diff changeset
942 index = int_const_binop (PLUS_EXPR, index, width);
kono
parents: 14
diff changeset
943 if (width == comp_width)
kono
parents: 14
diff changeset
944 comp_index = index;
kono
parents: 14
diff changeset
945 else
kono
parents: 14
diff changeset
946 comp_index = int_const_binop (PLUS_EXPR, comp_index, comp_width);
kono
parents: 14
diff changeset
947 }
kono
parents: 14
diff changeset
948
kono
parents: 14
diff changeset
949 constr = build_constructor (type, v);
kono
parents: 14
diff changeset
950 gimple_assign_set_rhs_from_tree (gsi, constr);
kono
parents: 14
diff changeset
951 update_stmt (gsi_stmt (*gsi));
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
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: 11
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,
16
kono
parents: 14
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 {
16
kono
parents: 14
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:
16
kono
parents: 14
diff changeset
973 if (ANY_INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_TRAPS (type))
kono
parents: 14
diff changeset
974 return expand_vector_addition (gsi, do_binop, do_plus_minus, type,
kono
parents: 14
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:
16
kono
parents: 14
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),
16
kono
parents: 14
diff changeset
996 NULL_TREE, code);
kono
parents: 14
diff changeset
997 case EQ_EXPR:
kono
parents: 14
diff changeset
998 case NE_EXPR:
kono
parents: 14
diff changeset
999 case GT_EXPR:
kono
parents: 14
diff changeset
1000 case LT_EXPR:
kono
parents: 14
diff changeset
1001 case GE_EXPR:
kono
parents: 14
diff changeset
1002 case LE_EXPR:
kono
parents: 14
diff changeset
1003 case UNEQ_EXPR:
kono
parents: 14
diff changeset
1004 case UNGT_EXPR:
kono
parents: 14
diff changeset
1005 case UNLT_EXPR:
kono
parents: 14
diff changeset
1006 case UNGE_EXPR:
kono
parents: 14
diff changeset
1007 case UNLE_EXPR:
kono
parents: 14
diff changeset
1008 case LTGT_EXPR:
kono
parents: 14
diff changeset
1009 case ORDERED_EXPR:
kono
parents: 14
diff changeset
1010 case UNORDERED_EXPR:
kono
parents: 14
diff changeset
1011 {
kono
parents: 14
diff changeset
1012 tree rhs1 = gimple_assign_rhs1 (assign);
kono
parents: 14
diff changeset
1013 tree rhs2 = gimple_assign_rhs2 (assign);
kono
parents: 14
diff changeset
1014
kono
parents: 14
diff changeset
1015 return expand_vector_comparison (gsi, type, rhs1, rhs2, code);
kono
parents: 14
diff changeset
1016 }
kono
parents: 14
diff changeset
1017
kono
parents: 14
diff changeset
1018 case TRUNC_DIV_EXPR:
kono
parents: 14
diff changeset
1019 case TRUNC_MOD_EXPR:
kono
parents: 14
diff changeset
1020 {
kono
parents: 14
diff changeset
1021 tree rhs1 = gimple_assign_rhs1 (assign);
kono
parents: 14
diff changeset
1022 tree rhs2 = gimple_assign_rhs2 (assign);
kono
parents: 14
diff changeset
1023 tree ret;
kono
parents: 14
diff changeset
1024
kono
parents: 14
diff changeset
1025 if (!optimize
kono
parents: 14
diff changeset
1026 || !VECTOR_INTEGER_TYPE_P (type)
kono
parents: 14
diff changeset
1027 || TREE_CODE (rhs2) != VECTOR_CST
kono
parents: 14
diff changeset
1028 || !VECTOR_MODE_P (TYPE_MODE (type)))
kono
parents: 14
diff changeset
1029 break;
kono
parents: 14
diff changeset
1030
kono
parents: 14
diff changeset
1031 ret = expand_vector_divmod (gsi, type, rhs1, rhs2, code);
kono
parents: 14
diff changeset
1032 if (ret != NULL_TREE)
kono
parents: 14
diff changeset
1033 return ret;
kono
parents: 14
diff changeset
1034 break;
kono
parents: 14
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 }
16
kono
parents: 14
diff changeset
1050
kono
parents: 14
diff changeset
1051 /* Try to optimize
kono
parents: 14
diff changeset
1052 a_5 = { b_7, b_7 + 3, b_7 + 6, b_7 + 9 };
kono
parents: 14
diff changeset
1053 style stmts into:
kono
parents: 14
diff changeset
1054 _9 = { b_7, b_7, b_7, b_7 };
kono
parents: 14
diff changeset
1055 a_5 = _9 + { 0, 3, 6, 9 };
kono
parents: 14
diff changeset
1056 because vector splat operation is usually more efficient
kono
parents: 14
diff changeset
1057 than piecewise initialization of the vector. */
kono
parents: 14
diff changeset
1058
kono
parents: 14
diff changeset
1059 static void
kono
parents: 14
diff changeset
1060 optimize_vector_constructor (gimple_stmt_iterator *gsi)
kono
parents: 14
diff changeset
1061 {
kono
parents: 14
diff changeset
1062 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
1063 tree lhs = gimple_assign_lhs (stmt);
kono
parents: 14
diff changeset
1064 tree rhs = gimple_assign_rhs1 (stmt);
kono
parents: 14
diff changeset
1065 tree type = TREE_TYPE (rhs);
kono
parents: 14
diff changeset
1066 unsigned int i, j, nelts = TYPE_VECTOR_SUBPARTS (type);
kono
parents: 14
diff changeset
1067 bool all_same = true;
kono
parents: 14
diff changeset
1068 constructor_elt *elt;
kono
parents: 14
diff changeset
1069 gimple *g;
kono
parents: 14
diff changeset
1070 tree base = NULL_TREE;
kono
parents: 14
diff changeset
1071 optab op;
kono
parents: 14
diff changeset
1072
kono
parents: 14
diff changeset
1073 if (nelts <= 2 || CONSTRUCTOR_NELTS (rhs) != nelts)
kono
parents: 14
diff changeset
1074 return;
kono
parents: 14
diff changeset
1075 op = optab_for_tree_code (PLUS_EXPR, type, optab_default);
kono
parents: 14
diff changeset
1076 if (op == unknown_optab
kono
parents: 14
diff changeset
1077 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing)
kono
parents: 14
diff changeset
1078 return;
kono
parents: 14
diff changeset
1079 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (rhs), i, elt)
kono
parents: 14
diff changeset
1080 if (TREE_CODE (elt->value) != SSA_NAME
kono
parents: 14
diff changeset
1081 || TREE_CODE (TREE_TYPE (elt->value)) == VECTOR_TYPE)
kono
parents: 14
diff changeset
1082 return;
kono
parents: 14
diff changeset
1083 else
kono
parents: 14
diff changeset
1084 {
kono
parents: 14
diff changeset
1085 tree this_base = elt->value;
kono
parents: 14
diff changeset
1086 if (this_base != CONSTRUCTOR_ELT (rhs, 0)->value)
kono
parents: 14
diff changeset
1087 all_same = false;
kono
parents: 14
diff changeset
1088 for (j = 0; j < nelts + 1; j++)
kono
parents: 14
diff changeset
1089 {
kono
parents: 14
diff changeset
1090 g = SSA_NAME_DEF_STMT (this_base);
kono
parents: 14
diff changeset
1091 if (is_gimple_assign (g)
kono
parents: 14
diff changeset
1092 && gimple_assign_rhs_code (g) == PLUS_EXPR
kono
parents: 14
diff changeset
1093 && TREE_CODE (gimple_assign_rhs2 (g)) == INTEGER_CST
kono
parents: 14
diff changeset
1094 && TREE_CODE (gimple_assign_rhs1 (g)) == SSA_NAME
kono
parents: 14
diff changeset
1095 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (gimple_assign_rhs1 (g)))
kono
parents: 14
diff changeset
1096 this_base = gimple_assign_rhs1 (g);
kono
parents: 14
diff changeset
1097 else
kono
parents: 14
diff changeset
1098 break;
kono
parents: 14
diff changeset
1099 }
kono
parents: 14
diff changeset
1100 if (i == 0)
kono
parents: 14
diff changeset
1101 base = this_base;
kono
parents: 14
diff changeset
1102 else if (this_base != base)
kono
parents: 14
diff changeset
1103 return;
kono
parents: 14
diff changeset
1104 }
kono
parents: 14
diff changeset
1105 if (all_same)
kono
parents: 14
diff changeset
1106 return;
kono
parents: 14
diff changeset
1107 auto_vec<tree, 32> cst (nelts);
kono
parents: 14
diff changeset
1108 for (i = 0; i < nelts; i++)
kono
parents: 14
diff changeset
1109 {
kono
parents: 14
diff changeset
1110 tree this_base = CONSTRUCTOR_ELT (rhs, i)->value;
kono
parents: 14
diff changeset
1111 tree elt = build_zero_cst (TREE_TYPE (base));
kono
parents: 14
diff changeset
1112 while (this_base != base)
kono
parents: 14
diff changeset
1113 {
kono
parents: 14
diff changeset
1114 g = SSA_NAME_DEF_STMT (this_base);
kono
parents: 14
diff changeset
1115 elt = fold_binary (PLUS_EXPR, TREE_TYPE (base),
kono
parents: 14
diff changeset
1116 elt, gimple_assign_rhs2 (g));
kono
parents: 14
diff changeset
1117 if (elt == NULL_TREE
kono
parents: 14
diff changeset
1118 || TREE_CODE (elt) != INTEGER_CST
kono
parents: 14
diff changeset
1119 || TREE_OVERFLOW (elt))
kono
parents: 14
diff changeset
1120 return;
kono
parents: 14
diff changeset
1121 this_base = gimple_assign_rhs1 (g);
kono
parents: 14
diff changeset
1122 }
kono
parents: 14
diff changeset
1123 cst.quick_push (elt);
kono
parents: 14
diff changeset
1124 }
kono
parents: 14
diff changeset
1125 for (i = 0; i < nelts; i++)
kono
parents: 14
diff changeset
1126 CONSTRUCTOR_ELT (rhs, i)->value = base;
kono
parents: 14
diff changeset
1127 g = gimple_build_assign (make_ssa_name (type), rhs);
kono
parents: 14
diff changeset
1128 gsi_insert_before (gsi, g, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1129 g = gimple_build_assign (lhs, PLUS_EXPR, gimple_assign_lhs (g),
kono
parents: 14
diff changeset
1130 build_vector (type, cst));
kono
parents: 14
diff changeset
1131 gsi_replace (gsi, g, false);
kono
parents: 14
diff changeset
1132 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133
16
kono
parents: 14
diff changeset
1134 /* Return a type for the widest vector mode whose components are of type
kono
parents: 14
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
16
kono
parents: 14
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 {
16
kono
parents: 14
diff changeset
1140 machine_mode inner_mode = TYPE_MODE (type);
kono
parents: 14
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
16
kono
parents: 14
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
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
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
16
kono
parents: 14
diff changeset
1166 return build_vector_type_for_mode (type, best_mode);
kono
parents: 14
diff changeset
1167 }
kono
parents: 14
diff changeset
1168
kono
parents: 14
diff changeset
1169
kono
parents: 14
diff changeset
1170 /* Build a reference to the element of the vector VECT. Function
kono
parents: 14
diff changeset
1171 returns either the element itself, either BIT_FIELD_REF, or an
kono
parents: 14
diff changeset
1172 ARRAY_REF expression.
kono
parents: 14
diff changeset
1173
kono
parents: 14
diff changeset
1174 GSI is required to insert temporary variables while building a
kono
parents: 14
diff changeset
1175 refernece to the element of the vector VECT.
kono
parents: 14
diff changeset
1176
kono
parents: 14
diff changeset
1177 PTMPVEC is a pointer to the temporary variable for caching
kono
parents: 14
diff changeset
1178 purposes. In case when PTMPVEC is NULL new temporary variable
kono
parents: 14
diff changeset
1179 will be created. */
kono
parents: 14
diff changeset
1180 static tree
kono
parents: 14
diff changeset
1181 vector_element (gimple_stmt_iterator *gsi, tree vect, tree idx, tree *ptmpvec)
kono
parents: 14
diff changeset
1182 {
kono
parents: 14
diff changeset
1183 tree vect_type, vect_elt_type;
kono
parents: 14
diff changeset
1184 gimple *asgn;
kono
parents: 14
diff changeset
1185 tree tmpvec;
kono
parents: 14
diff changeset
1186 tree arraytype;
kono
parents: 14
diff changeset
1187 bool need_asgn = true;
kono
parents: 14
diff changeset
1188 unsigned int elements;
kono
parents: 14
diff changeset
1189
kono
parents: 14
diff changeset
1190 vect_type = TREE_TYPE (vect);
kono
parents: 14
diff changeset
1191 vect_elt_type = TREE_TYPE (vect_type);
kono
parents: 14
diff changeset
1192 elements = TYPE_VECTOR_SUBPARTS (vect_type);
kono
parents: 14
diff changeset
1193
kono
parents: 14
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 {
16
kono
parents: 14
diff changeset
1196 unsigned HOST_WIDE_INT index;
kono
parents: 14
diff changeset
1197
kono
parents: 14
diff changeset
1198 /* Given that we're about to compute a binary modulus,
kono
parents: 14
diff changeset
1199 we don't care about the high bits of the value. */
kono
parents: 14
diff changeset
1200 index = TREE_INT_CST_LOW (idx);
kono
parents: 14
diff changeset
1201 if (!tree_fits_uhwi_p (idx) || index >= elements)
kono
parents: 14
diff changeset
1202 {
kono
parents: 14
diff changeset
1203 index &= elements - 1;
kono
parents: 14
diff changeset
1204 idx = build_int_cst (TREE_TYPE (idx), index);
kono
parents: 14
diff changeset
1205 }
kono
parents: 14
diff changeset
1206
kono
parents: 14
diff changeset
1207 /* When lowering a vector statement sequence do some easy
kono
parents: 14
diff changeset
1208 simplification by looking through intermediate vector results. */
kono
parents: 14
diff changeset
1209 if (TREE_CODE (vect) == SSA_NAME)
kono
parents: 14
diff changeset
1210 {
kono
parents: 14
diff changeset
1211 gimple *def_stmt = SSA_NAME_DEF_STMT (vect);
kono
parents: 14
diff changeset
1212 if (is_gimple_assign (def_stmt)
kono
parents: 14
diff changeset
1213 && (gimple_assign_rhs_code (def_stmt) == VECTOR_CST
kono
parents: 14
diff changeset
1214 || gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR))
kono
parents: 14
diff changeset
1215 vect = gimple_assign_rhs1 (def_stmt);
kono
parents: 14
diff changeset
1216 }
kono
parents: 14
diff changeset
1217
kono
parents: 14
diff changeset
1218 if (TREE_CODE (vect) == VECTOR_CST)
kono
parents: 14
diff changeset
1219 return VECTOR_CST_ELT (vect, index);
kono
parents: 14
diff changeset
1220 else if (TREE_CODE (vect) == CONSTRUCTOR
kono
parents: 14
diff changeset
1221 && (CONSTRUCTOR_NELTS (vect) == 0
kono
parents: 14
diff changeset
1222 || TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (vect, 0)->value))
kono
parents: 14
diff changeset
1223 != VECTOR_TYPE))
kono
parents: 14
diff changeset
1224 {
kono
parents: 14
diff changeset
1225 if (index < CONSTRUCTOR_NELTS (vect))
kono
parents: 14
diff changeset
1226 return CONSTRUCTOR_ELT (vect, index)->value;
kono
parents: 14
diff changeset
1227 return build_zero_cst (vect_elt_type);
kono
parents: 14
diff changeset
1228 }
kono
parents: 14
diff changeset
1229 else
kono
parents: 14
diff changeset
1230 {
kono
parents: 14
diff changeset
1231 tree size = TYPE_SIZE (vect_elt_type);
kono
parents: 14
diff changeset
1232 tree pos = fold_build2 (MULT_EXPR, bitsizetype, bitsize_int (index),
kono
parents: 14
diff changeset
1233 size);
kono
parents: 14
diff changeset
1234 return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
kono
parents: 14
diff changeset
1235 }
kono
parents: 14
diff changeset
1236 }
kono
parents: 14
diff changeset
1237
kono
parents: 14
diff changeset
1238 if (!ptmpvec)
kono
parents: 14
diff changeset
1239 tmpvec = create_tmp_var (vect_type, "vectmp");
kono
parents: 14
diff changeset
1240 else if (!*ptmpvec)
kono
parents: 14
diff changeset
1241 tmpvec = *ptmpvec = create_tmp_var (vect_type, "vectmp");
kono
parents: 14
diff changeset
1242 else
kono
parents: 14
diff changeset
1243 {
kono
parents: 14
diff changeset
1244 tmpvec = *ptmpvec;
kono
parents: 14
diff changeset
1245 need_asgn = false;
kono
parents: 14
diff changeset
1246 }
kono
parents: 14
diff changeset
1247
kono
parents: 14
diff changeset
1248 if (need_asgn)
kono
parents: 14
diff changeset
1249 {
kono
parents: 14
diff changeset
1250 TREE_ADDRESSABLE (tmpvec) = 1;
kono
parents: 14
diff changeset
1251 asgn = gimple_build_assign (tmpvec, vect);
kono
parents: 14
diff changeset
1252 gsi_insert_before (gsi, asgn, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1253 }
kono
parents: 14
diff changeset
1254
kono
parents: 14
diff changeset
1255 arraytype = build_array_type_nelts (vect_elt_type, elements);
kono
parents: 14
diff changeset
1256 return build4 (ARRAY_REF, vect_elt_type,
kono
parents: 14
diff changeset
1257 build1 (VIEW_CONVERT_EXPR, arraytype, tmpvec),
kono
parents: 14
diff changeset
1258 idx, NULL_TREE, NULL_TREE);
kono
parents: 14
diff changeset
1259 }
kono
parents: 14
diff changeset
1260
kono
parents: 14
diff changeset
1261 /* Check if VEC_PERM_EXPR within the given setting is supported
kono
parents: 14
diff changeset
1262 by hardware, or lower it piecewise.
kono
parents: 14
diff changeset
1263
kono
parents: 14
diff changeset
1264 When VEC_PERM_EXPR has the same first and second operands:
kono
parents: 14
diff changeset
1265 VEC_PERM_EXPR <v0, v0, mask> the lowered version would be
kono
parents: 14
diff changeset
1266 {v0[mask[0]], v0[mask[1]], ...}
kono
parents: 14
diff changeset
1267 MASK and V0 must have the same number of elements.
kono
parents: 14
diff changeset
1268
kono
parents: 14
diff changeset
1269 Otherwise VEC_PERM_EXPR <v0, v1, mask> is lowered to
kono
parents: 14
diff changeset
1270 {mask[0] < len(v0) ? v0[mask[0]] : v1[mask[0]], ...}
kono
parents: 14
diff changeset
1271 V0 and V1 must have the same type. MASK, V0, V1 must have the
kono
parents: 14
diff changeset
1272 same number of arguments. */
kono
parents: 14
diff changeset
1273
kono
parents: 14
diff changeset
1274 static void
kono
parents: 14
diff changeset
1275 lower_vec_perm (gimple_stmt_iterator *gsi)
kono
parents: 14
diff changeset
1276 {
kono
parents: 14
diff changeset
1277 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
1278 tree mask = gimple_assign_rhs3 (stmt);
kono
parents: 14
diff changeset
1279 tree vec0 = gimple_assign_rhs1 (stmt);
kono
parents: 14
diff changeset
1280 tree vec1 = gimple_assign_rhs2 (stmt);
kono
parents: 14
diff changeset
1281 tree vect_type = TREE_TYPE (vec0);
kono
parents: 14
diff changeset
1282 tree mask_type = TREE_TYPE (mask);
kono
parents: 14
diff changeset
1283 tree vect_elt_type = TREE_TYPE (vect_type);
kono
parents: 14
diff changeset
1284 tree mask_elt_type = TREE_TYPE (mask_type);
kono
parents: 14
diff changeset
1285 unsigned int elements = TYPE_VECTOR_SUBPARTS (vect_type);
kono
parents: 14
diff changeset
1286 vec<constructor_elt, va_gc> *v;
kono
parents: 14
diff changeset
1287 tree constr, t, si, i_val;
kono
parents: 14
diff changeset
1288 tree vec0tmp = NULL_TREE, vec1tmp = NULL_TREE, masktmp = NULL_TREE;
kono
parents: 14
diff changeset
1289 bool two_operand_p = !operand_equal_p (vec0, vec1, 0);
kono
parents: 14
diff changeset
1290 location_t loc = gimple_location (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
1291 unsigned i;
kono
parents: 14
diff changeset
1292
kono
parents: 14
diff changeset
1293 if (TREE_CODE (mask) == SSA_NAME)
kono
parents: 14
diff changeset
1294 {
kono
parents: 14
diff changeset
1295 gimple *def_stmt = SSA_NAME_DEF_STMT (mask);
kono
parents: 14
diff changeset
1296 if (is_gimple_assign (def_stmt)
kono
parents: 14
diff changeset
1297 && gimple_assign_rhs_code (def_stmt) == VECTOR_CST)
kono
parents: 14
diff changeset
1298 mask = gimple_assign_rhs1 (def_stmt);
kono
parents: 14
diff changeset
1299 }
kono
parents: 14
diff changeset
1300
kono
parents: 14
diff changeset
1301 if (TREE_CODE (mask) == VECTOR_CST)
kono
parents: 14
diff changeset
1302 {
kono
parents: 14
diff changeset
1303 auto_vec_perm_indices sel_int (elements);
kono
parents: 14
diff changeset
1304
kono
parents: 14
diff changeset
1305 for (i = 0; i < elements; ++i)
kono
parents: 14
diff changeset
1306 sel_int.quick_push (TREE_INT_CST_LOW (VECTOR_CST_ELT (mask, i))
kono
parents: 14
diff changeset
1307 & (2 * elements - 1));
kono
parents: 14
diff changeset
1308
kono
parents: 14
diff changeset
1309 if (can_vec_perm_p (TYPE_MODE (vect_type), false, &sel_int))
kono
parents: 14
diff changeset
1310 {
kono
parents: 14
diff changeset
1311 gimple_assign_set_rhs3 (stmt, mask);
kono
parents: 14
diff changeset
1312 update_stmt (stmt);
kono
parents: 14
diff changeset
1313 return;
kono
parents: 14
diff changeset
1314 }
kono
parents: 14
diff changeset
1315 /* Also detect vec_shr pattern - VEC_PERM_EXPR with zero
kono
parents: 14
diff changeset
1316 vector as VEC1 and a right element shift MASK. */
kono
parents: 14
diff changeset
1317 if (optab_handler (vec_shr_optab, TYPE_MODE (vect_type))
kono
parents: 14
diff changeset
1318 != CODE_FOR_nothing
kono
parents: 14
diff changeset
1319 && TREE_CODE (vec1) == VECTOR_CST
kono
parents: 14
diff changeset
1320 && initializer_zerop (vec1)
kono
parents: 14
diff changeset
1321 && sel_int[0]
kono
parents: 14
diff changeset
1322 && sel_int[0] < elements)
kono
parents: 14
diff changeset
1323 {
kono
parents: 14
diff changeset
1324 for (i = 1; i < elements; ++i)
kono
parents: 14
diff changeset
1325 {
kono
parents: 14
diff changeset
1326 unsigned int expected = i + sel_int[0];
kono
parents: 14
diff changeset
1327 /* Indices into the second vector are all equivalent. */
kono
parents: 14
diff changeset
1328 if (MIN (elements, (unsigned) sel_int[i])
kono
parents: 14
diff changeset
1329 != MIN (elements, expected))
kono
parents: 14
diff changeset
1330 break;
kono
parents: 14
diff changeset
1331 }
kono
parents: 14
diff changeset
1332 if (i == elements)
kono
parents: 14
diff changeset
1333 {
kono
parents: 14
diff changeset
1334 gimple_assign_set_rhs3 (stmt, mask);
kono
parents: 14
diff changeset
1335 update_stmt (stmt);
kono
parents: 14
diff changeset
1336 return;
kono
parents: 14
diff changeset
1337 }
kono
parents: 14
diff changeset
1338 }
kono
parents: 14
diff changeset
1339 }
kono
parents: 14
diff changeset
1340 else if (can_vec_perm_p (TYPE_MODE (vect_type), true, NULL))
kono
parents: 14
diff changeset
1341 return;
kono
parents: 14
diff changeset
1342
kono
parents: 14
diff changeset
1343 warning_at (loc, OPT_Wvector_operation_performance,
kono
parents: 14
diff changeset
1344 "vector shuffling operation will be expanded piecewise");
kono
parents: 14
diff changeset
1345
kono
parents: 14
diff changeset
1346 vec_alloc (v, elements);
kono
parents: 14
diff changeset
1347 for (i = 0; i < elements; i++)
kono
parents: 14
diff changeset
1348 {
kono
parents: 14
diff changeset
1349 si = size_int (i);
kono
parents: 14
diff changeset
1350 i_val = vector_element (gsi, mask, si, &masktmp);
kono
parents: 14
diff changeset
1351
kono
parents: 14
diff changeset
1352 if (TREE_CODE (i_val) == INTEGER_CST)
kono
parents: 14
diff changeset
1353 {
kono
parents: 14
diff changeset
1354 unsigned HOST_WIDE_INT index;
kono
parents: 14
diff changeset
1355
kono
parents: 14
diff changeset
1356 index = TREE_INT_CST_LOW (i_val);
kono
parents: 14
diff changeset
1357 if (!tree_fits_uhwi_p (i_val) || index >= elements)
kono
parents: 14
diff changeset
1358 i_val = build_int_cst (mask_elt_type, index & (elements - 1));
kono
parents: 14
diff changeset
1359
kono
parents: 14
diff changeset
1360 if (two_operand_p && (index & elements) != 0)
kono
parents: 14
diff changeset
1361 t = vector_element (gsi, vec1, i_val, &vec1tmp);
kono
parents: 14
diff changeset
1362 else
kono
parents: 14
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
16
kono
parents: 14
diff changeset
1365 t = force_gimple_operand_gsi (gsi, t, true, NULL_TREE,
kono
parents: 14
diff changeset
1366 true, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1367 }
kono
parents: 14
diff changeset
1368 else
kono
parents: 14
diff changeset
1369 {
kono
parents: 14
diff changeset
1370 tree cond = NULL_TREE, v0_val;
kono
parents: 14
diff changeset
1371
kono
parents: 14
diff changeset
1372 if (two_operand_p)
kono
parents: 14
diff changeset
1373 {
kono
parents: 14
diff changeset
1374 cond = fold_build2 (BIT_AND_EXPR, mask_elt_type, i_val,
kono
parents: 14
diff changeset
1375 build_int_cst (mask_elt_type, elements));
kono
parents: 14
diff changeset
1376 cond = force_gimple_operand_gsi (gsi, cond, true, NULL_TREE,
kono
parents: 14
diff changeset
1377 true, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1378 }
kono
parents: 14
diff changeset
1379
kono
parents: 14
diff changeset
1380 i_val = fold_build2 (BIT_AND_EXPR, mask_elt_type, i_val,
kono
parents: 14
diff changeset
1381 build_int_cst (mask_elt_type, elements - 1));
kono
parents: 14
diff changeset
1382 i_val = force_gimple_operand_gsi (gsi, i_val, true, NULL_TREE,
kono
parents: 14
diff changeset
1383 true, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1384
kono
parents: 14
diff changeset
1385 v0_val = vector_element (gsi, vec0, i_val, &vec0tmp);
kono
parents: 14
diff changeset
1386 v0_val = force_gimple_operand_gsi (gsi, v0_val, true, NULL_TREE,
kono
parents: 14
diff changeset
1387 true, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1388
kono
parents: 14
diff changeset
1389 if (two_operand_p)
kono
parents: 14
diff changeset
1390 {
kono
parents: 14
diff changeset
1391 tree v1_val;
kono
parents: 14
diff changeset
1392
kono
parents: 14
diff changeset
1393 v1_val = vector_element (gsi, vec1, i_val, &vec1tmp);
kono
parents: 14
diff changeset
1394 v1_val = force_gimple_operand_gsi (gsi, v1_val, true, NULL_TREE,
kono
parents: 14
diff changeset
1395 true, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1396
kono
parents: 14
diff changeset
1397 cond = fold_build2 (EQ_EXPR, boolean_type_node,
kono
parents: 14
diff changeset
1398 cond, build_zero_cst (mask_elt_type));
kono
parents: 14
diff changeset
1399 cond = fold_build3 (COND_EXPR, vect_elt_type,
kono
parents: 14
diff changeset
1400 cond, v0_val, v1_val);
kono
parents: 14
diff changeset
1401 t = force_gimple_operand_gsi (gsi, cond, true, NULL_TREE,
kono
parents: 14
diff changeset
1402 true, GSI_SAME_STMT);
kono
parents: 14
diff changeset
1403 }
kono
parents: 14
diff changeset
1404 else
kono
parents: 14
diff changeset
1405 t = v0_val;
kono
parents: 14
diff changeset
1406 }
kono
parents: 14
diff changeset
1407
kono
parents: 14
diff changeset
1408 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
kono
parents: 14
diff changeset
1409 }
kono
parents: 14
diff changeset
1410
kono
parents: 14
diff changeset
1411 constr = build_constructor (vect_type, v);
kono
parents: 14
diff changeset
1412 gimple_assign_set_rhs_from_tree (gsi, constr);
kono
parents: 14
diff changeset
1413 update_stmt (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
1414 }
kono
parents: 14
diff changeset
1415
kono
parents: 14
diff changeset
1416 /* If OP is a uniform vector return the element it is a splat from. */
kono
parents: 14
diff changeset
1417
kono
parents: 14
diff changeset
1418 static tree
kono
parents: 14
diff changeset
1419 ssa_uniform_vector_p (tree op)
kono
parents: 14
diff changeset
1420 {
kono
parents: 14
diff changeset
1421 if (TREE_CODE (op) == VECTOR_CST
kono
parents: 14
diff changeset
1422 || TREE_CODE (op) == CONSTRUCTOR)
kono
parents: 14
diff changeset
1423 return uniform_vector_p (op);
kono
parents: 14
diff changeset
1424 if (TREE_CODE (op) == SSA_NAME)
kono
parents: 14
diff changeset
1425 {
kono
parents: 14
diff changeset
1426 gimple *def_stmt = SSA_NAME_DEF_STMT (op);
kono
parents: 14
diff changeset
1427 if (gimple_assign_single_p (def_stmt))
kono
parents: 14
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 }
16
kono
parents: 14
diff changeset
1430 return NULL_TREE;
kono
parents: 14
diff changeset
1431 }
kono
parents: 14
diff changeset
1432
kono
parents: 14
diff changeset
1433 /* Return type in which CODE operation with optab OP can be
kono
parents: 14
diff changeset
1434 computed. */
kono
parents: 14
diff changeset
1435
kono
parents: 14
diff changeset
1436 static tree
kono
parents: 14
diff changeset
1437 get_compute_type (enum tree_code code, optab op, tree type)
kono
parents: 14
diff changeset
1438 {
kono
parents: 14
diff changeset
1439 /* For very wide vectors, try using a smaller vector mode. */
kono
parents: 14
diff changeset
1440 tree compute_type = type;
kono
parents: 14
diff changeset
1441 if (op
kono
parents: 14
diff changeset
1442 && (!VECTOR_MODE_P (TYPE_MODE (type))
kono
parents: 14
diff changeset
1443 || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing))
kono
parents: 14
diff changeset
1444 {
kono
parents: 14
diff changeset
1445 tree vector_compute_type
kono
parents: 14
diff changeset
1446 = type_for_widest_vector_mode (TREE_TYPE (type), op);
kono
parents: 14
diff changeset
1447 if (vector_compute_type != NULL_TREE
kono
parents: 14
diff changeset
1448 && (TYPE_VECTOR_SUBPARTS (vector_compute_type)
kono
parents: 14
diff changeset
1449 < TYPE_VECTOR_SUBPARTS (compute_type))
kono
parents: 14
diff changeset
1450 && TYPE_VECTOR_SUBPARTS (vector_compute_type) > 1
kono
parents: 14
diff changeset
1451 && (optab_handler (op, TYPE_MODE (vector_compute_type))
kono
parents: 14
diff changeset
1452 != CODE_FOR_nothing))
kono
parents: 14
diff changeset
1453 compute_type = vector_compute_type;
kono
parents: 14
diff changeset
1454 }
kono
parents: 14
diff changeset
1455
kono
parents: 14
diff changeset
1456 /* If we are breaking a BLKmode vector into smaller pieces,
kono
parents: 14
diff changeset
1457 type_for_widest_vector_mode has already looked into the optab,
kono
parents: 14
diff changeset
1458 so skip these checks. */
kono
parents: 14
diff changeset
1459 if (compute_type == type)
kono
parents: 14
diff changeset
1460 {
kono
parents: 14
diff changeset
1461 machine_mode compute_mode = TYPE_MODE (compute_type);
kono
parents: 14
diff changeset
1462 if (VECTOR_MODE_P (compute_mode))
kono
parents: 14
diff changeset
1463 {
kono
parents: 14
diff changeset
1464 if (op && optab_handler (op, compute_mode) != CODE_FOR_nothing)
kono
parents: 14
diff changeset
1465 return compute_type;
kono
parents: 14
diff changeset
1466 if (code == MULT_HIGHPART_EXPR
kono
parents: 14
diff changeset
1467 && can_mult_highpart_p (compute_mode,
kono
parents: 14
diff changeset
1468 TYPE_UNSIGNED (compute_type)))
kono
parents: 14
diff changeset
1469 return compute_type;
kono
parents: 14
diff changeset
1470 }
kono
parents: 14
diff changeset
1471 /* There is no operation in hardware, so fall back to scalars. */
kono
parents: 14
diff changeset
1472 compute_type = TREE_TYPE (type);
kono
parents: 14
diff changeset
1473 }
kono
parents: 14
diff changeset
1474
kono
parents: 14
diff changeset
1475 return compute_type;
kono
parents: 14
diff changeset
1476 }
kono
parents: 14
diff changeset
1477
kono
parents: 14
diff changeset
1478 /* Helper function of expand_vector_operations_1. Return number of
kono
parents: 14
diff changeset
1479 vector elements for vector types or 1 for other types. */
kono
parents: 14
diff changeset
1480
kono
parents: 14
diff changeset
1481 static inline int
kono
parents: 14
diff changeset
1482 count_type_subparts (tree type)
kono
parents: 14
diff changeset
1483 {
kono
parents: 14
diff changeset
1484 return VECTOR_TYPE_P (type) ? TYPE_VECTOR_SUBPARTS (type) : 1;
kono
parents: 14
diff changeset
1485 }
kono
parents: 14
diff changeset
1486
kono
parents: 14
diff changeset
1487 static tree
kono
parents: 14
diff changeset
1488 do_cond (gimple_stmt_iterator *gsi, tree inner_type, tree a, tree b,
kono
parents: 14
diff changeset
1489 tree bitpos, tree bitsize, enum tree_code code,
kono
parents: 14
diff changeset
1490 tree type ATTRIBUTE_UNUSED)
kono
parents: 14
diff changeset
1491 {
kono
parents: 14
diff changeset
1492 if (TREE_CODE (TREE_TYPE (a)) == VECTOR_TYPE)
kono
parents: 14
diff changeset
1493 a = tree_vec_extract (gsi, inner_type, a, bitsize, bitpos);
kono
parents: 14
diff changeset
1494 if (TREE_CODE (TREE_TYPE (b)) == VECTOR_TYPE)
kono
parents: 14
diff changeset
1495 b = tree_vec_extract (gsi, inner_type, b, bitsize, bitpos);
kono
parents: 14
diff changeset
1496 tree cond = gimple_assign_rhs1 (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
1497 return gimplify_build3 (gsi, code, inner_type, unshare_expr (cond), a, b);
kono
parents: 14
diff changeset
1498 }
kono
parents: 14
diff changeset
1499
kono
parents: 14
diff changeset
1500 /* Expand a vector COND_EXPR to scalars, piecewise. */
kono
parents: 14
diff changeset
1501 static void
kono
parents: 14
diff changeset
1502 expand_vector_scalar_condition (gimple_stmt_iterator *gsi)
kono
parents: 14
diff changeset
1503 {
kono
parents: 14
diff changeset
1504 gassign *stmt = as_a <gassign *> (gsi_stmt (*gsi));
kono
parents: 14
diff changeset
1505 tree type = gimple_expr_type (stmt);
kono
parents: 14
diff changeset
1506 tree compute_type = get_compute_type (COND_EXPR, mov_optab, type);
kono
parents: 14
diff changeset
1507 machine_mode compute_mode = TYPE_MODE (compute_type);
kono
parents: 14
diff changeset
1508 gcc_assert (compute_mode != BLKmode);
kono
parents: 14
diff changeset
1509 tree lhs = gimple_assign_lhs (stmt);
kono
parents: 14
diff changeset
1510 tree rhs2 = gimple_assign_rhs2 (stmt);
kono
parents: 14
diff changeset
1511 tree rhs3 = gimple_assign_rhs3 (stmt);
kono
parents: 14
diff changeset
1512 tree new_rhs;
kono
parents: 14
diff changeset
1513
kono
parents: 14
diff changeset
1514 /* If the compute mode is not a vector mode (hence we are not decomposing
kono
parents: 14
diff changeset
1515 a BLKmode vector to smaller, hardware-supported vectors), we may want
kono
parents: 14
diff changeset
1516 to expand the operations in parallel. */
kono
parents: 14
diff changeset
1517 if (GET_MODE_CLASS (compute_mode) != MODE_VECTOR_INT
kono
parents: 14
diff changeset
1518 && GET_MODE_CLASS (compute_mode) != MODE_VECTOR_FLOAT
kono
parents: 14
diff changeset
1519 && GET_MODE_CLASS (compute_mode) != MODE_VECTOR_FRACT
kono
parents: 14
diff changeset
1520 && GET_MODE_CLASS (compute_mode) != MODE_VECTOR_UFRACT
kono
parents: 14
diff changeset
1521 && GET_MODE_CLASS (compute_mode) != MODE_VECTOR_ACCUM
kono
parents: 14
diff changeset
1522 && GET_MODE_CLASS (compute_mode) != MODE_VECTOR_UACCUM)
kono
parents: 14
diff changeset
1523 new_rhs = expand_vector_parallel (gsi, do_cond, type, rhs2, rhs3,
kono
parents: 14
diff changeset
1524 COND_EXPR);
kono
parents: 14
diff changeset
1525 else
kono
parents: 14
diff changeset
1526 new_rhs = expand_vector_piecewise (gsi, do_cond, type, compute_type,
kono
parents: 14
diff changeset
1527 rhs2, rhs3, COND_EXPR);
kono
parents: 14
diff changeset
1528 if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (new_rhs)))
kono
parents: 14
diff changeset
1529 new_rhs = gimplify_build1 (gsi, VIEW_CONVERT_EXPR, TREE_TYPE (lhs),
kono
parents: 14
diff changeset
1530 new_rhs);
kono
parents: 14
diff changeset
1531
kono
parents: 14
diff changeset
1532 /* NOTE: We should avoid using gimple_assign_set_rhs_from_tree. One
kono
parents: 14
diff changeset
1533 way to do it is change expand_vector_operation and its callees to
kono
parents: 14
diff changeset
1534 return a tree_code, RHS1 and RHS2 instead of a tree. */
kono
parents: 14
diff changeset
1535 gimple_assign_set_rhs_from_tree (gsi, new_rhs);
kono
parents: 14
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 {
16
kono
parents: 14
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;
16
kono
parents: 14
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
16
kono
parents: 14
diff changeset
1550 /* Only consider code == GIMPLE_ASSIGN. */
kono
parents: 14
diff changeset
1551 gassign *stmt = dyn_cast <gassign *> (gsi_stmt (*gsi));
kono
parents: 14
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);
16
kono
parents: 14
diff changeset
1557 lhs = gimple_assign_lhs (stmt);
kono
parents: 14
diff changeset
1558
kono
parents: 14
diff changeset
1559 if (code == VEC_PERM_EXPR)
kono
parents: 14
diff changeset
1560 {
kono
parents: 14
diff changeset
1561 lower_vec_perm (gsi);
kono
parents: 14
diff changeset
1562 return;
kono
parents: 14
diff changeset
1563 }
kono
parents: 14
diff changeset
1564
kono
parents: 14
diff changeset
1565 if (code == VEC_COND_EXPR)
kono
parents: 14
diff changeset
1566 {
kono
parents: 14
diff changeset
1567 expand_vector_condition (gsi);
kono
parents: 14
diff changeset
1568 return;
kono
parents: 14
diff changeset
1569 }
kono
parents: 14
diff changeset
1570
kono
parents: 14
diff changeset
1571 if (code == COND_EXPR
kono
parents: 14
diff changeset
1572 && TREE_CODE (TREE_TYPE (gimple_assign_lhs (stmt))) == VECTOR_TYPE
kono
parents: 14
diff changeset
1573 && TYPE_MODE (TREE_TYPE (gimple_assign_lhs (stmt))) == BLKmode)
kono
parents: 14
diff changeset
1574 {
kono
parents: 14
diff changeset
1575 expand_vector_scalar_condition (gsi);
kono
parents: 14
diff changeset
1576 return;
kono
parents: 14
diff changeset
1577 }
kono
parents: 14
diff changeset
1578
kono
parents: 14
diff changeset
1579 if (code == CONSTRUCTOR
kono
parents: 14
diff changeset
1580 && TREE_CODE (lhs) == SSA_NAME
kono
parents: 14
diff changeset
1581 && VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (lhs)))
kono
parents: 14
diff changeset
1582 && !gimple_clobber_p (stmt)
kono
parents: 14
diff changeset
1583 && optimize)
kono
parents: 14
diff changeset
1584 {
kono
parents: 14
diff changeset
1585 optimize_vector_constructor (gsi);
kono
parents: 14
diff changeset
1586 return;
kono
parents: 14
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