Branch data Line data Source code
1 : : /* Vectorizer
2 : : Copyright (C) 2003-2025 Free Software Foundation, Inc.
3 : : Contributed by Dorit Naishlos <dorit@il.ibm.com>
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : /* Loop and basic block vectorizer.
22 : :
23 : : This file contains drivers for the three vectorizers:
24 : : (1) loop vectorizer (inter-iteration parallelism),
25 : : (2) loop-aware SLP (intra-iteration parallelism) (invoked by the loop
26 : : vectorizer)
27 : : (3) BB vectorizer (out-of-loops), aka SLP
28 : :
29 : : The rest of the vectorizer's code is organized as follows:
30 : : - tree-vect-loop.cc - loop specific parts such as reductions, etc. These are
31 : : used by drivers (1) and (2).
32 : : - tree-vect-loop-manip.cc - vectorizer's loop control-flow utilities, used by
33 : : drivers (1) and (2).
34 : : - tree-vect-slp.cc - BB vectorization specific analysis and transformation,
35 : : used by drivers (2) and (3).
36 : : - tree-vect-stmts.cc - statements analysis and transformation (used by all).
37 : : - tree-vect-data-refs.cc - vectorizer specific data-refs analysis and
38 : : manipulations (used by all).
39 : : - tree-vect-patterns.cc - vectorizable code patterns detector (used by all)
40 : :
41 : : Here's a poor attempt at illustrating that:
42 : :
43 : : tree-vectorizer.cc:
44 : : loop_vect() loop_aware_slp() slp_vect()
45 : : | / \ /
46 : : | / \ /
47 : : tree-vect-loop.cc tree-vect-slp.cc
48 : : | \ \ / / |
49 : : | \ \/ / |
50 : : | \ /\ / |
51 : : | \ / \ / |
52 : : tree-vect-stmts.cc tree-vect-data-refs.cc
53 : : \ /
54 : : tree-vect-patterns.cc
55 : : */
56 : :
57 : : #include "config.h"
58 : : #include "system.h"
59 : : #include "coretypes.h"
60 : : #include "backend.h"
61 : : #include "tree.h"
62 : : #include "gimple.h"
63 : : #include "predict.h"
64 : : #include "tree-pass.h"
65 : : #include "ssa.h"
66 : : #include "cgraph.h"
67 : : #include "fold-const.h"
68 : : #include "stor-layout.h"
69 : : #include "gimple-iterator.h"
70 : : #include "gimple-walk.h"
71 : : #include "tree-ssa-loop-manip.h"
72 : : #include "tree-ssa-loop-niter.h"
73 : : #include "tree-cfg.h"
74 : : #include "cfgloop.h"
75 : : #include "tree-vectorizer.h"
76 : : #include "tree-ssa-propagate.h"
77 : : #include "dbgcnt.h"
78 : : #include "tree-scalar-evolution.h"
79 : : #include "stringpool.h"
80 : : #include "attribs.h"
81 : : #include "gimple-pretty-print.h"
82 : : #include "opt-problem.h"
83 : : #include "internal-fn.h"
84 : : #include "tree-ssa-sccvn.h"
85 : : #include "tree-into-ssa.h"
86 : :
87 : : /* Loop or bb location, with hotness information. */
88 : : dump_user_location_t vect_location;
89 : :
90 : : /* auto_purge_vect_location's dtor: reset the vect_location
91 : : global, to avoid stale location_t values that could reference
92 : : GC-ed blocks. */
93 : :
94 : 1307711 : auto_purge_vect_location::~auto_purge_vect_location ()
95 : : {
96 : 1307711 : vect_location = dump_user_location_t ();
97 : 1307711 : }
98 : :
99 : : /* Dump a cost entry according to args to F. */
100 : :
101 : : void
102 : 225371 : dump_stmt_cost (FILE *f, int count, enum vect_cost_for_stmt kind,
103 : : stmt_vec_info stmt_info, slp_tree node, tree,
104 : : int misalign, unsigned cost,
105 : : enum vect_cost_model_location where)
106 : : {
107 : 225371 : if (stmt_info)
108 : : {
109 : 202857 : print_gimple_expr (f, STMT_VINFO_STMT (stmt_info), 0, TDF_SLIM);
110 : 202857 : fprintf (f, " ");
111 : : }
112 : 22514 : else if (node)
113 : 7881 : fprintf (f, "node %p ", (void *)node);
114 : : else
115 : 14633 : fprintf (f, "<unknown> ");
116 : 225371 : fprintf (f, "%d times ", count);
117 : 225371 : const char *ks = "unknown";
118 : 225371 : switch (kind)
119 : : {
120 : 49474 : case scalar_stmt:
121 : 49474 : ks = "scalar_stmt";
122 : 49474 : break;
123 : 35631 : case scalar_load:
124 : 35631 : ks = "scalar_load";
125 : 35631 : break;
126 : 27612 : case scalar_store:
127 : 27612 : ks = "scalar_store";
128 : 27612 : break;
129 : 38070 : case vector_stmt:
130 : 38070 : ks = "vector_stmt";
131 : 38070 : break;
132 : 23090 : case vector_load:
133 : 23090 : ks = "vector_load";
134 : 23090 : break;
135 : 0 : case vector_gather_load:
136 : 0 : ks = "vector_gather_load";
137 : 0 : break;
138 : 9128 : case unaligned_load:
139 : 9128 : ks = "unaligned_load";
140 : 9128 : break;
141 : 5210 : case unaligned_store:
142 : 5210 : ks = "unaligned_store";
143 : 5210 : break;
144 : 9128 : case vector_store:
145 : 9128 : ks = "vector_store";
146 : 9128 : break;
147 : 0 : case vector_scatter_store:
148 : 0 : ks = "vector_scatter_store";
149 : 0 : break;
150 : 3396 : case vec_to_scalar:
151 : 3396 : ks = "vec_to_scalar";
152 : 3396 : break;
153 : 9749 : case scalar_to_vec:
154 : 9749 : ks = "scalar_to_vec";
155 : 9749 : break;
156 : 6 : case cond_branch_not_taken:
157 : 6 : ks = "cond_branch_not_taken";
158 : 6 : break;
159 : 331 : case cond_branch_taken:
160 : 331 : ks = "cond_branch_taken";
161 : 331 : break;
162 : 7043 : case vec_perm:
163 : 7043 : ks = "vec_perm";
164 : 7043 : break;
165 : 6243 : case vec_promote_demote:
166 : 6243 : ks = "vec_promote_demote";
167 : 6243 : break;
168 : 1260 : case vec_construct:
169 : 1260 : ks = "vec_construct";
170 : 1260 : break;
171 : : }
172 : 225371 : fprintf (f, "%s ", ks);
173 : 225371 : if (kind == unaligned_load || kind == unaligned_store)
174 : 14338 : fprintf (f, "(misalign %d) ", misalign);
175 : 225371 : fprintf (f, "costs %u ", cost);
176 : 225371 : const char *ws = "unknown";
177 : 225371 : switch (where)
178 : : {
179 : 131623 : case vect_prologue:
180 : 131623 : ws = "prologue";
181 : 131623 : break;
182 : 87438 : case vect_body:
183 : 87438 : ws = "body";
184 : 87438 : break;
185 : 6310 : case vect_epilogue:
186 : 6310 : ws = "epilogue";
187 : 6310 : break;
188 : : }
189 : 225371 : fprintf (f, "in %s\n", ws);
190 : 225371 : }
191 : :
192 : : /* For mapping simduid to vectorization factor. */
193 : :
194 : : class simduid_to_vf : public free_ptr_hash<simduid_to_vf>
195 : : {
196 : : public:
197 : : unsigned int simduid;
198 : : poly_uint64 vf;
199 : :
200 : : /* hash_table support. */
201 : : static inline hashval_t hash (const simduid_to_vf *);
202 : : static inline int equal (const simduid_to_vf *, const simduid_to_vf *);
203 : : };
204 : :
205 : : inline hashval_t
206 : 7442 : simduid_to_vf::hash (const simduid_to_vf *p)
207 : : {
208 : 7442 : return p->simduid;
209 : : }
210 : :
211 : : inline int
212 : 13848 : simduid_to_vf::equal (const simduid_to_vf *p1, const simduid_to_vf *p2)
213 : : {
214 : 13848 : return p1->simduid == p2->simduid;
215 : : }
216 : :
217 : : /* This hash maps the OMP simd array to the corresponding simduid used
218 : : to index into it. Like thus,
219 : :
220 : : _7 = GOMP_SIMD_LANE (simduid.0)
221 : : ...
222 : : ...
223 : : D.1737[_7] = stuff;
224 : :
225 : :
226 : : This hash maps from the OMP simd array (D.1737[]) to DECL_UID of
227 : : simduid.0. */
228 : :
229 : : struct simd_array_to_simduid : free_ptr_hash<simd_array_to_simduid>
230 : : {
231 : : tree decl;
232 : : unsigned int simduid;
233 : :
234 : : /* hash_table support. */
235 : : static inline hashval_t hash (const simd_array_to_simduid *);
236 : : static inline int equal (const simd_array_to_simduid *,
237 : : const simd_array_to_simduid *);
238 : : };
239 : :
240 : : inline hashval_t
241 : 24020 : simd_array_to_simduid::hash (const simd_array_to_simduid *p)
242 : : {
243 : 24020 : return DECL_UID (p->decl);
244 : : }
245 : :
246 : : inline int
247 : 16809 : simd_array_to_simduid::equal (const simd_array_to_simduid *p1,
248 : : const simd_array_to_simduid *p2)
249 : : {
250 : 16809 : return p1->decl == p2->decl;
251 : : }
252 : :
253 : : /* Fold IFN_GOMP_SIMD_LANE, IFN_GOMP_SIMD_VF, IFN_GOMP_SIMD_LAST_LANE,
254 : : into their corresponding constants and remove
255 : : IFN_GOMP_SIMD_ORDERED_{START,END}. */
256 : :
257 : : static void
258 : 7812 : adjust_simduid_builtins (hash_table<simduid_to_vf> *htab, function *fun)
259 : : {
260 : 7812 : basic_block bb;
261 : :
262 : 122028 : FOR_EACH_BB_FN (bb, fun)
263 : : {
264 : 114216 : gimple_stmt_iterator i;
265 : :
266 : 745963 : for (i = gsi_start_bb (bb); !gsi_end_p (i); )
267 : : {
268 : 517531 : poly_uint64 vf = 1;
269 : 517531 : enum internal_fn ifn;
270 : 517531 : gimple *stmt = gsi_stmt (i);
271 : 517531 : tree t;
272 : 517531 : if (!is_gimple_call (stmt)
273 : 517531 : || !gimple_call_internal_p (stmt))
274 : : {
275 : 510196 : gsi_next (&i);
276 : 510882 : continue;
277 : : }
278 : 7335 : ifn = gimple_call_internal_fn (stmt);
279 : 7335 : switch (ifn)
280 : : {
281 : 6649 : case IFN_GOMP_SIMD_LANE:
282 : 6649 : case IFN_GOMP_SIMD_VF:
283 : 6649 : case IFN_GOMP_SIMD_LAST_LANE:
284 : 6649 : break;
285 : 158 : case IFN_GOMP_SIMD_ORDERED_START:
286 : 158 : case IFN_GOMP_SIMD_ORDERED_END:
287 : 158 : if (integer_onep (gimple_call_arg (stmt, 0)))
288 : : {
289 : 20 : enum built_in_function bcode
290 : : = (ifn == IFN_GOMP_SIMD_ORDERED_START
291 : 10 : ? BUILT_IN_GOMP_ORDERED_START
292 : : : BUILT_IN_GOMP_ORDERED_END);
293 : 10 : gimple *g
294 : 10 : = gimple_build_call (builtin_decl_explicit (bcode), 0);
295 : 10 : gimple_move_vops (g, stmt);
296 : 10 : gsi_replace (&i, g, true);
297 : 10 : continue;
298 : 10 : }
299 : 148 : gsi_remove (&i, true);
300 : 148 : unlink_stmt_vdef (stmt);
301 : 148 : continue;
302 : 528 : default:
303 : 528 : gsi_next (&i);
304 : 528 : continue;
305 : 676 : }
306 : 6649 : tree arg = gimple_call_arg (stmt, 0);
307 : 6649 : gcc_assert (arg != NULL_TREE);
308 : 6649 : gcc_assert (TREE_CODE (arg) == SSA_NAME);
309 : 6649 : simduid_to_vf *p = NULL, data;
310 : 6649 : data.simduid = DECL_UID (SSA_NAME_VAR (arg));
311 : : /* Need to nullify loop safelen field since it's value is not
312 : : valid after transformation. */
313 : 6649 : if (bb->loop_father && bb->loop_father->safelen > 0)
314 : 2172 : bb->loop_father->safelen = 0;
315 : 6649 : if (htab)
316 : : {
317 : 4732 : p = htab->find (&data);
318 : 4732 : if (p)
319 : 4691 : vf = p->vf;
320 : : }
321 : 6649 : switch (ifn)
322 : : {
323 : 971 : case IFN_GOMP_SIMD_VF:
324 : 971 : t = build_int_cst (unsigned_type_node, vf);
325 : 971 : break;
326 : 3487 : case IFN_GOMP_SIMD_LANE:
327 : 3487 : t = build_int_cst (unsigned_type_node, 0);
328 : 3487 : break;
329 : 2191 : case IFN_GOMP_SIMD_LAST_LANE:
330 : 2191 : t = gimple_call_arg (stmt, 1);
331 : 2191 : break;
332 : : default:
333 : : gcc_unreachable ();
334 : : }
335 : 6649 : tree lhs = gimple_call_lhs (stmt);
336 : 6649 : if (lhs)
337 : 6592 : replace_uses_by (lhs, t);
338 : 6649 : release_defs (stmt);
339 : 6649 : gsi_remove (&i, true);
340 : : }
341 : : }
342 : 7812 : }
343 : :
344 : : /* Helper structure for note_simd_array_uses. */
345 : :
346 : : struct note_simd_array_uses_struct
347 : : {
348 : : hash_table<simd_array_to_simduid> **htab;
349 : : unsigned int simduid;
350 : : };
351 : :
352 : : /* Callback for note_simd_array_uses, called through walk_gimple_op. */
353 : :
354 : : static tree
355 : 65202 : note_simd_array_uses_cb (tree *tp, int *walk_subtrees, void *data)
356 : : {
357 : 65202 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
358 : 65202 : struct note_simd_array_uses_struct *ns
359 : : = (struct note_simd_array_uses_struct *) wi->info;
360 : :
361 : 65202 : if (TYPE_P (*tp))
362 : 0 : *walk_subtrees = 0;
363 : 65202 : else if (VAR_P (*tp)
364 : 12359 : && lookup_attribute ("omp simd array", DECL_ATTRIBUTES (*tp))
365 : 77558 : && DECL_CONTEXT (*tp) == current_function_decl)
366 : : {
367 : 12356 : simd_array_to_simduid data;
368 : 12356 : if (!*ns->htab)
369 : 2207 : *ns->htab = new hash_table<simd_array_to_simduid> (15);
370 : 12356 : data.decl = *tp;
371 : 12356 : data.simduid = ns->simduid;
372 : 12356 : simd_array_to_simduid **slot = (*ns->htab)->find_slot (&data, INSERT);
373 : 12356 : if (*slot == NULL)
374 : : {
375 : 5498 : simd_array_to_simduid *p = XNEW (simd_array_to_simduid);
376 : 5498 : *p = data;
377 : 5498 : *slot = p;
378 : : }
379 : 6858 : else if ((*slot)->simduid != ns->simduid)
380 : 0 : (*slot)->simduid = -1U;
381 : 12356 : *walk_subtrees = 0;
382 : : }
383 : 65202 : return NULL_TREE;
384 : : }
385 : :
386 : : /* Find "omp simd array" temporaries and map them to corresponding
387 : : simduid. */
388 : :
389 : : static void
390 : 7812 : note_simd_array_uses (hash_table<simd_array_to_simduid> **htab, function *fun)
391 : : {
392 : 7812 : basic_block bb;
393 : 7812 : gimple_stmt_iterator gsi;
394 : 7812 : struct walk_stmt_info wi;
395 : 7812 : struct note_simd_array_uses_struct ns;
396 : :
397 : 7812 : memset (&wi, 0, sizeof (wi));
398 : 7812 : wi.info = &ns;
399 : 7812 : ns.htab = htab;
400 : :
401 : 106178 : FOR_EACH_BB_FN (bb, fun)
402 : 591461 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
403 : : {
404 : 394729 : gimple *stmt = gsi_stmt (gsi);
405 : 394729 : if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
406 : 388147 : continue;
407 : 7287 : switch (gimple_call_internal_fn (stmt))
408 : : {
409 : 6618 : case IFN_GOMP_SIMD_LANE:
410 : 6618 : case IFN_GOMP_SIMD_VF:
411 : 6618 : case IFN_GOMP_SIMD_LAST_LANE:
412 : 6618 : break;
413 : 669 : default:
414 : 669 : continue;
415 : : }
416 : 6618 : tree lhs = gimple_call_lhs (stmt);
417 : 6618 : if (lhs == NULL_TREE)
418 : 36 : continue;
419 : 6582 : imm_use_iterator use_iter;
420 : 6582 : gimple *use_stmt;
421 : 6582 : ns.simduid = DECL_UID (SSA_NAME_VAR (gimple_call_arg (stmt, 0)));
422 : 24613 : FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, lhs)
423 : 18031 : if (!is_gimple_debug (use_stmt))
424 : 24521 : walk_gimple_op (use_stmt, note_simd_array_uses_cb, &wi);
425 : : }
426 : 7812 : }
427 : :
428 : : /* Shrink arrays with "omp simd array" attribute to the corresponding
429 : : vectorization factor. */
430 : :
431 : : static void
432 : 2207 : shrink_simd_arrays
433 : : (hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab,
434 : : hash_table<simduid_to_vf> *simduid_to_vf_htab)
435 : : {
436 : 7705 : for (hash_table<simd_array_to_simduid>::iterator iter
437 : 2207 : = simd_array_to_simduid_htab->begin ();
438 : 13203 : iter != simd_array_to_simduid_htab->end (); ++iter)
439 : 5498 : if ((*iter)->simduid != -1U)
440 : : {
441 : 5498 : tree decl = (*iter)->decl;
442 : 5498 : poly_uint64 vf = 1;
443 : 5498 : if (simduid_to_vf_htab)
444 : : {
445 : 4541 : simduid_to_vf *p = NULL, data;
446 : 4541 : data.simduid = (*iter)->simduid;
447 : 4541 : p = simduid_to_vf_htab->find (&data);
448 : 4541 : if (p)
449 : 4507 : vf = p->vf;
450 : : }
451 : 5498 : tree atype
452 : 5498 : = build_array_type_nelts (TREE_TYPE (TREE_TYPE (decl)), vf);
453 : 5498 : TREE_TYPE (decl) = atype;
454 : 5498 : relayout_decl (decl);
455 : : }
456 : :
457 : 2207 : delete simd_array_to_simduid_htab;
458 : 2207 : }
459 : :
460 : : /* Initialize the vec_info with kind KIND_IN and target cost data
461 : : TARGET_COST_DATA_IN. */
462 : :
463 : 2700209 : vec_info::vec_info (vec_info::vec_kind kind_in, vec_info_shared *shared_)
464 : 2700209 : : kind (kind_in),
465 : 2700209 : shared (shared_),
466 : 2700209 : stmt_vec_info_ro (false),
467 : 2700209 : bbs (NULL),
468 : 2700209 : nbbs (0),
469 : 2700209 : inv_pattern_def_seq (NULL)
470 : : {
471 : 2700209 : stmt_vec_infos.create (50);
472 : 2700209 : }
473 : :
474 : 2700209 : vec_info::~vec_info ()
475 : : {
476 : 4190977 : for (slp_instance &instance : slp_instances)
477 : 759644 : vect_free_slp_instance (instance);
478 : :
479 : 2700209 : free_stmt_vec_infos ();
480 : 2700209 : }
481 : :
482 : 2449902 : vec_info_shared::vec_info_shared ()
483 : 2449902 : : datarefs (vNULL),
484 : 2449902 : datarefs_copy (vNULL),
485 : 2449902 : ddrs (vNULL)
486 : : {
487 : 2449902 : }
488 : :
489 : 2449902 : vec_info_shared::~vec_info_shared ()
490 : : {
491 : 2449902 : free_data_refs (datarefs);
492 : 2449902 : free_dependence_relations (ddrs);
493 : 2449902 : datarefs_copy.release ();
494 : 2449902 : }
495 : :
496 : : void
497 : 2208813 : vec_info_shared::save_datarefs ()
498 : : {
499 : 2208813 : if (!flag_checking)
500 : : return;
501 : 3240984 : datarefs_copy.reserve_exact (datarefs.length ());
502 : 12245644 : for (unsigned i = 0; i < datarefs.length (); ++i)
503 : 10036844 : datarefs_copy.quick_push (*datarefs[i]);
504 : : }
505 : :
506 : : void
507 : 791816 : vec_info_shared::check_datarefs ()
508 : : {
509 : 791816 : if (!flag_checking)
510 : : return;
511 : 2372550 : gcc_assert (datarefs.length () == datarefs_copy.length ());
512 : 11251503 : for (unsigned i = 0; i < datarefs.length (); ++i)
513 : 10459687 : if (memcmp (&datarefs_copy[i], datarefs[i],
514 : : offsetof (data_reference, alt_indices)) != 0)
515 : 0 : gcc_unreachable ();
516 : : }
517 : :
518 : : /* Record that STMT belongs to the vectorizable region. Create and return
519 : : an associated stmt_vec_info. */
520 : :
521 : : stmt_vec_info
522 : 56364840 : vec_info::add_stmt (gimple *stmt)
523 : : {
524 : 56364840 : stmt_vec_info res = new_stmt_vec_info (stmt);
525 : 56364840 : set_vinfo_for_stmt (stmt, res);
526 : 56364840 : return res;
527 : : }
528 : :
529 : : /* Record that STMT belongs to the vectorizable region. Create a new
530 : : stmt_vec_info and mark VECINFO as being related and return the new
531 : : stmt_vec_info. */
532 : :
533 : : stmt_vec_info
534 : 448 : vec_info::add_pattern_stmt (gimple *stmt, stmt_vec_info stmt_info)
535 : : {
536 : 448 : stmt_vec_info res = new_stmt_vec_info (stmt);
537 : 448 : res->pattern_stmt_p = true;
538 : 448 : set_vinfo_for_stmt (stmt, res, false);
539 : 448 : STMT_VINFO_RELATED_STMT (res) = stmt_info;
540 : 448 : return res;
541 : : }
542 : :
543 : : /* If STMT was previously associated with a stmt_vec_info and STMT now resides
544 : : at a different address than before (e.g., because STMT is a phi node that has
545 : : been resized), update the stored address to match the new one. It is not
546 : : possible to use lookup_stmt () to perform this task, because that function
547 : : returns NULL if the stored stmt pointer does not match the one being looked
548 : : up. */
549 : :
550 : : stmt_vec_info
551 : 10212 : vec_info::resync_stmt_addr (gimple *stmt)
552 : : {
553 : 10212 : unsigned int uid = gimple_uid (stmt);
554 : 10212 : if (uid > 0 && uid - 1 < stmt_vec_infos.length ())
555 : : {
556 : 10212 : stmt_vec_info res = stmt_vec_infos[uid - 1];
557 : 10212 : if (res && res->stmt)
558 : : {
559 : 10212 : res->stmt = stmt;
560 : 10212 : return res;
561 : : }
562 : : }
563 : : return nullptr;
564 : : }
565 : :
566 : : /* If STMT has an associated stmt_vec_info, return that vec_info, otherwise
567 : : return null. It is safe to call this function on any statement, even if
568 : : it might not be part of the vectorizable region. */
569 : :
570 : : stmt_vec_info
571 : 416717747 : vec_info::lookup_stmt (gimple *stmt)
572 : : {
573 : 416717747 : unsigned int uid = gimple_uid (stmt);
574 : 416717747 : if (uid > 0 && uid - 1 < stmt_vec_infos.length ())
575 : : {
576 : 284824713 : stmt_vec_info res = stmt_vec_infos[uid - 1];
577 : 284824713 : if (res && res->stmt == stmt)
578 : 284531953 : return res;
579 : : }
580 : : return NULL;
581 : : }
582 : :
583 : : /* If NAME is an SSA_NAME and its definition has an associated stmt_vec_info,
584 : : return that stmt_vec_info, otherwise return null. It is safe to call
585 : : this on arbitrary operands. */
586 : :
587 : : stmt_vec_info
588 : 48251111 : vec_info::lookup_def (tree name)
589 : : {
590 : 48251111 : if (TREE_CODE (name) == SSA_NAME
591 : 48251111 : && !SSA_NAME_IS_DEFAULT_DEF (name))
592 : 45706457 : return lookup_stmt (SSA_NAME_DEF_STMT (name));
593 : : return NULL;
594 : : }
595 : :
596 : : /* See whether there is a single non-debug statement that uses LHS and
597 : : whether that statement has an associated stmt_vec_info. Return the
598 : : stmt_vec_info if so, otherwise return null. */
599 : :
600 : : stmt_vec_info
601 : 28845 : vec_info::lookup_single_use (tree lhs)
602 : : {
603 : 28845 : use_operand_p dummy;
604 : 28845 : gimple *use_stmt;
605 : 28845 : if (single_imm_use (lhs, &dummy, &use_stmt))
606 : 22684 : return lookup_stmt (use_stmt);
607 : : return NULL;
608 : : }
609 : :
610 : : /* Return vectorization information about DR. */
611 : :
612 : : dr_vec_info *
613 : 46658830 : vec_info::lookup_dr (data_reference *dr)
614 : : {
615 : 46658830 : stmt_vec_info stmt_info = lookup_stmt (DR_STMT (dr));
616 : : /* DR_STMT should never refer to a stmt in a pattern replacement. */
617 : 46658830 : gcc_checking_assert (!is_pattern_stmt_p (stmt_info));
618 : 46658830 : return STMT_VINFO_DR_INFO (stmt_info->dr_aux.stmt);
619 : : }
620 : :
621 : : /* Record that NEW_STMT_INFO now implements the same data reference
622 : : as OLD_STMT_INFO. */
623 : :
624 : : void
625 : 6163 : vec_info::move_dr (stmt_vec_info new_stmt_info, stmt_vec_info old_stmt_info)
626 : : {
627 : 6163 : gcc_assert (!is_pattern_stmt_p (old_stmt_info));
628 : 6163 : STMT_VINFO_DR_INFO (old_stmt_info)->stmt = new_stmt_info;
629 : 6163 : new_stmt_info->dr_aux = old_stmt_info->dr_aux;
630 : 6163 : STMT_VINFO_DR_WRT_VEC_LOOP (new_stmt_info)
631 : 6163 : = STMT_VINFO_DR_WRT_VEC_LOOP (old_stmt_info);
632 : 6163 : STMT_VINFO_GATHER_SCATTER_P (new_stmt_info)
633 : 6163 : = STMT_VINFO_GATHER_SCATTER_P (old_stmt_info);
634 : 6163 : STMT_VINFO_STRIDED_P (new_stmt_info)
635 : 6163 : = STMT_VINFO_STRIDED_P (old_stmt_info);
636 : 6163 : STMT_VINFO_SIMD_LANE_ACCESS_P (new_stmt_info)
637 : 6163 : = STMT_VINFO_SIMD_LANE_ACCESS_P (old_stmt_info);
638 : 6163 : }
639 : :
640 : : /* Permanently remove the statement described by STMT_INFO from the
641 : : function. */
642 : :
643 : : void
644 : 1440073 : vec_info::remove_stmt (stmt_vec_info stmt_info)
645 : : {
646 : 1440073 : gcc_assert (!stmt_info->pattern_stmt_p);
647 : 1440073 : set_vinfo_for_stmt (stmt_info->stmt, NULL);
648 : 1440073 : unlink_stmt_vdef (stmt_info->stmt);
649 : 1440073 : gimple_stmt_iterator si = gsi_for_stmt (stmt_info->stmt);
650 : 1440073 : gsi_remove (&si, true);
651 : 1440073 : release_defs (stmt_info->stmt);
652 : 1440073 : free_stmt_vec_info (stmt_info);
653 : 1440073 : }
654 : :
655 : : /* Replace the statement at GSI by NEW_STMT, both the vectorization
656 : : information and the function itself. STMT_INFO describes the statement
657 : : at GSI. */
658 : :
659 : : void
660 : 4060 : vec_info::replace_stmt (gimple_stmt_iterator *gsi, stmt_vec_info stmt_info,
661 : : gimple *new_stmt)
662 : : {
663 : 4060 : gimple *old_stmt = stmt_info->stmt;
664 : 4060 : gcc_assert (!stmt_info->pattern_stmt_p && old_stmt == gsi_stmt (*gsi));
665 : 4060 : gimple_set_uid (new_stmt, gimple_uid (old_stmt));
666 : 4060 : stmt_info->stmt = new_stmt;
667 : 4060 : gsi_replace (gsi, new_stmt, true);
668 : 4060 : }
669 : :
670 : : /* Insert stmts in SEQ on the VEC_INFO region entry. If CONTEXT is
671 : : not NULL it specifies whether to use the sub-region entry
672 : : determined by it, currently used for loop vectorization to insert
673 : : on the inner loop entry vs. the outer loop entry. */
674 : :
675 : : void
676 : 111243 : vec_info::insert_seq_on_entry (stmt_vec_info context, gimple_seq seq)
677 : : {
678 : 111243 : if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (this))
679 : : {
680 : 17148 : class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
681 : 17148 : basic_block new_bb;
682 : 17148 : edge pe;
683 : :
684 : 17148 : if (context && nested_in_vect_loop_p (loop, context))
685 : : loop = loop->inner;
686 : :
687 : 17148 : pe = loop_preheader_edge (loop);
688 : 17148 : new_bb = gsi_insert_seq_on_edge_immediate (pe, seq);
689 : 17148 : gcc_assert (!new_bb);
690 : : }
691 : : else
692 : : {
693 : 94095 : gimple_stmt_iterator gsi_region_begin
694 : 94095 : = gsi_after_labels (bbs[0]);
695 : 94095 : gsi_insert_seq_before (&gsi_region_begin, seq, GSI_SAME_STMT);
696 : : }
697 : 111243 : }
698 : :
699 : : /* Like insert_seq_on_entry but just inserts the single stmt NEW_STMT. */
700 : :
701 : : void
702 : 3251 : vec_info::insert_on_entry (stmt_vec_info context, gimple *new_stmt)
703 : : {
704 : 3251 : gimple_seq seq = NULL;
705 : 3251 : gimple_stmt_iterator gsi = gsi_start (seq);
706 : 3251 : gsi_insert_before_without_update (&gsi, new_stmt, GSI_SAME_STMT);
707 : 3251 : insert_seq_on_entry (context, seq);
708 : 3251 : }
709 : :
710 : : /* Create and initialize a new stmt_vec_info struct for STMT. */
711 : :
712 : : stmt_vec_info
713 : 56365288 : vec_info::new_stmt_vec_info (gimple *stmt)
714 : : {
715 : 56365288 : stmt_vec_info res = XCNEW (class _stmt_vec_info);
716 : 56365288 : res->stmt = stmt;
717 : :
718 : 56365288 : STMT_VINFO_TYPE (res) = undef_vec_info_type;
719 : 56365288 : STMT_VINFO_RELEVANT (res) = vect_unused_in_scope;
720 : 56365288 : STMT_VINFO_VECTORIZABLE (res) = true;
721 : 56365288 : STMT_VINFO_REDUC_TYPE (res) = TREE_CODE_REDUCTION;
722 : 56365288 : STMT_VINFO_REDUC_CODE (res) = ERROR_MARK;
723 : 56365288 : STMT_VINFO_REDUC_FN (res) = IFN_LAST;
724 : 56365288 : STMT_VINFO_REDUC_IDX (res) = -1;
725 : 56365288 : STMT_VINFO_SLP_VECT_ONLY (res) = false;
726 : 56365288 : STMT_VINFO_SLP_VECT_ONLY_PATTERN (res) = false;
727 : 56365288 : STMT_VINFO_VEC_STMTS (res) = vNULL;
728 : 56365288 : res->reduc_initial_values = vNULL;
729 : 56365288 : res->reduc_scalar_results = vNULL;
730 : :
731 : 56365288 : if (is_a <loop_vec_info> (this)
732 : 6024300 : && gimple_code (stmt) == GIMPLE_PHI
733 : 57421199 : && is_loop_header_bb_p (gimple_bb (stmt)))
734 : 1046371 : STMT_VINFO_DEF_TYPE (res) = vect_unknown_def_type;
735 : : else
736 : 55318917 : STMT_VINFO_DEF_TYPE (res) = vect_internal_def;
737 : :
738 : 56365288 : STMT_SLP_TYPE (res) = loop_vect;
739 : :
740 : : /* This is really "uninitialized" until vect_compute_data_ref_alignment. */
741 : 56365288 : res->dr_aux.misalignment = DR_MISALIGNMENT_UNINITIALIZED;
742 : :
743 : 56365288 : return res;
744 : : }
745 : :
746 : : /* Associate STMT with INFO. */
747 : :
748 : : void
749 : 57805361 : vec_info::set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info, bool check_ro)
750 : : {
751 : 57805361 : unsigned int uid = gimple_uid (stmt);
752 : 57805361 : if (uid == 0)
753 : : {
754 : 56365288 : gcc_assert (!check_ro || !stmt_vec_info_ro);
755 : 56365288 : gcc_checking_assert (info);
756 : 56365288 : uid = stmt_vec_infos.length () + 1;
757 : 56365288 : gimple_set_uid (stmt, uid);
758 : 56365288 : stmt_vec_infos.safe_push (info);
759 : : }
760 : : else
761 : : {
762 : 1440073 : gcc_checking_assert (info == NULL);
763 : 1440073 : stmt_vec_infos[uid - 1] = info;
764 : : }
765 : 57805361 : }
766 : :
767 : : /* Free the contents of stmt_vec_infos. */
768 : :
769 : : void
770 : 2700209 : vec_info::free_stmt_vec_infos (void)
771 : : {
772 : 64465915 : for (stmt_vec_info &info : stmt_vec_infos)
773 : 56365288 : if (info != NULL)
774 : 54925215 : free_stmt_vec_info (info);
775 : 2700209 : stmt_vec_infos.release ();
776 : 2700209 : }
777 : :
778 : : /* Free STMT_INFO. */
779 : :
780 : : void
781 : 56365288 : vec_info::free_stmt_vec_info (stmt_vec_info stmt_info)
782 : : {
783 : 56365288 : if (stmt_info->pattern_stmt_p)
784 : : {
785 : 1714917 : gimple_set_bb (stmt_info->stmt, NULL);
786 : 1714917 : tree lhs = gimple_get_lhs (stmt_info->stmt);
787 : 1714917 : if (lhs && TREE_CODE (lhs) == SSA_NAME)
788 : 1466212 : release_ssa_name (lhs);
789 : : }
790 : :
791 : 56365288 : stmt_info->reduc_initial_values.release ();
792 : 56365288 : stmt_info->reduc_scalar_results.release ();
793 : 56365288 : STMT_VINFO_SIMD_CLONE_INFO (stmt_info).release ();
794 : 56365288 : STMT_VINFO_VEC_STMTS (stmt_info).release ();
795 : 56365288 : free (stmt_info);
796 : 56365288 : }
797 : :
798 : : /* Returns true if S1 dominates S2. */
799 : :
800 : : bool
801 : 405649 : vect_stmt_dominates_stmt_p (gimple *s1, gimple *s2)
802 : : {
803 : 405649 : basic_block bb1 = gimple_bb (s1), bb2 = gimple_bb (s2);
804 : :
805 : : /* If bb1 is NULL, it should be a GIMPLE_NOP def stmt of an (D)
806 : : SSA_NAME. Assume it lives at the beginning of function and
807 : : thus dominates everything. */
808 : 405649 : if (!bb1 || s1 == s2)
809 : : return true;
810 : :
811 : : /* If bb2 is NULL, it doesn't dominate any stmt with a bb. */
812 : 403979 : if (!bb2)
813 : : return false;
814 : :
815 : 403979 : if (bb1 != bb2)
816 : 158277 : return dominated_by_p (CDI_DOMINATORS, bb2, bb1);
817 : :
818 : : /* PHIs in the same basic block are assumed to be
819 : : executed all in parallel, if only one stmt is a PHI,
820 : : it dominates the other stmt in the same basic block. */
821 : 245702 : if (gimple_code (s1) == GIMPLE_PHI)
822 : : return true;
823 : :
824 : 229488 : if (gimple_code (s2) == GIMPLE_PHI)
825 : : return false;
826 : :
827 : : /* Inserted vectorized stmts all have UID 0 while the original stmts
828 : : in the IL have UID increasing within a BB. Walk from both sides
829 : : until we find the other stmt or a stmt with UID != 0. */
830 : 213566 : gimple_stmt_iterator gsi1 = gsi_for_stmt (s1);
831 : 490185 : while (gimple_uid (gsi_stmt (gsi1)) == 0)
832 : : {
833 : 350056 : gsi_next (&gsi1);
834 : 350056 : if (gsi_end_p (gsi1))
835 : : return false;
836 : 348392 : if (gsi_stmt (gsi1) == s2)
837 : : return true;
838 : : }
839 : 140129 : if (gimple_uid (gsi_stmt (gsi1)) == -1u)
840 : : return false;
841 : :
842 : 140129 : gimple_stmt_iterator gsi2 = gsi_for_stmt (s2);
843 : 513195 : while (gimple_uid (gsi_stmt (gsi2)) == 0)
844 : : {
845 : 386420 : gsi_prev (&gsi2);
846 : 386420 : if (gsi_end_p (gsi2))
847 : : return false;
848 : 373066 : if (gsi_stmt (gsi2) == s1)
849 : : return true;
850 : : }
851 : 126775 : if (gimple_uid (gsi_stmt (gsi2)) == -1u)
852 : : return false;
853 : :
854 : 126775 : if (gimple_uid (gsi_stmt (gsi1)) <= gimple_uid (gsi_stmt (gsi2)))
855 : : return true;
856 : : return false;
857 : : }
858 : :
859 : : /* A helper function to free scev and LOOP niter information, as well as
860 : : clear loop constraint LOOP_C_FINITE. */
861 : :
862 : : void
863 : 42906 : vect_free_loop_info_assumptions (class loop *loop)
864 : : {
865 : 42906 : scev_reset_htab ();
866 : : /* We need to explicitly reset upper bound information since they are
867 : : used even after free_numbers_of_iterations_estimates. */
868 : 42906 : loop->any_upper_bound = false;
869 : 42906 : loop->any_likely_upper_bound = false;
870 : 42906 : free_numbers_of_iterations_estimates (loop);
871 : 42906 : loop_constraint_clear (loop, LOOP_C_FINITE);
872 : 42906 : }
873 : :
874 : : /* If LOOP has been versioned during ifcvt, return the internal call
875 : : guarding it. */
876 : :
877 : : gimple *
878 : 474363 : vect_loop_vectorized_call (class loop *loop, gcond **cond)
879 : : {
880 : 474363 : basic_block bb = loop_preheader_edge (loop)->src;
881 : 869128 : gimple *g;
882 : 1263893 : do
883 : : {
884 : 869128 : g = *gsi_last_bb (bb);
885 : 545835 : if ((g && gimple_code (g) == GIMPLE_COND)
886 : 1875363 : || !single_succ_p (bb))
887 : : break;
888 : 531872 : if (!single_pred_p (bb))
889 : : break;
890 : 394765 : bb = single_pred (bb);
891 : : }
892 : : while (1);
893 : 474363 : if (g && gimple_code (g) == GIMPLE_COND)
894 : : {
895 : 330749 : if (cond)
896 : 0 : *cond = as_a <gcond *> (g);
897 : 330749 : gimple_stmt_iterator gsi = gsi_for_stmt (g);
898 : 330749 : gsi_prev (&gsi);
899 : 330749 : if (!gsi_end_p (gsi))
900 : : {
901 : 302818 : g = gsi_stmt (gsi);
902 : 302818 : if (gimple_call_internal_p (g, IFN_LOOP_VECTORIZED)
903 : 302818 : && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->num
904 : 24565 : || tree_to_shwi (gimple_call_arg (g, 1)) == loop->num))
905 : 49659 : return g;
906 : : }
907 : : }
908 : : return NULL;
909 : : }
910 : :
911 : : /* If LOOP has been versioned during loop distribution, return the gurading
912 : : internal call. */
913 : :
914 : : static gimple *
915 : 443666 : vect_loop_dist_alias_call (class loop *loop, function *fun)
916 : : {
917 : 443666 : basic_block bb;
918 : 443666 : basic_block entry;
919 : 443666 : class loop *outer, *orig;
920 : :
921 : 443666 : if (loop->orig_loop_num == 0)
922 : : return NULL;
923 : :
924 : 130 : orig = get_loop (fun, loop->orig_loop_num);
925 : 130 : if (orig == NULL)
926 : : {
927 : : /* The original loop is somehow destroyed. Clear the information. */
928 : 0 : loop->orig_loop_num = 0;
929 : 0 : return NULL;
930 : : }
931 : :
932 : 130 : if (loop != orig)
933 : 79 : bb = nearest_common_dominator (CDI_DOMINATORS, loop->header, orig->header);
934 : : else
935 : 51 : bb = loop_preheader_edge (loop)->src;
936 : :
937 : 130 : outer = bb->loop_father;
938 : 130 : entry = ENTRY_BLOCK_PTR_FOR_FN (fun);
939 : :
940 : : /* Look upward in dominance tree. */
941 : 265 : for (; bb != entry && flow_bb_inside_loop_p (outer, bb);
942 : 135 : bb = get_immediate_dominator (CDI_DOMINATORS, bb))
943 : : {
944 : 232 : gimple_stmt_iterator gsi = gsi_last_bb (bb);
945 : 232 : if (!safe_is_a <gcond *> (*gsi))
946 : 135 : continue;
947 : :
948 : 181 : gsi_prev (&gsi);
949 : 181 : if (gsi_end_p (gsi))
950 : 8 : continue;
951 : :
952 : 173 : gimple *g = gsi_stmt (gsi);
953 : : /* The guarding internal function call must have the same distribution
954 : : alias id. */
955 : 173 : if (gimple_call_internal_p (g, IFN_LOOP_DIST_ALIAS)
956 : 173 : && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->orig_loop_num))
957 : 443666 : return g;
958 : : }
959 : : return NULL;
960 : : }
961 : :
962 : : /* Set the uids of all the statements in basic blocks inside loop
963 : : represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal
964 : : call guarding the loop which has been if converted. */
965 : : static void
966 : 5411 : set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call,
967 : : function *fun)
968 : : {
969 : 5411 : tree arg = gimple_call_arg (loop_vectorized_call, 1);
970 : 5411 : basic_block *bbs;
971 : 5411 : unsigned int i;
972 : 5411 : class loop *scalar_loop = get_loop (fun, tree_to_shwi (arg));
973 : :
974 : 5411 : LOOP_VINFO_SCALAR_LOOP (loop_vinfo) = scalar_loop;
975 : 5411 : LOOP_VINFO_SCALAR_IV_EXIT (loop_vinfo)
976 : 5411 : = vec_init_loop_exit_info (scalar_loop);
977 : 5411 : gcc_checking_assert (vect_loop_vectorized_call (scalar_loop)
978 : : == loop_vectorized_call);
979 : : /* If we are going to vectorize outer loop, prevent vectorization
980 : : of the inner loop in the scalar loop - either the scalar loop is
981 : : thrown away, so it is a wasted work, or is used only for
982 : : a few iterations. */
983 : 5411 : if (scalar_loop->inner)
984 : : {
985 : 44 : gimple *g = vect_loop_vectorized_call (scalar_loop->inner);
986 : 44 : if (g)
987 : : {
988 : 44 : arg = gimple_call_arg (g, 0);
989 : 44 : get_loop (fun, tree_to_shwi (arg))->dont_vectorize = true;
990 : 44 : fold_loop_internal_call (g, boolean_false_node);
991 : : }
992 : : }
993 : 5411 : bbs = get_loop_body (scalar_loop);
994 : 29831 : for (i = 0; i < scalar_loop->num_nodes; i++)
995 : : {
996 : 24420 : basic_block bb = bbs[i];
997 : 24420 : gimple_stmt_iterator gsi;
998 : 46382 : for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
999 : : {
1000 : 21962 : gimple *phi = gsi_stmt (gsi);
1001 : 21962 : gimple_set_uid (phi, 0);
1002 : : }
1003 : 123595 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1004 : : {
1005 : 74755 : gimple *stmt = gsi_stmt (gsi);
1006 : 74755 : gimple_set_uid (stmt, 0);
1007 : : }
1008 : : }
1009 : 5411 : free (bbs);
1010 : 5411 : }
1011 : :
1012 : : /* Generate vectorized code for LOOP and its epilogues. */
1013 : :
1014 : : static unsigned
1015 : 55131 : vect_transform_loops (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
1016 : : loop_p loop, gimple *loop_vectorized_call,
1017 : : function *fun)
1018 : : {
1019 : 55131 : loop_vec_info loop_vinfo = loop_vec_info_for_loop (loop);
1020 : :
1021 : 55131 : if (loop_vectorized_call)
1022 : 5411 : set_uid_loop_bbs (loop_vinfo, loop_vectorized_call, fun);
1023 : :
1024 : 55131 : unsigned HOST_WIDE_INT bytes;
1025 : 55131 : if (dump_enabled_p ())
1026 : : {
1027 : 19822 : if (GET_MODE_SIZE (loop_vinfo->vector_mode).is_constant (&bytes))
1028 : 9911 : dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
1029 : : "loop vectorized using %wu byte vectors\n", bytes);
1030 : : else
1031 : : dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
1032 : : "loop vectorized using variable length vectors\n");
1033 : : }
1034 : :
1035 : 55131 : loop_p new_loop = vect_transform_loop (loop_vinfo,
1036 : : loop_vectorized_call);
1037 : : /* Now that the loop has been vectorized, allow it to be unrolled
1038 : : etc. */
1039 : 55131 : loop->force_vectorize = false;
1040 : :
1041 : 55131 : if (loop->simduid)
1042 : : {
1043 : 1886 : simduid_to_vf *simduid_to_vf_data = XNEW (simduid_to_vf);
1044 : 1886 : if (!simduid_to_vf_htab)
1045 : 1529 : simduid_to_vf_htab = new hash_table<simduid_to_vf> (15);
1046 : 1886 : simduid_to_vf_data->simduid = DECL_UID (loop->simduid);
1047 : 1886 : simduid_to_vf_data->vf = loop_vinfo->vectorization_factor;
1048 : 1886 : *simduid_to_vf_htab->find_slot (simduid_to_vf_data, INSERT)
1049 : 1886 : = simduid_to_vf_data;
1050 : : }
1051 : :
1052 : : /* We should not have to update virtual SSA form here but some
1053 : : transforms involve creating new virtual definitions which makes
1054 : : updating difficult.
1055 : : We delay the actual update to the end of the pass but avoid
1056 : : confusing ourselves by forcing need_ssa_update_p () to false. */
1057 : 55131 : unsigned todo = 0;
1058 : 55131 : if (need_ssa_update_p (cfun))
1059 : : {
1060 : 113 : gcc_assert (loop_vinfo->any_known_not_updated_vssa);
1061 : 113 : fun->gimple_df->ssa_renaming_needed = false;
1062 : 113 : todo |= TODO_update_ssa_only_virtuals;
1063 : : }
1064 : 55131 : gcc_assert (!need_ssa_update_p (cfun));
1065 : :
1066 : : /* Epilogue of vectorized loop must be vectorized too. */
1067 : 55131 : if (new_loop)
1068 : 6369 : todo |= vect_transform_loops (simduid_to_vf_htab, new_loop, NULL, fun);
1069 : :
1070 : 55131 : return todo;
1071 : : }
1072 : :
1073 : : /* Try to vectorize LOOP. */
1074 : :
1075 : : static unsigned
1076 : 430889 : try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
1077 : : unsigned *num_vectorized_loops, loop_p loop,
1078 : : gimple *loop_vectorized_call,
1079 : : gimple *loop_dist_alias_call,
1080 : : function *fun)
1081 : : {
1082 : 430889 : unsigned ret = 0;
1083 : 430889 : vec_info_shared shared;
1084 : 430889 : auto_purge_vect_location sentinel;
1085 : 430889 : vect_location = find_loop_location (loop);
1086 : :
1087 : 430889 : if (LOCATION_LOCUS (vect_location.get_location_t ()) != UNKNOWN_LOCATION
1088 : 430889 : && dump_enabled_p ())
1089 : 13697 : dump_printf (MSG_NOTE | MSG_PRIORITY_INTERNALS,
1090 : : "\nAnalyzing loop at %s:%d\n",
1091 : 13697 : LOCATION_FILE (vect_location.get_location_t ()),
1092 : 27394 : LOCATION_LINE (vect_location.get_location_t ()));
1093 : :
1094 : : /* Try to analyze the loop, retaining an opt_problem if dump_enabled_p. */
1095 : 430889 : opt_loop_vec_info loop_vinfo = vect_analyze_loop (loop, loop_vectorized_call,
1096 : : &shared);
1097 : 430889 : loop->aux = loop_vinfo;
1098 : :
1099 : 430889 : if (!loop_vinfo)
1100 : 382123 : if (dump_enabled_p ())
1101 : 5314 : if (opt_problem *problem = loop_vinfo.get_problem ())
1102 : : {
1103 : 5314 : dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
1104 : : "couldn't vectorize loop\n");
1105 : 5314 : problem->emit_and_clear ();
1106 : : }
1107 : :
1108 : 430889 : if (!loop_vinfo || !LOOP_VINFO_VECTORIZABLE_P (loop_vinfo))
1109 : : {
1110 : : /* Free existing information if loop is analyzed with some
1111 : : assumptions. */
1112 : 382123 : if (loop_constraint_set_p (loop, LOOP_C_FINITE))
1113 : 8233 : vect_free_loop_info_assumptions (loop);
1114 : :
1115 : : /* If we applied if-conversion then try to vectorize the
1116 : : BB of innermost loops.
1117 : : ??? Ideally BB vectorization would learn to vectorize
1118 : : control flow by applying if-conversion on-the-fly, the
1119 : : following retains the if-converted loop body even when
1120 : : only non-if-converted parts took part in BB vectorization. */
1121 : 382123 : if (flag_tree_slp_vectorize != 0
1122 : 381094 : && loop_vectorized_call
1123 : 18093 : && ! loop->inner)
1124 : : {
1125 : 17327 : basic_block bb = loop->header;
1126 : 17327 : bool require_loop_vectorize = false;
1127 : 34654 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
1128 : 429123 : !gsi_end_p (gsi); gsi_next (&gsi))
1129 : : {
1130 : 412646 : gimple *stmt = gsi_stmt (gsi);
1131 : 412646 : gcall *call = dyn_cast <gcall *> (stmt);
1132 : 2179 : if (call && gimple_call_internal_p (call))
1133 : : {
1134 : 2061 : internal_fn ifn = gimple_call_internal_fn (call);
1135 : 2061 : if (ifn == IFN_MASK_LOAD || ifn == IFN_MASK_STORE
1136 : : /* Don't keep the if-converted parts when the ifn with
1137 : : specifc type is not supported by the backend. */
1138 : 2061 : || (direct_internal_fn_p (ifn)
1139 : 427 : && !direct_internal_fn_supported_p
1140 : 427 : (call, OPTIMIZE_FOR_SPEED)))
1141 : : {
1142 : : require_loop_vectorize = true;
1143 : : break;
1144 : : }
1145 : : }
1146 : 411796 : gimple_set_uid (stmt, -1);
1147 : 411796 : gimple_set_visited (stmt, false);
1148 : : }
1149 : 17327 : if (!require_loop_vectorize)
1150 : : {
1151 : 16477 : tree arg = gimple_call_arg (loop_vectorized_call, 1);
1152 : 16477 : class loop *scalar_loop = get_loop (fun, tree_to_shwi (arg));
1153 : 16477 : if (vect_slp_if_converted_bb (bb, scalar_loop))
1154 : : {
1155 : 77 : fold_loop_internal_call (loop_vectorized_call,
1156 : : boolean_true_node);
1157 : 77 : loop_vectorized_call = NULL;
1158 : 77 : ret |= TODO_cleanup_cfg | TODO_update_ssa_only_virtuals;
1159 : : }
1160 : : }
1161 : : }
1162 : : /* If outer loop vectorization fails for LOOP_VECTORIZED guarded
1163 : : loop, don't vectorize its inner loop; we'll attempt to
1164 : : vectorize LOOP_VECTORIZED guarded inner loop of the scalar
1165 : : loop version. */
1166 : 19122 : if (loop_vectorized_call && loop->inner)
1167 : 768 : loop->inner->dont_vectorize = true;
1168 : 382123 : return ret;
1169 : : }
1170 : :
1171 : 48766 : if (!dbg_cnt (vect_loop))
1172 : : {
1173 : : /* Free existing information if loop is analyzed with some
1174 : : assumptions. */
1175 : 4 : if (loop_constraint_set_p (loop, LOOP_C_FINITE))
1176 : 0 : vect_free_loop_info_assumptions (loop);
1177 : 4 : return ret;
1178 : : }
1179 : :
1180 : 48762 : (*num_vectorized_loops)++;
1181 : : /* Transform LOOP and its epilogues. */
1182 : 48762 : ret |= vect_transform_loops (simduid_to_vf_htab, loop,
1183 : : loop_vectorized_call, fun);
1184 : :
1185 : 48762 : if (loop_vectorized_call)
1186 : : {
1187 : 5411 : fold_loop_internal_call (loop_vectorized_call, boolean_true_node);
1188 : 5411 : ret |= TODO_cleanup_cfg;
1189 : : }
1190 : 48762 : if (loop_dist_alias_call)
1191 : : {
1192 : 7 : tree value = gimple_call_arg (loop_dist_alias_call, 1);
1193 : 7 : fold_loop_internal_call (loop_dist_alias_call, value);
1194 : 7 : ret |= TODO_cleanup_cfg;
1195 : : }
1196 : :
1197 : : return ret;
1198 : 430889 : }
1199 : :
1200 : : /* Try to vectorize LOOP. */
1201 : :
1202 : : static unsigned
1203 : 461124 : try_vectorize_loop (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
1204 : : unsigned *num_vectorized_loops, loop_p loop,
1205 : : function *fun)
1206 : : {
1207 : 461124 : if (!((flag_tree_loop_vectorize
1208 : 456492 : && optimize_loop_nest_for_speed_p (loop))
1209 : 32035 : || loop->force_vectorize))
1210 : : return 0;
1211 : :
1212 : 430889 : return try_vectorize_loop_1 (simduid_to_vf_htab, num_vectorized_loops, loop,
1213 : : vect_loop_vectorized_call (loop),
1214 : 430889 : vect_loop_dist_alias_call (loop, fun), fun);
1215 : : }
1216 : :
1217 : :
1218 : : /* Loop autovectorization. */
1219 : :
1220 : : namespace {
1221 : :
1222 : : const pass_data pass_data_vectorize =
1223 : : {
1224 : : GIMPLE_PASS, /* type */
1225 : : "vect", /* name */
1226 : : OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
1227 : : TV_TREE_VECTORIZATION, /* tv_id */
1228 : : ( PROP_cfg | PROP_ssa ), /* properties_required */
1229 : : 0, /* properties_provided */
1230 : : 0, /* properties_destroyed */
1231 : : 0, /* todo_flags_start */
1232 : : 0, /* todo_flags_finish */
1233 : : };
1234 : :
1235 : : class pass_vectorize : public gimple_opt_pass
1236 : : {
1237 : : public:
1238 : 280831 : pass_vectorize (gcc::context *ctxt)
1239 : 561662 : : gimple_opt_pass (pass_data_vectorize, ctxt)
1240 : : {}
1241 : :
1242 : : /* opt_pass methods: */
1243 : 227376 : bool gate (function *fun) final override
1244 : : {
1245 : 227376 : return flag_tree_loop_vectorize || fun->has_force_vectorize_loops;
1246 : : }
1247 : :
1248 : : unsigned int execute (function *) final override;
1249 : :
1250 : : }; // class pass_vectorize
1251 : :
1252 : : /* Function vectorize_loops.
1253 : :
1254 : : Entry point to loop vectorization phase. */
1255 : :
1256 : : unsigned
1257 : 196344 : pass_vectorize::execute (function *fun)
1258 : : {
1259 : 196344 : unsigned int i;
1260 : 196344 : unsigned int num_vectorized_loops = 0;
1261 : 196344 : unsigned int vect_loops_num;
1262 : 196344 : hash_table<simduid_to_vf> *simduid_to_vf_htab = NULL;
1263 : 196344 : hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
1264 : 196344 : bool any_ifcvt_loops = false;
1265 : 196344 : unsigned ret = 0;
1266 : :
1267 : 196344 : vect_loops_num = number_of_loops (fun);
1268 : :
1269 : : /* Bail out if there are no loops. */
1270 : 196344 : if (vect_loops_num <= 1)
1271 : : return 0;
1272 : :
1273 : 196344 : vect_slp_init ();
1274 : :
1275 : 196344 : if (fun->has_simduid_loops)
1276 : 5603 : note_simd_array_uses (&simd_array_to_simduid_htab, fun);
1277 : :
1278 : : /* ----------- Analyze loops. ----------- */
1279 : :
1280 : : /* If some loop was duplicated, it gets bigger number
1281 : : than all previously defined loops. This fact allows us to run
1282 : : only over initial loops skipping newly generated ones. */
1283 : 1078583 : for (auto loop : loops_list (fun, 0))
1284 : 489551 : if (loop->dont_vectorize)
1285 : : {
1286 : 29239 : any_ifcvt_loops = true;
1287 : : /* If-conversion sometimes versions both the outer loop
1288 : : (for the case when outer loop vectorization might be
1289 : : desirable) as well as the inner loop in the scalar version
1290 : : of the loop. So we have:
1291 : : if (LOOP_VECTORIZED (1, 3))
1292 : : {
1293 : : loop1
1294 : : loop2
1295 : : }
1296 : : else
1297 : : loop3 (copy of loop1)
1298 : : if (LOOP_VECTORIZED (4, 5))
1299 : : loop4 (copy of loop2)
1300 : : else
1301 : : loop5 (copy of loop4)
1302 : : If loops' iteration gives us loop3 first (which has
1303 : : dont_vectorize set), make sure to process loop1 before loop4;
1304 : : so that we can prevent vectorization of loop4 if loop1
1305 : : is successfully vectorized. */
1306 : 29239 : if (loop->inner)
1307 : : {
1308 : 1890 : gimple *loop_vectorized_call
1309 : 1890 : = vect_loop_vectorized_call (loop);
1310 : 1890 : if (loop_vectorized_call
1311 : 1890 : && vect_loop_vectorized_call (loop->inner))
1312 : : {
1313 : 812 : tree arg = gimple_call_arg (loop_vectorized_call, 0);
1314 : 812 : class loop *vector_loop
1315 : 812 : = get_loop (fun, tree_to_shwi (arg));
1316 : 812 : if (vector_loop && vector_loop != loop)
1317 : : {
1318 : : /* Make sure we don't vectorize it twice. */
1319 : 812 : vector_loop->dont_vectorize = true;
1320 : 812 : ret |= try_vectorize_loop (simduid_to_vf_htab,
1321 : : &num_vectorized_loops,
1322 : : vector_loop, fun);
1323 : : }
1324 : : }
1325 : : }
1326 : : }
1327 : : else
1328 : 460312 : ret |= try_vectorize_loop (simduid_to_vf_htab, &num_vectorized_loops,
1329 : 196344 : loop, fun);
1330 : :
1331 : 196344 : vect_location = dump_user_location_t ();
1332 : :
1333 : 196344 : statistics_counter_event (fun, "Vectorized loops", num_vectorized_loops);
1334 : 196344 : if (dump_enabled_p ()
1335 : 196344 : || (num_vectorized_loops > 0 && dump_enabled_p ()))
1336 : 10449 : dump_printf_loc (MSG_NOTE, vect_location,
1337 : : "vectorized %u loops in function.\n",
1338 : : num_vectorized_loops);
1339 : :
1340 : : /* ----------- Finalize. ----------- */
1341 : :
1342 : 196344 : if (any_ifcvt_loops)
1343 : 258490 : for (i = 1; i < number_of_loops (fun); i++)
1344 : : {
1345 : 110531 : class loop *loop = get_loop (fun, i);
1346 : 110531 : if (loop && loop->dont_vectorize)
1347 : : {
1348 : 31031 : gimple *g = vect_loop_vectorized_call (loop);
1349 : 31031 : if (g)
1350 : : {
1351 : 18254 : fold_loop_internal_call (g, boolean_false_node);
1352 : 18254 : loop->dont_vectorize = false;
1353 : 18254 : ret |= TODO_cleanup_cfg;
1354 : 18254 : g = NULL;
1355 : : }
1356 : : else
1357 : 12777 : g = vect_loop_dist_alias_call (loop, fun);
1358 : :
1359 : 31031 : if (g)
1360 : : {
1361 : 25 : fold_loop_internal_call (g, boolean_false_node);
1362 : 25 : loop->dont_vectorize = false;
1363 : 25 : ret |= TODO_cleanup_cfg;
1364 : : }
1365 : : }
1366 : : }
1367 : :
1368 : : /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
1369 : 196344 : if (fun->has_simduid_loops)
1370 : : {
1371 : 5603 : adjust_simduid_builtins (simduid_to_vf_htab, fun);
1372 : : /* Avoid stale SCEV cache entries for the SIMD_LANE defs. */
1373 : 5603 : scev_reset ();
1374 : : }
1375 : : /* Shrink any "omp array simd" temporary arrays to the
1376 : : actual vectorization factors. */
1377 : 196344 : if (simd_array_to_simduid_htab)
1378 : 2203 : shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab);
1379 : 196344 : delete simduid_to_vf_htab;
1380 : 196344 : fun->has_simduid_loops = false;
1381 : :
1382 : 196344 : if (num_vectorized_loops > 0)
1383 : : {
1384 : : /* We are collecting some corner cases where we need to update
1385 : : virtual SSA form via the TODO but delete the queued update-SSA
1386 : : state. Force renaming if we think that might be necessary. */
1387 : 32979 : if (ret & TODO_update_ssa_only_virtuals)
1388 : 86 : mark_virtual_operands_for_renaming (cfun);
1389 : : /* If we vectorized any loop only virtual SSA form needs to be updated.
1390 : : ??? Also while we try hard to update loop-closed SSA form we fail
1391 : : to properly do this in some corner-cases (see PR56286). */
1392 : 32979 : rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
1393 : 32979 : ret |= TODO_cleanup_cfg;
1394 : : }
1395 : :
1396 : 1712386 : for (i = 1; i < number_of_loops (fun); i++)
1397 : : {
1398 : 659849 : loop_vec_info loop_vinfo;
1399 : 659849 : bool has_mask_store;
1400 : :
1401 : 659849 : class loop *loop = get_loop (fun, i);
1402 : 659849 : if (!loop || !loop->aux)
1403 : 604714 : continue;
1404 : 55135 : loop_vinfo = (loop_vec_info) loop->aux;
1405 : 55135 : has_mask_store = LOOP_VINFO_HAS_MASK_STORE (loop_vinfo);
1406 : 55135 : delete loop_vinfo;
1407 : 55135 : if (has_mask_store
1408 : 55135 : && targetm.vectorize.empty_mask_is_expensive (IFN_MASK_STORE))
1409 : 450 : optimize_mask_stores (loop);
1410 : :
1411 : 55135 : auto_bitmap exit_bbs;
1412 : : /* Perform local CSE, this esp. helps because we emit code for
1413 : : predicates that need to be shared for optimal predicate usage.
1414 : : However reassoc will re-order them and prevent CSE from working
1415 : : as it should. CSE only the loop body, not the entry. */
1416 : 55135 : auto_vec<edge> exits = get_loop_exit_edges (loop);
1417 : 222216 : for (edge exit : exits)
1418 : 56811 : bitmap_set_bit (exit_bbs, exit->dest->index);
1419 : :
1420 : 55135 : edge entry = EDGE_PRED (loop_preheader_edge (loop)->src, 0);
1421 : 55135 : do_rpo_vn (fun, entry, exit_bbs);
1422 : :
1423 : 55135 : loop->aux = NULL;
1424 : 55135 : }
1425 : :
1426 : 196344 : vect_slp_fini ();
1427 : :
1428 : 196344 : return ret;
1429 : : }
1430 : :
1431 : : } // anon namespace
1432 : :
1433 : : gimple_opt_pass *
1434 : 280831 : make_pass_vectorize (gcc::context *ctxt)
1435 : : {
1436 : 280831 : return new pass_vectorize (ctxt);
1437 : : }
1438 : :
1439 : : /* Entry point to the simduid cleanup pass. */
1440 : :
1441 : : namespace {
1442 : :
1443 : : const pass_data pass_data_simduid_cleanup =
1444 : : {
1445 : : GIMPLE_PASS, /* type */
1446 : : "simduid", /* name */
1447 : : OPTGROUP_NONE, /* optinfo_flags */
1448 : : TV_NONE, /* tv_id */
1449 : : ( PROP_ssa | PROP_cfg ), /* properties_required */
1450 : : 0, /* properties_provided */
1451 : : 0, /* properties_destroyed */
1452 : : 0, /* todo_flags_start */
1453 : : 0, /* todo_flags_finish */
1454 : : };
1455 : :
1456 : : class pass_simduid_cleanup : public gimple_opt_pass
1457 : : {
1458 : : public:
1459 : 561662 : pass_simduid_cleanup (gcc::context *ctxt)
1460 : 1123324 : : gimple_opt_pass (pass_data_simduid_cleanup, ctxt)
1461 : : {}
1462 : :
1463 : : /* opt_pass methods: */
1464 : 280831 : opt_pass * clone () final override
1465 : : {
1466 : 280831 : return new pass_simduid_cleanup (m_ctxt);
1467 : : }
1468 : 2428758 : bool gate (function *fun) final override { return fun->has_simduid_loops; }
1469 : : unsigned int execute (function *) final override;
1470 : :
1471 : : }; // class pass_simduid_cleanup
1472 : :
1473 : : unsigned int
1474 : 2209 : pass_simduid_cleanup::execute (function *fun)
1475 : : {
1476 : 2209 : hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
1477 : :
1478 : 2209 : note_simd_array_uses (&simd_array_to_simduid_htab, fun);
1479 : :
1480 : : /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
1481 : 2209 : adjust_simduid_builtins (NULL, fun);
1482 : :
1483 : : /* Shrink any "omp array simd" temporary arrays to the
1484 : : actual vectorization factors. */
1485 : 2209 : if (simd_array_to_simduid_htab)
1486 : 4 : shrink_simd_arrays (simd_array_to_simduid_htab, NULL);
1487 : 2209 : fun->has_simduid_loops = false;
1488 : 2209 : return 0;
1489 : : }
1490 : :
1491 : : } // anon namespace
1492 : :
1493 : : gimple_opt_pass *
1494 : 280831 : make_pass_simduid_cleanup (gcc::context *ctxt)
1495 : : {
1496 : 280831 : return new pass_simduid_cleanup (ctxt);
1497 : : }
1498 : :
1499 : :
1500 : : /* Entry point to basic block SLP phase. */
1501 : :
1502 : : namespace {
1503 : :
1504 : : const pass_data pass_data_slp_vectorize =
1505 : : {
1506 : : GIMPLE_PASS, /* type */
1507 : : "slp", /* name */
1508 : : OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
1509 : : TV_TREE_SLP_VECTORIZATION, /* tv_id */
1510 : : ( PROP_ssa | PROP_cfg ), /* properties_required */
1511 : : 0, /* properties_provided */
1512 : : 0, /* properties_destroyed */
1513 : : 0, /* todo_flags_start */
1514 : : TODO_update_ssa, /* todo_flags_finish */
1515 : : };
1516 : :
1517 : : class pass_slp_vectorize : public gimple_opt_pass
1518 : : {
1519 : : public:
1520 : 561662 : pass_slp_vectorize (gcc::context *ctxt)
1521 : 1123324 : : gimple_opt_pass (pass_data_slp_vectorize, ctxt)
1522 : : {}
1523 : :
1524 : : /* opt_pass methods: */
1525 : 280831 : opt_pass * clone () final override { return new pass_slp_vectorize (m_ctxt); }
1526 : 1000784 : bool gate (function *) final override { return flag_tree_slp_vectorize != 0; }
1527 : : unsigned int execute (function *) final override;
1528 : :
1529 : : }; // class pass_slp_vectorize
1530 : :
1531 : : unsigned int
1532 : 876372 : pass_slp_vectorize::execute (function *fun)
1533 : : {
1534 : 876372 : auto_purge_vect_location sentinel;
1535 : 876372 : basic_block bb;
1536 : :
1537 : 876372 : bool in_loop_pipeline = scev_initialized_p ();
1538 : 876372 : if (!in_loop_pipeline)
1539 : : {
1540 : 681663 : loop_optimizer_init (LOOPS_NORMAL);
1541 : 681663 : scev_initialize ();
1542 : : }
1543 : :
1544 : : /* Mark all stmts as not belonging to the current region and unvisited. */
1545 : 11227544 : FOR_EACH_BB_FN (bb, fun)
1546 : : {
1547 : 15199994 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
1548 : 4848822 : gsi_next (&gsi))
1549 : : {
1550 : 4848822 : gphi *stmt = gsi.phi ();
1551 : 4848822 : gimple_set_uid (stmt, -1);
1552 : 4848822 : gimple_set_visited (stmt, false);
1553 : : }
1554 : 90239862 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
1555 : 69537518 : gsi_next (&gsi))
1556 : : {
1557 : 69537518 : gimple *stmt = gsi_stmt (gsi);
1558 : 69537518 : gimple_set_uid (stmt, -1);
1559 : 69537518 : gimple_set_visited (stmt, false);
1560 : : }
1561 : : }
1562 : :
1563 : 876372 : vect_slp_init ();
1564 : :
1565 : 876372 : vect_slp_function (fun);
1566 : :
1567 : 876372 : vect_slp_fini ();
1568 : :
1569 : 876372 : if (!in_loop_pipeline)
1570 : : {
1571 : 681663 : scev_finalize ();
1572 : 681663 : loop_optimizer_finalize ();
1573 : : }
1574 : :
1575 : 1752744 : return 0;
1576 : 876372 : }
1577 : :
1578 : : } // anon namespace
1579 : :
1580 : : gimple_opt_pass *
1581 : 280831 : make_pass_slp_vectorize (gcc::context *ctxt)
1582 : : {
1583 : 280831 : return new pass_slp_vectorize (ctxt);
1584 : : }
1585 : :
1586 : :
1587 : : /* Increase alignment of global arrays to improve vectorization potential.
1588 : : TODO:
1589 : : - Consider also structs that have an array field.
1590 : : - Use ipa analysis to prune arrays that can't be vectorized?
1591 : : This should involve global alignment analysis and in the future also
1592 : : array padding. */
1593 : :
1594 : : static unsigned get_vec_alignment_for_type (tree);
1595 : : static hash_map<tree, unsigned> *type_align_map;
1596 : :
1597 : : /* Return alignment of array's vector type corresponding to scalar type.
1598 : : 0 if no vector type exists. */
1599 : : static unsigned
1600 : 0 : get_vec_alignment_for_array_type (tree type)
1601 : : {
1602 : 0 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
1603 : 0 : poly_uint64 array_size, vector_size;
1604 : :
1605 : 0 : tree scalar_type = strip_array_types (type);
1606 : 0 : tree vectype = get_related_vectype_for_scalar_type (VOIDmode, scalar_type);
1607 : 0 : if (!vectype
1608 : 0 : || !poly_int_tree_p (TYPE_SIZE (type), &array_size)
1609 : 0 : || !poly_int_tree_p (TYPE_SIZE (vectype), &vector_size)
1610 : 0 : || maybe_lt (array_size, vector_size))
1611 : 0 : return 0;
1612 : :
1613 : 0 : return TYPE_ALIGN (vectype);
1614 : : }
1615 : :
1616 : : /* Return alignment of field having maximum alignment of vector type
1617 : : corresponding to it's scalar type. For now, we only consider fields whose
1618 : : offset is a multiple of it's vector alignment.
1619 : : 0 if no suitable field is found. */
1620 : : static unsigned
1621 : 0 : get_vec_alignment_for_record_type (tree type)
1622 : : {
1623 : 0 : gcc_assert (TREE_CODE (type) == RECORD_TYPE);
1624 : :
1625 : 0 : unsigned max_align = 0, alignment;
1626 : 0 : HOST_WIDE_INT offset;
1627 : 0 : tree offset_tree;
1628 : :
1629 : 0 : if (TYPE_PACKED (type))
1630 : : return 0;
1631 : :
1632 : 0 : unsigned *slot = type_align_map->get (type);
1633 : 0 : if (slot)
1634 : 0 : return *slot;
1635 : :
1636 : 0 : for (tree field = first_field (type);
1637 : 0 : field != NULL_TREE;
1638 : 0 : field = DECL_CHAIN (field))
1639 : : {
1640 : : /* Skip if not FIELD_DECL or if alignment is set by user. */
1641 : 0 : if (TREE_CODE (field) != FIELD_DECL
1642 : 0 : || DECL_USER_ALIGN (field)
1643 : 0 : || DECL_ARTIFICIAL (field))
1644 : 0 : continue;
1645 : :
1646 : : /* We don't need to process the type further if offset is variable,
1647 : : since the offsets of remaining members will also be variable. */
1648 : 0 : if (TREE_CODE (DECL_FIELD_OFFSET (field)) != INTEGER_CST
1649 : 0 : || TREE_CODE (DECL_FIELD_BIT_OFFSET (field)) != INTEGER_CST)
1650 : : break;
1651 : :
1652 : : /* Similarly stop processing the type if offset_tree
1653 : : does not fit in unsigned HOST_WIDE_INT. */
1654 : 0 : offset_tree = bit_position (field);
1655 : 0 : if (!tree_fits_uhwi_p (offset_tree))
1656 : : break;
1657 : :
1658 : 0 : offset = tree_to_uhwi (offset_tree);
1659 : 0 : alignment = get_vec_alignment_for_type (TREE_TYPE (field));
1660 : :
1661 : : /* Get maximum alignment of vectorized field/array among those members
1662 : : whose offset is multiple of the vector alignment. */
1663 : 0 : if (alignment
1664 : 0 : && (offset % alignment == 0)
1665 : 0 : && (alignment > max_align))
1666 : 0 : max_align = alignment;
1667 : : }
1668 : :
1669 : 0 : type_align_map->put (type, max_align);
1670 : 0 : return max_align;
1671 : : }
1672 : :
1673 : : /* Return alignment of vector type corresponding to decl's scalar type
1674 : : or 0 if it doesn't exist or the vector alignment is lesser than
1675 : : decl's alignment. */
1676 : : static unsigned
1677 : 0 : get_vec_alignment_for_type (tree type)
1678 : : {
1679 : 0 : if (type == NULL_TREE)
1680 : : return 0;
1681 : :
1682 : 0 : gcc_assert (TYPE_P (type));
1683 : :
1684 : 0 : static unsigned alignment = 0;
1685 : 0 : switch (TREE_CODE (type))
1686 : : {
1687 : 0 : case ARRAY_TYPE:
1688 : 0 : alignment = get_vec_alignment_for_array_type (type);
1689 : 0 : break;
1690 : 0 : case RECORD_TYPE:
1691 : 0 : alignment = get_vec_alignment_for_record_type (type);
1692 : 0 : break;
1693 : 0 : default:
1694 : 0 : alignment = 0;
1695 : 0 : break;
1696 : : }
1697 : :
1698 : 0 : return (alignment > TYPE_ALIGN (type)) ? alignment : 0;
1699 : : }
1700 : :
1701 : : /* Entry point to increase_alignment pass. */
1702 : : static unsigned int
1703 : 0 : increase_alignment (void)
1704 : : {
1705 : 0 : varpool_node *vnode;
1706 : :
1707 : 0 : vect_location = dump_user_location_t ();
1708 : 0 : type_align_map = new hash_map<tree, unsigned>;
1709 : :
1710 : : /* Increase the alignment of all global arrays for vectorization. */
1711 : 0 : FOR_EACH_DEFINED_VARIABLE (vnode)
1712 : : {
1713 : 0 : tree decl = vnode->decl;
1714 : 0 : unsigned int alignment;
1715 : :
1716 : 0 : if ((decl_in_symtab_p (decl)
1717 : 0 : && !symtab_node::get (decl)->can_increase_alignment_p ())
1718 : 0 : || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl))
1719 : 0 : continue;
1720 : :
1721 : 0 : alignment = get_vec_alignment_for_type (TREE_TYPE (decl));
1722 : 0 : if (alignment && vect_can_force_dr_alignment_p (decl, alignment))
1723 : : {
1724 : 0 : vnode->increase_alignment (alignment);
1725 : 0 : if (dump_enabled_p ())
1726 : 0 : dump_printf (MSG_NOTE, "Increasing alignment of decl: %T\n", decl);
1727 : : }
1728 : : }
1729 : :
1730 : 0 : delete type_align_map;
1731 : 0 : return 0;
1732 : : }
1733 : :
1734 : :
1735 : : namespace {
1736 : :
1737 : : const pass_data pass_data_ipa_increase_alignment =
1738 : : {
1739 : : SIMPLE_IPA_PASS, /* type */
1740 : : "increase_alignment", /* name */
1741 : : OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
1742 : : TV_IPA_OPT, /* tv_id */
1743 : : 0, /* properties_required */
1744 : : 0, /* properties_provided */
1745 : : 0, /* properties_destroyed */
1746 : : 0, /* todo_flags_start */
1747 : : 0, /* todo_flags_finish */
1748 : : };
1749 : :
1750 : : class pass_ipa_increase_alignment : public simple_ipa_opt_pass
1751 : : {
1752 : : public:
1753 : 280831 : pass_ipa_increase_alignment (gcc::context *ctxt)
1754 : 561662 : : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt)
1755 : : {}
1756 : :
1757 : : /* opt_pass methods: */
1758 : 225767 : bool gate (function *) final override
1759 : : {
1760 : 225767 : return flag_section_anchors && flag_tree_loop_vectorize;
1761 : : }
1762 : :
1763 : 0 : unsigned int execute (function *) final override
1764 : : {
1765 : 0 : return increase_alignment ();
1766 : : }
1767 : :
1768 : : }; // class pass_ipa_increase_alignment
1769 : :
1770 : : } // anon namespace
1771 : :
1772 : : simple_ipa_opt_pass *
1773 : 280831 : make_pass_ipa_increase_alignment (gcc::context *ctxt)
1774 : : {
1775 : 280831 : return new pass_ipa_increase_alignment (ctxt);
1776 : : }
1777 : :
1778 : : /* If the condition represented by T is a comparison or the SSA name
1779 : : result of a comparison, extract the comparison's operands. Represent
1780 : : T as NE_EXPR <T, 0> otherwise. */
1781 : :
1782 : : void
1783 : 47722 : scalar_cond_masked_key::get_cond_ops_from_tree (tree t)
1784 : : {
1785 : 47722 : if (TREE_CODE_CLASS (TREE_CODE (t)) == tcc_comparison)
1786 : : {
1787 : 0 : this->code = TREE_CODE (t);
1788 : 0 : this->op0 = TREE_OPERAND (t, 0);
1789 : 0 : this->op1 = TREE_OPERAND (t, 1);
1790 : 0 : this->inverted_p = false;
1791 : 0 : return;
1792 : : }
1793 : :
1794 : 47722 : if (TREE_CODE (t) == SSA_NAME)
1795 : 19779 : if (gassign *stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (t)))
1796 : : {
1797 : 19779 : tree_code code = gimple_assign_rhs_code (stmt);
1798 : 19779 : if (TREE_CODE_CLASS (code) == tcc_comparison)
1799 : : {
1800 : 14113 : this->code = code;
1801 : 14113 : this->op0 = gimple_assign_rhs1 (stmt);
1802 : 14113 : this->op1 = gimple_assign_rhs2 (stmt);
1803 : 14113 : this->inverted_p = false;
1804 : 14113 : return;
1805 : : }
1806 : 5666 : else if (code == BIT_NOT_EXPR)
1807 : : {
1808 : 2845 : tree n_op = gimple_assign_rhs1 (stmt);
1809 : 2845 : if ((stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (n_op))))
1810 : : {
1811 : 2845 : code = gimple_assign_rhs_code (stmt);
1812 : 2845 : if (TREE_CODE_CLASS (code) == tcc_comparison)
1813 : : {
1814 : 2825 : this->code = code;
1815 : 2825 : this->op0 = gimple_assign_rhs1 (stmt);
1816 : 2825 : this->op1 = gimple_assign_rhs2 (stmt);
1817 : 2825 : this->inverted_p = true;
1818 : 2825 : return;
1819 : : }
1820 : : }
1821 : : }
1822 : : }
1823 : :
1824 : 30784 : this->code = NE_EXPR;
1825 : 30784 : this->op0 = t;
1826 : 30784 : this->op1 = build_zero_cst (TREE_TYPE (t));
1827 : 30784 : this->inverted_p = false;
1828 : : }
1829 : :
1830 : : /* See the comment above the declaration for details. */
1831 : :
1832 : : unsigned int
1833 : 0 : vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
1834 : : stmt_vec_info stmt_info, slp_tree,
1835 : : tree vectype, int misalign,
1836 : : vect_cost_model_location where)
1837 : : {
1838 : 0 : unsigned int cost
1839 : 0 : = builtin_vectorization_cost (kind, vectype, misalign) * count;
1840 : 0 : return record_stmt_cost (stmt_info, where, cost);
1841 : : }
1842 : :
1843 : : /* See the comment above the declaration for details. */
1844 : :
1845 : : void
1846 : 1584708 : vector_costs::finish_cost (const vector_costs *)
1847 : : {
1848 : 1584708 : gcc_assert (!m_finished);
1849 : 1584708 : m_finished = true;
1850 : 1584708 : }
1851 : :
1852 : : /* Record a base cost of COST units against WHERE. If STMT_INFO is
1853 : : nonnull, use it to adjust the cost based on execution frequency
1854 : : (where appropriate). */
1855 : :
1856 : : unsigned int
1857 : 0 : vector_costs::record_stmt_cost (stmt_vec_info stmt_info,
1858 : : vect_cost_model_location where,
1859 : : unsigned int cost)
1860 : : {
1861 : 0 : cost = adjust_cost_for_freq (stmt_info, where, cost);
1862 : 0 : m_costs[where] += cost;
1863 : 0 : return cost;
1864 : : }
1865 : :
1866 : : /* COST is the base cost we have calculated for an operation in location WHERE.
1867 : : If STMT_INFO is nonnull, use it to adjust the cost based on execution
1868 : : frequency (where appropriate). Return the adjusted cost. */
1869 : :
1870 : : unsigned int
1871 : 6333785 : vector_costs::adjust_cost_for_freq (stmt_vec_info stmt_info,
1872 : : vect_cost_model_location where,
1873 : : unsigned int cost)
1874 : : {
1875 : : /* Statements in an inner loop relative to the loop being
1876 : : vectorized are weighted more heavily. The value here is
1877 : : arbitrary and could potentially be improved with analysis. */
1878 : 6333785 : if (where == vect_body
1879 : 6333785 : && stmt_info
1880 : 6333785 : && stmt_in_inner_loop_p (m_vinfo, stmt_info))
1881 : : {
1882 : 5581 : loop_vec_info loop_vinfo = as_a<loop_vec_info> (m_vinfo);
1883 : 5581 : cost *= LOOP_VINFO_INNER_LOOP_COST_FACTOR (loop_vinfo);
1884 : : }
1885 : 6333785 : return cost;
1886 : : }
1887 : :
1888 : : /* See the comment above the declaration for details. */
1889 : :
1890 : : bool
1891 : 0 : vector_costs::better_main_loop_than_p (const vector_costs *other) const
1892 : : {
1893 : 0 : int diff = compare_inside_loop_cost (other);
1894 : 0 : if (diff != 0)
1895 : 0 : return diff < 0;
1896 : :
1897 : : /* If there's nothing to choose between the loop bodies, see whether
1898 : : there's a difference in the prologue and epilogue costs. */
1899 : 0 : diff = compare_outside_loop_cost (other);
1900 : 0 : if (diff != 0)
1901 : 0 : return diff < 0;
1902 : :
1903 : : return false;
1904 : : }
1905 : :
1906 : :
1907 : : /* See the comment above the declaration for details. */
1908 : :
1909 : : bool
1910 : 0 : vector_costs::better_epilogue_loop_than_p (const vector_costs *other,
1911 : : loop_vec_info main_loop) const
1912 : : {
1913 : 0 : loop_vec_info this_loop_vinfo = as_a<loop_vec_info> (this->m_vinfo);
1914 : 0 : loop_vec_info other_loop_vinfo = as_a<loop_vec_info> (other->m_vinfo);
1915 : :
1916 : 0 : poly_int64 this_vf = LOOP_VINFO_VECT_FACTOR (this_loop_vinfo);
1917 : 0 : poly_int64 other_vf = LOOP_VINFO_VECT_FACTOR (other_loop_vinfo);
1918 : :
1919 : 0 : poly_uint64 main_poly_vf = LOOP_VINFO_VECT_FACTOR (main_loop);
1920 : 0 : unsigned HOST_WIDE_INT main_vf;
1921 : 0 : unsigned HOST_WIDE_INT other_factor, this_factor, other_cost, this_cost;
1922 : : /* If we can determine how many iterations are left for the epilogue
1923 : : loop, that is if both the main loop's vectorization factor and number
1924 : : of iterations are constant, then we use them to calculate the cost of
1925 : : the epilogue loop together with a 'likely value' for the epilogues
1926 : : vectorization factor. Otherwise we use the main loop's vectorization
1927 : : factor and the maximum poly value for the epilogue's. If the target
1928 : : has not provided with a sensible upper bound poly vectorization
1929 : : factors are likely to be favored over constant ones. */
1930 : 0 : if (main_poly_vf.is_constant (&main_vf)
1931 : 0 : && LOOP_VINFO_NITERS_KNOWN_P (main_loop))
1932 : : {
1933 : 0 : unsigned HOST_WIDE_INT niters
1934 : 0 : = LOOP_VINFO_INT_NITERS (main_loop) % main_vf;
1935 : 0 : HOST_WIDE_INT other_likely_vf
1936 : 0 : = estimated_poly_value (other_vf, POLY_VALUE_LIKELY);
1937 : 0 : HOST_WIDE_INT this_likely_vf
1938 : 0 : = estimated_poly_value (this_vf, POLY_VALUE_LIKELY);
1939 : :
1940 : : /* If the epilogue is using partial vectors we account for the
1941 : : partial iteration here too. */
1942 : 0 : other_factor = niters / other_likely_vf;
1943 : 0 : if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (other_loop_vinfo)
1944 : 0 : && niters % other_likely_vf != 0)
1945 : 0 : other_factor++;
1946 : :
1947 : 0 : this_factor = niters / this_likely_vf;
1948 : 0 : if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (this_loop_vinfo)
1949 : 0 : && niters % this_likely_vf != 0)
1950 : 0 : this_factor++;
1951 : : }
1952 : : else
1953 : : {
1954 : 0 : unsigned HOST_WIDE_INT main_vf_max
1955 : 0 : = estimated_poly_value (main_poly_vf, POLY_VALUE_MAX);
1956 : 0 : unsigned HOST_WIDE_INT other_vf_max
1957 : 0 : = estimated_poly_value (other_vf, POLY_VALUE_MAX);
1958 : 0 : unsigned HOST_WIDE_INT this_vf_max
1959 : 0 : = estimated_poly_value (this_vf, POLY_VALUE_MAX);
1960 : :
1961 : 0 : other_factor = CEIL (main_vf_max, other_vf_max);
1962 : 0 : this_factor = CEIL (main_vf_max, this_vf_max);
1963 : :
1964 : : /* If the loop is not using partial vectors then it will iterate one
1965 : : time less than one that does. It is safe to subtract one here,
1966 : : because the main loop's vf is always at least 2x bigger than that
1967 : : of an epilogue. */
1968 : 0 : if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (other_loop_vinfo))
1969 : 0 : other_factor -= 1;
1970 : 0 : if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (this_loop_vinfo))
1971 : 0 : this_factor -= 1;
1972 : : }
1973 : :
1974 : : /* Compute the costs by multiplying the inside costs with the factor and
1975 : : add the outside costs for a more complete picture. The factor is the
1976 : : amount of times we are expecting to iterate this epilogue. */
1977 : 0 : other_cost = other->body_cost () * other_factor;
1978 : 0 : this_cost = this->body_cost () * this_factor;
1979 : 0 : other_cost += other->outside_cost ();
1980 : 0 : this_cost += this->outside_cost ();
1981 : 0 : return this_cost < other_cost;
1982 : : }
1983 : :
1984 : : /* A <=>-style subroutine of better_main_loop_than_p. Check whether we can
1985 : : determine the return value of better_main_loop_than_p by comparing the
1986 : : inside (loop body) costs of THIS and OTHER. Return:
1987 : :
1988 : : * -1 if better_main_loop_than_p should return true.
1989 : : * 1 if better_main_loop_than_p should return false.
1990 : : * 0 if we can't decide. */
1991 : :
1992 : : int
1993 : 0 : vector_costs::compare_inside_loop_cost (const vector_costs *other) const
1994 : : {
1995 : 0 : loop_vec_info this_loop_vinfo = as_a<loop_vec_info> (this->m_vinfo);
1996 : 0 : loop_vec_info other_loop_vinfo = as_a<loop_vec_info> (other->m_vinfo);
1997 : :
1998 : 0 : struct loop *loop = LOOP_VINFO_LOOP (this_loop_vinfo);
1999 : 0 : gcc_assert (LOOP_VINFO_LOOP (other_loop_vinfo) == loop);
2000 : :
2001 : 0 : poly_int64 this_vf = LOOP_VINFO_VECT_FACTOR (this_loop_vinfo);
2002 : 0 : poly_int64 other_vf = LOOP_VINFO_VECT_FACTOR (other_loop_vinfo);
2003 : :
2004 : : /* Limit the VFs to what is likely to be the maximum number of iterations,
2005 : : to handle cases in which at least one loop_vinfo is fully-masked. */
2006 : 0 : HOST_WIDE_INT estimated_max_niter = likely_max_stmt_executions_int (loop);
2007 : 0 : if (estimated_max_niter != -1)
2008 : : {
2009 : 0 : if (estimated_poly_value (this_vf, POLY_VALUE_MIN)
2010 : : >= estimated_max_niter)
2011 : : this_vf = estimated_max_niter;
2012 : 0 : if (estimated_poly_value (other_vf, POLY_VALUE_MIN)
2013 : : >= estimated_max_niter)
2014 : : other_vf = estimated_max_niter;
2015 : : }
2016 : :
2017 : : /* Check whether the (fractional) cost per scalar iteration is lower or
2018 : : higher: this_inside_cost / this_vf vs. other_inside_cost / other_vf. */
2019 : 0 : poly_int64 rel_this = this_loop_vinfo->vector_costs->body_cost () * other_vf;
2020 : 0 : poly_int64 rel_other
2021 : 0 : = other_loop_vinfo->vector_costs->body_cost () * this_vf;
2022 : :
2023 : 0 : HOST_WIDE_INT est_rel_this_min
2024 : 0 : = estimated_poly_value (rel_this, POLY_VALUE_MIN);
2025 : 0 : HOST_WIDE_INT est_rel_this_max
2026 : 0 : = estimated_poly_value (rel_this, POLY_VALUE_MAX);
2027 : :
2028 : 0 : HOST_WIDE_INT est_rel_other_min
2029 : 0 : = estimated_poly_value (rel_other, POLY_VALUE_MIN);
2030 : 0 : HOST_WIDE_INT est_rel_other_max
2031 : 0 : = estimated_poly_value (rel_other, POLY_VALUE_MAX);
2032 : :
2033 : : /* Check first if we can make out an unambigous total order from the minimum
2034 : : and maximum estimates. */
2035 : 0 : if (est_rel_this_min < est_rel_other_min
2036 : : && est_rel_this_max < est_rel_other_max)
2037 : : return -1;
2038 : :
2039 : 0 : if (est_rel_other_min < est_rel_this_min
2040 : : && est_rel_other_max < est_rel_this_max)
2041 : 0 : return 1;
2042 : :
2043 : : /* When other_loop_vinfo uses a variable vectorization factor,
2044 : : we know that it has a lower cost for at least one runtime VF.
2045 : : However, we don't know how likely that VF is.
2046 : :
2047 : : One option would be to compare the costs for the estimated VFs.
2048 : : The problem is that that can put too much pressure on the cost
2049 : : model. E.g. if the estimated VF is also the lowest possible VF,
2050 : : and if other_loop_vinfo is 1 unit worse than this_loop_vinfo
2051 : : for the estimated VF, we'd then choose this_loop_vinfo even
2052 : : though (a) this_loop_vinfo might not actually be better than
2053 : : other_loop_vinfo for that VF and (b) it would be significantly
2054 : : worse at larger VFs.
2055 : :
2056 : : Here we go for a hacky compromise: pick this_loop_vinfo if it is
2057 : : no more expensive than other_loop_vinfo even after doubling the
2058 : : estimated other_loop_vinfo VF. For all but trivial loops, this
2059 : : ensures that we only pick this_loop_vinfo if it is significantly
2060 : : better than other_loop_vinfo at the estimated VF. */
2061 : : if (est_rel_other_min != est_rel_this_min
2062 : : || est_rel_other_max != est_rel_this_max)
2063 : : {
2064 : : HOST_WIDE_INT est_rel_this_likely
2065 : : = estimated_poly_value (rel_this, POLY_VALUE_LIKELY);
2066 : : HOST_WIDE_INT est_rel_other_likely
2067 : : = estimated_poly_value (rel_other, POLY_VALUE_LIKELY);
2068 : :
2069 : : return est_rel_this_likely * 2 <= est_rel_other_likely ? -1 : 1;
2070 : : }
2071 : :
2072 : : return 0;
2073 : : }
2074 : :
2075 : : /* A <=>-style subroutine of better_main_loop_than_p, used when there is
2076 : : nothing to choose between the inside (loop body) costs of THIS and OTHER.
2077 : : Check whether we can determine the return value of better_main_loop_than_p
2078 : : by comparing the outside (prologue and epilogue) costs of THIS and OTHER.
2079 : : Return:
2080 : :
2081 : : * -1 if better_main_loop_than_p should return true.
2082 : : * 1 if better_main_loop_than_p should return false.
2083 : : * 0 if we can't decide. */
2084 : :
2085 : : int
2086 : 0 : vector_costs::compare_outside_loop_cost (const vector_costs *other) const
2087 : : {
2088 : 0 : auto this_outside_cost = this->outside_cost ();
2089 : 0 : auto other_outside_cost = other->outside_cost ();
2090 : 0 : if (this_outside_cost != other_outside_cost)
2091 : 0 : return this_outside_cost < other_outside_cost ? -1 : 1;
2092 : :
2093 : : return 0;
2094 : : }
|