PR jit/66779: fix segfault
[official-gcc.git] / gcc / tree-vectorizer.c
blobe49929ab8886c17607034b887f929153ac54b0f6
1 /* Vectorizer
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
5 This file is part of GCC.
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.
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.
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/>. */
21 /* Loop and basic block vectorizer.
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
29 The rest of the vectorizer's code is organized as follows:
30 - tree-vect-loop.c - loop specific parts such as reductions, etc. These are
31 used by drivers (1) and (2).
32 - tree-vect-loop-manip.c - vectorizer's loop control-flow utilities, used by
33 drivers (1) and (2).
34 - tree-vect-slp.c - BB vectorization specific analysis and transformation,
35 used by drivers (2) and (3).
36 - tree-vect-stmts.c - statements analysis and transformation (used by all).
37 - tree-vect-data-refs.c - vectorizer specific data-refs analysis and
38 manipulations (used by all).
39 - tree-vect-patterns.c - vectorizable code patterns detector (used by all)
41 Here's a poor attempt at illustrating that:
43 tree-vectorizer.c:
44 loop_vect() loop_aware_slp() slp_vect()
45 | / \ /
46 | / \ /
47 tree-vect-loop.c tree-vect-slp.c
48 | \ \ / / |
49 | \ \/ / |
50 | \ /\ / |
51 | \ / \ / |
52 tree-vect-stmts.c tree-vect-data-refs.c
53 \ /
54 tree-vect-patterns.c
57 #include "config.h"
58 #include "system.h"
59 #include "coretypes.h"
60 #include "dumpfile.h"
61 #include "tm.h"
62 #include "alias.h"
63 #include "symtab.h"
64 #include "tree.h"
65 #include "fold-const.h"
66 #include "stor-layout.h"
67 #include "tree-pretty-print.h"
68 #include "predict.h"
69 #include "hard-reg-set.h"
70 #include "function.h"
71 #include "dominance.h"
72 #include "cfg.h"
73 #include "basic-block.h"
74 #include "tree-ssa-alias.h"
75 #include "internal-fn.h"
76 #include "gimple-expr.h"
77 #include "gimple.h"
78 #include "gimple-iterator.h"
79 #include "gimple-walk.h"
80 #include "gimple-ssa.h"
81 #include "cgraph.h"
82 #include "tree-phinodes.h"
83 #include "ssa-iterators.h"
84 #include "tree-ssa-loop-manip.h"
85 #include "tree-cfg.h"
86 #include "cfgloop.h"
87 #include "tree-vectorizer.h"
88 #include "tree-pass.h"
89 #include "tree-ssa-propagate.h"
90 #include "dbgcnt.h"
91 #include "gimple-fold.h"
92 #include "tree-scalar-evolution.h"
95 /* Loop or bb location. */
96 source_location vect_location;
98 /* Vector mapping GIMPLE stmt to stmt_vec_info. */
99 vec<vec_void_p> stmt_vec_info_vec;
101 /* For mapping simduid to vectorization factor. */
103 struct simduid_to_vf : free_ptr_hash<simduid_to_vf>
105 unsigned int simduid;
106 int vf;
108 /* hash_table support. */
109 static inline hashval_t hash (const simduid_to_vf *);
110 static inline int equal (const simduid_to_vf *, const simduid_to_vf *);
113 inline hashval_t
114 simduid_to_vf::hash (const simduid_to_vf *p)
116 return p->simduid;
119 inline int
120 simduid_to_vf::equal (const simduid_to_vf *p1, const simduid_to_vf *p2)
122 return p1->simduid == p2->simduid;
125 /* This hash maps the OMP simd array to the corresponding simduid used
126 to index into it. Like thus,
128 _7 = GOMP_SIMD_LANE (simduid.0)
131 D.1737[_7] = stuff;
134 This hash maps from the OMP simd array (D.1737[]) to DECL_UID of
135 simduid.0. */
137 struct simd_array_to_simduid : free_ptr_hash<simd_array_to_simduid>
139 tree decl;
140 unsigned int simduid;
142 /* hash_table support. */
143 static inline hashval_t hash (const simd_array_to_simduid *);
144 static inline int equal (const simd_array_to_simduid *,
145 const simd_array_to_simduid *);
148 inline hashval_t
149 simd_array_to_simduid::hash (const simd_array_to_simduid *p)
151 return DECL_UID (p->decl);
154 inline int
155 simd_array_to_simduid::equal (const simd_array_to_simduid *p1,
156 const simd_array_to_simduid *p2)
158 return p1->decl == p2->decl;
161 /* Fold IFN_GOMP_SIMD_LANE, IFN_GOMP_SIMD_VF and IFN_GOMP_SIMD_LAST_LANE
162 into their corresponding constants. */
164 static void
165 adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
167 basic_block bb;
169 FOR_EACH_BB_FN (bb, cfun)
171 gimple_stmt_iterator i;
173 for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
175 unsigned int vf = 1;
176 enum internal_fn ifn;
177 gimple stmt = gsi_stmt (i);
178 tree t;
179 if (!is_gimple_call (stmt)
180 || !gimple_call_internal_p (stmt))
181 continue;
182 ifn = gimple_call_internal_fn (stmt);
183 switch (ifn)
185 case IFN_GOMP_SIMD_LANE:
186 case IFN_GOMP_SIMD_VF:
187 case IFN_GOMP_SIMD_LAST_LANE:
188 break;
189 default:
190 continue;
192 tree arg = gimple_call_arg (stmt, 0);
193 gcc_assert (arg != NULL_TREE);
194 gcc_assert (TREE_CODE (arg) == SSA_NAME);
195 simduid_to_vf *p = NULL, data;
196 data.simduid = DECL_UID (SSA_NAME_VAR (arg));
197 if (htab)
199 p = htab->find (&data);
200 if (p)
201 vf = p->vf;
203 switch (ifn)
205 case IFN_GOMP_SIMD_VF:
206 t = build_int_cst (unsigned_type_node, vf);
207 break;
208 case IFN_GOMP_SIMD_LANE:
209 t = build_int_cst (unsigned_type_node, 0);
210 break;
211 case IFN_GOMP_SIMD_LAST_LANE:
212 t = gimple_call_arg (stmt, 1);
213 break;
214 default:
215 gcc_unreachable ();
217 update_call_from_tree (&i, t);
222 /* Helper structure for note_simd_array_uses. */
224 struct note_simd_array_uses_struct
226 hash_table<simd_array_to_simduid> **htab;
227 unsigned int simduid;
230 /* Callback for note_simd_array_uses, called through walk_gimple_op. */
232 static tree
233 note_simd_array_uses_cb (tree *tp, int *walk_subtrees, void *data)
235 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
236 struct note_simd_array_uses_struct *ns
237 = (struct note_simd_array_uses_struct *) wi->info;
239 if (TYPE_P (*tp))
240 *walk_subtrees = 0;
241 else if (VAR_P (*tp)
242 && lookup_attribute ("omp simd array", DECL_ATTRIBUTES (*tp))
243 && DECL_CONTEXT (*tp) == current_function_decl)
245 simd_array_to_simduid data;
246 if (!*ns->htab)
247 *ns->htab = new hash_table<simd_array_to_simduid> (15);
248 data.decl = *tp;
249 data.simduid = ns->simduid;
250 simd_array_to_simduid **slot = (*ns->htab)->find_slot (&data, INSERT);
251 if (*slot == NULL)
253 simd_array_to_simduid *p = XNEW (simd_array_to_simduid);
254 *p = data;
255 *slot = p;
257 else if ((*slot)->simduid != ns->simduid)
258 (*slot)->simduid = -1U;
259 *walk_subtrees = 0;
261 return NULL_TREE;
264 /* Find "omp simd array" temporaries and map them to corresponding
265 simduid. */
267 static void
268 note_simd_array_uses (hash_table<simd_array_to_simduid> **htab)
270 basic_block bb;
271 gimple_stmt_iterator gsi;
272 struct walk_stmt_info wi;
273 struct note_simd_array_uses_struct ns;
275 memset (&wi, 0, sizeof (wi));
276 wi.info = &ns;
277 ns.htab = htab;
279 FOR_EACH_BB_FN (bb, cfun)
280 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
282 gimple stmt = gsi_stmt (gsi);
283 if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
284 continue;
285 switch (gimple_call_internal_fn (stmt))
287 case IFN_GOMP_SIMD_LANE:
288 case IFN_GOMP_SIMD_VF:
289 case IFN_GOMP_SIMD_LAST_LANE:
290 break;
291 default:
292 continue;
294 tree lhs = gimple_call_lhs (stmt);
295 if (lhs == NULL_TREE)
296 continue;
297 imm_use_iterator use_iter;
298 gimple use_stmt;
299 ns.simduid = DECL_UID (SSA_NAME_VAR (gimple_call_arg (stmt, 0)));
300 FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, lhs)
301 if (!is_gimple_debug (use_stmt))
302 walk_gimple_op (use_stmt, note_simd_array_uses_cb, &wi);
306 /* Shrink arrays with "omp simd array" attribute to the corresponding
307 vectorization factor. */
309 static void
310 shrink_simd_arrays
311 (hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab,
312 hash_table<simduid_to_vf> *simduid_to_vf_htab)
314 for (hash_table<simd_array_to_simduid>::iterator iter
315 = simd_array_to_simduid_htab->begin ();
316 iter != simd_array_to_simduid_htab->end (); ++iter)
317 if ((*iter)->simduid != -1U)
319 tree decl = (*iter)->decl;
320 int vf = 1;
321 if (simduid_to_vf_htab)
323 simduid_to_vf *p = NULL, data;
324 data.simduid = (*iter)->simduid;
325 p = simduid_to_vf_htab->find (&data);
326 if (p)
327 vf = p->vf;
329 tree atype
330 = build_array_type_nelts (TREE_TYPE (TREE_TYPE (decl)), vf);
331 TREE_TYPE (decl) = atype;
332 relayout_decl (decl);
335 delete simd_array_to_simduid_htab;
338 /* A helper function to free data refs. */
340 void
341 vect_destroy_datarefs (loop_vec_info loop_vinfo, bb_vec_info bb_vinfo)
343 vec<data_reference_p> datarefs;
344 struct data_reference *dr;
345 unsigned int i;
347 if (loop_vinfo)
348 datarefs = LOOP_VINFO_DATAREFS (loop_vinfo);
349 else
350 datarefs = BB_VINFO_DATAREFS (bb_vinfo);
352 FOR_EACH_VEC_ELT (datarefs, i, dr)
353 if (dr->aux)
355 free (dr->aux);
356 dr->aux = NULL;
359 free_data_refs (datarefs);
363 /* If LOOP has been versioned during ifcvt, return the internal call
364 guarding it. */
366 static gimple
367 vect_loop_vectorized_call (struct loop *loop)
369 basic_block bb = loop_preheader_edge (loop)->src;
370 gimple g;
373 g = last_stmt (bb);
374 if (g)
375 break;
376 if (!single_pred_p (bb))
377 break;
378 bb = single_pred (bb);
380 while (1);
381 if (g && gimple_code (g) == GIMPLE_COND)
383 gimple_stmt_iterator gsi = gsi_for_stmt (g);
384 gsi_prev (&gsi);
385 if (!gsi_end_p (gsi))
387 g = gsi_stmt (gsi);
388 if (is_gimple_call (g)
389 && gimple_call_internal_p (g)
390 && gimple_call_internal_fn (g) == IFN_LOOP_VECTORIZED
391 && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->num
392 || tree_to_shwi (gimple_call_arg (g, 1)) == loop->num))
393 return g;
396 return NULL;
399 /* Fold LOOP_VECTORIZED internal call G to VALUE and
400 update any immediate uses of it's LHS. */
402 static void
403 fold_loop_vectorized_call (gimple g, tree value)
405 tree lhs = gimple_call_lhs (g);
406 use_operand_p use_p;
407 imm_use_iterator iter;
408 gimple use_stmt;
409 gimple_stmt_iterator gsi = gsi_for_stmt (g);
411 update_call_from_tree (&gsi, value);
412 FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
414 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
415 SET_USE (use_p, value);
416 update_stmt (use_stmt);
419 /* Set the uids of all the statements in basic blocks inside loop
420 represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal
421 call guarding the loop which has been if converted. */
422 static void
423 set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple loop_vectorized_call)
425 tree arg = gimple_call_arg (loop_vectorized_call, 1);
426 basic_block *bbs;
427 unsigned int i;
428 struct loop *scalar_loop = get_loop (cfun, tree_to_shwi (arg));
430 LOOP_VINFO_SCALAR_LOOP (loop_vinfo) = scalar_loop;
431 gcc_checking_assert (vect_loop_vectorized_call
432 (LOOP_VINFO_SCALAR_LOOP (loop_vinfo))
433 == loop_vectorized_call);
434 bbs = get_loop_body (scalar_loop);
435 for (i = 0; i < scalar_loop->num_nodes; i++)
437 basic_block bb = bbs[i];
438 gimple_stmt_iterator gsi;
439 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
441 gimple phi = gsi_stmt (gsi);
442 gimple_set_uid (phi, 0);
444 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
446 gimple stmt = gsi_stmt (gsi);
447 gimple_set_uid (stmt, 0);
450 free (bbs);
453 /* Function vectorize_loops.
455 Entry point to loop vectorization phase. */
457 unsigned
458 vectorize_loops (void)
460 unsigned int i;
461 unsigned int num_vectorized_loops = 0;
462 unsigned int vect_loops_num;
463 struct loop *loop;
464 hash_table<simduid_to_vf> *simduid_to_vf_htab = NULL;
465 hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
466 bool any_ifcvt_loops = false;
467 unsigned ret = 0;
469 vect_loops_num = number_of_loops (cfun);
471 /* Bail out if there are no loops. */
472 if (vect_loops_num <= 1)
473 return 0;
475 if (cfun->has_simduid_loops)
476 note_simd_array_uses (&simd_array_to_simduid_htab);
478 init_stmt_vec_info_vec ();
480 /* ----------- Analyze loops. ----------- */
482 /* If some loop was duplicated, it gets bigger number
483 than all previously defined loops. This fact allows us to run
484 only over initial loops skipping newly generated ones. */
485 FOR_EACH_LOOP (loop, 0)
486 if (loop->dont_vectorize)
487 any_ifcvt_loops = true;
488 else if ((flag_tree_loop_vectorize
489 && optimize_loop_nest_for_speed_p (loop))
490 || loop->force_vectorize)
492 loop_vec_info loop_vinfo;
493 vect_location = find_loop_location (loop);
494 if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
495 && dump_enabled_p ())
496 dump_printf (MSG_NOTE, "\nAnalyzing loop at %s:%d\n",
497 LOCATION_FILE (vect_location),
498 LOCATION_LINE (vect_location));
500 loop_vinfo = vect_analyze_loop (loop);
501 loop->aux = loop_vinfo;
503 if (!loop_vinfo || !LOOP_VINFO_VECTORIZABLE_P (loop_vinfo))
504 continue;
506 if (!dbg_cnt (vect_loop))
507 break;
509 gimple loop_vectorized_call = vect_loop_vectorized_call (loop);
510 if (loop_vectorized_call)
511 set_uid_loop_bbs (loop_vinfo, loop_vectorized_call);
512 if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
513 && dump_enabled_p ())
514 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
515 "loop vectorized\n");
516 vect_transform_loop (loop_vinfo);
517 num_vectorized_loops++;
518 /* Now that the loop has been vectorized, allow it to be unrolled
519 etc. */
520 loop->force_vectorize = false;
522 if (loop->simduid)
524 simduid_to_vf *simduid_to_vf_data = XNEW (simduid_to_vf);
525 if (!simduid_to_vf_htab)
526 simduid_to_vf_htab = new hash_table<simduid_to_vf> (15);
527 simduid_to_vf_data->simduid = DECL_UID (loop->simduid);
528 simduid_to_vf_data->vf = loop_vinfo->vectorization_factor;
529 *simduid_to_vf_htab->find_slot (simduid_to_vf_data, INSERT)
530 = simduid_to_vf_data;
533 if (loop_vectorized_call)
535 fold_loop_vectorized_call (loop_vectorized_call, boolean_true_node);
536 ret |= TODO_cleanup_cfg;
540 vect_location = UNKNOWN_LOCATION;
542 statistics_counter_event (cfun, "Vectorized loops", num_vectorized_loops);
543 if (dump_enabled_p ()
544 || (num_vectorized_loops > 0 && dump_enabled_p ()))
545 dump_printf_loc (MSG_NOTE, vect_location,
546 "vectorized %u loops in function.\n",
547 num_vectorized_loops);
549 /* ----------- Finalize. ----------- */
551 if (any_ifcvt_loops)
552 for (i = 1; i < vect_loops_num; i++)
554 loop = get_loop (cfun, i);
555 if (loop && loop->dont_vectorize)
557 gimple g = vect_loop_vectorized_call (loop);
558 if (g)
560 fold_loop_vectorized_call (g, boolean_false_node);
561 ret |= TODO_cleanup_cfg;
566 for (i = 1; i < vect_loops_num; i++)
568 loop_vec_info loop_vinfo;
570 loop = get_loop (cfun, i);
571 if (!loop)
572 continue;
573 loop_vinfo = (loop_vec_info) loop->aux;
574 destroy_loop_vec_info (loop_vinfo, true);
575 loop->aux = NULL;
578 free_stmt_vec_info_vec ();
580 /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE} builtins. */
581 if (cfun->has_simduid_loops)
582 adjust_simduid_builtins (simduid_to_vf_htab);
584 /* Shrink any "omp array simd" temporary arrays to the
585 actual vectorization factors. */
586 if (simd_array_to_simduid_htab)
587 shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab);
588 delete simduid_to_vf_htab;
589 cfun->has_simduid_loops = false;
591 if (num_vectorized_loops > 0)
593 /* If we vectorized any loop only virtual SSA form needs to be updated.
594 ??? Also while we try hard to update loop-closed SSA form we fail
595 to properly do this in some corner-cases (see PR56286). */
596 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
597 return TODO_cleanup_cfg;
600 return ret;
604 /* Entry point to the simduid cleanup pass. */
606 namespace {
608 const pass_data pass_data_simduid_cleanup =
610 GIMPLE_PASS, /* type */
611 "simduid", /* name */
612 OPTGROUP_NONE, /* optinfo_flags */
613 TV_NONE, /* tv_id */
614 ( PROP_ssa | PROP_cfg ), /* properties_required */
615 0, /* properties_provided */
616 0, /* properties_destroyed */
617 0, /* todo_flags_start */
618 0, /* todo_flags_finish */
621 class pass_simduid_cleanup : public gimple_opt_pass
623 public:
624 pass_simduid_cleanup (gcc::context *ctxt)
625 : gimple_opt_pass (pass_data_simduid_cleanup, ctxt)
628 /* opt_pass methods: */
629 opt_pass * clone () { return new pass_simduid_cleanup (m_ctxt); }
630 virtual bool gate (function *fun) { return fun->has_simduid_loops; }
631 virtual unsigned int execute (function *);
633 }; // class pass_simduid_cleanup
635 unsigned int
636 pass_simduid_cleanup::execute (function *fun)
638 hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
640 note_simd_array_uses (&simd_array_to_simduid_htab);
642 /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE} builtins. */
643 adjust_simduid_builtins (NULL);
645 /* Shrink any "omp array simd" temporary arrays to the
646 actual vectorization factors. */
647 if (simd_array_to_simduid_htab)
648 shrink_simd_arrays (simd_array_to_simduid_htab, NULL);
649 fun->has_simduid_loops = false;
650 return 0;
653 } // anon namespace
655 gimple_opt_pass *
656 make_pass_simduid_cleanup (gcc::context *ctxt)
658 return new pass_simduid_cleanup (ctxt);
662 /* Entry point to basic block SLP phase. */
664 namespace {
666 const pass_data pass_data_slp_vectorize =
668 GIMPLE_PASS, /* type */
669 "slp", /* name */
670 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
671 TV_TREE_SLP_VECTORIZATION, /* tv_id */
672 ( PROP_ssa | PROP_cfg ), /* properties_required */
673 0, /* properties_provided */
674 0, /* properties_destroyed */
675 0, /* todo_flags_start */
676 TODO_update_ssa, /* todo_flags_finish */
679 class pass_slp_vectorize : public gimple_opt_pass
681 public:
682 pass_slp_vectorize (gcc::context *ctxt)
683 : gimple_opt_pass (pass_data_slp_vectorize, ctxt)
686 /* opt_pass methods: */
687 opt_pass * clone () { return new pass_slp_vectorize (m_ctxt); }
688 virtual bool gate (function *) { return flag_tree_slp_vectorize != 0; }
689 virtual unsigned int execute (function *);
691 }; // class pass_slp_vectorize
693 unsigned int
694 pass_slp_vectorize::execute (function *fun)
696 basic_block bb;
698 bool in_loop_pipeline = scev_initialized_p ();
699 if (!in_loop_pipeline)
701 loop_optimizer_init (LOOPS_NORMAL);
702 scev_initialize ();
705 init_stmt_vec_info_vec ();
707 FOR_EACH_BB_FN (bb, fun)
709 vect_location = find_bb_location (bb);
711 if (vect_slp_analyze_bb (bb))
713 if (!dbg_cnt (vect_slp))
714 break;
716 vect_slp_transform_bb (bb);
717 if (dump_enabled_p ())
718 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
719 "basic block vectorized\n");
723 free_stmt_vec_info_vec ();
725 if (!in_loop_pipeline)
727 scev_finalize ();
728 loop_optimizer_finalize ();
731 return 0;
734 } // anon namespace
736 gimple_opt_pass *
737 make_pass_slp_vectorize (gcc::context *ctxt)
739 return new pass_slp_vectorize (ctxt);
743 /* Increase alignment of global arrays to improve vectorization potential.
744 TODO:
745 - Consider also structs that have an array field.
746 - Use ipa analysis to prune arrays that can't be vectorized?
747 This should involve global alignment analysis and in the future also
748 array padding. */
750 static unsigned int
751 increase_alignment (void)
753 varpool_node *vnode;
755 vect_location = UNKNOWN_LOCATION;
757 /* Increase the alignment of all global arrays for vectorization. */
758 FOR_EACH_DEFINED_VARIABLE (vnode)
760 tree vectype, decl = vnode->decl;
761 tree t;
762 unsigned int alignment;
764 t = TREE_TYPE (decl);
765 if (TREE_CODE (t) != ARRAY_TYPE)
766 continue;
767 vectype = get_vectype_for_scalar_type (strip_array_types (t));
768 if (!vectype)
769 continue;
770 alignment = TYPE_ALIGN (vectype);
771 if (DECL_ALIGN (decl) >= alignment)
772 continue;
774 if (vect_can_force_dr_alignment_p (decl, alignment))
776 vnode->increase_alignment (TYPE_ALIGN (vectype));
777 dump_printf (MSG_NOTE, "Increasing alignment of decl: ");
778 dump_generic_expr (MSG_NOTE, TDF_SLIM, decl);
779 dump_printf (MSG_NOTE, "\n");
782 return 0;
786 namespace {
788 const pass_data pass_data_ipa_increase_alignment =
790 SIMPLE_IPA_PASS, /* type */
791 "increase_alignment", /* name */
792 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
793 TV_IPA_OPT, /* tv_id */
794 0, /* properties_required */
795 0, /* properties_provided */
796 0, /* properties_destroyed */
797 0, /* todo_flags_start */
798 0, /* todo_flags_finish */
801 class pass_ipa_increase_alignment : public simple_ipa_opt_pass
803 public:
804 pass_ipa_increase_alignment (gcc::context *ctxt)
805 : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt)
808 /* opt_pass methods: */
809 virtual bool gate (function *)
811 return flag_section_anchors && flag_tree_loop_vectorize;
814 virtual unsigned int execute (function *) { return increase_alignment (); }
816 }; // class pass_ipa_increase_alignment
818 } // anon namespace
820 simple_ipa_opt_pass *
821 make_pass_ipa_increase_alignment (gcc::context *ctxt)
823 return new pass_ipa_increase_alignment (ctxt);