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 : 1372162 : auto_purge_vect_location::~auto_purge_vect_location ()
95 : : {
96 : 1372162 : vect_location = dump_user_location_t ();
97 : 1372162 : }
98 : :
99 : : /* Dump a cost entry according to args to F. */
100 : :
101 : : void
102 : 203361 : 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 : 203361 : if (stmt_info)
108 : : {
109 : 187504 : print_gimple_expr (f, STMT_VINFO_STMT (stmt_info), 0, TDF_SLIM);
110 : 187504 : fprintf (f, " ");
111 : : }
112 : 15857 : else if (node)
113 : 3193 : fprintf (f, "node %p ", (void *)node);
114 : : else
115 : 12664 : fprintf (f, "<unknown> ");
116 : 203361 : fprintf (f, "%d times ", count);
117 : 203361 : const char *ks = "unknown";
118 : 203361 : switch (kind)
119 : : {
120 : 47874 : case scalar_stmt:
121 : 47874 : ks = "scalar_stmt";
122 : 47874 : break;
123 : 33589 : case scalar_load:
124 : 33589 : ks = "scalar_load";
125 : 33589 : break;
126 : 25843 : case scalar_store:
127 : 25843 : ks = "scalar_store";
128 : 25843 : break;
129 : 31953 : case vector_stmt:
130 : 31953 : ks = "vector_stmt";
131 : 31953 : break;
132 : 20610 : case vector_load:
133 : 20610 : ks = "vector_load";
134 : 20610 : break;
135 : 0 : case vector_gather_load:
136 : 0 : ks = "vector_gather_load";
137 : 0 : break;
138 : 7026 : case unaligned_load:
139 : 7026 : ks = "unaligned_load";
140 : 7026 : break;
141 : 4259 : case unaligned_store:
142 : 4259 : ks = "unaligned_store";
143 : 4259 : break;
144 : 8397 : case vector_store:
145 : 8397 : ks = "vector_store";
146 : 8397 : break;
147 : 0 : case vector_scatter_store:
148 : 0 : ks = "vector_scatter_store";
149 : 0 : break;
150 : 2900 : case vec_to_scalar:
151 : 2900 : ks = "vec_to_scalar";
152 : 2900 : break;
153 : 8574 : case scalar_to_vec:
154 : 8574 : ks = "scalar_to_vec";
155 : 8574 : break;
156 : 4 : case cond_branch_not_taken:
157 : 4 : ks = "cond_branch_not_taken";
158 : 4 : break;
159 : 352 : case cond_branch_taken:
160 : 352 : ks = "cond_branch_taken";
161 : 352 : break;
162 : 5795 : case vec_perm:
163 : 5795 : ks = "vec_perm";
164 : 5795 : break;
165 : 5187 : case vec_promote_demote:
166 : 5187 : ks = "vec_promote_demote";
167 : 5187 : break;
168 : 998 : case vec_construct:
169 : 998 : ks = "vec_construct";
170 : 998 : break;
171 : : }
172 : 203361 : fprintf (f, "%s ", ks);
173 : 203361 : if (kind == unaligned_load || kind == unaligned_store)
174 : 11285 : fprintf (f, "(misalign %d) ", misalign);
175 : 203361 : fprintf (f, "costs %u ", cost);
176 : 203361 : const char *ws = "unknown";
177 : 203361 : switch (where)
178 : : {
179 : 123336 : case vect_prologue:
180 : 123336 : ws = "prologue";
181 : 123336 : break;
182 : 74090 : case vect_body:
183 : 74090 : ws = "body";
184 : 74090 : break;
185 : 5935 : case vect_epilogue:
186 : 5935 : ws = "epilogue";
187 : 5935 : break;
188 : : }
189 : 203361 : fprintf (f, "in %s\n", ws);
190 : 203361 : }
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 : 7891 : simduid_to_vf::hash (const simduid_to_vf *p)
207 : : {
208 : 7891 : return p->simduid;
209 : : }
210 : :
211 : : inline int
212 : 14251 : simduid_to_vf::equal (const simduid_to_vf *p1, const simduid_to_vf *p2)
213 : : {
214 : 14251 : 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 : 23713 : simd_array_to_simduid::hash (const simd_array_to_simduid *p)
242 : : {
243 : 23713 : return DECL_UID (p->decl);
244 : : }
245 : :
246 : : inline int
247 : 16306 : simd_array_to_simduid::equal (const simd_array_to_simduid *p1,
248 : : const simd_array_to_simduid *p2)
249 : : {
250 : 16306 : 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 : 7805 : adjust_simduid_builtins (hash_table<simduid_to_vf> *htab, function *fun)
259 : : {
260 : 7805 : basic_block bb;
261 : :
262 : 121999 : FOR_EACH_BB_FN (bb, fun)
263 : : {
264 : 114194 : gimple_stmt_iterator i;
265 : :
266 : 745940 : for (i = gsi_start_bb (bb); !gsi_end_p (i); )
267 : : {
268 : 517552 : poly_uint64 vf = 1;
269 : 517552 : enum internal_fn ifn;
270 : 517552 : gimple *stmt = gsi_stmt (i);
271 : 517552 : tree t;
272 : 517552 : if (!is_gimple_call (stmt)
273 : 517552 : || !gimple_call_internal_p (stmt))
274 : : {
275 : 510222 : gsi_next (&i);
276 : 510907 : continue;
277 : : }
278 : 7330 : ifn = gimple_call_internal_fn (stmt);
279 : 7330 : switch (ifn)
280 : : {
281 : 6645 : case IFN_GOMP_SIMD_LANE:
282 : 6645 : case IFN_GOMP_SIMD_VF:
283 : 6645 : case IFN_GOMP_SIMD_LAST_LANE:
284 : 6645 : 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 : 5 : 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 : 527 : default:
303 : 527 : gsi_next (&i);
304 : 527 : continue;
305 : 675 : }
306 : 6645 : tree arg = gimple_call_arg (stmt, 0);
307 : 6645 : gcc_assert (arg != NULL_TREE);
308 : 6645 : gcc_assert (TREE_CODE (arg) == SSA_NAME);
309 : 6645 : simduid_to_vf *p = NULL, data;
310 : 6645 : 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 : 6645 : if (bb->loop_father && bb->loop_father->safelen > 0)
314 : 2169 : bb->loop_father->safelen = 0;
315 : 6645 : if (htab)
316 : : {
317 : 4730 : p = htab->find (&data);
318 : 4730 : if (p)
319 : 4689 : vf = p->vf;
320 : : }
321 : 6645 : switch (ifn)
322 : : {
323 : 969 : case IFN_GOMP_SIMD_VF:
324 : 969 : t = build_int_cst (unsigned_type_node, vf);
325 : 969 : break;
326 : 3482 : case IFN_GOMP_SIMD_LANE:
327 : 3482 : t = build_int_cst (unsigned_type_node, 0);
328 : 3482 : break;
329 : 2194 : case IFN_GOMP_SIMD_LAST_LANE:
330 : 2194 : t = gimple_call_arg (stmt, 1);
331 : 2194 : break;
332 : : default:
333 : : gcc_unreachable ();
334 : : }
335 : 6645 : tree lhs = gimple_call_lhs (stmt);
336 : 6645 : if (lhs)
337 : 6588 : replace_uses_by (lhs, t);
338 : 6645 : release_defs (stmt);
339 : 6645 : gsi_remove (&i, true);
340 : : }
341 : : }
342 : 7805 : }
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 : 65220 : note_simd_array_uses_cb (tree *tp, int *walk_subtrees, void *data)
356 : : {
357 : 65220 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
358 : 65220 : struct note_simd_array_uses_struct *ns
359 : : = (struct note_simd_array_uses_struct *) wi->info;
360 : :
361 : 65220 : if (TYPE_P (*tp))
362 : 0 : *walk_subtrees = 0;
363 : 65220 : else if (VAR_P (*tp)
364 : 12362 : && lookup_attribute ("omp simd array", DECL_ATTRIBUTES (*tp))
365 : 77582 : && DECL_CONTEXT (*tp) == current_function_decl)
366 : : {
367 : 12362 : simd_array_to_simduid data;
368 : 12362 : if (!*ns->htab)
369 : 2208 : *ns->htab = new hash_table<simd_array_to_simduid> (15);
370 : 12362 : data.decl = *tp;
371 : 12362 : data.simduid = ns->simduid;
372 : 12362 : simd_array_to_simduid **slot = (*ns->htab)->find_slot (&data, INSERT);
373 : 12362 : if (*slot == NULL)
374 : : {
375 : 5501 : simd_array_to_simduid *p = XNEW (simd_array_to_simduid);
376 : 5501 : *p = data;
377 : 5501 : *slot = p;
378 : : }
379 : 6861 : else if ((*slot)->simduid != ns->simduid)
380 : 0 : (*slot)->simduid = -1U;
381 : 12362 : *walk_subtrees = 0;
382 : : }
383 : 65220 : return NULL_TREE;
384 : : }
385 : :
386 : : /* Find "omp simd array" temporaries and map them to corresponding
387 : : simduid. */
388 : :
389 : : static void
390 : 7805 : note_simd_array_uses (hash_table<simd_array_to_simduid> **htab, function *fun)
391 : : {
392 : 7805 : basic_block bb;
393 : 7805 : gimple_stmt_iterator gsi;
394 : 7805 : struct walk_stmt_info wi;
395 : 7805 : struct note_simd_array_uses_struct ns;
396 : :
397 : 7805 : memset (&wi, 0, sizeof (wi));
398 : 7805 : wi.info = &ns;
399 : 7805 : ns.htab = htab;
400 : :
401 : 106164 : FOR_EACH_BB_FN (bb, fun)
402 : 590817 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
403 : : {
404 : 394099 : gimple *stmt = gsi_stmt (gsi);
405 : 394099 : if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
406 : 387515 : continue;
407 : 7284 : switch (gimple_call_internal_fn (stmt))
408 : : {
409 : 6620 : case IFN_GOMP_SIMD_LANE:
410 : 6620 : case IFN_GOMP_SIMD_VF:
411 : 6620 : case IFN_GOMP_SIMD_LAST_LANE:
412 : 6620 : break;
413 : 664 : default:
414 : 664 : continue;
415 : : }
416 : 6620 : tree lhs = gimple_call_lhs (stmt);
417 : 6620 : if (lhs == NULL_TREE)
418 : 36 : continue;
419 : 6584 : imm_use_iterator use_iter;
420 : 6584 : gimple *use_stmt;
421 : 6584 : ns.simduid = DECL_UID (SSA_NAME_VAR (gimple_call_arg (stmt, 0)));
422 : 24616 : FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, lhs)
423 : 18032 : if (!is_gimple_debug (use_stmt))
424 : 24524 : walk_gimple_op (use_stmt, note_simd_array_uses_cb, &wi);
425 : : }
426 : 7805 : }
427 : :
428 : : /* Shrink arrays with "omp simd array" attribute to the corresponding
429 : : vectorization factor. */
430 : :
431 : : static void
432 : 2208 : 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 : 7709 : for (hash_table<simd_array_to_simduid>::iterator iter
437 : 2208 : = simd_array_to_simduid_htab->begin ();
438 : 13210 : iter != simd_array_to_simduid_htab->end (); ++iter)
439 : 5501 : if ((*iter)->simduid != -1U)
440 : : {
441 : 5501 : tree decl = (*iter)->decl;
442 : 5501 : poly_uint64 vf = 1;
443 : 5501 : if (simduid_to_vf_htab)
444 : : {
445 : 4554 : simduid_to_vf *p = NULL, data;
446 : 4554 : data.simduid = (*iter)->simduid;
447 : 4554 : p = simduid_to_vf_htab->find (&data);
448 : 4554 : if (p)
449 : 4520 : vf = p->vf;
450 : : }
451 : 5501 : tree atype
452 : 5501 : = build_array_type_nelts (TREE_TYPE (TREE_TYPE (decl)), vf);
453 : 5501 : TREE_TYPE (decl) = atype;
454 : 5501 : relayout_decl (decl);
455 : : }
456 : :
457 : 2208 : delete simd_array_to_simduid_htab;
458 : 2208 : }
459 : :
460 : : /* Initialize the vec_info with kind KIND_IN and target cost data
461 : : TARGET_COST_DATA_IN. */
462 : :
463 : 2799084 : vec_info::vec_info (vec_info::vec_kind kind_in, vec_info_shared *shared_)
464 : 2799084 : : kind (kind_in),
465 : 2799084 : shared (shared_),
466 : 2799084 : stmt_vec_info_ro (false),
467 : 2799084 : bbs (NULL),
468 : 2799084 : nbbs (0),
469 : 2799084 : inv_pattern_def_seq (NULL)
470 : : {
471 : 2799084 : stmt_vec_infos.create (50);
472 : 2799084 : }
473 : :
474 : 2799084 : vec_info::~vec_info ()
475 : : {
476 : 4973180 : for (slp_instance &instance : slp_instances)
477 : 1193578 : vect_free_slp_instance (instance);
478 : :
479 : 2799084 : free_stmt_vec_infos ();
480 : 2799084 : }
481 : :
482 : 2530293 : vec_info_shared::vec_info_shared ()
483 : 2530293 : : datarefs (vNULL),
484 : 2530293 : datarefs_copy (vNULL),
485 : 2530293 : ddrs (vNULL)
486 : : {
487 : 2530293 : }
488 : :
489 : 2530293 : vec_info_shared::~vec_info_shared ()
490 : : {
491 : 2530293 : free_data_refs (datarefs);
492 : 2530293 : free_dependence_relations (ddrs);
493 : 2530293 : datarefs_copy.release ();
494 : 2530293 : }
495 : :
496 : : void
497 : 2255646 : vec_info_shared::save_datarefs ()
498 : : {
499 : 2255646 : if (!flag_checking)
500 : : return;
501 : 3313011 : datarefs_copy.reserve_exact (datarefs.length ());
502 : 12963899 : for (unsigned i = 0; i < datarefs.length (); ++i)
503 : 10708266 : datarefs_copy.quick_push (*datarefs[i]);
504 : : }
505 : :
506 : : void
507 : 799354 : vec_info_shared::check_datarefs ()
508 : : {
509 : 799354 : if (!flag_checking)
510 : : return;
511 : 2395246 : gcc_assert (datarefs.length () == datarefs_copy.length ());
512 : 11861105 : for (unsigned i = 0; i < datarefs.length (); ++i)
513 : 11061751 : 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 : 60901768 : vec_info::add_stmt (gimple *stmt)
523 : : {
524 : 60901768 : stmt_vec_info res = new_stmt_vec_info (stmt);
525 : 60901768 : set_vinfo_for_stmt (stmt, res);
526 : 60901768 : 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 : 1159 : vec_info::add_pattern_stmt (gimple *stmt, stmt_vec_info stmt_info)
535 : : {
536 : 1159 : stmt_vec_info res = new_stmt_vec_info (stmt);
537 : 1159 : res->pattern_stmt_p = true;
538 : 1159 : set_vinfo_for_stmt (stmt, res, false);
539 : 1159 : STMT_VINFO_RELATED_STMT (res) = stmt_info;
540 : 1159 : 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 : 10410 : vec_info::resync_stmt_addr (gimple *stmt)
552 : : {
553 : 10410 : unsigned int uid = gimple_uid (stmt);
554 : 10410 : if (uid > 0 && uid - 1 < stmt_vec_infos.length ())
555 : : {
556 : 10410 : stmt_vec_info res = stmt_vec_infos[uid - 1];
557 : 10410 : if (res && res->stmt)
558 : : {
559 : 10410 : res->stmt = stmt;
560 : 10410 : 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 : 445086578 : vec_info::lookup_stmt (gimple *stmt)
572 : : {
573 : 445086578 : unsigned int uid = gimple_uid (stmt);
574 : 445086578 : if (uid > 0 && uid - 1 < stmt_vec_infos.length ())
575 : : {
576 : 285034084 : stmt_vec_info res = stmt_vec_infos[uid - 1];
577 : 285034084 : if (res && res->stmt == stmt)
578 : 284738146 : 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 : 49392119 : vec_info::lookup_def (tree name)
589 : : {
590 : 49392119 : if (TREE_CODE (name) == SSA_NAME
591 : 49392119 : && !SSA_NAME_IS_DEFAULT_DEF (name))
592 : 46693418 : 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 : 28122 : vec_info::lookup_single_use (tree lhs)
602 : : {
603 : 28122 : use_operand_p dummy;
604 : 28122 : gimple *use_stmt;
605 : 28122 : if (single_imm_use (lhs, &dummy, &use_stmt))
606 : 21584 : return lookup_stmt (use_stmt);
607 : : return NULL;
608 : : }
609 : :
610 : : /* Return vectorization information about DR. */
611 : :
612 : : dr_vec_info *
613 : 46336721 : vec_info::lookup_dr (data_reference *dr)
614 : : {
615 : 46336721 : stmt_vec_info stmt_info = lookup_stmt (DR_STMT (dr));
616 : : /* DR_STMT should never refer to a stmt in a pattern replacement. */
617 : 46336721 : gcc_checking_assert (!is_pattern_stmt_p (stmt_info));
618 : 46336721 : 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 : 5805 : vec_info::move_dr (stmt_vec_info new_stmt_info, stmt_vec_info old_stmt_info)
626 : : {
627 : 5805 : gcc_assert (!is_pattern_stmt_p (old_stmt_info));
628 : 5805 : STMT_VINFO_DR_INFO (old_stmt_info)->stmt = new_stmt_info;
629 : 5805 : new_stmt_info->dr_aux = old_stmt_info->dr_aux;
630 : 5805 : STMT_VINFO_DR_WRT_VEC_LOOP (new_stmt_info)
631 : 5805 : = STMT_VINFO_DR_WRT_VEC_LOOP (old_stmt_info);
632 : 5805 : STMT_VINFO_GATHER_SCATTER_P (new_stmt_info)
633 : 5805 : = STMT_VINFO_GATHER_SCATTER_P (old_stmt_info);
634 : 5805 : STMT_VINFO_STRIDED_P (new_stmt_info)
635 : 5805 : = STMT_VINFO_STRIDED_P (old_stmt_info);
636 : 5805 : STMT_VINFO_SIMD_LANE_ACCESS_P (new_stmt_info)
637 : 5805 : = STMT_VINFO_SIMD_LANE_ACCESS_P (old_stmt_info);
638 : 5805 : }
639 : :
640 : : /* Permanently remove the statement described by STMT_INFO from the
641 : : function. */
642 : :
643 : : void
644 : 1483753 : vec_info::remove_stmt (stmt_vec_info stmt_info)
645 : : {
646 : 1483753 : gcc_assert (!stmt_info->pattern_stmt_p);
647 : 1483753 : set_vinfo_for_stmt (stmt_info->stmt, NULL);
648 : 1483753 : unlink_stmt_vdef (stmt_info->stmt);
649 : 1483753 : gimple_stmt_iterator si = gsi_for_stmt (stmt_info->stmt);
650 : 1483753 : gsi_remove (&si, true);
651 : 1483753 : release_defs (stmt_info->stmt);
652 : 1483753 : free_stmt_vec_info (stmt_info);
653 : 1483753 : }
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 : 4729 : vec_info::replace_stmt (gimple_stmt_iterator *gsi, stmt_vec_info stmt_info,
661 : : gimple *new_stmt)
662 : : {
663 : 4729 : gimple *old_stmt = stmt_info->stmt;
664 : 4729 : gcc_assert (!stmt_info->pattern_stmt_p && old_stmt == gsi_stmt (*gsi));
665 : 4729 : gimple_set_uid (new_stmt, gimple_uid (old_stmt));
666 : 4729 : stmt_info->stmt = new_stmt;
667 : 4729 : gsi_replace (gsi, new_stmt, true);
668 : 4729 : }
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 : 102815 : vec_info::insert_seq_on_entry (stmt_vec_info context, gimple_seq seq)
677 : : {
678 : 102815 : if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (this))
679 : : {
680 : 16640 : class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
681 : 16640 : basic_block new_bb;
682 : 16640 : edge pe;
683 : :
684 : 16640 : if (context && nested_in_vect_loop_p (loop, context))
685 : : loop = loop->inner;
686 : :
687 : 16640 : pe = loop_preheader_edge (loop);
688 : 16640 : new_bb = gsi_insert_seq_on_edge_immediate (pe, seq);
689 : 16640 : gcc_assert (!new_bb);
690 : : }
691 : : else
692 : : {
693 : 86175 : gimple_stmt_iterator gsi_region_begin
694 : 86175 : = gsi_after_labels (bbs[0]);
695 : 86175 : gsi_insert_seq_before (&gsi_region_begin, seq, GSI_SAME_STMT);
696 : : }
697 : 102815 : }
698 : :
699 : : /* Like insert_seq_on_entry but just inserts the single stmt NEW_STMT. */
700 : :
701 : : void
702 : 3278 : vec_info::insert_on_entry (stmt_vec_info context, gimple *new_stmt)
703 : : {
704 : 3278 : gimple_seq seq = NULL;
705 : 3278 : gimple_stmt_iterator gsi = gsi_start (seq);
706 : 3278 : gsi_insert_before_without_update (&gsi, new_stmt, GSI_SAME_STMT);
707 : 3278 : insert_seq_on_entry (context, seq);
708 : 3278 : }
709 : :
710 : : /* Create and initialize a new stmt_vec_info struct for STMT. */
711 : :
712 : : stmt_vec_info
713 : 60902927 : vec_info::new_stmt_vec_info (gimple *stmt)
714 : : {
715 : 60902927 : stmt_vec_info res = XCNEW (class _stmt_vec_info);
716 : 60902927 : res->stmt = stmt;
717 : :
718 : 60902927 : STMT_VINFO_RELEVANT (res) = vect_unused_in_scope;
719 : 60902927 : STMT_VINFO_VECTORIZABLE (res) = true;
720 : 60902927 : STMT_VINFO_REDUC_TYPE (res) = TREE_CODE_REDUCTION;
721 : 60902927 : STMT_VINFO_REDUC_CODE (res) = ERROR_MARK;
722 : 60902927 : STMT_VINFO_REDUC_FN (res) = IFN_LAST;
723 : 60902927 : STMT_VINFO_REDUC_IDX (res) = -1;
724 : 60902927 : STMT_VINFO_SLP_VECT_ONLY (res) = false;
725 : 60902927 : STMT_VINFO_SLP_VECT_ONLY_PATTERN (res) = false;
726 : 60902927 : res->reduc_initial_values = vNULL;
727 : 60902927 : res->reduc_scalar_results = vNULL;
728 : :
729 : 60902927 : if (is_a <loop_vec_info> (this)
730 : 6302567 : && gimple_code (stmt) == GIMPLE_PHI
731 : 62015619 : && is_loop_header_bb_p (gimple_bb (stmt)))
732 : 1102858 : STMT_VINFO_DEF_TYPE (res) = vect_unknown_def_type;
733 : : else
734 : 59800069 : STMT_VINFO_DEF_TYPE (res) = vect_internal_def;
735 : :
736 : 60902927 : STMT_SLP_TYPE (res) = not_vect;
737 : :
738 : : /* This is really "uninitialized" until vect_compute_data_ref_alignment. */
739 : 60902927 : res->dr_aux.misalignment = DR_MISALIGNMENT_UNINITIALIZED;
740 : :
741 : 60902927 : return res;
742 : : }
743 : :
744 : : /* Associate STMT with INFO. */
745 : :
746 : : void
747 : 62386680 : vec_info::set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info, bool check_ro)
748 : : {
749 : 62386680 : unsigned int uid = gimple_uid (stmt);
750 : 62386680 : if (uid == 0)
751 : : {
752 : 60902927 : gcc_assert (!check_ro || !stmt_vec_info_ro);
753 : 60902927 : gcc_checking_assert (info);
754 : 60902927 : uid = stmt_vec_infos.length () + 1;
755 : 60902927 : gimple_set_uid (stmt, uid);
756 : 60902927 : stmt_vec_infos.safe_push (info);
757 : : }
758 : : else
759 : : {
760 : 1483753 : gcc_checking_assert (info == NULL);
761 : 1483753 : stmt_vec_infos[uid - 1] = info;
762 : : }
763 : 62386680 : }
764 : :
765 : : /* Free the contents of stmt_vec_infos. */
766 : :
767 : : void
768 : 2799084 : vec_info::free_stmt_vec_infos (void)
769 : : {
770 : 69300179 : for (stmt_vec_info &info : stmt_vec_infos)
771 : 60902927 : if (info != NULL)
772 : 59419174 : free_stmt_vec_info (info);
773 : 2799084 : stmt_vec_infos.release ();
774 : 2799084 : }
775 : :
776 : : /* Free STMT_INFO. */
777 : :
778 : : void
779 : 60902927 : vec_info::free_stmt_vec_info (stmt_vec_info stmt_info)
780 : : {
781 : 60902927 : if (stmt_info->pattern_stmt_p)
782 : : {
783 : 1930866 : gimple_set_bb (stmt_info->stmt, NULL);
784 : 1930866 : tree lhs = gimple_get_lhs (stmt_info->stmt);
785 : 1930866 : if (lhs && TREE_CODE (lhs) == SSA_NAME)
786 : 1648866 : release_ssa_name (lhs);
787 : : }
788 : :
789 : 60902927 : stmt_info->reduc_initial_values.release ();
790 : 60902927 : stmt_info->reduc_scalar_results.release ();
791 : 60902927 : free (stmt_info);
792 : 60902927 : }
793 : :
794 : : /* Returns true if S1 dominates S2. */
795 : :
796 : : bool
797 : 526613 : vect_stmt_dominates_stmt_p (gimple *s1, gimple *s2)
798 : : {
799 : 526613 : basic_block bb1 = gimple_bb (s1), bb2 = gimple_bb (s2);
800 : :
801 : : /* If bb1 is NULL, it should be a GIMPLE_NOP def stmt of an (D)
802 : : SSA_NAME. Assume it lives at the beginning of function and
803 : : thus dominates everything. */
804 : 526613 : if (!bb1 || s1 == s2)
805 : : return true;
806 : :
807 : : /* If bb2 is NULL, it doesn't dominate any stmt with a bb. */
808 : 524881 : if (!bb2)
809 : : return false;
810 : :
811 : 524881 : if (bb1 != bb2)
812 : 197732 : return dominated_by_p (CDI_DOMINATORS, bb2, bb1);
813 : :
814 : : /* PHIs in the same basic block are assumed to be
815 : : executed all in parallel, if only one stmt is a PHI,
816 : : it dominates the other stmt in the same basic block. */
817 : 327149 : if (gimple_code (s1) == GIMPLE_PHI)
818 : : return true;
819 : :
820 : 289959 : if (gimple_code (s2) == GIMPLE_PHI)
821 : : return false;
822 : :
823 : : /* Inserted vectorized stmts all have UID 0 while the original stmts
824 : : in the IL have UID increasing within a BB. Walk from both sides
825 : : until we find the other stmt or a stmt with UID != 0. */
826 : 272612 : gimple_stmt_iterator gsi1 = gsi_for_stmt (s1);
827 : 699036 : while (gimple_uid (gsi_stmt (gsi1)) == 0)
828 : : {
829 : 529391 : gsi_next (&gsi1);
830 : 529391 : if (gsi_end_p (gsi1))
831 : : return false;
832 : 527820 : if (gsi_stmt (gsi1) == s2)
833 : : return true;
834 : : }
835 : 169645 : if (gimple_uid (gsi_stmt (gsi1)) == -1u)
836 : : return false;
837 : :
838 : 169645 : gimple_stmt_iterator gsi2 = gsi_for_stmt (s2);
839 : 689903 : while (gimple_uid (gsi_stmt (gsi2)) == 0)
840 : : {
841 : 531218 : gsi_prev (&gsi2);
842 : 531218 : if (gsi_end_p (gsi2))
843 : : return false;
844 : 520278 : if (gsi_stmt (gsi2) == s1)
845 : : return true;
846 : : }
847 : 158685 : if (gimple_uid (gsi_stmt (gsi2)) == -1u)
848 : : return false;
849 : :
850 : 158685 : if (gimple_uid (gsi_stmt (gsi1)) <= gimple_uid (gsi_stmt (gsi2)))
851 : : return true;
852 : : return false;
853 : : }
854 : :
855 : : /* A helper function to free scev and LOOP niter information, as well as
856 : : clear loop constraint LOOP_C_FINITE. */
857 : :
858 : : void
859 : 60403 : vect_free_loop_info_assumptions (class loop *loop)
860 : : {
861 : 60403 : scev_reset_htab ();
862 : : /* We need to explicitly reset upper bound information since they are
863 : : used even after free_numbers_of_iterations_estimates. */
864 : 60403 : loop->any_upper_bound = false;
865 : 60403 : loop->any_likely_upper_bound = false;
866 : 60403 : free_numbers_of_iterations_estimates (loop);
867 : 60403 : loop_constraint_clear (loop, LOOP_C_FINITE);
868 : 60403 : }
869 : :
870 : : /* If LOOP has been versioned during ifcvt, return the internal call
871 : : guarding it. */
872 : :
873 : : gimple *
874 : 518069 : vect_loop_vectorized_call (class loop *loop, gcond **cond)
875 : : {
876 : 518069 : basic_block bb = loop_preheader_edge (loop)->src;
877 : 950932 : gimple *g;
878 : 1383795 : do
879 : : {
880 : 950932 : g = *gsi_last_bb (bb);
881 : 601222 : if ((g && gimple_code (g) == GIMPLE_COND)
882 : 2046317 : || !single_succ_p (bb))
883 : : break;
884 : 577316 : if (!single_pred_p (bb))
885 : : break;
886 : 432863 : bb = single_pred (bb);
887 : : }
888 : : while (1);
889 : 518069 : if (g && gimple_code (g) == GIMPLE_COND)
890 : : {
891 : 366456 : if (cond)
892 : 0 : *cond = as_a <gcond *> (g);
893 : 366456 : gimple_stmt_iterator gsi = gsi_for_stmt (g);
894 : 366456 : gsi_prev (&gsi);
895 : 366456 : if (!gsi_end_p (gsi))
896 : : {
897 : 337031 : g = gsi_stmt (gsi);
898 : 337031 : if (gimple_call_internal_p (g, IFN_LOOP_VECTORIZED)
899 : 337031 : && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->num
900 : 27083 : || tree_to_shwi (gimple_call_arg (g, 1)) == loop->num))
901 : 54550 : return g;
902 : : }
903 : : }
904 : : return NULL;
905 : : }
906 : :
907 : : /* If LOOP has been versioned during loop distribution, return the gurading
908 : : internal call. */
909 : :
910 : : static gimple *
911 : 484595 : vect_loop_dist_alias_call (class loop *loop, function *fun)
912 : : {
913 : 484595 : basic_block bb;
914 : 484595 : basic_block entry;
915 : 484595 : class loop *outer, *orig;
916 : :
917 : 484595 : if (loop->orig_loop_num == 0)
918 : : return NULL;
919 : :
920 : 162 : orig = get_loop (fun, loop->orig_loop_num);
921 : 162 : if (orig == NULL)
922 : : {
923 : : /* The original loop is somehow destroyed. Clear the information. */
924 : 0 : loop->orig_loop_num = 0;
925 : 0 : return NULL;
926 : : }
927 : :
928 : 162 : if (loop != orig)
929 : 91 : bb = nearest_common_dominator (CDI_DOMINATORS, loop->header, orig->header);
930 : : else
931 : 71 : bb = loop_preheader_edge (loop)->src;
932 : :
933 : 162 : outer = bb->loop_father;
934 : 162 : entry = ENTRY_BLOCK_PTR_FOR_FN (fun);
935 : :
936 : : /* Look upward in dominance tree. */
937 : 743 : for (; bb != entry && flow_bb_inside_loop_p (outer, bb);
938 : 581 : bb = get_immediate_dominator (CDI_DOMINATORS, bb))
939 : : {
940 : 691 : gimple_stmt_iterator gsi = gsi_last_bb (bb);
941 : 691 : if (!safe_is_a <gcond *> (*gsi))
942 : 581 : continue;
943 : :
944 : 508 : gsi_prev (&gsi);
945 : 508 : if (gsi_end_p (gsi))
946 : 8 : continue;
947 : :
948 : 500 : gimple *g = gsi_stmt (gsi);
949 : : /* The guarding internal function call must have the same distribution
950 : : alias id. */
951 : 500 : if (gimple_call_internal_p (g, IFN_LOOP_DIST_ALIAS)
952 : 500 : && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->orig_loop_num))
953 : 484595 : return g;
954 : : }
955 : : return NULL;
956 : : }
957 : :
958 : : /* Set the uids of all the statements in basic blocks inside loop
959 : : represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal
960 : : call guarding the loop which has been if converted. */
961 : : static void
962 : 5815 : set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call,
963 : : function *fun)
964 : : {
965 : 5815 : tree arg = gimple_call_arg (loop_vectorized_call, 1);
966 : 5815 : basic_block *bbs;
967 : 5815 : unsigned int i;
968 : 5815 : class loop *scalar_loop = get_loop (fun, tree_to_shwi (arg));
969 : :
970 : 5815 : LOOP_VINFO_SCALAR_LOOP (loop_vinfo) = scalar_loop;
971 : 5815 : LOOP_VINFO_SCALAR_IV_EXIT (loop_vinfo)
972 : 5815 : = vec_init_loop_exit_info (scalar_loop);
973 : 5815 : gcc_checking_assert (vect_loop_vectorized_call (scalar_loop)
974 : : == loop_vectorized_call);
975 : : /* If we are going to vectorize outer loop, prevent vectorization
976 : : of the inner loop in the scalar loop - either the scalar loop is
977 : : thrown away, so it is a wasted work, or is used only for
978 : : a few iterations. */
979 : 5815 : if (scalar_loop->inner)
980 : : {
981 : 100 : gimple *g = vect_loop_vectorized_call (scalar_loop->inner);
982 : 100 : if (g)
983 : : {
984 : 100 : arg = gimple_call_arg (g, 0);
985 : 100 : get_loop (fun, tree_to_shwi (arg))->dont_vectorize = true;
986 : 100 : fold_loop_internal_call (g, boolean_false_node);
987 : : }
988 : : }
989 : 5815 : bbs = get_loop_body (scalar_loop);
990 : 32253 : for (i = 0; i < scalar_loop->num_nodes; i++)
991 : : {
992 : 26438 : basic_block bb = bbs[i];
993 : 26438 : gimple_stmt_iterator gsi;
994 : 50645 : for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
995 : : {
996 : 24207 : gimple *phi = gsi_stmt (gsi);
997 : 24207 : gimple_set_uid (phi, 0);
998 : : }
999 : 136859 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1000 : : {
1001 : 83983 : gimple *stmt = gsi_stmt (gsi);
1002 : 83983 : gimple_set_uid (stmt, 0);
1003 : : }
1004 : : }
1005 : 5815 : free (bbs);
1006 : 5815 : }
1007 : :
1008 : : /* Generate vectorized code for LOOP and its epilogues. */
1009 : :
1010 : : static unsigned
1011 : 57504 : vect_transform_loops (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
1012 : : loop_p loop, gimple *loop_vectorized_call,
1013 : : function *fun)
1014 : : {
1015 : 57504 : loop_vec_info loop_vinfo = loop_vec_info_for_loop (loop);
1016 : :
1017 : 57504 : if (loop_vectorized_call)
1018 : 5815 : set_uid_loop_bbs (loop_vinfo, loop_vectorized_call, fun);
1019 : :
1020 : 57504 : unsigned HOST_WIDE_INT bytes;
1021 : 57504 : if (dump_enabled_p ())
1022 : : {
1023 : 20300 : if (GET_MODE_SIZE (loop_vinfo->vector_mode).is_constant (&bytes))
1024 : 10150 : dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
1025 : : "%sloop vectorized using %s%wu byte vectors and"
1026 : : " unroll factor %u\n",
1027 : 10150 : LOOP_VINFO_EPILOGUE_P (loop_vinfo)
1028 : : ? "epilogue " : "",
1029 : 10150 : LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)
1030 : : ? "masked " : "", bytes,
1031 : : (unsigned int) LOOP_VINFO_VECT_FACTOR
1032 : 10150 : (loop_vinfo).to_constant ());
1033 : : else
1034 : : dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
1035 : : "%sloop vectorized using variable length vectors\n",
1036 : : LOOP_VINFO_EPILOGUE_P (loop_vinfo)
1037 : : ? "epilogue " : "");
1038 : : }
1039 : :
1040 : 57504 : loop_p new_loop = vect_transform_loop (loop_vinfo,
1041 : : loop_vectorized_call);
1042 : : /* Now that the loop has been vectorized, allow it to be unrolled
1043 : : etc. */
1044 : 57504 : loop->force_vectorize = false;
1045 : :
1046 : 57504 : if (loop->simduid)
1047 : : {
1048 : 1891 : simduid_to_vf *simduid_to_vf_data = XNEW (simduid_to_vf);
1049 : 1891 : if (!simduid_to_vf_htab)
1050 : 1531 : simduid_to_vf_htab = new hash_table<simduid_to_vf> (15);
1051 : 1891 : simduid_to_vf_data->simduid = DECL_UID (loop->simduid);
1052 : 1891 : simduid_to_vf_data->vf = loop_vinfo->vectorization_factor;
1053 : 1891 : *simduid_to_vf_htab->find_slot (simduid_to_vf_data, INSERT)
1054 : 1891 : = simduid_to_vf_data;
1055 : : }
1056 : :
1057 : : /* We should not have to update virtual SSA form here but some
1058 : : transforms involve creating new virtual definitions which makes
1059 : : updating difficult.
1060 : : We delay the actual update to the end of the pass but avoid
1061 : : confusing ourselves by forcing need_ssa_update_p () to false. */
1062 : 57504 : unsigned todo = 0;
1063 : 57504 : if (need_ssa_update_p (cfun))
1064 : : {
1065 : 119 : gcc_assert (loop_vinfo->any_known_not_updated_vssa);
1066 : 119 : fun->gimple_df->ssa_renaming_needed = false;
1067 : 119 : todo |= TODO_update_ssa_only_virtuals;
1068 : : }
1069 : 57504 : gcc_assert (!need_ssa_update_p (cfun));
1070 : :
1071 : : /* Epilogue of vectorized loop must be vectorized too. */
1072 : 57504 : if (new_loop)
1073 : 6655 : todo |= vect_transform_loops (simduid_to_vf_htab, new_loop, NULL, fun);
1074 : :
1075 : 57504 : return todo;
1076 : : }
1077 : :
1078 : : /* Try to vectorize LOOP. */
1079 : :
1080 : : static unsigned
1081 : 470681 : try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
1082 : : unsigned *num_vectorized_loops, loop_p loop,
1083 : : gimple *loop_vectorized_call,
1084 : : gimple *loop_dist_alias_call,
1085 : : function *fun)
1086 : : {
1087 : 470681 : unsigned ret = 0;
1088 : 470681 : vec_info_shared shared;
1089 : 470681 : auto_purge_vect_location sentinel;
1090 : 470681 : vect_location = find_loop_location (loop);
1091 : :
1092 : 470681 : if (LOCATION_LOCUS (vect_location.get_location_t ()) != UNKNOWN_LOCATION
1093 : 470681 : && dump_enabled_p ())
1094 : 13960 : dump_printf (MSG_NOTE | MSG_PRIORITY_INTERNALS,
1095 : : "\nAnalyzing loop at %s:%d\n",
1096 : 13960 : LOCATION_FILE (vect_location.get_location_t ()),
1097 : 27920 : LOCATION_LINE (vect_location.get_location_t ()));
1098 : :
1099 : : /* Try to analyze the loop, retaining an opt_problem if dump_enabled_p. */
1100 : 470681 : opt_loop_vec_info loop_vinfo = vect_analyze_loop (loop, loop_vectorized_call,
1101 : : &shared);
1102 : 470681 : loop->aux = loop_vinfo;
1103 : :
1104 : 470681 : if (!loop_vinfo)
1105 : 419828 : if (dump_enabled_p ())
1106 : 5413 : if (opt_problem *problem = loop_vinfo.get_problem ())
1107 : : {
1108 : 5413 : dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
1109 : : "couldn't vectorize loop\n");
1110 : 5413 : problem->emit_and_clear ();
1111 : : }
1112 : :
1113 : 470681 : if (!loop_vinfo || !LOOP_VINFO_VECTORIZABLE_P (loop_vinfo))
1114 : : {
1115 : : /* Free existing information if loop is analyzed with some
1116 : : assumptions. */
1117 : 419828 : if (loop_constraint_set_p (loop, LOOP_C_FINITE))
1118 : 9866 : vect_free_loop_info_assumptions (loop);
1119 : :
1120 : : /* If we applied if-conversion then try to vectorize the
1121 : : BB of innermost loops.
1122 : : ??? Ideally BB vectorization would learn to vectorize
1123 : : control flow by applying if-conversion on-the-fly, the
1124 : : following retains the if-converted loop body even when
1125 : : only non-if-converted parts took part in BB vectorization. */
1126 : 419828 : if (flag_tree_slp_vectorize != 0
1127 : 418798 : && loop_vectorized_call
1128 : 19984 : && ! loop->inner)
1129 : : {
1130 : 19179 : basic_block bb = loop->header;
1131 : 19179 : bool require_loop_vectorize = false;
1132 : 38358 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
1133 : 544800 : !gsi_end_p (gsi); gsi_next (&gsi))
1134 : : {
1135 : 526492 : gimple *stmt = gsi_stmt (gsi);
1136 : 526492 : gcall *call = dyn_cast <gcall *> (stmt);
1137 : 1281 : if (call && gimple_call_internal_p (call))
1138 : : {
1139 : 1156 : internal_fn ifn = gimple_call_internal_fn (call);
1140 : 1156 : if (ifn == IFN_MASK_LOAD
1141 : 1156 : || ifn == IFN_MASK_STORE
1142 : 744 : || ifn == IFN_MASK_CALL
1143 : : /* Don't keep the if-converted parts when the ifn with
1144 : : specifc type is not supported by the backend. */
1145 : 1884 : || (direct_internal_fn_p (ifn)
1146 : 443 : && !direct_internal_fn_supported_p
1147 : 443 : (call, OPTIMIZE_FOR_SPEED)))
1148 : : {
1149 : : require_loop_vectorize = true;
1150 : : break;
1151 : : }
1152 : : }
1153 : 525621 : gimple_set_uid (stmt, -1);
1154 : 525621 : gimple_set_visited (stmt, false);
1155 : : }
1156 : 19179 : if (!require_loop_vectorize)
1157 : : {
1158 : 18308 : tree arg = gimple_call_arg (loop_vectorized_call, 1);
1159 : 18308 : class loop *scalar_loop = get_loop (fun, tree_to_shwi (arg));
1160 : 18308 : if (vect_slp_if_converted_bb (bb, scalar_loop))
1161 : : {
1162 : 77 : fold_loop_internal_call (loop_vectorized_call,
1163 : : boolean_true_node);
1164 : 77 : loop_vectorized_call = NULL;
1165 : 77 : ret |= TODO_cleanup_cfg | TODO_update_ssa_only_virtuals;
1166 : : }
1167 : : }
1168 : : }
1169 : : /* If outer loop vectorization fails for LOOP_VECTORIZED guarded
1170 : : loop, don't vectorize its inner loop; we'll attempt to
1171 : : vectorize LOOP_VECTORIZED guarded inner loop of the scalar
1172 : : loop version. */
1173 : 21014 : if (loop_vectorized_call && loop->inner)
1174 : 807 : loop->inner->dont_vectorize = true;
1175 : 419828 : return ret;
1176 : : }
1177 : :
1178 : 50853 : if (!dbg_cnt (vect_loop))
1179 : : {
1180 : : /* Free existing information if loop is analyzed with some
1181 : : assumptions. */
1182 : 4 : if (loop_constraint_set_p (loop, LOOP_C_FINITE))
1183 : 0 : vect_free_loop_info_assumptions (loop);
1184 : 4 : return ret;
1185 : : }
1186 : :
1187 : 50849 : (*num_vectorized_loops)++;
1188 : : /* Transform LOOP and its epilogues. */
1189 : 50849 : ret |= vect_transform_loops (simduid_to_vf_htab, loop,
1190 : : loop_vectorized_call, fun);
1191 : :
1192 : 50849 : if (loop_vectorized_call)
1193 : : {
1194 : 5815 : fold_loop_internal_call (loop_vectorized_call, boolean_true_node);
1195 : 5815 : ret |= TODO_cleanup_cfg;
1196 : : }
1197 : 50849 : if (loop_dist_alias_call)
1198 : : {
1199 : 8 : tree value = gimple_call_arg (loop_dist_alias_call, 1);
1200 : 8 : fold_loop_internal_call (loop_dist_alias_call, value);
1201 : 8 : ret |= TODO_cleanup_cfg;
1202 : : }
1203 : :
1204 : : return ret;
1205 : 470681 : }
1206 : :
1207 : : /* Try to vectorize LOOP. */
1208 : :
1209 : : static unsigned
1210 : 502753 : try_vectorize_loop (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
1211 : : unsigned *num_vectorized_loops, loop_p loop,
1212 : : function *fun)
1213 : : {
1214 : 502753 : if (!((flag_tree_loop_vectorize
1215 : 498121 : && optimize_loop_nest_for_speed_p (loop))
1216 : 33872 : || loop->force_vectorize))
1217 : : return 0;
1218 : :
1219 : 470681 : return try_vectorize_loop_1 (simduid_to_vf_htab, num_vectorized_loops, loop,
1220 : : vect_loop_vectorized_call (loop),
1221 : 470681 : vect_loop_dist_alias_call (loop, fun), fun);
1222 : : }
1223 : :
1224 : :
1225 : : /* Loop autovectorization. */
1226 : :
1227 : : namespace {
1228 : :
1229 : : const pass_data pass_data_vectorize =
1230 : : {
1231 : : GIMPLE_PASS, /* type */
1232 : : "vect", /* name */
1233 : : OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
1234 : : TV_TREE_VECTORIZATION, /* tv_id */
1235 : : ( PROP_cfg | PROP_ssa ), /* properties_required */
1236 : : 0, /* properties_provided */
1237 : : 0, /* properties_destroyed */
1238 : : 0, /* todo_flags_start */
1239 : : 0, /* todo_flags_finish */
1240 : : };
1241 : :
1242 : : class pass_vectorize : public gimple_opt_pass
1243 : : {
1244 : : public:
1245 : 287349 : pass_vectorize (gcc::context *ctxt)
1246 : 574698 : : gimple_opt_pass (pass_data_vectorize, ctxt)
1247 : : {}
1248 : :
1249 : : /* opt_pass methods: */
1250 : 239295 : bool gate (function *fun) final override
1251 : : {
1252 : 239295 : return flag_tree_loop_vectorize || fun->has_force_vectorize_loops;
1253 : : }
1254 : :
1255 : : unsigned int execute (function *) final override;
1256 : :
1257 : : }; // class pass_vectorize
1258 : :
1259 : : /* Function vectorize_loops.
1260 : :
1261 : : Entry point to loop vectorization phase. */
1262 : :
1263 : : unsigned
1264 : 207816 : pass_vectorize::execute (function *fun)
1265 : : {
1266 : 207816 : unsigned int i;
1267 : 207816 : unsigned int num_vectorized_loops = 0;
1268 : 207816 : unsigned int vect_loops_num;
1269 : 207816 : hash_table<simduid_to_vf> *simduid_to_vf_htab = NULL;
1270 : 207816 : hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
1271 : 207816 : bool any_ifcvt_loops = false;
1272 : 207816 : unsigned ret = 0;
1273 : :
1274 : 207816 : vect_loops_num = number_of_loops (fun);
1275 : :
1276 : : /* Bail out if there are no loops. */
1277 : 207816 : if (vect_loops_num <= 1)
1278 : : return 0;
1279 : :
1280 : 207816 : vect_slp_init ();
1281 : :
1282 : 207816 : if (fun->has_simduid_loops)
1283 : 5601 : note_simd_array_uses (&simd_array_to_simduid_htab, fun);
1284 : :
1285 : : /* ----------- Analyze loops. ----------- */
1286 : :
1287 : : /* If some loop was duplicated, it gets bigger number
1288 : : than all previously defined loops. This fact allows us to run
1289 : : only over initial loops skipping newly generated ones. */
1290 : 1157410 : for (auto loop : loops_list (fun, 0))
1291 : 533962 : if (loop->dont_vectorize)
1292 : : {
1293 : 32116 : any_ifcvt_loops = true;
1294 : : /* If-conversion sometimes versions both the outer loop
1295 : : (for the case when outer loop vectorization might be
1296 : : desirable) as well as the inner loop in the scalar version
1297 : : of the loop. So we have:
1298 : : if (LOOP_VECTORIZED (1, 3))
1299 : : {
1300 : : loop1
1301 : : loop2
1302 : : }
1303 : : else
1304 : : loop3 (copy of loop1)
1305 : : if (LOOP_VECTORIZED (4, 5))
1306 : : loop4 (copy of loop2)
1307 : : else
1308 : : loop5 (copy of loop4)
1309 : : If loops' iteration gives us loop3 first (which has
1310 : : dont_vectorize set), make sure to process loop1 before loop4;
1311 : : so that we can prevent vectorization of loop4 if loop1
1312 : : is successfully vectorized. */
1313 : 32116 : if (loop->inner)
1314 : : {
1315 : 2080 : gimple *loop_vectorized_call
1316 : 2080 : = vect_loop_vectorized_call (loop);
1317 : 2080 : if (loop_vectorized_call
1318 : 2080 : && vect_loop_vectorized_call (loop->inner))
1319 : : {
1320 : 907 : tree arg = gimple_call_arg (loop_vectorized_call, 0);
1321 : 907 : class loop *vector_loop
1322 : 907 : = get_loop (fun, tree_to_shwi (arg));
1323 : 907 : if (vector_loop && vector_loop != loop)
1324 : : {
1325 : : /* Make sure we don't vectorize it twice. */
1326 : 907 : vector_loop->dont_vectorize = true;
1327 : 907 : ret |= try_vectorize_loop (simduid_to_vf_htab,
1328 : : &num_vectorized_loops,
1329 : : vector_loop, fun);
1330 : : }
1331 : : }
1332 : : }
1333 : : }
1334 : : else
1335 : 501846 : ret |= try_vectorize_loop (simduid_to_vf_htab, &num_vectorized_loops,
1336 : 207816 : loop, fun);
1337 : :
1338 : 207816 : vect_location = dump_user_location_t ();
1339 : :
1340 : 207816 : statistics_counter_event (fun, "Vectorized loops", num_vectorized_loops);
1341 : 207816 : if (dump_enabled_p ()
1342 : 207816 : || (num_vectorized_loops > 0 && dump_enabled_p ()))
1343 : 10643 : dump_printf_loc (MSG_NOTE, vect_location,
1344 : : "vectorized %u loops in function.\n",
1345 : : num_vectorized_loops);
1346 : :
1347 : : /* ----------- Finalize. ----------- */
1348 : :
1349 : 207816 : if (any_ifcvt_loops)
1350 : 292402 : for (i = 1; i < number_of_loops (fun); i++)
1351 : : {
1352 : 126402 : class loop *loop = get_loop (fun, i);
1353 : 126402 : if (loop && loop->dont_vectorize)
1354 : : {
1355 : 34075 : gimple *g = vect_loop_vectorized_call (loop);
1356 : 34075 : if (g)
1357 : : {
1358 : 20161 : fold_loop_internal_call (g, boolean_false_node);
1359 : 20161 : loop->dont_vectorize = false;
1360 : 20161 : ret |= TODO_cleanup_cfg;
1361 : 20161 : g = NULL;
1362 : : }
1363 : : else
1364 : 13914 : g = vect_loop_dist_alias_call (loop, fun);
1365 : :
1366 : 34075 : if (g)
1367 : : {
1368 : 28 : fold_loop_internal_call (g, boolean_false_node);
1369 : 28 : loop->dont_vectorize = false;
1370 : 28 : ret |= TODO_cleanup_cfg;
1371 : : }
1372 : : }
1373 : : }
1374 : :
1375 : : /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
1376 : 207816 : if (fun->has_simduid_loops)
1377 : : {
1378 : 5601 : adjust_simduid_builtins (simduid_to_vf_htab, fun);
1379 : : /* Avoid stale SCEV cache entries for the SIMD_LANE defs. */
1380 : 5601 : scev_reset ();
1381 : : }
1382 : : /* Shrink any "omp array simd" temporary arrays to the
1383 : : actual vectorization factors. */
1384 : 207816 : if (simd_array_to_simduid_htab)
1385 : 2204 : shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab);
1386 : 207816 : delete simduid_to_vf_htab;
1387 : 207816 : fun->has_simduid_loops = false;
1388 : :
1389 : 207816 : if (num_vectorized_loops > 0)
1390 : : {
1391 : : /* We are collecting some corner cases where we need to update
1392 : : virtual SSA form via the TODO but delete the queued update-SSA
1393 : : state. Force renaming if we think that might be necessary. */
1394 : 34246 : if (ret & TODO_update_ssa_only_virtuals)
1395 : 89 : mark_virtual_operands_for_renaming (cfun);
1396 : : /* If we vectorized any loop only virtual SSA form needs to be updated.
1397 : : ??? Also while we try hard to update loop-closed SSA form we fail
1398 : : to properly do this in some corner-cases (see PR56286). */
1399 : 34246 : rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
1400 : 34246 : ret |= TODO_cleanup_cfg;
1401 : : }
1402 : :
1403 : 1863110 : for (i = 1; i < number_of_loops (fun); i++)
1404 : : {
1405 : 723739 : loop_vec_info loop_vinfo;
1406 : 723739 : bool has_mask_store;
1407 : :
1408 : 723739 : class loop *loop = get_loop (fun, i);
1409 : 723739 : if (!loop || !loop->aux)
1410 : 666231 : continue;
1411 : 57508 : loop_vinfo = (loop_vec_info) loop->aux;
1412 : 57508 : has_mask_store = LOOP_VINFO_HAS_MASK_STORE (loop_vinfo);
1413 : 57508 : delete loop_vinfo;
1414 : 57508 : if (has_mask_store
1415 : 57508 : && targetm.vectorize.empty_mask_is_expensive (IFN_MASK_STORE))
1416 : 480 : optimize_mask_stores (loop);
1417 : :
1418 : 57508 : auto_bitmap exit_bbs;
1419 : : /* Perform local CSE, this esp. helps because we emit code for
1420 : : predicates that need to be shared for optimal predicate usage.
1421 : : However reassoc will re-order them and prevent CSE from working
1422 : : as it should. CSE only the loop body, not the entry. */
1423 : 57508 : auto_vec<edge> exits = get_loop_exit_edges (loop);
1424 : 231652 : for (edge exit : exits)
1425 : 59128 : bitmap_set_bit (exit_bbs, exit->dest->index);
1426 : :
1427 : 57508 : edge entry = EDGE_PRED (loop_preheader_edge (loop)->src, 0);
1428 : 57508 : do_rpo_vn (fun, entry, exit_bbs);
1429 : :
1430 : 57508 : loop->aux = NULL;
1431 : 57508 : }
1432 : :
1433 : 207816 : vect_slp_fini ();
1434 : :
1435 : 207816 : return ret;
1436 : : }
1437 : :
1438 : : } // anon namespace
1439 : :
1440 : : gimple_opt_pass *
1441 : 287349 : make_pass_vectorize (gcc::context *ctxt)
1442 : : {
1443 : 287349 : return new pass_vectorize (ctxt);
1444 : : }
1445 : :
1446 : : /* Entry point to the simduid cleanup pass. */
1447 : :
1448 : : namespace {
1449 : :
1450 : : const pass_data pass_data_simduid_cleanup =
1451 : : {
1452 : : GIMPLE_PASS, /* type */
1453 : : "simduid", /* name */
1454 : : OPTGROUP_NONE, /* optinfo_flags */
1455 : : TV_NONE, /* tv_id */
1456 : : ( PROP_ssa | PROP_cfg ), /* properties_required */
1457 : : 0, /* properties_provided */
1458 : : 0, /* properties_destroyed */
1459 : : 0, /* todo_flags_start */
1460 : : 0, /* todo_flags_finish */
1461 : : };
1462 : :
1463 : : class pass_simduid_cleanup : public gimple_opt_pass
1464 : : {
1465 : : public:
1466 : 574698 : pass_simduid_cleanup (gcc::context *ctxt)
1467 : 1149396 : : gimple_opt_pass (pass_data_simduid_cleanup, ctxt)
1468 : : {}
1469 : :
1470 : : /* opt_pass methods: */
1471 : 287349 : opt_pass * clone () final override
1472 : : {
1473 : 287349 : return new pass_simduid_cleanup (m_ctxt);
1474 : : }
1475 : 2489169 : bool gate (function *fun) final override { return fun->has_simduid_loops; }
1476 : : unsigned int execute (function *) final override;
1477 : :
1478 : : }; // class pass_simduid_cleanup
1479 : :
1480 : : unsigned int
1481 : 2204 : pass_simduid_cleanup::execute (function *fun)
1482 : : {
1483 : 2204 : hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
1484 : :
1485 : 2204 : note_simd_array_uses (&simd_array_to_simduid_htab, fun);
1486 : :
1487 : : /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
1488 : 2204 : adjust_simduid_builtins (NULL, fun);
1489 : :
1490 : : /* Shrink any "omp array simd" temporary arrays to the
1491 : : actual vectorization factors. */
1492 : 2204 : if (simd_array_to_simduid_htab)
1493 : 4 : shrink_simd_arrays (simd_array_to_simduid_htab, NULL);
1494 : 2204 : fun->has_simduid_loops = false;
1495 : 2204 : return 0;
1496 : : }
1497 : :
1498 : : } // anon namespace
1499 : :
1500 : : gimple_opt_pass *
1501 : 287349 : make_pass_simduid_cleanup (gcc::context *ctxt)
1502 : : {
1503 : 287349 : return new pass_simduid_cleanup (ctxt);
1504 : : }
1505 : :
1506 : :
1507 : : /* Entry point to basic block SLP phase. */
1508 : :
1509 : : namespace {
1510 : :
1511 : : const pass_data pass_data_slp_vectorize =
1512 : : {
1513 : : GIMPLE_PASS, /* type */
1514 : : "slp", /* name */
1515 : : OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
1516 : : TV_TREE_SLP_VECTORIZATION, /* tv_id */
1517 : : ( PROP_ssa | PROP_cfg ), /* properties_required */
1518 : : 0, /* properties_provided */
1519 : : 0, /* properties_destroyed */
1520 : : 0, /* todo_flags_start */
1521 : : TODO_update_ssa, /* todo_flags_finish */
1522 : : };
1523 : :
1524 : : class pass_slp_vectorize : public gimple_opt_pass
1525 : : {
1526 : : public:
1527 : 574698 : pass_slp_vectorize (gcc::context *ctxt)
1528 : 1149396 : : gimple_opt_pass (pass_data_slp_vectorize, ctxt)
1529 : : {}
1530 : :
1531 : : /* opt_pass methods: */
1532 : 287349 : opt_pass * clone () final override { return new pass_slp_vectorize (m_ctxt); }
1533 : 1027742 : bool gate (function *) final override { return flag_tree_slp_vectorize != 0; }
1534 : : unsigned int execute (function *) final override;
1535 : :
1536 : : }; // class pass_slp_vectorize
1537 : :
1538 : : unsigned int
1539 : 901001 : pass_slp_vectorize::execute (function *fun)
1540 : : {
1541 : 901001 : auto_purge_vect_location sentinel;
1542 : 901001 : basic_block bb;
1543 : :
1544 : 901001 : bool in_loop_pipeline = scev_initialized_p ();
1545 : 901001 : if (!in_loop_pipeline)
1546 : : {
1547 : 694819 : loop_optimizer_init (LOOPS_NORMAL);
1548 : 694819 : scev_initialize ();
1549 : : }
1550 : :
1551 : : /* Mark all stmts as not belonging to the current region and unvisited. */
1552 : 12074024 : FOR_EACH_BB_FN (bb, fun)
1553 : : {
1554 : 16450361 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
1555 : 5277338 : gsi_next (&gsi))
1556 : : {
1557 : 5277338 : gphi *stmt = gsi.phi ();
1558 : 5277338 : gimple_set_uid (stmt, -1);
1559 : 5277338 : gimple_set_visited (stmt, false);
1560 : : }
1561 : 101247965 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
1562 : 78901919 : gsi_next (&gsi))
1563 : : {
1564 : 78901919 : gimple *stmt = gsi_stmt (gsi);
1565 : 78901919 : gimple_set_uid (stmt, -1);
1566 : 78901919 : gimple_set_visited (stmt, false);
1567 : : }
1568 : : }
1569 : :
1570 : 901001 : vect_slp_init ();
1571 : :
1572 : 901001 : vect_slp_function (fun);
1573 : :
1574 : 901001 : vect_slp_fini ();
1575 : :
1576 : 901001 : if (!in_loop_pipeline)
1577 : : {
1578 : 694819 : scev_finalize ();
1579 : 694819 : loop_optimizer_finalize ();
1580 : : }
1581 : :
1582 : 1802002 : return 0;
1583 : 901001 : }
1584 : :
1585 : : } // anon namespace
1586 : :
1587 : : gimple_opt_pass *
1588 : 287349 : make_pass_slp_vectorize (gcc::context *ctxt)
1589 : : {
1590 : 287349 : return new pass_slp_vectorize (ctxt);
1591 : : }
1592 : :
1593 : :
1594 : : /* Increase alignment of global arrays to improve vectorization potential.
1595 : : TODO:
1596 : : - Consider also structs that have an array field.
1597 : : - Use ipa analysis to prune arrays that can't be vectorized?
1598 : : This should involve global alignment analysis and in the future also
1599 : : array padding. */
1600 : :
1601 : : static unsigned get_vec_alignment_for_type (tree);
1602 : : static hash_map<tree, unsigned> *type_align_map;
1603 : :
1604 : : /* Return alignment of array's vector type corresponding to scalar type.
1605 : : 0 if no vector type exists. */
1606 : : static unsigned
1607 : 0 : get_vec_alignment_for_array_type (tree type)
1608 : : {
1609 : 0 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
1610 : 0 : poly_uint64 array_size, vector_size;
1611 : :
1612 : 0 : tree scalar_type = strip_array_types (type);
1613 : 0 : tree vectype = get_related_vectype_for_scalar_type (VOIDmode, scalar_type);
1614 : 0 : if (!vectype
1615 : 0 : || !poly_int_tree_p (TYPE_SIZE (type), &array_size)
1616 : 0 : || !poly_int_tree_p (TYPE_SIZE (vectype), &vector_size)
1617 : 0 : || maybe_lt (array_size, vector_size))
1618 : 0 : return 0;
1619 : :
1620 : 0 : return TYPE_ALIGN (vectype);
1621 : : }
1622 : :
1623 : : /* Return alignment of field having maximum alignment of vector type
1624 : : corresponding to it's scalar type. For now, we only consider fields whose
1625 : : offset is a multiple of it's vector alignment.
1626 : : 0 if no suitable field is found. */
1627 : : static unsigned
1628 : 0 : get_vec_alignment_for_record_type (tree type)
1629 : : {
1630 : 0 : gcc_assert (TREE_CODE (type) == RECORD_TYPE);
1631 : :
1632 : 0 : unsigned max_align = 0, alignment;
1633 : 0 : HOST_WIDE_INT offset;
1634 : 0 : tree offset_tree;
1635 : :
1636 : 0 : if (TYPE_PACKED (type))
1637 : : return 0;
1638 : :
1639 : 0 : unsigned *slot = type_align_map->get (type);
1640 : 0 : if (slot)
1641 : 0 : return *slot;
1642 : :
1643 : 0 : for (tree field = first_field (type);
1644 : 0 : field != NULL_TREE;
1645 : 0 : field = DECL_CHAIN (field))
1646 : : {
1647 : : /* Skip if not FIELD_DECL or if alignment is set by user. */
1648 : 0 : if (TREE_CODE (field) != FIELD_DECL
1649 : 0 : || DECL_USER_ALIGN (field)
1650 : 0 : || DECL_ARTIFICIAL (field))
1651 : 0 : continue;
1652 : :
1653 : : /* We don't need to process the type further if offset is variable,
1654 : : since the offsets of remaining members will also be variable. */
1655 : 0 : if (TREE_CODE (DECL_FIELD_OFFSET (field)) != INTEGER_CST
1656 : 0 : || TREE_CODE (DECL_FIELD_BIT_OFFSET (field)) != INTEGER_CST)
1657 : : break;
1658 : :
1659 : : /* Similarly stop processing the type if offset_tree
1660 : : does not fit in unsigned HOST_WIDE_INT. */
1661 : 0 : offset_tree = bit_position (field);
1662 : 0 : if (!tree_fits_uhwi_p (offset_tree))
1663 : : break;
1664 : :
1665 : 0 : offset = tree_to_uhwi (offset_tree);
1666 : 0 : alignment = get_vec_alignment_for_type (TREE_TYPE (field));
1667 : :
1668 : : /* Get maximum alignment of vectorized field/array among those members
1669 : : whose offset is multiple of the vector alignment. */
1670 : 0 : if (alignment
1671 : 0 : && (offset % alignment == 0)
1672 : 0 : && (alignment > max_align))
1673 : 0 : max_align = alignment;
1674 : : }
1675 : :
1676 : 0 : type_align_map->put (type, max_align);
1677 : 0 : return max_align;
1678 : : }
1679 : :
1680 : : /* Return alignment of vector type corresponding to decl's scalar type
1681 : : or 0 if it doesn't exist or the vector alignment is lesser than
1682 : : decl's alignment. */
1683 : : static unsigned
1684 : 0 : get_vec_alignment_for_type (tree type)
1685 : : {
1686 : 0 : if (type == NULL_TREE)
1687 : : return 0;
1688 : :
1689 : 0 : gcc_assert (TYPE_P (type));
1690 : :
1691 : 0 : static unsigned alignment = 0;
1692 : 0 : switch (TREE_CODE (type))
1693 : : {
1694 : 0 : case ARRAY_TYPE:
1695 : 0 : alignment = get_vec_alignment_for_array_type (type);
1696 : 0 : break;
1697 : 0 : case RECORD_TYPE:
1698 : 0 : alignment = get_vec_alignment_for_record_type (type);
1699 : 0 : break;
1700 : 0 : default:
1701 : 0 : alignment = 0;
1702 : 0 : break;
1703 : : }
1704 : :
1705 : 0 : return (alignment > TYPE_ALIGN (type)) ? alignment : 0;
1706 : : }
1707 : :
1708 : : /* Entry point to increase_alignment pass. */
1709 : : static unsigned int
1710 : 0 : increase_alignment (void)
1711 : : {
1712 : 0 : varpool_node *vnode;
1713 : :
1714 : 0 : vect_location = dump_user_location_t ();
1715 : 0 : type_align_map = new hash_map<tree, unsigned>;
1716 : :
1717 : : /* Increase the alignment of all global arrays for vectorization. */
1718 : 0 : FOR_EACH_DEFINED_VARIABLE (vnode)
1719 : : {
1720 : 0 : tree decl = vnode->decl;
1721 : 0 : unsigned int alignment;
1722 : :
1723 : 0 : if ((decl_in_symtab_p (decl)
1724 : 0 : && !symtab_node::get (decl)->can_increase_alignment_p ())
1725 : 0 : || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl))
1726 : 0 : continue;
1727 : :
1728 : 0 : alignment = get_vec_alignment_for_type (TREE_TYPE (decl));
1729 : 0 : if (alignment && vect_can_force_dr_alignment_p (decl, alignment))
1730 : : {
1731 : 0 : vnode->increase_alignment (alignment);
1732 : 0 : if (dump_enabled_p ())
1733 : 0 : dump_printf (MSG_NOTE, "Increasing alignment of decl: %T\n", decl);
1734 : : }
1735 : : }
1736 : :
1737 : 0 : delete type_align_map;
1738 : 0 : return 0;
1739 : : }
1740 : :
1741 : :
1742 : : namespace {
1743 : :
1744 : : const pass_data pass_data_ipa_increase_alignment =
1745 : : {
1746 : : SIMPLE_IPA_PASS, /* type */
1747 : : "increase_alignment", /* name */
1748 : : OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
1749 : : TV_IPA_OPT, /* tv_id */
1750 : : 0, /* properties_required */
1751 : : 0, /* properties_provided */
1752 : : 0, /* properties_destroyed */
1753 : : 0, /* todo_flags_start */
1754 : : 0, /* todo_flags_finish */
1755 : : };
1756 : :
1757 : : class pass_ipa_increase_alignment : public simple_ipa_opt_pass
1758 : : {
1759 : : public:
1760 : 287349 : pass_ipa_increase_alignment (gcc::context *ctxt)
1761 : 574698 : : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt)
1762 : : {}
1763 : :
1764 : : /* opt_pass methods: */
1765 : 230751 : bool gate (function *) final override
1766 : : {
1767 : 230751 : return flag_section_anchors && flag_tree_loop_vectorize;
1768 : : }
1769 : :
1770 : 0 : unsigned int execute (function *) final override
1771 : : {
1772 : 0 : return increase_alignment ();
1773 : : }
1774 : :
1775 : : }; // class pass_ipa_increase_alignment
1776 : :
1777 : : } // anon namespace
1778 : :
1779 : : simple_ipa_opt_pass *
1780 : 287349 : make_pass_ipa_increase_alignment (gcc::context *ctxt)
1781 : : {
1782 : 287349 : return new pass_ipa_increase_alignment (ctxt);
1783 : : }
1784 : :
1785 : : /* If the condition represented by T is a comparison or the SSA name
1786 : : result of a comparison, extract the comparison's operands. Represent
1787 : : T as NE_EXPR <T, 0> otherwise. */
1788 : :
1789 : : void
1790 : 50831 : scalar_cond_masked_key::get_cond_ops_from_tree (tree t)
1791 : : {
1792 : 50831 : if (TREE_CODE_CLASS (TREE_CODE (t)) == tcc_comparison)
1793 : : {
1794 : 0 : this->code = TREE_CODE (t);
1795 : 0 : this->op0 = TREE_OPERAND (t, 0);
1796 : 0 : this->op1 = TREE_OPERAND (t, 1);
1797 : 0 : this->inverted_p = false;
1798 : 0 : return;
1799 : : }
1800 : :
1801 : 50831 : if (TREE_CODE (t) == SSA_NAME)
1802 : 19840 : if (gassign *stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (t)))
1803 : : {
1804 : 19840 : tree_code code = gimple_assign_rhs_code (stmt);
1805 : 19840 : if (TREE_CODE_CLASS (code) == tcc_comparison)
1806 : : {
1807 : 14311 : this->code = code;
1808 : 14311 : this->op0 = gimple_assign_rhs1 (stmt);
1809 : 14311 : this->op1 = gimple_assign_rhs2 (stmt);
1810 : 14311 : this->inverted_p = false;
1811 : 14311 : return;
1812 : : }
1813 : 5529 : else if (code == BIT_NOT_EXPR)
1814 : : {
1815 : 2843 : tree n_op = gimple_assign_rhs1 (stmt);
1816 : 2843 : if ((stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (n_op))))
1817 : : {
1818 : 2843 : code = gimple_assign_rhs_code (stmt);
1819 : 2843 : if (TREE_CODE_CLASS (code) == tcc_comparison)
1820 : : {
1821 : 2823 : this->code = code;
1822 : 2823 : this->op0 = gimple_assign_rhs1 (stmt);
1823 : 2823 : this->op1 = gimple_assign_rhs2 (stmt);
1824 : 2823 : this->inverted_p = true;
1825 : 2823 : return;
1826 : : }
1827 : : }
1828 : : }
1829 : : }
1830 : :
1831 : 33697 : this->code = NE_EXPR;
1832 : 33697 : this->op0 = t;
1833 : 33697 : this->op1 = build_zero_cst (TREE_TYPE (t));
1834 : 33697 : this->inverted_p = false;
1835 : : }
1836 : :
1837 : : /* See the comment above the declaration for details. */
1838 : :
1839 : : unsigned int
1840 : 0 : vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
1841 : : stmt_vec_info stmt_info, slp_tree,
1842 : : tree vectype, int misalign,
1843 : : vect_cost_model_location where)
1844 : : {
1845 : 0 : unsigned int cost
1846 : 0 : = builtin_vectorization_cost (kind, vectype, misalign) * count;
1847 : 0 : return record_stmt_cost (stmt_info, where, cost);
1848 : : }
1849 : :
1850 : : /* See the comment above the declaration for details. */
1851 : :
1852 : : void
1853 : 1689207 : vector_costs::finish_cost (const vector_costs *)
1854 : : {
1855 : 1689207 : gcc_assert (!m_finished);
1856 : 1689207 : m_finished = true;
1857 : 1689207 : }
1858 : :
1859 : : /* Record a base cost of COST units against WHERE. If STMT_INFO is
1860 : : nonnull, use it to adjust the cost based on execution frequency
1861 : : (where appropriate). */
1862 : :
1863 : : unsigned int
1864 : 0 : vector_costs::record_stmt_cost (stmt_vec_info stmt_info,
1865 : : vect_cost_model_location where,
1866 : : unsigned int cost)
1867 : : {
1868 : 0 : cost = adjust_cost_for_freq (stmt_info, where, cost);
1869 : 0 : m_costs[where] += cost;
1870 : 0 : return cost;
1871 : : }
1872 : :
1873 : : /* COST is the base cost we have calculated for an operation in location WHERE.
1874 : : If STMT_INFO is nonnull, use it to adjust the cost based on execution
1875 : : frequency (where appropriate). Return the adjusted cost. */
1876 : :
1877 : : unsigned int
1878 : 6718550 : vector_costs::adjust_cost_for_freq (stmt_vec_info stmt_info,
1879 : : vect_cost_model_location where,
1880 : : unsigned int cost)
1881 : : {
1882 : : /* Statements in an inner loop relative to the loop being
1883 : : vectorized are weighted more heavily. The value here is
1884 : : arbitrary and could potentially be improved with analysis. */
1885 : 6718550 : if (where == vect_body
1886 : 6718550 : && stmt_info
1887 : 6718550 : && stmt_in_inner_loop_p (m_vinfo, stmt_info))
1888 : : {
1889 : 4144 : loop_vec_info loop_vinfo = as_a<loop_vec_info> (m_vinfo);
1890 : 4144 : cost *= LOOP_VINFO_INNER_LOOP_COST_FACTOR (loop_vinfo);
1891 : : }
1892 : 6718550 : return cost;
1893 : : }
1894 : :
1895 : : /* See the comment above the declaration for details. */
1896 : :
1897 : : bool
1898 : 0 : vector_costs::better_main_loop_than_p (const vector_costs *other) const
1899 : : {
1900 : 0 : int diff = compare_inside_loop_cost (other);
1901 : 0 : if (diff != 0)
1902 : 0 : return diff < 0;
1903 : :
1904 : : /* If there's nothing to choose between the loop bodies, see whether
1905 : : there's a difference in the prologue and epilogue costs. */
1906 : 0 : diff = compare_outside_loop_cost (other);
1907 : 0 : if (diff != 0)
1908 : 0 : return diff < 0;
1909 : :
1910 : : return false;
1911 : : }
1912 : :
1913 : :
1914 : : /* See the comment above the declaration for details. */
1915 : :
1916 : : bool
1917 : 0 : vector_costs::better_epilogue_loop_than_p (const vector_costs *other,
1918 : : loop_vec_info main_loop) const
1919 : : {
1920 : 0 : loop_vec_info this_loop_vinfo = as_a<loop_vec_info> (this->m_vinfo);
1921 : 0 : loop_vec_info other_loop_vinfo = as_a<loop_vec_info> (other->m_vinfo);
1922 : :
1923 : 0 : poly_int64 this_vf = LOOP_VINFO_VECT_FACTOR (this_loop_vinfo);
1924 : 0 : poly_int64 other_vf = LOOP_VINFO_VECT_FACTOR (other_loop_vinfo);
1925 : :
1926 : 0 : poly_uint64 main_poly_vf = LOOP_VINFO_VECT_FACTOR (main_loop);
1927 : 0 : unsigned HOST_WIDE_INT main_vf;
1928 : 0 : unsigned HOST_WIDE_INT other_factor, this_factor, other_cost, this_cost;
1929 : : /* If we can determine how many iterations are left for the epilogue
1930 : : loop, that is if both the main loop's vectorization factor and number
1931 : : of iterations are constant, then we use them to calculate the cost of
1932 : : the epilogue loop together with a 'likely value' for the epilogues
1933 : : vectorization factor. Otherwise we use the main loop's vectorization
1934 : : factor and the maximum poly value for the epilogue's. If the target
1935 : : has not provided with a sensible upper bound poly vectorization
1936 : : factors are likely to be favored over constant ones. */
1937 : 0 : if (main_poly_vf.is_constant (&main_vf)
1938 : 0 : && LOOP_VINFO_NITERS_KNOWN_P (main_loop))
1939 : : {
1940 : 0 : unsigned HOST_WIDE_INT niters
1941 : 0 : = LOOP_VINFO_INT_NITERS (main_loop) % main_vf;
1942 : 0 : HOST_WIDE_INT other_likely_vf
1943 : 0 : = estimated_poly_value (other_vf, POLY_VALUE_LIKELY);
1944 : 0 : HOST_WIDE_INT this_likely_vf
1945 : 0 : = estimated_poly_value (this_vf, POLY_VALUE_LIKELY);
1946 : :
1947 : : /* If the epilogue is using partial vectors we account for the
1948 : : partial iteration here too. */
1949 : 0 : other_factor = niters / other_likely_vf;
1950 : 0 : if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (other_loop_vinfo)
1951 : 0 : && niters % other_likely_vf != 0)
1952 : 0 : other_factor++;
1953 : :
1954 : 0 : this_factor = niters / this_likely_vf;
1955 : 0 : if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (this_loop_vinfo)
1956 : 0 : && niters % this_likely_vf != 0)
1957 : 0 : this_factor++;
1958 : : }
1959 : : else
1960 : : {
1961 : 0 : unsigned HOST_WIDE_INT main_vf_max
1962 : 0 : = estimated_poly_value (main_poly_vf, POLY_VALUE_MAX);
1963 : 0 : unsigned HOST_WIDE_INT other_vf_max
1964 : 0 : = estimated_poly_value (other_vf, POLY_VALUE_MAX);
1965 : 0 : unsigned HOST_WIDE_INT this_vf_max
1966 : 0 : = estimated_poly_value (this_vf, POLY_VALUE_MAX);
1967 : :
1968 : 0 : other_factor = CEIL (main_vf_max, other_vf_max);
1969 : 0 : this_factor = CEIL (main_vf_max, this_vf_max);
1970 : :
1971 : : /* If the loop is not using partial vectors then it will iterate one
1972 : : time less than one that does. It is safe to subtract one here,
1973 : : because the main loop's vf is always at least 2x bigger than that
1974 : : of an epilogue. */
1975 : 0 : if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (other_loop_vinfo))
1976 : 0 : other_factor -= 1;
1977 : 0 : if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (this_loop_vinfo))
1978 : 0 : this_factor -= 1;
1979 : : }
1980 : :
1981 : : /* Compute the costs by multiplying the inside costs with the factor and
1982 : : add the outside costs for a more complete picture. The factor is the
1983 : : amount of times we are expecting to iterate this epilogue. */
1984 : 0 : other_cost = other->body_cost () * other_factor;
1985 : 0 : this_cost = this->body_cost () * this_factor;
1986 : 0 : other_cost += other->outside_cost ();
1987 : 0 : this_cost += this->outside_cost ();
1988 : 0 : return this_cost < other_cost;
1989 : : }
1990 : :
1991 : : /* A <=>-style subroutine of better_main_loop_than_p. Check whether we can
1992 : : determine the return value of better_main_loop_than_p by comparing the
1993 : : inside (loop body) costs of THIS and OTHER. Return:
1994 : :
1995 : : * -1 if better_main_loop_than_p should return true.
1996 : : * 1 if better_main_loop_than_p should return false.
1997 : : * 0 if we can't decide. */
1998 : :
1999 : : int
2000 : 0 : vector_costs::compare_inside_loop_cost (const vector_costs *other) const
2001 : : {
2002 : 0 : loop_vec_info this_loop_vinfo = as_a<loop_vec_info> (this->m_vinfo);
2003 : 0 : loop_vec_info other_loop_vinfo = as_a<loop_vec_info> (other->m_vinfo);
2004 : :
2005 : 0 : struct loop *loop = LOOP_VINFO_LOOP (this_loop_vinfo);
2006 : 0 : gcc_assert (LOOP_VINFO_LOOP (other_loop_vinfo) == loop);
2007 : :
2008 : 0 : poly_int64 this_vf = LOOP_VINFO_VECT_FACTOR (this_loop_vinfo);
2009 : 0 : poly_int64 other_vf = LOOP_VINFO_VECT_FACTOR (other_loop_vinfo);
2010 : :
2011 : : /* Limit the VFs to what is likely to be the maximum number of iterations,
2012 : : to handle cases in which at least one loop_vinfo is fully-masked. */
2013 : 0 : HOST_WIDE_INT estimated_max_niter = likely_max_stmt_executions_int (loop);
2014 : 0 : if (estimated_max_niter != -1)
2015 : : {
2016 : 0 : if (estimated_poly_value (this_vf, POLY_VALUE_MIN)
2017 : : >= estimated_max_niter)
2018 : : this_vf = estimated_max_niter;
2019 : 0 : if (estimated_poly_value (other_vf, POLY_VALUE_MIN)
2020 : : >= estimated_max_niter)
2021 : : other_vf = estimated_max_niter;
2022 : : }
2023 : :
2024 : : /* Check whether the (fractional) cost per scalar iteration is lower or
2025 : : higher: this_inside_cost / this_vf vs. other_inside_cost / other_vf. */
2026 : 0 : poly_int64 rel_this = this_loop_vinfo->vector_costs->body_cost () * other_vf;
2027 : 0 : poly_int64 rel_other
2028 : 0 : = other_loop_vinfo->vector_costs->body_cost () * this_vf;
2029 : :
2030 : 0 : HOST_WIDE_INT est_rel_this_min
2031 : 0 : = estimated_poly_value (rel_this, POLY_VALUE_MIN);
2032 : 0 : HOST_WIDE_INT est_rel_this_max
2033 : 0 : = estimated_poly_value (rel_this, POLY_VALUE_MAX);
2034 : :
2035 : 0 : HOST_WIDE_INT est_rel_other_min
2036 : 0 : = estimated_poly_value (rel_other, POLY_VALUE_MIN);
2037 : 0 : HOST_WIDE_INT est_rel_other_max
2038 : 0 : = estimated_poly_value (rel_other, POLY_VALUE_MAX);
2039 : :
2040 : : /* Check first if we can make out an unambigous total order from the minimum
2041 : : and maximum estimates. */
2042 : 0 : if (est_rel_this_min < est_rel_other_min
2043 : : && est_rel_this_max < est_rel_other_max)
2044 : : return -1;
2045 : :
2046 : 0 : if (est_rel_other_min < est_rel_this_min
2047 : : && est_rel_other_max < est_rel_this_max)
2048 : 0 : return 1;
2049 : :
2050 : : /* When other_loop_vinfo uses a variable vectorization factor,
2051 : : we know that it has a lower cost for at least one runtime VF.
2052 : : However, we don't know how likely that VF is.
2053 : :
2054 : : One option would be to compare the costs for the estimated VFs.
2055 : : The problem is that that can put too much pressure on the cost
2056 : : model. E.g. if the estimated VF is also the lowest possible VF,
2057 : : and if other_loop_vinfo is 1 unit worse than this_loop_vinfo
2058 : : for the estimated VF, we'd then choose this_loop_vinfo even
2059 : : though (a) this_loop_vinfo might not actually be better than
2060 : : other_loop_vinfo for that VF and (b) it would be significantly
2061 : : worse at larger VFs.
2062 : :
2063 : : Here we go for a hacky compromise: pick this_loop_vinfo if it is
2064 : : no more expensive than other_loop_vinfo even after doubling the
2065 : : estimated other_loop_vinfo VF. For all but trivial loops, this
2066 : : ensures that we only pick this_loop_vinfo if it is significantly
2067 : : better than other_loop_vinfo at the estimated VF. */
2068 : : if (est_rel_other_min != est_rel_this_min
2069 : : || est_rel_other_max != est_rel_this_max)
2070 : : {
2071 : : HOST_WIDE_INT est_rel_this_likely
2072 : : = estimated_poly_value (rel_this, POLY_VALUE_LIKELY);
2073 : : HOST_WIDE_INT est_rel_other_likely
2074 : : = estimated_poly_value (rel_other, POLY_VALUE_LIKELY);
2075 : :
2076 : : return est_rel_this_likely * 2 <= est_rel_other_likely ? -1 : 1;
2077 : : }
2078 : :
2079 : : return 0;
2080 : : }
2081 : :
2082 : : /* A <=>-style subroutine of better_main_loop_than_p, used when there is
2083 : : nothing to choose between the inside (loop body) costs of THIS and OTHER.
2084 : : Check whether we can determine the return value of better_main_loop_than_p
2085 : : by comparing the outside (prologue and epilogue) costs of THIS and OTHER.
2086 : : Return:
2087 : :
2088 : : * -1 if better_main_loop_than_p should return true.
2089 : : * 1 if better_main_loop_than_p should return false.
2090 : : * 0 if we can't decide. */
2091 : :
2092 : : int
2093 : 0 : vector_costs::compare_outside_loop_cost (const vector_costs *other) const
2094 : : {
2095 : 0 : auto this_outside_cost = this->outside_cost ();
2096 : 0 : auto other_outside_cost = other->outside_cost ();
2097 : 0 : if (this_outside_cost != other_outside_cost)
2098 : 0 : return this_outside_cost < other_outside_cost ? -1 : 1;
2099 : :
2100 : : return 0;
2101 : : }
|