annotate gcc/tree-ssa-loop-ivcanon.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents: 67
diff changeset
1 /* Induction variable canonicalization and loop peeling.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
3
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
5
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Free Software Foundation; either version 3, or (at your option) any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 later version.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 /* This pass detects the loops that iterate a constant number of times,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
21 adds a canonical induction variable (step -1, tested against 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 and replaces the exit test. This enables the less powerful rtl
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 level analysis to use this information.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 This might spoil the code in some cases (by increasing register pressure).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 Note that in the case the new variable is not needed, ivopts will get rid
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 of it, so it might only be a problem when there are no other linear induction
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 variables. In that case the created optimization possibilities are likely
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 to pay up.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
111
kono
parents: 67
diff changeset
31 We also perform
kono
parents: 67
diff changeset
32 - complete unrolling (or peeling) when the loops is rolling few enough
kono
parents: 67
diff changeset
33 times
kono
parents: 67
diff changeset
34 - simple peeling (i.e. copying few initial iterations prior the loop)
kono
parents: 67
diff changeset
35 when number of iteration estimate is known (typically by the profile
kono
parents: 67
diff changeset
36 info). */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 #include "coretypes.h"
111
kono
parents: 67
diff changeset
41 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #include "tree.h"
111
kono
parents: 67
diff changeset
43 #include "gimple.h"
kono
parents: 67
diff changeset
44 #include "cfghooks.h"
kono
parents: 67
diff changeset
45 #include "tree-pass.h"
kono
parents: 67
diff changeset
46 #include "ssa.h"
kono
parents: 67
diff changeset
47 #include "cgraph.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
48 #include "gimple-pretty-print.h"
111
kono
parents: 67
diff changeset
49 #include "fold-const.h"
kono
parents: 67
diff changeset
50 #include "profile.h"
kono
parents: 67
diff changeset
51 #include "gimple-fold.h"
kono
parents: 67
diff changeset
52 #include "tree-eh.h"
kono
parents: 67
diff changeset
53 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
54 #include "tree-cfg.h"
kono
parents: 67
diff changeset
55 #include "tree-ssa-loop-manip.h"
kono
parents: 67
diff changeset
56 #include "tree-ssa-loop-niter.h"
kono
parents: 67
diff changeset
57 #include "tree-ssa-loop.h"
kono
parents: 67
diff changeset
58 #include "tree-into-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 #include "cfgloop.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 #include "tree-chrec.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 #include "tree-scalar-evolution.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 #include "tree-inline.h"
111
kono
parents: 67
diff changeset
63 #include "tree-cfgcleanup.h"
kono
parents: 67
diff changeset
64 #include "builtins.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 #include "tree-ssa-sccvn.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
66 #include "dbgcnt.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 /* Specifies types of loops that may be unrolled. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 enum unroll_level
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 UL_SINGLE_ITER, /* Only loops that exit immediately in the first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 iteration. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 UL_NO_GROWTH, /* Only loops whose unrolling will not cause increase
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 of code size. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 UL_ALL /* All suitable loops. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 /* Adds a canonical induction variable to LOOP iterating NITER times. EXIT
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 is the exit edge whose condition is replaced. The ssa versions of the new
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
81 IV before and after increment will be stored in VAR_BEFORE and VAR_AFTER
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
82 if they are not NULL. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
85 create_canonical_iv (class loop *loop, edge exit, tree niter,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 tree *var_before = NULL, tree *var_after = NULL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 edge in;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 tree type, var;
111
kono
parents: 67
diff changeset
90 gcond *cond;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 gimple_stmt_iterator incr_at;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 enum tree_code cmp;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 fprintf (dump_file, "Added canonical iv to loop %d, ", loop->num);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 print_generic_expr (dump_file, niter, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 fprintf (dump_file, " iterations.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
111
kono
parents: 67
diff changeset
101 cond = as_a <gcond *> (last_stmt (exit->src));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 in = EDGE_SUCC (exit->src, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 if (in == exit)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 in = EDGE_SUCC (exit->src, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 /* Note that we do not need to worry about overflows, since
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 type of niter is always unsigned and all comparisons are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 just for equality/nonequality -- i.e. everything works
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 with a modulo arithmetics. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 type = TREE_TYPE (niter);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 niter = fold_build2 (PLUS_EXPR, type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 niter,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 build_int_cst (type, 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 incr_at = gsi_last_bb (in->src);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 create_iv (niter,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 build_int_cst (type, -1),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 NULL_TREE, loop,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
119 &incr_at, false, var_before, &var);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
120 if (var_after)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
121 *var_after = var;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 cmp = (exit->flags & EDGE_TRUE_VALUE) ? EQ_EXPR : NE_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 gimple_cond_set_code (cond, cmp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 gimple_cond_set_lhs (cond, var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 gimple_cond_set_rhs (cond, build_int_cst (type, 0));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 update_stmt (cond);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
130 /* Describe size of loop as detected by tree_estimate_loop_size. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
131 struct loop_size
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
132 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
133 /* Number of instructions in the loop. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
134 int overall;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
135
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
136 /* Number of instructions that will be likely optimized out in
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
137 peeled iterations of loop (i.e. computation based on induction
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
138 variable where induction variable starts at known constant.) */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
139 int eliminated_by_peeling;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
140
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
141 /* Same statistics for last iteration of loop: it is smaller because
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
142 instructions after exit are not executed. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
143 int last_iteration;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
144 int last_iteration_eliminated_by_peeling;
111
kono
parents: 67
diff changeset
145
kono
parents: 67
diff changeset
146 /* If some IV computation will become constant. */
kono
parents: 67
diff changeset
147 bool constant_iv;
kono
parents: 67
diff changeset
148
kono
parents: 67
diff changeset
149 /* Number of call stmts that are not a builtin and are pure or const
kono
parents: 67
diff changeset
150 present on the hot path. */
kono
parents: 67
diff changeset
151 int num_pure_calls_on_hot_path;
kono
parents: 67
diff changeset
152 /* Number of call stmts that are not a builtin and are not pure nor const
kono
parents: 67
diff changeset
153 present on the hot path. */
kono
parents: 67
diff changeset
154 int num_non_pure_calls_on_hot_path;
kono
parents: 67
diff changeset
155 /* Number of statements other than calls in the loop. */
kono
parents: 67
diff changeset
156 int non_call_stmts_on_hot_path;
kono
parents: 67
diff changeset
157 /* Number of branches seen on the hot path. */
kono
parents: 67
diff changeset
158 int num_branches_on_hot_path;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
159 };
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
160
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
161 /* Return true if OP in STMT will be constant after peeling LOOP. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
162
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
163 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
164 constant_after_peeling (tree op, gimple *stmt, class loop *loop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
165 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
166 if (CONSTANT_CLASS_P (op))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
167 return true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
168
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
169 /* We can still fold accesses to constant arrays when index is known. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
170 if (TREE_CODE (op) != SSA_NAME)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
171 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
172 tree base = op;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
173
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
174 /* First make fast look if we see constant array inside. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
175 while (handled_component_p (base))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
176 base = TREE_OPERAND (base, 0);
111
kono
parents: 67
diff changeset
177 if ((DECL_P (base)
kono
parents: 67
diff changeset
178 && ctor_for_folding (base) != error_mark_node)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
179 || CONSTANT_CLASS_P (base))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
180 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
181 /* If so, see if we understand all the indices. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
182 base = op;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
183 while (handled_component_p (base))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
184 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
185 if (TREE_CODE (base) == ARRAY_REF
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
186 && !constant_after_peeling (TREE_OPERAND (base, 1), stmt, loop))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
187 return false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
188 base = TREE_OPERAND (base, 0);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
189 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
190 return true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
191 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
192 return false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
193 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
194
111
kono
parents: 67
diff changeset
195 /* Induction variables are constants when defined in loop. */
kono
parents: 67
diff changeset
196 if (loop_containing_stmt (stmt) != loop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
197 return false;
111
kono
parents: 67
diff changeset
198 tree ev = analyze_scalar_evolution (loop, op);
kono
parents: 67
diff changeset
199 if (chrec_contains_undetermined (ev)
kono
parents: 67
diff changeset
200 || chrec_contains_symbols (ev))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
201 return false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
202 return true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
203 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
204
111
kono
parents: 67
diff changeset
205 /* Computes an estimated number of insns in LOOP.
kono
parents: 67
diff changeset
206 EXIT (if non-NULL) is an exite edge that will be eliminated in all but last
kono
parents: 67
diff changeset
207 iteration of the loop.
kono
parents: 67
diff changeset
208 EDGE_TO_CANCEL (if non-NULL) is an non-exit edge eliminated in the last iteration
kono
parents: 67
diff changeset
209 of loop.
kono
parents: 67
diff changeset
210 Return results in SIZE, estimate benefits for complete unrolling exiting by EXIT.
kono
parents: 67
diff changeset
211 Stop estimating after UPPER_BOUND is met. Return true in this case. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
212
111
kono
parents: 67
diff changeset
213 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
214 tree_estimate_loop_size (class loop *loop, edge exit, edge edge_to_cancel,
111
kono
parents: 67
diff changeset
215 struct loop_size *size, int upper_bound)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
216 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
217 basic_block *body = get_loop_body (loop);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
218 gimple_stmt_iterator gsi;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
219 unsigned int i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
220 bool after_exit;
111
kono
parents: 67
diff changeset
221 vec<basic_block> path = get_loop_hot_path (loop);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
222
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
223 size->overall = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
224 size->eliminated_by_peeling = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
225 size->last_iteration = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
226 size->last_iteration_eliminated_by_peeling = 0;
111
kono
parents: 67
diff changeset
227 size->num_pure_calls_on_hot_path = 0;
kono
parents: 67
diff changeset
228 size->num_non_pure_calls_on_hot_path = 0;
kono
parents: 67
diff changeset
229 size->non_call_stmts_on_hot_path = 0;
kono
parents: 67
diff changeset
230 size->num_branches_on_hot_path = 0;
kono
parents: 67
diff changeset
231 size->constant_iv = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
233 if (dump_file && (dump_flags & TDF_DETAILS))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
234 fprintf (dump_file, "Estimating sizes for loop %i\n", loop->num);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
235 for (i = 0; i < loop->num_nodes; i++)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
236 {
111
kono
parents: 67
diff changeset
237 if (edge_to_cancel && body[i] != edge_to_cancel->src
kono
parents: 67
diff changeset
238 && dominated_by_p (CDI_DOMINATORS, body[i], edge_to_cancel->src))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
239 after_exit = true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
240 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
241 after_exit = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
242 if (dump_file && (dump_flags & TDF_DETAILS))
111
kono
parents: 67
diff changeset
243 fprintf (dump_file, " BB: %i, after_exit: %i\n", body[i]->index,
kono
parents: 67
diff changeset
244 after_exit);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
245
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
246 for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi); gsi_next (&gsi))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
247 {
111
kono
parents: 67
diff changeset
248 gimple *stmt = gsi_stmt (gsi);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
249 int num = estimate_num_insns (stmt, &eni_size_weights);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
250 bool likely_eliminated = false;
111
kono
parents: 67
diff changeset
251 bool likely_eliminated_last = false;
kono
parents: 67
diff changeset
252 bool likely_eliminated_peeled = false;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
253
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
254 if (dump_file && (dump_flags & TDF_DETAILS))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
255 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
256 fprintf (dump_file, " size: %3i ", num);
111
kono
parents: 67
diff changeset
257 print_gimple_stmt (dump_file, gsi_stmt (gsi), 0);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
258 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
259
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
260 /* Look for reasons why we might optimize this stmt away. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
111
kono
parents: 67
diff changeset
262 if (!gimple_has_side_effects (stmt))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
263 {
111
kono
parents: 67
diff changeset
264 /* Exit conditional. */
kono
parents: 67
diff changeset
265 if (exit && body[i] == exit->src
kono
parents: 67
diff changeset
266 && stmt == last_stmt (exit->src))
kono
parents: 67
diff changeset
267 {
kono
parents: 67
diff changeset
268 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
269 fprintf (dump_file, " Exit condition will be eliminated "
kono
parents: 67
diff changeset
270 "in peeled copies.\n");
kono
parents: 67
diff changeset
271 likely_eliminated_peeled = true;
kono
parents: 67
diff changeset
272 }
kono
parents: 67
diff changeset
273 if (edge_to_cancel && body[i] == edge_to_cancel->src
kono
parents: 67
diff changeset
274 && stmt == last_stmt (edge_to_cancel->src))
kono
parents: 67
diff changeset
275 {
kono
parents: 67
diff changeset
276 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
277 fprintf (dump_file, " Exit condition will be eliminated "
kono
parents: 67
diff changeset
278 "in last copy.\n");
kono
parents: 67
diff changeset
279 likely_eliminated_last = true;
kono
parents: 67
diff changeset
280 }
kono
parents: 67
diff changeset
281 /* Sets of IV variables */
kono
parents: 67
diff changeset
282 if (gimple_code (stmt) == GIMPLE_ASSIGN
kono
parents: 67
diff changeset
283 && constant_after_peeling (gimple_assign_lhs (stmt), stmt, loop))
kono
parents: 67
diff changeset
284 {
kono
parents: 67
diff changeset
285 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
286 fprintf (dump_file, " Induction variable computation will"
kono
parents: 67
diff changeset
287 " be folded away.\n");
kono
parents: 67
diff changeset
288 likely_eliminated = true;
kono
parents: 67
diff changeset
289 }
kono
parents: 67
diff changeset
290 /* Assignments of IV variables. */
kono
parents: 67
diff changeset
291 else if (gimple_code (stmt) == GIMPLE_ASSIGN
kono
parents: 67
diff changeset
292 && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME
kono
parents: 67
diff changeset
293 && constant_after_peeling (gimple_assign_rhs1 (stmt),
kono
parents: 67
diff changeset
294 stmt, loop)
kono
parents: 67
diff changeset
295 && (gimple_assign_rhs_class (stmt) != GIMPLE_BINARY_RHS
kono
parents: 67
diff changeset
296 || constant_after_peeling (gimple_assign_rhs2 (stmt),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
297 stmt, loop))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
298 && gimple_assign_rhs_class (stmt) != GIMPLE_TERNARY_RHS)
111
kono
parents: 67
diff changeset
299 {
kono
parents: 67
diff changeset
300 size->constant_iv = true;
kono
parents: 67
diff changeset
301 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
302 fprintf (dump_file,
kono
parents: 67
diff changeset
303 " Constant expression will be folded away.\n");
kono
parents: 67
diff changeset
304 likely_eliminated = true;
kono
parents: 67
diff changeset
305 }
kono
parents: 67
diff changeset
306 /* Conditionals. */
kono
parents: 67
diff changeset
307 else if ((gimple_code (stmt) == GIMPLE_COND
kono
parents: 67
diff changeset
308 && constant_after_peeling (gimple_cond_lhs (stmt), stmt,
kono
parents: 67
diff changeset
309 loop)
kono
parents: 67
diff changeset
310 && constant_after_peeling (gimple_cond_rhs (stmt), stmt,
kono
parents: 67
diff changeset
311 loop)
kono
parents: 67
diff changeset
312 /* We don't simplify all constant compares so make sure
kono
parents: 67
diff changeset
313 they are not both constant already. See PR70288. */
kono
parents: 67
diff changeset
314 && (! is_gimple_min_invariant (gimple_cond_lhs (stmt))
kono
parents: 67
diff changeset
315 || ! is_gimple_min_invariant
kono
parents: 67
diff changeset
316 (gimple_cond_rhs (stmt))))
kono
parents: 67
diff changeset
317 || (gimple_code (stmt) == GIMPLE_SWITCH
kono
parents: 67
diff changeset
318 && constant_after_peeling (gimple_switch_index (
kono
parents: 67
diff changeset
319 as_a <gswitch *>
kono
parents: 67
diff changeset
320 (stmt)),
kono
parents: 67
diff changeset
321 stmt, loop)
kono
parents: 67
diff changeset
322 && ! is_gimple_min_invariant
kono
parents: 67
diff changeset
323 (gimple_switch_index
kono
parents: 67
diff changeset
324 (as_a <gswitch *> (stmt)))))
kono
parents: 67
diff changeset
325 {
kono
parents: 67
diff changeset
326 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
327 fprintf (dump_file, " Constant conditional.\n");
kono
parents: 67
diff changeset
328 likely_eliminated = true;
kono
parents: 67
diff changeset
329 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
330 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
331
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
332 size->overall += num;
111
kono
parents: 67
diff changeset
333 if (likely_eliminated || likely_eliminated_peeled)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
334 size->eliminated_by_peeling += num;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
335 if (!after_exit)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
336 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
337 size->last_iteration += num;
111
kono
parents: 67
diff changeset
338 if (likely_eliminated || likely_eliminated_last)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
339 size->last_iteration_eliminated_by_peeling += num;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
340 }
111
kono
parents: 67
diff changeset
341 if ((size->overall * 3 / 2 - size->eliminated_by_peeling
kono
parents: 67
diff changeset
342 - size->last_iteration_eliminated_by_peeling) > upper_bound)
kono
parents: 67
diff changeset
343 {
kono
parents: 67
diff changeset
344 free (body);
kono
parents: 67
diff changeset
345 path.release ();
kono
parents: 67
diff changeset
346 return true;
kono
parents: 67
diff changeset
347 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
348 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
349 }
111
kono
parents: 67
diff changeset
350 while (path.length ())
kono
parents: 67
diff changeset
351 {
kono
parents: 67
diff changeset
352 basic_block bb = path.pop ();
kono
parents: 67
diff changeset
353 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
354 {
kono
parents: 67
diff changeset
355 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
356 if (gimple_code (stmt) == GIMPLE_CALL
kono
parents: 67
diff changeset
357 && !gimple_inexpensive_call_p (as_a <gcall *> (stmt)))
kono
parents: 67
diff changeset
358 {
kono
parents: 67
diff changeset
359 int flags = gimple_call_flags (stmt);
kono
parents: 67
diff changeset
360 if (flags & (ECF_PURE | ECF_CONST))
kono
parents: 67
diff changeset
361 size->num_pure_calls_on_hot_path++;
kono
parents: 67
diff changeset
362 else
kono
parents: 67
diff changeset
363 size->num_non_pure_calls_on_hot_path++;
kono
parents: 67
diff changeset
364 size->num_branches_on_hot_path ++;
kono
parents: 67
diff changeset
365 }
kono
parents: 67
diff changeset
366 /* Count inexpensive calls as non-calls, because they will likely
kono
parents: 67
diff changeset
367 expand inline. */
kono
parents: 67
diff changeset
368 else if (gimple_code (stmt) != GIMPLE_DEBUG)
kono
parents: 67
diff changeset
369 size->non_call_stmts_on_hot_path++;
kono
parents: 67
diff changeset
370 if (((gimple_code (stmt) == GIMPLE_COND
kono
parents: 67
diff changeset
371 && (!constant_after_peeling (gimple_cond_lhs (stmt), stmt, loop)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
372 || !constant_after_peeling (gimple_cond_rhs (stmt), stmt,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
373 loop)))
111
kono
parents: 67
diff changeset
374 || (gimple_code (stmt) == GIMPLE_SWITCH
kono
parents: 67
diff changeset
375 && !constant_after_peeling (gimple_switch_index (
kono
parents: 67
diff changeset
376 as_a <gswitch *> (stmt)),
kono
parents: 67
diff changeset
377 stmt, loop)))
kono
parents: 67
diff changeset
378 && (!exit || bb != exit->src))
kono
parents: 67
diff changeset
379 size->num_branches_on_hot_path++;
kono
parents: 67
diff changeset
380 }
kono
parents: 67
diff changeset
381 }
kono
parents: 67
diff changeset
382 path.release ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
383 if (dump_file && (dump_flags & TDF_DETAILS))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
384 fprintf (dump_file, "size: %i-%i, last_iteration: %i-%i\n", size->overall,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
385 size->eliminated_by_peeling, size->last_iteration,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
386 size->last_iteration_eliminated_by_peeling);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
387
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
388 free (body);
111
kono
parents: 67
diff changeset
389 return false;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
390 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
391
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
392 /* Estimate number of insns of completely unrolled loop.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
393 It is (NUNROLL + 1) * size of loop body with taking into account
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
394 the fact that in last copy everything after exit conditional
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
395 is dead and that some instructions will be eliminated after
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
396 peeling.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
397
111
kono
parents: 67
diff changeset
398 Loop body is likely going to simplify further, this is difficult
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
399 to guess, we just decrease the result by 1/3. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 static unsigned HOST_WIDE_INT
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
402 estimated_unrolled_size (struct loop_size *size,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 unsigned HOST_WIDE_INT nunroll)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
405 HOST_WIDE_INT unr_insns = ((nunroll)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
406 * (HOST_WIDE_INT) (size->overall
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
407 - size->eliminated_by_peeling));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
408 if (!nunroll)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
409 unr_insns = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
410 unr_insns += size->last_iteration - size->last_iteration_eliminated_by_peeling;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
411
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
412 unr_insns = unr_insns * 2 / 3;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 if (unr_insns <= 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 unr_insns = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 return unr_insns;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418
111
kono
parents: 67
diff changeset
419 /* Loop LOOP is known to not loop. See if there is an edge in the loop
kono
parents: 67
diff changeset
420 body that can be remove to make the loop to always exit and at
kono
parents: 67
diff changeset
421 the same time it does not make any code potentially executed
kono
parents: 67
diff changeset
422 during the last iteration dead.
kono
parents: 67
diff changeset
423
kono
parents: 67
diff changeset
424 After complete unrolling we still may get rid of the conditional
kono
parents: 67
diff changeset
425 on the exit in the last copy even if we have no idea what it does.
kono
parents: 67
diff changeset
426 This is quite common case for loops of form
kono
parents: 67
diff changeset
427
kono
parents: 67
diff changeset
428 int a[5];
kono
parents: 67
diff changeset
429 for (i=0;i<b;i++)
kono
parents: 67
diff changeset
430 a[i]=0;
kono
parents: 67
diff changeset
431
kono
parents: 67
diff changeset
432 Here we prove the loop to iterate 5 times but we do not know
kono
parents: 67
diff changeset
433 it from induction variable.
kono
parents: 67
diff changeset
434
kono
parents: 67
diff changeset
435 For now we handle only simple case where there is exit condition
kono
parents: 67
diff changeset
436 just before the latch block and the latch block contains no statements
kono
parents: 67
diff changeset
437 with side effect that may otherwise terminate the execution of loop
kono
parents: 67
diff changeset
438 (such as by EH or by terminating the program or longjmp).
kono
parents: 67
diff changeset
439
kono
parents: 67
diff changeset
440 In the general case we may want to cancel the paths leading to statements
kono
parents: 67
diff changeset
441 loop-niter identified as having undefined effect in the last iteration.
kono
parents: 67
diff changeset
442 The other cases are hopefully rare and will be cleaned up later. */
kono
parents: 67
diff changeset
443
kono
parents: 67
diff changeset
444 static edge
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
445 loop_edge_to_cancel (class loop *loop)
111
kono
parents: 67
diff changeset
446 {
kono
parents: 67
diff changeset
447 vec<edge> exits;
kono
parents: 67
diff changeset
448 unsigned i;
kono
parents: 67
diff changeset
449 edge edge_to_cancel;
kono
parents: 67
diff changeset
450 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
451
kono
parents: 67
diff changeset
452 /* We want only one predecestor of the loop. */
kono
parents: 67
diff changeset
453 if (EDGE_COUNT (loop->latch->preds) > 1)
kono
parents: 67
diff changeset
454 return NULL;
kono
parents: 67
diff changeset
455
kono
parents: 67
diff changeset
456 exits = get_loop_exit_edges (loop);
kono
parents: 67
diff changeset
457
kono
parents: 67
diff changeset
458 FOR_EACH_VEC_ELT (exits, i, edge_to_cancel)
kono
parents: 67
diff changeset
459 {
kono
parents: 67
diff changeset
460 /* Find the other edge than the loop exit
kono
parents: 67
diff changeset
461 leaving the conditoinal. */
kono
parents: 67
diff changeset
462 if (EDGE_COUNT (edge_to_cancel->src->succs) != 2)
kono
parents: 67
diff changeset
463 continue;
kono
parents: 67
diff changeset
464 if (EDGE_SUCC (edge_to_cancel->src, 0) == edge_to_cancel)
kono
parents: 67
diff changeset
465 edge_to_cancel = EDGE_SUCC (edge_to_cancel->src, 1);
kono
parents: 67
diff changeset
466 else
kono
parents: 67
diff changeset
467 edge_to_cancel = EDGE_SUCC (edge_to_cancel->src, 0);
kono
parents: 67
diff changeset
468
kono
parents: 67
diff changeset
469 /* We only can handle conditionals. */
kono
parents: 67
diff changeset
470 if (!(edge_to_cancel->flags & (EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
kono
parents: 67
diff changeset
471 continue;
kono
parents: 67
diff changeset
472
kono
parents: 67
diff changeset
473 /* We should never have conditionals in the loop latch. */
kono
parents: 67
diff changeset
474 gcc_assert (edge_to_cancel->dest != loop->header);
kono
parents: 67
diff changeset
475
kono
parents: 67
diff changeset
476 /* Check that it leads to loop latch. */
kono
parents: 67
diff changeset
477 if (edge_to_cancel->dest != loop->latch)
kono
parents: 67
diff changeset
478 continue;
kono
parents: 67
diff changeset
479
kono
parents: 67
diff changeset
480 exits.release ();
kono
parents: 67
diff changeset
481
kono
parents: 67
diff changeset
482 /* Verify that the code in loop latch does nothing that may end program
kono
parents: 67
diff changeset
483 execution without really reaching the exit. This may include
kono
parents: 67
diff changeset
484 non-pure/const function calls, EH statements, volatile ASMs etc. */
kono
parents: 67
diff changeset
485 for (gsi = gsi_start_bb (loop->latch); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
486 if (gimple_has_side_effects (gsi_stmt (gsi)))
kono
parents: 67
diff changeset
487 return NULL;
kono
parents: 67
diff changeset
488 return edge_to_cancel;
kono
parents: 67
diff changeset
489 }
kono
parents: 67
diff changeset
490 exits.release ();
kono
parents: 67
diff changeset
491 return NULL;
kono
parents: 67
diff changeset
492 }
kono
parents: 67
diff changeset
493
kono
parents: 67
diff changeset
494 /* Remove all tests for exits that are known to be taken after LOOP was
kono
parents: 67
diff changeset
495 peeled NPEELED times. Put gcc_unreachable before every statement
kono
parents: 67
diff changeset
496 known to not be executed. */
kono
parents: 67
diff changeset
497
kono
parents: 67
diff changeset
498 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
499 remove_exits_and_undefined_stmts (class loop *loop, unsigned int npeeled)
111
kono
parents: 67
diff changeset
500 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
501 class nb_iter_bound *elt;
111
kono
parents: 67
diff changeset
502 bool changed = false;
kono
parents: 67
diff changeset
503
kono
parents: 67
diff changeset
504 for (elt = loop->bounds; elt; elt = elt->next)
kono
parents: 67
diff changeset
505 {
kono
parents: 67
diff changeset
506 /* If statement is known to be undefined after peeling, turn it
kono
parents: 67
diff changeset
507 into unreachable (or trap when debugging experience is supposed
kono
parents: 67
diff changeset
508 to be good). */
kono
parents: 67
diff changeset
509 if (!elt->is_exit
kono
parents: 67
diff changeset
510 && wi::ltu_p (elt->bound, npeeled))
kono
parents: 67
diff changeset
511 {
kono
parents: 67
diff changeset
512 gimple_stmt_iterator gsi = gsi_for_stmt (elt->stmt);
kono
parents: 67
diff changeset
513 gcall *stmt = gimple_build_call
kono
parents: 67
diff changeset
514 (builtin_decl_implicit (BUILT_IN_UNREACHABLE), 0);
kono
parents: 67
diff changeset
515 gimple_set_location (stmt, gimple_location (elt->stmt));
kono
parents: 67
diff changeset
516 gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
kono
parents: 67
diff changeset
517 split_block (gimple_bb (stmt), stmt);
kono
parents: 67
diff changeset
518 changed = true;
kono
parents: 67
diff changeset
519 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
520 {
kono
parents: 67
diff changeset
521 fprintf (dump_file, "Forced statement unreachable: ");
kono
parents: 67
diff changeset
522 print_gimple_stmt (dump_file, elt->stmt, 0);
kono
parents: 67
diff changeset
523 }
kono
parents: 67
diff changeset
524 }
kono
parents: 67
diff changeset
525 /* If we know the exit will be taken after peeling, update. */
kono
parents: 67
diff changeset
526 else if (elt->is_exit
kono
parents: 67
diff changeset
527 && wi::leu_p (elt->bound, npeeled))
kono
parents: 67
diff changeset
528 {
kono
parents: 67
diff changeset
529 basic_block bb = gimple_bb (elt->stmt);
kono
parents: 67
diff changeset
530 edge exit_edge = EDGE_SUCC (bb, 0);
kono
parents: 67
diff changeset
531
kono
parents: 67
diff changeset
532 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
533 {
kono
parents: 67
diff changeset
534 fprintf (dump_file, "Forced exit to be taken: ");
kono
parents: 67
diff changeset
535 print_gimple_stmt (dump_file, elt->stmt, 0);
kono
parents: 67
diff changeset
536 }
kono
parents: 67
diff changeset
537 if (!loop_exit_edge_p (loop, exit_edge))
kono
parents: 67
diff changeset
538 exit_edge = EDGE_SUCC (bb, 1);
kono
parents: 67
diff changeset
539 exit_edge->probability = profile_probability::always ();
kono
parents: 67
diff changeset
540 gcc_checking_assert (loop_exit_edge_p (loop, exit_edge));
kono
parents: 67
diff changeset
541 gcond *cond_stmt = as_a <gcond *> (elt->stmt);
kono
parents: 67
diff changeset
542 if (exit_edge->flags & EDGE_TRUE_VALUE)
kono
parents: 67
diff changeset
543 gimple_cond_make_true (cond_stmt);
kono
parents: 67
diff changeset
544 else
kono
parents: 67
diff changeset
545 gimple_cond_make_false (cond_stmt);
kono
parents: 67
diff changeset
546 update_stmt (cond_stmt);
kono
parents: 67
diff changeset
547 changed = true;
kono
parents: 67
diff changeset
548 }
kono
parents: 67
diff changeset
549 }
kono
parents: 67
diff changeset
550 return changed;
kono
parents: 67
diff changeset
551 }
kono
parents: 67
diff changeset
552
kono
parents: 67
diff changeset
553 /* Remove all exits that are known to be never taken because of the loop bound
kono
parents: 67
diff changeset
554 discovered. */
kono
parents: 67
diff changeset
555
kono
parents: 67
diff changeset
556 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
557 remove_redundant_iv_tests (class loop *loop)
111
kono
parents: 67
diff changeset
558 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
559 class nb_iter_bound *elt;
111
kono
parents: 67
diff changeset
560 bool changed = false;
kono
parents: 67
diff changeset
561
kono
parents: 67
diff changeset
562 if (!loop->any_upper_bound)
kono
parents: 67
diff changeset
563 return false;
kono
parents: 67
diff changeset
564 for (elt = loop->bounds; elt; elt = elt->next)
kono
parents: 67
diff changeset
565 {
kono
parents: 67
diff changeset
566 /* Exit is pointless if it won't be taken before loop reaches
kono
parents: 67
diff changeset
567 upper bound. */
kono
parents: 67
diff changeset
568 if (elt->is_exit && loop->any_upper_bound
kono
parents: 67
diff changeset
569 && wi::ltu_p (loop->nb_iterations_upper_bound, elt->bound))
kono
parents: 67
diff changeset
570 {
kono
parents: 67
diff changeset
571 basic_block bb = gimple_bb (elt->stmt);
kono
parents: 67
diff changeset
572 edge exit_edge = EDGE_SUCC (bb, 0);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
573 class tree_niter_desc niter;
111
kono
parents: 67
diff changeset
574
kono
parents: 67
diff changeset
575 if (!loop_exit_edge_p (loop, exit_edge))
kono
parents: 67
diff changeset
576 exit_edge = EDGE_SUCC (bb, 1);
kono
parents: 67
diff changeset
577
kono
parents: 67
diff changeset
578 /* Only when we know the actual number of iterations, not
kono
parents: 67
diff changeset
579 just a bound, we can remove the exit. */
kono
parents: 67
diff changeset
580 if (!number_of_iterations_exit (loop, exit_edge,
kono
parents: 67
diff changeset
581 &niter, false, false)
kono
parents: 67
diff changeset
582 || !integer_onep (niter.assumptions)
kono
parents: 67
diff changeset
583 || !integer_zerop (niter.may_be_zero)
kono
parents: 67
diff changeset
584 || !niter.niter
kono
parents: 67
diff changeset
585 || TREE_CODE (niter.niter) != INTEGER_CST
kono
parents: 67
diff changeset
586 || !wi::ltu_p (loop->nb_iterations_upper_bound,
kono
parents: 67
diff changeset
587 wi::to_widest (niter.niter)))
kono
parents: 67
diff changeset
588 continue;
kono
parents: 67
diff changeset
589
kono
parents: 67
diff changeset
590 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
591 {
kono
parents: 67
diff changeset
592 fprintf (dump_file, "Removed pointless exit: ");
kono
parents: 67
diff changeset
593 print_gimple_stmt (dump_file, elt->stmt, 0);
kono
parents: 67
diff changeset
594 }
kono
parents: 67
diff changeset
595 gcond *cond_stmt = as_a <gcond *> (elt->stmt);
kono
parents: 67
diff changeset
596 if (exit_edge->flags & EDGE_TRUE_VALUE)
kono
parents: 67
diff changeset
597 gimple_cond_make_false (cond_stmt);
kono
parents: 67
diff changeset
598 else
kono
parents: 67
diff changeset
599 gimple_cond_make_true (cond_stmt);
kono
parents: 67
diff changeset
600 update_stmt (cond_stmt);
kono
parents: 67
diff changeset
601 changed = true;
kono
parents: 67
diff changeset
602 }
kono
parents: 67
diff changeset
603 }
kono
parents: 67
diff changeset
604 return changed;
kono
parents: 67
diff changeset
605 }
kono
parents: 67
diff changeset
606
kono
parents: 67
diff changeset
607 /* Stores loops that will be unlooped and edges that will be removed
kono
parents: 67
diff changeset
608 after we process whole loop tree. */
kono
parents: 67
diff changeset
609 static vec<loop_p> loops_to_unloop;
kono
parents: 67
diff changeset
610 static vec<int> loops_to_unloop_nunroll;
kono
parents: 67
diff changeset
611 static vec<edge> edges_to_remove;
kono
parents: 67
diff changeset
612 /* Stores loops that has been peeled. */
kono
parents: 67
diff changeset
613 static bitmap peeled_loops;
kono
parents: 67
diff changeset
614
kono
parents: 67
diff changeset
615 /* Cancel all fully unrolled loops by putting __builtin_unreachable
kono
parents: 67
diff changeset
616 on the latch edge.
kono
parents: 67
diff changeset
617 We do it after all unrolling since unlooping moves basic blocks
kono
parents: 67
diff changeset
618 across loop boundaries trashing loop closed SSA form as well
kono
parents: 67
diff changeset
619 as SCEV info needed to be intact during unrolling.
kono
parents: 67
diff changeset
620
kono
parents: 67
diff changeset
621 IRRED_INVALIDATED is used to bookkeep if information about
kono
parents: 67
diff changeset
622 irreducible regions may become invalid as a result
kono
parents: 67
diff changeset
623 of the transformation.
kono
parents: 67
diff changeset
624 LOOP_CLOSED_SSA_INVALIDATED is used to bookkepp the case
kono
parents: 67
diff changeset
625 when we need to go into loop closed SSA form. */
kono
parents: 67
diff changeset
626
kono
parents: 67
diff changeset
627 static void
kono
parents: 67
diff changeset
628 unloop_loops (bitmap loop_closed_ssa_invalidated,
kono
parents: 67
diff changeset
629 bool *irred_invalidated)
kono
parents: 67
diff changeset
630 {
kono
parents: 67
diff changeset
631 while (loops_to_unloop.length ())
kono
parents: 67
diff changeset
632 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
633 class loop *loop = loops_to_unloop.pop ();
111
kono
parents: 67
diff changeset
634 int n_unroll = loops_to_unloop_nunroll.pop ();
kono
parents: 67
diff changeset
635 basic_block latch = loop->latch;
kono
parents: 67
diff changeset
636 edge latch_edge = loop_latch_edge (loop);
kono
parents: 67
diff changeset
637 int flags = latch_edge->flags;
kono
parents: 67
diff changeset
638 location_t locus = latch_edge->goto_locus;
kono
parents: 67
diff changeset
639 gcall *stmt;
kono
parents: 67
diff changeset
640 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
641
kono
parents: 67
diff changeset
642 remove_exits_and_undefined_stmts (loop, n_unroll);
kono
parents: 67
diff changeset
643
kono
parents: 67
diff changeset
644 /* Unloop destroys the latch edge. */
kono
parents: 67
diff changeset
645 unloop (loop, irred_invalidated, loop_closed_ssa_invalidated);
kono
parents: 67
diff changeset
646
kono
parents: 67
diff changeset
647 /* Create new basic block for the latch edge destination and wire
kono
parents: 67
diff changeset
648 it in. */
kono
parents: 67
diff changeset
649 stmt = gimple_build_call (builtin_decl_implicit (BUILT_IN_UNREACHABLE), 0);
kono
parents: 67
diff changeset
650 latch_edge = make_edge (latch, create_basic_block (NULL, NULL, latch), flags);
kono
parents: 67
diff changeset
651 latch_edge->probability = profile_probability::never ();
kono
parents: 67
diff changeset
652 latch_edge->flags |= flags;
kono
parents: 67
diff changeset
653 latch_edge->goto_locus = locus;
kono
parents: 67
diff changeset
654
kono
parents: 67
diff changeset
655 add_bb_to_loop (latch_edge->dest, current_loops->tree_root);
kono
parents: 67
diff changeset
656 latch_edge->dest->count = profile_count::zero ();
kono
parents: 67
diff changeset
657 set_immediate_dominator (CDI_DOMINATORS, latch_edge->dest, latch_edge->src);
kono
parents: 67
diff changeset
658
kono
parents: 67
diff changeset
659 gsi = gsi_start_bb (latch_edge->dest);
kono
parents: 67
diff changeset
660 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
kono
parents: 67
diff changeset
661 }
kono
parents: 67
diff changeset
662 loops_to_unloop.release ();
kono
parents: 67
diff changeset
663 loops_to_unloop_nunroll.release ();
kono
parents: 67
diff changeset
664
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
665 /* Remove edges in peeled copies. Given remove_path removes dominated
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
666 regions we need to cope with removal of already removed paths. */
111
kono
parents: 67
diff changeset
667 unsigned i;
kono
parents: 67
diff changeset
668 edge e;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
669 auto_vec<int, 20> src_bbs;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
670 src_bbs.reserve_exact (edges_to_remove.length ());
111
kono
parents: 67
diff changeset
671 FOR_EACH_VEC_ELT (edges_to_remove, i, e)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
672 src_bbs.quick_push (e->src->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
673 FOR_EACH_VEC_ELT (edges_to_remove, i, e)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
674 if (BASIC_BLOCK_FOR_FN (cfun, src_bbs[i]))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
675 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
676 bool ok = remove_path (e, irred_invalidated,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
677 loop_closed_ssa_invalidated);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
678 gcc_assert (ok);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
679 }
111
kono
parents: 67
diff changeset
680 edges_to_remove.release ();
kono
parents: 67
diff changeset
681 }
kono
parents: 67
diff changeset
682
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 /* Tries to unroll LOOP completely, i.e. NITER times.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
684 UL determines which loops we are allowed to unroll.
111
kono
parents: 67
diff changeset
685 EXIT is the exit of the loop that should be eliminated.
kono
parents: 67
diff changeset
686 MAXITER specfy bound on number of iterations, -1 if it is
kono
parents: 67
diff changeset
687 not known or too large for HOST_WIDE_INT. The location
kono
parents: 67
diff changeset
688 LOCUS corresponding to the loop is used when emitting
kono
parents: 67
diff changeset
689 a summary of the unroll to the dump file. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
692 try_unroll_loop_completely (class loop *loop,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
693 edge exit, tree niter, bool may_be_zero,
111
kono
parents: 67
diff changeset
694 enum unroll_level ul,
kono
parents: 67
diff changeset
695 HOST_WIDE_INT maxiter,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
696 dump_user_location_t locus, bool allow_peel)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
698 unsigned HOST_WIDE_INT n_unroll = 0;
111
kono
parents: 67
diff changeset
699 bool n_unroll_found = false;
kono
parents: 67
diff changeset
700 edge edge_to_cancel = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701
111
kono
parents: 67
diff changeset
702 /* See if we proved number of iterations to be low constant.
kono
parents: 67
diff changeset
703
kono
parents: 67
diff changeset
704 EXIT is an edge that will be removed in all but last iteration of
kono
parents: 67
diff changeset
705 the loop.
kono
parents: 67
diff changeset
706
kono
parents: 67
diff changeset
707 EDGE_TO_CACNEL is an edge that will be removed from the last iteration
kono
parents: 67
diff changeset
708 of the unrolled sequence and is expected to make the final loop not
kono
parents: 67
diff changeset
709 rolling.
kono
parents: 67
diff changeset
710
kono
parents: 67
diff changeset
711 If the number of execution of loop is determined by standard induction
kono
parents: 67
diff changeset
712 variable test, then EXIT and EDGE_TO_CANCEL are the two edges leaving
kono
parents: 67
diff changeset
713 from the iv test. */
kono
parents: 67
diff changeset
714 if (tree_fits_uhwi_p (niter))
kono
parents: 67
diff changeset
715 {
kono
parents: 67
diff changeset
716 n_unroll = tree_to_uhwi (niter);
kono
parents: 67
diff changeset
717 n_unroll_found = true;
kono
parents: 67
diff changeset
718 edge_to_cancel = EDGE_SUCC (exit->src, 0);
kono
parents: 67
diff changeset
719 if (edge_to_cancel == exit)
kono
parents: 67
diff changeset
720 edge_to_cancel = EDGE_SUCC (exit->src, 1);
kono
parents: 67
diff changeset
721 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
722 /* We do not know the number of iterations and thus we cannot eliminate
111
kono
parents: 67
diff changeset
723 the EXIT edge. */
kono
parents: 67
diff changeset
724 else
kono
parents: 67
diff changeset
725 exit = NULL;
kono
parents: 67
diff changeset
726
kono
parents: 67
diff changeset
727 /* See if we can improve our estimate by using recorded loop bounds. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
728 if ((allow_peel || maxiter == 0 || ul == UL_NO_GROWTH)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
729 && maxiter >= 0
111
kono
parents: 67
diff changeset
730 && (!n_unroll_found || (unsigned HOST_WIDE_INT)maxiter < n_unroll))
kono
parents: 67
diff changeset
731 {
kono
parents: 67
diff changeset
732 n_unroll = maxiter;
kono
parents: 67
diff changeset
733 n_unroll_found = true;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
734 /* Loop terminates before the IV variable test, so we cannot
111
kono
parents: 67
diff changeset
735 remove it in the last iteration. */
kono
parents: 67
diff changeset
736 edge_to_cancel = NULL;
kono
parents: 67
diff changeset
737 }
kono
parents: 67
diff changeset
738
kono
parents: 67
diff changeset
739 if (!n_unroll_found)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
742 if (!loop->unroll
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
743 && n_unroll > (unsigned) param_max_completely_peel_times)
111
kono
parents: 67
diff changeset
744 {
kono
parents: 67
diff changeset
745 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
746 fprintf (dump_file, "Not unrolling loop %d "
kono
parents: 67
diff changeset
747 "(--param max-completely-peel-times limit reached).\n",
kono
parents: 67
diff changeset
748 loop->num);
kono
parents: 67
diff changeset
749 return false;
kono
parents: 67
diff changeset
750 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
111
kono
parents: 67
diff changeset
752 if (!edge_to_cancel)
kono
parents: 67
diff changeset
753 edge_to_cancel = loop_edge_to_cancel (loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 if (n_unroll)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 if (ul == UL_SINGLE_ITER)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
760 if (loop->unroll)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
762 /* If the unrolling factor is too large, bail out. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
763 if (n_unroll > (unsigned)loop->unroll)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
764 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
765 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
766 fprintf (dump_file,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
767 "Not unrolling loop %d: "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
768 "user didn't want it unrolled completely.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
769 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
770 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
771 }
111
kono
parents: 67
diff changeset
772 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
773 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
775 struct loop_size size;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
776 /* EXIT can be removed only if we are sure it passes first N_UNROLL
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
777 iterations. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
778 bool remove_exit = (exit && niter
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
779 && TREE_CODE (niter) == INTEGER_CST
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
780 && wi::leu_p (n_unroll, wi::to_widest (niter)));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
781 bool large
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
782 = tree_estimate_loop_size
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
783 (loop, remove_exit ? exit : NULL, edge_to_cancel, &size,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
784 param_max_completely_peeled_insns);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
785 if (large)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
786 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
787 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
788 fprintf (dump_file, "Not unrolling loop %d: it is too large.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
789 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
790 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
791 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
792
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
793 unsigned HOST_WIDE_INT ninsns = size.overall;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
794 unsigned HOST_WIDE_INT unr_insns
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
795 = estimated_unrolled_size (&size, n_unroll);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 if (dump_file && (dump_flags & TDF_DETAILS))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
797 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
798 fprintf (dump_file, " Loop size: %d\n", (int) ninsns);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
799 fprintf (dump_file, " Estimated size after unrolling: %d\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
800 (int) unr_insns);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
801 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
802
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
803 /* If the code is going to shrink, we don't need to be extra
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
804 cautious on guessing if the unrolling is going to be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
805 profitable. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
806 if (unr_insns
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
807 /* If there is IV variable that will become constant, we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
808 save one instruction in the loop prologue we do not
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
809 account otherwise. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
810 <= ninsns + (size.constant_iv != false))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
811 ;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
812 /* We unroll only inner loops, because we do not consider it
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
813 profitable otheriwse. We still can cancel loopback edge
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
814 of not rolling loop; this is always a good idea. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
815 else if (ul == UL_NO_GROWTH)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
816 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
817 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
818 fprintf (dump_file, "Not unrolling loop %d: size would grow.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
819 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
820 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
821 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
822 /* Outer loops tend to be less interesting candidates for
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
823 complete unrolling unless we can do a lot of propagation
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
824 into the inner loop body. For now we disable outer loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
825 unrolling when the code would grow. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
826 else if (loop->inner)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
827 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
828 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
829 fprintf (dump_file, "Not unrolling loop %d: "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
830 "it is not innermost and code would grow.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
831 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
832 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
833 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
834 /* If there is call on a hot path through the loop, then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
835 there is most probably not much to optimize. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
836 else if (size.num_non_pure_calls_on_hot_path)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
837 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
838 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
839 fprintf (dump_file, "Not unrolling loop %d: "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
840 "contains call and code would grow.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
841 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
842 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
843 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
844 /* If there is pure/const call in the function, then we can
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
845 still optimize the unrolled loop body if it contains some
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
846 other interesting code than the calls and code storing or
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
847 cumulating the return value. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
848 else if (size.num_pure_calls_on_hot_path
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
849 /* One IV increment, one test, one ivtmp store and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
850 one useful stmt. That is about minimal loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
851 doing pure call. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
852 && (size.non_call_stmts_on_hot_path
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
853 <= 3 + size.num_pure_calls_on_hot_path))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
854 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
855 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
856 fprintf (dump_file, "Not unrolling loop %d: "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
857 "contains just pure calls and code would grow.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
858 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
859 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
860 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
861 /* Complete unrolling is major win when control flow is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
862 removed and one big basic block is created. If the loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
863 contains control flow the optimization may still be a win
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
864 because of eliminating the loop overhead but it also may
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
865 blow the branch predictor tables. Limit number of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
866 branches on the hot path through the peeled sequence. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
867 else if (size.num_branches_on_hot_path * (int)n_unroll
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
868 > param_max_peel_branches)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
869 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
870 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
871 fprintf (dump_file, "Not unrolling loop %d: "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
872 "number of branches on hot path in the unrolled "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
873 "sequence reaches --param max-peel-branches limit.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
874 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
875 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
876 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
877 else if (unr_insns
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
878 > (unsigned) param_max_completely_peeled_insns)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
879 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
880 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
881 fprintf (dump_file, "Not unrolling loop %d: "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
882 "number of insns in the unrolled sequence reaches "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
883 "--param max-completely-peeled-insns limit.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
884 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
885 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
886 }
111
kono
parents: 67
diff changeset
887 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
889 if (!dbg_cnt (gimple_unroll))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
890 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
891
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 initialize_original_copy_tables ();
111
kono
parents: 67
diff changeset
893 auto_sbitmap wont_exit (n_unroll + 1);
kono
parents: 67
diff changeset
894 if (exit && niter
kono
parents: 67
diff changeset
895 && TREE_CODE (niter) == INTEGER_CST
kono
parents: 67
diff changeset
896 && wi::leu_p (n_unroll, wi::to_widest (niter)))
kono
parents: 67
diff changeset
897 {
kono
parents: 67
diff changeset
898 bitmap_ones (wont_exit);
kono
parents: 67
diff changeset
899 if (wi::eq_p (wi::to_widest (niter), n_unroll)
kono
parents: 67
diff changeset
900 || edge_to_cancel)
kono
parents: 67
diff changeset
901 bitmap_clear_bit (wont_exit, 0);
kono
parents: 67
diff changeset
902 }
kono
parents: 67
diff changeset
903 else
kono
parents: 67
diff changeset
904 {
kono
parents: 67
diff changeset
905 exit = NULL;
kono
parents: 67
diff changeset
906 bitmap_clear (wont_exit);
kono
parents: 67
diff changeset
907 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
908 if (may_be_zero)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
909 bitmap_clear_bit (wont_exit, 1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 if (!gimple_duplicate_loop_to_header_edge (loop, loop_preheader_edge (loop),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 n_unroll, wont_exit,
111
kono
parents: 67
diff changeset
913 exit, &edges_to_remove,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 DLTHE_FLAG_UPDATE_FREQ
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 | DLTHE_FLAG_COMPLETTE_PEEL))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 free_original_copy_tables ();
111
kono
parents: 67
diff changeset
918 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
919 fprintf (dump_file, "Failed to duplicate the loop\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 free_original_copy_tables ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925
111
kono
parents: 67
diff changeset
926 /* Remove the conditional from the last copy of the loop. */
kono
parents: 67
diff changeset
927 if (edge_to_cancel)
kono
parents: 67
diff changeset
928 {
kono
parents: 67
diff changeset
929 gcond *cond = as_a <gcond *> (last_stmt (edge_to_cancel->src));
kono
parents: 67
diff changeset
930 force_edge_cold (edge_to_cancel, true);
kono
parents: 67
diff changeset
931 if (edge_to_cancel->flags & EDGE_TRUE_VALUE)
kono
parents: 67
diff changeset
932 gimple_cond_make_false (cond);
kono
parents: 67
diff changeset
933 else
kono
parents: 67
diff changeset
934 gimple_cond_make_true (cond);
kono
parents: 67
diff changeset
935 update_stmt (cond);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
936 /* Do not remove the path, as doing so may remove outer loop and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
937 confuse bookkeeping code in tree_unroll_loops_completely. */
111
kono
parents: 67
diff changeset
938 }
kono
parents: 67
diff changeset
939
kono
parents: 67
diff changeset
940 /* Store the loop for later unlooping and exit removal. */
kono
parents: 67
diff changeset
941 loops_to_unloop.safe_push (loop);
kono
parents: 67
diff changeset
942 loops_to_unloop_nunroll.safe_push (n_unroll);
kono
parents: 67
diff changeset
943
kono
parents: 67
diff changeset
944 if (dump_enabled_p ())
kono
parents: 67
diff changeset
945 {
kono
parents: 67
diff changeset
946 if (!n_unroll)
kono
parents: 67
diff changeset
947 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | TDF_DETAILS, locus,
kono
parents: 67
diff changeset
948 "loop turned into non-loop; it never loops\n");
kono
parents: 67
diff changeset
949 else
kono
parents: 67
diff changeset
950 {
kono
parents: 67
diff changeset
951 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | TDF_DETAILS, locus,
kono
parents: 67
diff changeset
952 "loop with %d iterations completely unrolled",
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
953 (int) n_unroll);
111
kono
parents: 67
diff changeset
954 if (loop->header->count.initialized_p ())
kono
parents: 67
diff changeset
955 dump_printf (MSG_OPTIMIZED_LOCATIONS | TDF_DETAILS,
kono
parents: 67
diff changeset
956 " (header execution count %d)",
kono
parents: 67
diff changeset
957 (int)loop->header->count.to_gcov_type ());
kono
parents: 67
diff changeset
958 dump_printf (MSG_OPTIMIZED_LOCATIONS | TDF_DETAILS, "\n");
kono
parents: 67
diff changeset
959 }
kono
parents: 67
diff changeset
960 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 if (dump_file && (dump_flags & TDF_DETAILS))
111
kono
parents: 67
diff changeset
963 {
kono
parents: 67
diff changeset
964 if (exit)
kono
parents: 67
diff changeset
965 fprintf (dump_file, "Exit condition of peeled iterations was "
kono
parents: 67
diff changeset
966 "eliminated.\n");
kono
parents: 67
diff changeset
967 if (edge_to_cancel)
kono
parents: 67
diff changeset
968 fprintf (dump_file, "Last iteration exit edge was proved true.\n");
kono
parents: 67
diff changeset
969 else
kono
parents: 67
diff changeset
970 fprintf (dump_file, "Latch of last iteration was marked by "
kono
parents: 67
diff changeset
971 "__builtin_unreachable ().\n");
kono
parents: 67
diff changeset
972 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976
111
kono
parents: 67
diff changeset
977 /* Return number of instructions after peeling. */
kono
parents: 67
diff changeset
978 static unsigned HOST_WIDE_INT
kono
parents: 67
diff changeset
979 estimated_peeled_sequence_size (struct loop_size *size,
kono
parents: 67
diff changeset
980 unsigned HOST_WIDE_INT npeel)
kono
parents: 67
diff changeset
981 {
kono
parents: 67
diff changeset
982 return MAX (npeel * (HOST_WIDE_INT) (size->overall
kono
parents: 67
diff changeset
983 - size->eliminated_by_peeling), 1);
kono
parents: 67
diff changeset
984 }
kono
parents: 67
diff changeset
985
kono
parents: 67
diff changeset
986 /* If the loop is expected to iterate N times and is
kono
parents: 67
diff changeset
987 small enough, duplicate the loop body N+1 times before
kono
parents: 67
diff changeset
988 the loop itself. This way the hot path will never
kono
parents: 67
diff changeset
989 enter the loop.
kono
parents: 67
diff changeset
990 Parameters are the same as for try_unroll_loops_completely */
kono
parents: 67
diff changeset
991
kono
parents: 67
diff changeset
992 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
993 try_peel_loop (class loop *loop,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
994 edge exit, tree niter, bool may_be_zero,
111
kono
parents: 67
diff changeset
995 HOST_WIDE_INT maxiter)
kono
parents: 67
diff changeset
996 {
kono
parents: 67
diff changeset
997 HOST_WIDE_INT npeel;
kono
parents: 67
diff changeset
998 struct loop_size size;
kono
parents: 67
diff changeset
999 int peeled_size;
kono
parents: 67
diff changeset
1000
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1001 if (!flag_peel_loops
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1002 || param_max_peel_times <= 0
111
kono
parents: 67
diff changeset
1003 || !peeled_loops)
kono
parents: 67
diff changeset
1004 return false;
kono
parents: 67
diff changeset
1005
kono
parents: 67
diff changeset
1006 if (bitmap_bit_p (peeled_loops, loop->num))
kono
parents: 67
diff changeset
1007 {
kono
parents: 67
diff changeset
1008 if (dump_file)
kono
parents: 67
diff changeset
1009 fprintf (dump_file, "Not peeling: loop is already peeled\n");
kono
parents: 67
diff changeset
1010 return false;
kono
parents: 67
diff changeset
1011 }
kono
parents: 67
diff changeset
1012
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1013 /* We don't peel loops that will be unrolled as this can duplicate a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1014 loop more times than the user requested. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1015 if (loop->unroll)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1016 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1017 if (dump_file)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1018 fprintf (dump_file, "Not peeling: user didn't want it peeled.\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1019 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1020 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1021
111
kono
parents: 67
diff changeset
1022 /* Peel only innermost loops.
kono
parents: 67
diff changeset
1023 While the code is perfectly capable of peeling non-innermost loops,
kono
parents: 67
diff changeset
1024 the heuristics would probably need some improvements. */
kono
parents: 67
diff changeset
1025 if (loop->inner)
kono
parents: 67
diff changeset
1026 {
kono
parents: 67
diff changeset
1027 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1028 fprintf (dump_file, "Not peeling: outer loop\n");
111
kono
parents: 67
diff changeset
1029 return false;
kono
parents: 67
diff changeset
1030 }
kono
parents: 67
diff changeset
1031
kono
parents: 67
diff changeset
1032 if (!optimize_loop_for_speed_p (loop))
kono
parents: 67
diff changeset
1033 {
kono
parents: 67
diff changeset
1034 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1035 fprintf (dump_file, "Not peeling: cold loop\n");
111
kono
parents: 67
diff changeset
1036 return false;
kono
parents: 67
diff changeset
1037 }
kono
parents: 67
diff changeset
1038
kono
parents: 67
diff changeset
1039 /* Check if there is an estimate on the number of iterations. */
kono
parents: 67
diff changeset
1040 npeel = estimated_loop_iterations_int (loop);
kono
parents: 67
diff changeset
1041 if (npeel < 0)
kono
parents: 67
diff changeset
1042 npeel = likely_max_loop_iterations_int (loop);
kono
parents: 67
diff changeset
1043 if (npeel < 0)
kono
parents: 67
diff changeset
1044 {
kono
parents: 67
diff changeset
1045 if (dump_file)
kono
parents: 67
diff changeset
1046 fprintf (dump_file, "Not peeling: number of iterations is not "
kono
parents: 67
diff changeset
1047 "estimated\n");
kono
parents: 67
diff changeset
1048 return false;
kono
parents: 67
diff changeset
1049 }
kono
parents: 67
diff changeset
1050 if (maxiter >= 0 && maxiter <= npeel)
kono
parents: 67
diff changeset
1051 {
kono
parents: 67
diff changeset
1052 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1053 fprintf (dump_file, "Not peeling: upper bound is known so can "
111
kono
parents: 67
diff changeset
1054 "unroll completely\n");
kono
parents: 67
diff changeset
1055 return false;
kono
parents: 67
diff changeset
1056 }
kono
parents: 67
diff changeset
1057
kono
parents: 67
diff changeset
1058 /* We want to peel estimated number of iterations + 1 (so we never
kono
parents: 67
diff changeset
1059 enter the loop on quick path). Check against PARAM_MAX_PEEL_TIMES
kono
parents: 67
diff changeset
1060 and be sure to avoid overflows. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1061 if (npeel > param_max_peel_times - 1)
111
kono
parents: 67
diff changeset
1062 {
kono
parents: 67
diff changeset
1063 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1064 fprintf (dump_file, "Not peeling: rolls too much "
111
kono
parents: 67
diff changeset
1065 "(%i + 1 > --param max-peel-times)\n", (int) npeel);
kono
parents: 67
diff changeset
1066 return false;
kono
parents: 67
diff changeset
1067 }
kono
parents: 67
diff changeset
1068 npeel++;
kono
parents: 67
diff changeset
1069
kono
parents: 67
diff changeset
1070 /* Check peeled loops size. */
kono
parents: 67
diff changeset
1071 tree_estimate_loop_size (loop, exit, NULL, &size,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1072 param_max_peeled_insns);
111
kono
parents: 67
diff changeset
1073 if ((peeled_size = estimated_peeled_sequence_size (&size, (int) npeel))
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1074 > param_max_peeled_insns)
111
kono
parents: 67
diff changeset
1075 {
kono
parents: 67
diff changeset
1076 if (dump_file)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1077 fprintf (dump_file, "Not peeling: peeled sequence size is too large "
111
kono
parents: 67
diff changeset
1078 "(%i insns > --param max-peel-insns)", peeled_size);
kono
parents: 67
diff changeset
1079 return false;
kono
parents: 67
diff changeset
1080 }
kono
parents: 67
diff changeset
1081
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1082 if (!dbg_cnt (gimple_unroll))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1083 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1084
111
kono
parents: 67
diff changeset
1085 /* Duplicate possibly eliminating the exits. */
kono
parents: 67
diff changeset
1086 initialize_original_copy_tables ();
kono
parents: 67
diff changeset
1087 auto_sbitmap wont_exit (npeel + 1);
kono
parents: 67
diff changeset
1088 if (exit && niter
kono
parents: 67
diff changeset
1089 && TREE_CODE (niter) == INTEGER_CST
kono
parents: 67
diff changeset
1090 && wi::leu_p (npeel, wi::to_widest (niter)))
kono
parents: 67
diff changeset
1091 {
kono
parents: 67
diff changeset
1092 bitmap_ones (wont_exit);
kono
parents: 67
diff changeset
1093 bitmap_clear_bit (wont_exit, 0);
kono
parents: 67
diff changeset
1094 }
kono
parents: 67
diff changeset
1095 else
kono
parents: 67
diff changeset
1096 {
kono
parents: 67
diff changeset
1097 exit = NULL;
kono
parents: 67
diff changeset
1098 bitmap_clear (wont_exit);
kono
parents: 67
diff changeset
1099 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1100 if (may_be_zero)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1101 bitmap_clear_bit (wont_exit, 1);
111
kono
parents: 67
diff changeset
1102 if (!gimple_duplicate_loop_to_header_edge (loop, loop_preheader_edge (loop),
kono
parents: 67
diff changeset
1103 npeel, wont_exit,
kono
parents: 67
diff changeset
1104 exit, &edges_to_remove,
kono
parents: 67
diff changeset
1105 DLTHE_FLAG_UPDATE_FREQ))
kono
parents: 67
diff changeset
1106 {
kono
parents: 67
diff changeset
1107 free_original_copy_tables ();
kono
parents: 67
diff changeset
1108 return false;
kono
parents: 67
diff changeset
1109 }
kono
parents: 67
diff changeset
1110 free_original_copy_tables ();
kono
parents: 67
diff changeset
1111 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
1112 {
kono
parents: 67
diff changeset
1113 fprintf (dump_file, "Peeled loop %d, %i times.\n",
kono
parents: 67
diff changeset
1114 loop->num, (int) npeel);
kono
parents: 67
diff changeset
1115 }
kono
parents: 67
diff changeset
1116 if (loop->any_estimate)
kono
parents: 67
diff changeset
1117 {
kono
parents: 67
diff changeset
1118 if (wi::ltu_p (npeel, loop->nb_iterations_estimate))
kono
parents: 67
diff changeset
1119 loop->nb_iterations_estimate -= npeel;
kono
parents: 67
diff changeset
1120 else
kono
parents: 67
diff changeset
1121 loop->nb_iterations_estimate = 0;
kono
parents: 67
diff changeset
1122 }
kono
parents: 67
diff changeset
1123 if (loop->any_upper_bound)
kono
parents: 67
diff changeset
1124 {
kono
parents: 67
diff changeset
1125 if (wi::ltu_p (npeel, loop->nb_iterations_upper_bound))
kono
parents: 67
diff changeset
1126 loop->nb_iterations_upper_bound -= npeel;
kono
parents: 67
diff changeset
1127 else
kono
parents: 67
diff changeset
1128 loop->nb_iterations_upper_bound = 0;
kono
parents: 67
diff changeset
1129 }
kono
parents: 67
diff changeset
1130 if (loop->any_likely_upper_bound)
kono
parents: 67
diff changeset
1131 {
kono
parents: 67
diff changeset
1132 if (wi::ltu_p (npeel, loop->nb_iterations_likely_upper_bound))
kono
parents: 67
diff changeset
1133 loop->nb_iterations_likely_upper_bound -= npeel;
kono
parents: 67
diff changeset
1134 else
kono
parents: 67
diff changeset
1135 {
kono
parents: 67
diff changeset
1136 loop->any_estimate = true;
kono
parents: 67
diff changeset
1137 loop->nb_iterations_estimate = 0;
kono
parents: 67
diff changeset
1138 loop->nb_iterations_likely_upper_bound = 0;
kono
parents: 67
diff changeset
1139 }
kono
parents: 67
diff changeset
1140 }
kono
parents: 67
diff changeset
1141 profile_count entry_count = profile_count::zero ();
kono
parents: 67
diff changeset
1142
kono
parents: 67
diff changeset
1143 edge e;
kono
parents: 67
diff changeset
1144 edge_iterator ei;
kono
parents: 67
diff changeset
1145 FOR_EACH_EDGE (e, ei, loop->header->preds)
kono
parents: 67
diff changeset
1146 if (e->src != loop->latch)
kono
parents: 67
diff changeset
1147 {
kono
parents: 67
diff changeset
1148 if (e->src->count.initialized_p ())
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1149 entry_count += e->src->count;
111
kono
parents: 67
diff changeset
1150 gcc_assert (!flow_bb_inside_loop_p (loop, e->src));
kono
parents: 67
diff changeset
1151 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1152 profile_probability p;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1153 p = entry_count.probability_in (loop->header->count);
111
kono
parents: 67
diff changeset
1154 scale_loop_profile (loop, p, 0);
kono
parents: 67
diff changeset
1155 bitmap_set_bit (peeled_loops, loop->num);
kono
parents: 67
diff changeset
1156 return true;
kono
parents: 67
diff changeset
1157 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 /* Adds a canonical induction variable to LOOP if suitable.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1159 CREATE_IV is true if we may create a new iv. UL determines
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 which loops we are allowed to completely unroll. If TRY_EVAL is true, we try
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1161 to determine the number of iterations of a loop by direct evaluation.
111
kono
parents: 67
diff changeset
1162 Returns true if cfg is changed. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1165 canonicalize_loop_induction_variables (class loop *loop,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 bool create_iv, enum unroll_level ul,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1167 bool try_eval, bool allow_peel)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 edge exit = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 tree niter;
111
kono
parents: 67
diff changeset
1171 HOST_WIDE_INT maxiter;
kono
parents: 67
diff changeset
1172 bool modified = false;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1173 dump_user_location_t locus;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1174 class tree_niter_desc niter_desc;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1175 bool may_be_zero = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1177 /* For unrolling allow conditional constant or zero iterations, thus
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1178 perform loop-header copying on-the-fly. */
111
kono
parents: 67
diff changeset
1179 exit = single_exit (loop);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1180 niter = chrec_dont_know;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1181 if (exit && number_of_iterations_exit (loop, exit, &niter_desc, false))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1182 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1183 niter = niter_desc.niter;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1184 may_be_zero
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1185 = niter_desc.may_be_zero && !integer_zerop (niter_desc.may_be_zero);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1186 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 if (TREE_CODE (niter) == INTEGER_CST)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1188 locus = last_stmt (exit->src);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1191 /* For non-constant niter fold may_be_zero into niter again. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1192 if (may_be_zero)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1193 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1194 if (COMPARISON_CLASS_P (niter_desc.may_be_zero))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1195 niter = fold_build3 (COND_EXPR, TREE_TYPE (niter),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1196 niter_desc.may_be_zero,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1197 build_int_cst (TREE_TYPE (niter), 0), niter);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1198 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1199 niter = chrec_dont_know;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1200 may_be_zero = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1201 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1202
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 /* If the loop has more than one exit, try checking all of them
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 for # of iterations determinable through scev. */
111
kono
parents: 67
diff changeset
1205 if (!exit)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 niter = find_loop_niter (loop, &exit);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208 /* Finally if everything else fails, try brute force evaluation. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 if (try_eval
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 && (chrec_contains_undetermined (niter)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 || TREE_CODE (niter) != INTEGER_CST))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 niter = find_loop_niter_by_eval (loop, &exit);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213
111
kono
parents: 67
diff changeset
1214 if (exit)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1215 locus = last_stmt (exit->src);
111
kono
parents: 67
diff changeset
1216
kono
parents: 67
diff changeset
1217 if (TREE_CODE (niter) != INTEGER_CST)
kono
parents: 67
diff changeset
1218 exit = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220
111
kono
parents: 67
diff changeset
1221 /* We work exceptionally hard here to estimate the bound
kono
parents: 67
diff changeset
1222 by find_loop_niter_by_eval. Be sure to keep it for future. */
kono
parents: 67
diff changeset
1223 if (niter && TREE_CODE (niter) == INTEGER_CST)
kono
parents: 67
diff changeset
1224 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1225 vec<edge> exits = get_loop_exit_edges (loop);
111
kono
parents: 67
diff changeset
1226 record_niter_bound (loop, wi::to_widest (niter),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1227 exit == single_likely_exit (loop, exits), true);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1228 exits.release ();
111
kono
parents: 67
diff changeset
1229 }
kono
parents: 67
diff changeset
1230
kono
parents: 67
diff changeset
1231 /* Force re-computation of loop bounds so we can remove redundant exits. */
kono
parents: 67
diff changeset
1232 maxiter = max_loop_iterations_int (loop);
kono
parents: 67
diff changeset
1233
kono
parents: 67
diff changeset
1234 if (dump_file && (dump_flags & TDF_DETAILS)
kono
parents: 67
diff changeset
1235 && TREE_CODE (niter) == INTEGER_CST)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 fprintf (dump_file, "Loop %d iterates ", loop->num);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 print_generic_expr (dump_file, niter, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 fprintf (dump_file, " times.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 }
111
kono
parents: 67
diff changeset
1241 if (dump_file && (dump_flags & TDF_DETAILS)
kono
parents: 67
diff changeset
1242 && maxiter >= 0)
kono
parents: 67
diff changeset
1243 {
kono
parents: 67
diff changeset
1244 fprintf (dump_file, "Loop %d iterates at most %i times.\n", loop->num,
kono
parents: 67
diff changeset
1245 (int)maxiter);
kono
parents: 67
diff changeset
1246 }
kono
parents: 67
diff changeset
1247 if (dump_file && (dump_flags & TDF_DETAILS)
kono
parents: 67
diff changeset
1248 && likely_max_loop_iterations_int (loop) >= 0)
kono
parents: 67
diff changeset
1249 {
kono
parents: 67
diff changeset
1250 fprintf (dump_file, "Loop %d likely iterates at most %i times.\n",
kono
parents: 67
diff changeset
1251 loop->num, (int)likely_max_loop_iterations_int (loop));
kono
parents: 67
diff changeset
1252 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253
111
kono
parents: 67
diff changeset
1254 /* Remove exits that are known to be never taken based on loop bound.
kono
parents: 67
diff changeset
1255 Needs to be called after compilation of max_loop_iterations_int that
kono
parents: 67
diff changeset
1256 populates the loop bounds. */
kono
parents: 67
diff changeset
1257 modified |= remove_redundant_iv_tests (loop);
kono
parents: 67
diff changeset
1258
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1259 if (try_unroll_loop_completely (loop, exit, niter, may_be_zero, ul,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1260 maxiter, locus, allow_peel))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262
111
kono
parents: 67
diff changeset
1263 if (create_iv
kono
parents: 67
diff changeset
1264 && niter && !chrec_contains_undetermined (niter)
kono
parents: 67
diff changeset
1265 && exit && just_once_each_iteration_p (loop, exit->src))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1266 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1267 tree iv_niter = niter;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1268 if (may_be_zero)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1269 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1270 if (COMPARISON_CLASS_P (niter_desc.may_be_zero))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1271 iv_niter = fold_build3 (COND_EXPR, TREE_TYPE (iv_niter),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1272 niter_desc.may_be_zero,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1273 build_int_cst (TREE_TYPE (iv_niter), 0),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1274 iv_niter);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1275 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1276 iv_niter = NULL_TREE;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1277 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1278 if (iv_niter)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1279 create_canonical_iv (loop, exit, iv_niter);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1280 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281
111
kono
parents: 67
diff changeset
1282 if (ul == UL_ALL)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1283 modified |= try_peel_loop (loop, exit, niter, may_be_zero, maxiter);
111
kono
parents: 67
diff changeset
1284
kono
parents: 67
diff changeset
1285 return modified;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 /* The main entry point of the pass. Adds canonical induction variables
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 to the suitable loops. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291 unsigned int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 canonicalize_induction_variables (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1294 class loop *loop;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 bool changed = false;
111
kono
parents: 67
diff changeset
1296 bool irred_invalidated = false;
kono
parents: 67
diff changeset
1297 bitmap loop_closed_ssa_invalidated = BITMAP_ALLOC (NULL);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1298
111
kono
parents: 67
diff changeset
1299 estimate_numbers_of_iterations (cfun);
kono
parents: 67
diff changeset
1300
kono
parents: 67
diff changeset
1301 FOR_EACH_LOOP (loop, LI_FROM_INNERMOST)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 changed |= canonicalize_loop_induction_variables (loop,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 true, UL_SINGLE_ITER,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1305 true, false);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 }
111
kono
parents: 67
diff changeset
1307 gcc_assert (!need_ssa_update_p (cfun));
kono
parents: 67
diff changeset
1308
kono
parents: 67
diff changeset
1309 unloop_loops (loop_closed_ssa_invalidated, &irred_invalidated);
kono
parents: 67
diff changeset
1310 if (irred_invalidated
kono
parents: 67
diff changeset
1311 && loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS))
kono
parents: 67
diff changeset
1312 mark_irreducible_loops ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 /* Clean up the information about numbers of iterations, since brute force
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 evaluation could reveal new information. */
111
kono
parents: 67
diff changeset
1316 free_numbers_of_iterations_estimates (cfun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317 scev_reset ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318
111
kono
parents: 67
diff changeset
1319 if (!bitmap_empty_p (loop_closed_ssa_invalidated))
kono
parents: 67
diff changeset
1320 {
kono
parents: 67
diff changeset
1321 gcc_checking_assert (loops_state_satisfies_p (LOOP_CLOSED_SSA));
kono
parents: 67
diff changeset
1322 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
kono
parents: 67
diff changeset
1323 }
kono
parents: 67
diff changeset
1324 BITMAP_FREE (loop_closed_ssa_invalidated);
kono
parents: 67
diff changeset
1325
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 if (changed)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 return TODO_cleanup_cfg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330
111
kono
parents: 67
diff changeset
1331 /* Process loops from innermost to outer, stopping at the innermost
kono
parents: 67
diff changeset
1332 loop we unrolled. */
kono
parents: 67
diff changeset
1333
kono
parents: 67
diff changeset
1334 static bool
kono
parents: 67
diff changeset
1335 tree_unroll_loops_completely_1 (bool may_increase_size, bool unroll_outer,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1336 bitmap father_bbs, class loop *loop)
111
kono
parents: 67
diff changeset
1337 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1338 class loop *loop_father;
111
kono
parents: 67
diff changeset
1339 bool changed = false;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1340 class loop *inner;
111
kono
parents: 67
diff changeset
1341 enum unroll_level ul;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1342 unsigned num = number_of_loops (cfun);
111
kono
parents: 67
diff changeset
1343
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1344 /* Process inner loops first. Don't walk loops added by the recursive
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1345 calls because SSA form is not up-to-date. They can be handled in the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1346 next iteration. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1347 bitmap child_father_bbs = NULL;
111
kono
parents: 67
diff changeset
1348 for (inner = loop->inner; inner != NULL; inner = inner->next)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1349 if ((unsigned) inner->num < num)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1350 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1351 if (!child_father_bbs)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1352 child_father_bbs = BITMAP_ALLOC (NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1353 if (tree_unroll_loops_completely_1 (may_increase_size, unroll_outer,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1354 child_father_bbs, inner))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1355 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1356 bitmap_ior_into (father_bbs, child_father_bbs);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1357 bitmap_clear (child_father_bbs);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1358 changed = true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1359 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1360 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1361 if (child_father_bbs)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1362 BITMAP_FREE (child_father_bbs);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1363
111
kono
parents: 67
diff changeset
1364 /* If we changed an inner loop we cannot process outer loops in this
kono
parents: 67
diff changeset
1365 iteration because SSA form is not up-to-date. Continue with
kono
parents: 67
diff changeset
1366 siblings of outer loops instead. */
kono
parents: 67
diff changeset
1367 if (changed)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1368 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1369 /* If we are recorded as father clear all other fathers that
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1370 are necessarily covered already to avoid redundant work. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1371 if (bitmap_bit_p (father_bbs, loop->header->index))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1372 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1373 bitmap_clear (father_bbs);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1374 bitmap_set_bit (father_bbs, loop->header->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1375 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1376 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1377 }
111
kono
parents: 67
diff changeset
1378
kono
parents: 67
diff changeset
1379 /* Don't unroll #pragma omp simd loops until the vectorizer
kono
parents: 67
diff changeset
1380 attempts to vectorize those. */
kono
parents: 67
diff changeset
1381 if (loop->force_vectorize)
kono
parents: 67
diff changeset
1382 return false;
kono
parents: 67
diff changeset
1383
kono
parents: 67
diff changeset
1384 /* Try to unroll this loop. */
kono
parents: 67
diff changeset
1385 loop_father = loop_outer (loop);
kono
parents: 67
diff changeset
1386 if (!loop_father)
kono
parents: 67
diff changeset
1387 return false;
kono
parents: 67
diff changeset
1388
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1389 if (loop->unroll > 1)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1390 ul = UL_ALL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1391 else if (may_increase_size && optimize_loop_nest_for_speed_p (loop)
111
kono
parents: 67
diff changeset
1392 /* Unroll outermost loops only if asked to do so or they do
kono
parents: 67
diff changeset
1393 not cause code growth. */
kono
parents: 67
diff changeset
1394 && (unroll_outer || loop_outer (loop_father)))
kono
parents: 67
diff changeset
1395 ul = UL_ALL;
kono
parents: 67
diff changeset
1396 else
kono
parents: 67
diff changeset
1397 ul = UL_NO_GROWTH;
kono
parents: 67
diff changeset
1398
kono
parents: 67
diff changeset
1399 if (canonicalize_loop_induction_variables
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1400 (loop, false, ul, !flag_tree_loop_ivcanon, unroll_outer))
111
kono
parents: 67
diff changeset
1401 {
kono
parents: 67
diff changeset
1402 /* If we'll continue unrolling, we need to propagate constants
kono
parents: 67
diff changeset
1403 within the new basic blocks to fold away induction variable
kono
parents: 67
diff changeset
1404 computations; otherwise, the size might blow up before the
kono
parents: 67
diff changeset
1405 iteration is complete and the IR eventually cleaned up. */
kono
parents: 67
diff changeset
1406 if (loop_outer (loop_father))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1407 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1408 /* Once we process our father we will have processed
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1409 the fathers of our children as well, so avoid doing
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1410 redundant work and clear fathers we've gathered sofar. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1411 bitmap_clear (father_bbs);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1412 bitmap_set_bit (father_bbs, loop_father->header->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1413 }
111
kono
parents: 67
diff changeset
1414
kono
parents: 67
diff changeset
1415 return true;
kono
parents: 67
diff changeset
1416 }
kono
parents: 67
diff changeset
1417
kono
parents: 67
diff changeset
1418 return false;
kono
parents: 67
diff changeset
1419 }
kono
parents: 67
diff changeset
1420
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1421 /* Unroll LOOPS completely if they iterate just few times. Unless
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422 MAY_INCREASE_SIZE is true, perform the unrolling only if the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 size of the code does not increase. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1425 static unsigned int
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 tree_unroll_loops_completely (bool may_increase_size, bool unroll_outer)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1427 {
111
kono
parents: 67
diff changeset
1428 bitmap father_bbs = BITMAP_ALLOC (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1429 bool changed;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1430 int iteration = 0;
111
kono
parents: 67
diff changeset
1431 bool irred_invalidated = false;
kono
parents: 67
diff changeset
1432
kono
parents: 67
diff changeset
1433 estimate_numbers_of_iterations (cfun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1436 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1437 changed = false;
111
kono
parents: 67
diff changeset
1438 bitmap loop_closed_ssa_invalidated = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439
111
kono
parents: 67
diff changeset
1440 if (loops_state_satisfies_p (LOOP_CLOSED_SSA))
kono
parents: 67
diff changeset
1441 loop_closed_ssa_invalidated = BITMAP_ALLOC (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442
111
kono
parents: 67
diff changeset
1443 free_numbers_of_iterations_estimates (cfun);
kono
parents: 67
diff changeset
1444 estimate_numbers_of_iterations (cfun);
kono
parents: 67
diff changeset
1445
kono
parents: 67
diff changeset
1446 changed = tree_unroll_loops_completely_1 (may_increase_size,
kono
parents: 67
diff changeset
1447 unroll_outer, father_bbs,
kono
parents: 67
diff changeset
1448 current_loops->tree_root);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1449 if (changed)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1450 {
111
kono
parents: 67
diff changeset
1451 unsigned i;
kono
parents: 67
diff changeset
1452
kono
parents: 67
diff changeset
1453 unloop_loops (loop_closed_ssa_invalidated, &irred_invalidated);
kono
parents: 67
diff changeset
1454
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1455 /* We cannot use TODO_update_ssa_no_phi because VOPS gets confused. */
111
kono
parents: 67
diff changeset
1456 if (loop_closed_ssa_invalidated
kono
parents: 67
diff changeset
1457 && !bitmap_empty_p (loop_closed_ssa_invalidated))
kono
parents: 67
diff changeset
1458 rewrite_into_loop_closed_ssa (loop_closed_ssa_invalidated,
kono
parents: 67
diff changeset
1459 TODO_update_ssa);
kono
parents: 67
diff changeset
1460 else
kono
parents: 67
diff changeset
1461 update_ssa (TODO_update_ssa);
kono
parents: 67
diff changeset
1462
kono
parents: 67
diff changeset
1463 /* father_bbs is a bitmap of loop father header BB indices.
kono
parents: 67
diff changeset
1464 Translate that to what non-root loops these BBs belong to now. */
kono
parents: 67
diff changeset
1465 bitmap_iterator bi;
kono
parents: 67
diff changeset
1466 bitmap fathers = BITMAP_ALLOC (NULL);
kono
parents: 67
diff changeset
1467 EXECUTE_IF_SET_IN_BITMAP (father_bbs, 0, i, bi)
kono
parents: 67
diff changeset
1468 {
kono
parents: 67
diff changeset
1469 basic_block unrolled_loop_bb = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents: 67
diff changeset
1470 if (! unrolled_loop_bb)
kono
parents: 67
diff changeset
1471 continue;
kono
parents: 67
diff changeset
1472 if (loop_outer (unrolled_loop_bb->loop_father))
kono
parents: 67
diff changeset
1473 bitmap_set_bit (fathers,
kono
parents: 67
diff changeset
1474 unrolled_loop_bb->loop_father->num);
kono
parents: 67
diff changeset
1475 }
kono
parents: 67
diff changeset
1476 bitmap_clear (father_bbs);
kono
parents: 67
diff changeset
1477 /* Propagate the constants within the new basic blocks. */
kono
parents: 67
diff changeset
1478 EXECUTE_IF_SET_IN_BITMAP (fathers, 0, i, bi)
kono
parents: 67
diff changeset
1479 {
kono
parents: 67
diff changeset
1480 loop_p father = get_loop (cfun, i);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1481 bitmap exit_bbs = BITMAP_ALLOC (NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1482 loop_exit *exit = father->exits->next;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1483 while (exit->e)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1484 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1485 bitmap_set_bit (exit_bbs, exit->e->dest->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1486 exit = exit->next;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1487 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1488 do_rpo_vn (cfun, loop_preheader_edge (father), exit_bbs);
111
kono
parents: 67
diff changeset
1489 }
kono
parents: 67
diff changeset
1490 BITMAP_FREE (fathers);
kono
parents: 67
diff changeset
1491
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1492 /* This will take care of removing completely unrolled loops
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1493 from the loop structures so we can continue unrolling now
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1494 innermost loops. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1495 if (cleanup_tree_cfg ())
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1496 update_ssa (TODO_update_ssa_only_virtuals);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1497
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1498 /* Clean up the information about numbers of iterations, since
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1499 complete unrolling might have invalidated it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1500 scev_reset ();
111
kono
parents: 67
diff changeset
1501 if (flag_checking && loops_state_satisfies_p (LOOP_CLOSED_SSA))
kono
parents: 67
diff changeset
1502 verify_loop_closed_ssa (true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1503 }
111
kono
parents: 67
diff changeset
1504 if (loop_closed_ssa_invalidated)
kono
parents: 67
diff changeset
1505 BITMAP_FREE (loop_closed_ssa_invalidated);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1506 }
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1507 while (changed
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1508 && ++iteration <= param_max_unroll_iterations);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1509
111
kono
parents: 67
diff changeset
1510 BITMAP_FREE (father_bbs);
kono
parents: 67
diff changeset
1511
kono
parents: 67
diff changeset
1512 if (irred_invalidated
kono
parents: 67
diff changeset
1513 && loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS))
kono
parents: 67
diff changeset
1514 mark_irreducible_loops ();
kono
parents: 67
diff changeset
1515
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1516 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1517 }
111
kono
parents: 67
diff changeset
1518
kono
parents: 67
diff changeset
1519 /* Canonical induction variable creation pass. */
kono
parents: 67
diff changeset
1520
kono
parents: 67
diff changeset
1521 namespace {
kono
parents: 67
diff changeset
1522
kono
parents: 67
diff changeset
1523 const pass_data pass_data_iv_canon =
kono
parents: 67
diff changeset
1524 {
kono
parents: 67
diff changeset
1525 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
1526 "ivcanon", /* name */
kono
parents: 67
diff changeset
1527 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 67
diff changeset
1528 TV_TREE_LOOP_IVCANON, /* tv_id */
kono
parents: 67
diff changeset
1529 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
1530 0, /* properties_provided */
kono
parents: 67
diff changeset
1531 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1532 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1533 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
1534 };
kono
parents: 67
diff changeset
1535
kono
parents: 67
diff changeset
1536 class pass_iv_canon : public gimple_opt_pass
kono
parents: 67
diff changeset
1537 {
kono
parents: 67
diff changeset
1538 public:
kono
parents: 67
diff changeset
1539 pass_iv_canon (gcc::context *ctxt)
kono
parents: 67
diff changeset
1540 : gimple_opt_pass (pass_data_iv_canon, ctxt)
kono
parents: 67
diff changeset
1541 {}
kono
parents: 67
diff changeset
1542
kono
parents: 67
diff changeset
1543 /* opt_pass methods: */
kono
parents: 67
diff changeset
1544 virtual bool gate (function *) { return flag_tree_loop_ivcanon != 0; }
kono
parents: 67
diff changeset
1545 virtual unsigned int execute (function *fun);
kono
parents: 67
diff changeset
1546
kono
parents: 67
diff changeset
1547 }; // class pass_iv_canon
kono
parents: 67
diff changeset
1548
kono
parents: 67
diff changeset
1549 unsigned int
kono
parents: 67
diff changeset
1550 pass_iv_canon::execute (function *fun)
kono
parents: 67
diff changeset
1551 {
kono
parents: 67
diff changeset
1552 if (number_of_loops (fun) <= 1)
kono
parents: 67
diff changeset
1553 return 0;
kono
parents: 67
diff changeset
1554
kono
parents: 67
diff changeset
1555 return canonicalize_induction_variables ();
kono
parents: 67
diff changeset
1556 }
kono
parents: 67
diff changeset
1557
kono
parents: 67
diff changeset
1558 } // anon namespace
kono
parents: 67
diff changeset
1559
kono
parents: 67
diff changeset
1560 gimple_opt_pass *
kono
parents: 67
diff changeset
1561 make_pass_iv_canon (gcc::context *ctxt)
kono
parents: 67
diff changeset
1562 {
kono
parents: 67
diff changeset
1563 return new pass_iv_canon (ctxt);
kono
parents: 67
diff changeset
1564 }
kono
parents: 67
diff changeset
1565
kono
parents: 67
diff changeset
1566 /* Complete unrolling of loops. */
kono
parents: 67
diff changeset
1567
kono
parents: 67
diff changeset
1568 namespace {
kono
parents: 67
diff changeset
1569
kono
parents: 67
diff changeset
1570 const pass_data pass_data_complete_unroll =
kono
parents: 67
diff changeset
1571 {
kono
parents: 67
diff changeset
1572 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
1573 "cunroll", /* name */
kono
parents: 67
diff changeset
1574 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 67
diff changeset
1575 TV_COMPLETE_UNROLL, /* tv_id */
kono
parents: 67
diff changeset
1576 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
1577 0, /* properties_provided */
kono
parents: 67
diff changeset
1578 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1579 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1580 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
1581 };
kono
parents: 67
diff changeset
1582
kono
parents: 67
diff changeset
1583 class pass_complete_unroll : public gimple_opt_pass
kono
parents: 67
diff changeset
1584 {
kono
parents: 67
diff changeset
1585 public:
kono
parents: 67
diff changeset
1586 pass_complete_unroll (gcc::context *ctxt)
kono
parents: 67
diff changeset
1587 : gimple_opt_pass (pass_data_complete_unroll, ctxt)
kono
parents: 67
diff changeset
1588 {}
kono
parents: 67
diff changeset
1589
kono
parents: 67
diff changeset
1590 /* opt_pass methods: */
kono
parents: 67
diff changeset
1591 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
1592
kono
parents: 67
diff changeset
1593 }; // class pass_complete_unroll
kono
parents: 67
diff changeset
1594
kono
parents: 67
diff changeset
1595 unsigned int
kono
parents: 67
diff changeset
1596 pass_complete_unroll::execute (function *fun)
kono
parents: 67
diff changeset
1597 {
kono
parents: 67
diff changeset
1598 if (number_of_loops (fun) <= 1)
kono
parents: 67
diff changeset
1599 return 0;
kono
parents: 67
diff changeset
1600
kono
parents: 67
diff changeset
1601 /* If we ever decide to run loop peeling more than once, we will need to
kono
parents: 67
diff changeset
1602 track loops already peeled in loop structures themselves to avoid
kono
parents: 67
diff changeset
1603 re-peeling the same loop multiple times. */
kono
parents: 67
diff changeset
1604 if (flag_peel_loops)
kono
parents: 67
diff changeset
1605 peeled_loops = BITMAP_ALLOC (NULL);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1606 unsigned int val = tree_unroll_loops_completely (flag_unroll_loops
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1607 || flag_peel_loops
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1608 || optimize >= 3, true);
111
kono
parents: 67
diff changeset
1609 if (peeled_loops)
kono
parents: 67
diff changeset
1610 {
kono
parents: 67
diff changeset
1611 BITMAP_FREE (peeled_loops);
kono
parents: 67
diff changeset
1612 peeled_loops = NULL;
kono
parents: 67
diff changeset
1613 }
kono
parents: 67
diff changeset
1614 return val;
kono
parents: 67
diff changeset
1615 }
kono
parents: 67
diff changeset
1616
kono
parents: 67
diff changeset
1617 } // anon namespace
kono
parents: 67
diff changeset
1618
kono
parents: 67
diff changeset
1619 gimple_opt_pass *
kono
parents: 67
diff changeset
1620 make_pass_complete_unroll (gcc::context *ctxt)
kono
parents: 67
diff changeset
1621 {
kono
parents: 67
diff changeset
1622 return new pass_complete_unroll (ctxt);
kono
parents: 67
diff changeset
1623 }
kono
parents: 67
diff changeset
1624
kono
parents: 67
diff changeset
1625 /* Complete unrolling of inner loops. */
kono
parents: 67
diff changeset
1626
kono
parents: 67
diff changeset
1627 namespace {
kono
parents: 67
diff changeset
1628
kono
parents: 67
diff changeset
1629 const pass_data pass_data_complete_unrolli =
kono
parents: 67
diff changeset
1630 {
kono
parents: 67
diff changeset
1631 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
1632 "cunrolli", /* name */
kono
parents: 67
diff changeset
1633 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 67
diff changeset
1634 TV_COMPLETE_UNROLL, /* tv_id */
kono
parents: 67
diff changeset
1635 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
1636 0, /* properties_provided */
kono
parents: 67
diff changeset
1637 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1638 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1639 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
1640 };
kono
parents: 67
diff changeset
1641
kono
parents: 67
diff changeset
1642 class pass_complete_unrolli : public gimple_opt_pass
kono
parents: 67
diff changeset
1643 {
kono
parents: 67
diff changeset
1644 public:
kono
parents: 67
diff changeset
1645 pass_complete_unrolli (gcc::context *ctxt)
kono
parents: 67
diff changeset
1646 : gimple_opt_pass (pass_data_complete_unrolli, ctxt)
kono
parents: 67
diff changeset
1647 {}
kono
parents: 67
diff changeset
1648
kono
parents: 67
diff changeset
1649 /* opt_pass methods: */
kono
parents: 67
diff changeset
1650 virtual bool gate (function *) { return optimize >= 2; }
kono
parents: 67
diff changeset
1651 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
1652
kono
parents: 67
diff changeset
1653 }; // class pass_complete_unrolli
kono
parents: 67
diff changeset
1654
kono
parents: 67
diff changeset
1655 unsigned int
kono
parents: 67
diff changeset
1656 pass_complete_unrolli::execute (function *fun)
kono
parents: 67
diff changeset
1657 {
kono
parents: 67
diff changeset
1658 unsigned ret = 0;
kono
parents: 67
diff changeset
1659
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1660 loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
111
kono
parents: 67
diff changeset
1661 if (number_of_loops (fun) > 1)
kono
parents: 67
diff changeset
1662 {
kono
parents: 67
diff changeset
1663 scev_initialize ();
kono
parents: 67
diff changeset
1664 ret = tree_unroll_loops_completely (optimize >= 3, false);
kono
parents: 67
diff changeset
1665 scev_finalize ();
kono
parents: 67
diff changeset
1666 }
kono
parents: 67
diff changeset
1667 loop_optimizer_finalize ();
kono
parents: 67
diff changeset
1668
kono
parents: 67
diff changeset
1669 return ret;
kono
parents: 67
diff changeset
1670 }
kono
parents: 67
diff changeset
1671
kono
parents: 67
diff changeset
1672 } // anon namespace
kono
parents: 67
diff changeset
1673
kono
parents: 67
diff changeset
1674 gimple_opt_pass *
kono
parents: 67
diff changeset
1675 make_pass_complete_unrolli (gcc::context *ctxt)
kono
parents: 67
diff changeset
1676 {
kono
parents: 67
diff changeset
1677 return new pass_complete_unrolli (ctxt);
kono
parents: 67
diff changeset
1678 }
kono
parents: 67
diff changeset
1679
kono
parents: 67
diff changeset
1680