annotate gcc/tree-ssa-loop-ch.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Loop header copying on trees.
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
9
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.
9
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.
9
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.
9
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 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
16
kono
parents: 14
diff changeset
23 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "tree.h"
16
kono
parents: 14
diff changeset
25 #include "gimple.h"
kono
parents: 14
diff changeset
26 #include "cfghooks.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "tree-pass.h"
16
kono
parents: 14
diff changeset
28 #include "gimple-ssa.h"
kono
parents: 14
diff changeset
29 #include "gimple-iterator.h"
kono
parents: 14
diff changeset
30 #include "tree-cfg.h"
kono
parents: 14
diff changeset
31 #include "tree-into-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "cfgloop.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #include "tree-inline.h"
16
kono
parents: 14
diff changeset
34 #include "tree-ssa-scopedtables.h"
kono
parents: 14
diff changeset
35 #include "tree-ssa-threadedge.h"
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
36 #include "tree-ssa-sccvn.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
37 #include "tree-phinodes.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
38 #include "ssa-iterators.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 /* Duplicates headers of loops if they are small enough, so that the statements
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 in the loop body are always executed when the loop is entered. This
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 increases effectiveness of code motion optimizations, and reduces the need
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 for loop preconditioning. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 /* Check whether we should duplicate HEADER of LOOP. At most *LIMIT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 instructions should be duplicated, limit is decreased by the actual
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 amount. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 static bool
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
50 should_duplicate_loop_header_p (basic_block header, class loop *loop,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 int *limit)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 gimple_stmt_iterator bsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
16
kono
parents: 14
diff changeset
55 gcc_assert (!header->aux);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 /* Loop header copying usually increases size of the code. This used not to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 be true, since quite often it is possible to verify that the condition is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 satisfied in the first iteration and therefore to eliminate it. Jump
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 threading handles these cases now. */
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
61 if (optimize_loop_for_size_p (loop)
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
62 && !loop->force_vectorize)
16
kono
parents: 14
diff changeset
63 {
kono
parents: 14
diff changeset
64 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
65 fprintf (dump_file,
kono
parents: 14
diff changeset
66 " Not duplicating bb %i: optimizing for size.\n",
kono
parents: 14
diff changeset
67 header->index);
kono
parents: 14
diff changeset
68 return false;
kono
parents: 14
diff changeset
69 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 gcc_assert (EDGE_COUNT (header->succs) > 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 if (single_succ_p (header))
16
kono
parents: 14
diff changeset
73 {
kono
parents: 14
diff changeset
74 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
75 fprintf (dump_file,
kono
parents: 14
diff changeset
76 " Not duplicating bb %i: it is single succ.\n",
kono
parents: 14
diff changeset
77 header->index);
kono
parents: 14
diff changeset
78 return false;
kono
parents: 14
diff changeset
79 }
kono
parents: 14
diff changeset
80
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 && flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 1)->dest))
16
kono
parents: 14
diff changeset
83 {
kono
parents: 14
diff changeset
84 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
85 fprintf (dump_file,
kono
parents: 14
diff changeset
86 " Not duplicating bb %i: both sucessors are in loop.\n",
kono
parents: 14
diff changeset
87 loop->num);
kono
parents: 14
diff changeset
88 return false;
kono
parents: 14
diff changeset
89 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 /* If this is not the original loop header, we want it to have just
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 one predecessor in order to match the && pattern. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 if (header != loop->header && !single_pred_p (header))
16
kono
parents: 14
diff changeset
94 {
kono
parents: 14
diff changeset
95 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
96 fprintf (dump_file,
kono
parents: 14
diff changeset
97 " Not duplicating bb %i: it has mutiple predecestors.\n",
kono
parents: 14
diff changeset
98 header->index);
kono
parents: 14
diff changeset
99 return false;
kono
parents: 14
diff changeset
100 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
102 gcond *last = safe_dyn_cast <gcond *> (last_stmt (header));
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
103 if (!last)
16
kono
parents: 14
diff changeset
104 {
kono
parents: 14
diff changeset
105 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
106 fprintf (dump_file,
kono
parents: 14
diff changeset
107 " Not duplicating bb %i: it does not end by conditional.\n",
kono
parents: 14
diff changeset
108 header->index);
kono
parents: 14
diff changeset
109 return false;
kono
parents: 14
diff changeset
110 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
112 for (gphi_iterator psi = gsi_start_phis (header); !gsi_end_p (psi);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
113 gsi_next (&psi))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
114 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
115 gphi *phi = psi.phi ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
116 tree res = gimple_phi_result (phi);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
117 if (INTEGRAL_TYPE_P (TREE_TYPE (res))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
118 || POINTER_TYPE_P (TREE_TYPE (res)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
119 gimple_set_uid (phi, 1 /* IV */);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
120 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
121 gimple_set_uid (phi, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
122 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
123
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
124 /* Count number of instructions and punt on calls.
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
125 Populate stmts INV/IV flag to later apply heuristics to the
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
126 kind of conditions we want to copy. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 for (bsi = gsi_start_bb (header); !gsi_end_p (bsi); gsi_next (&bsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 {
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
129 gimple *last = gsi_stmt (bsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 if (gimple_code (last) == GIMPLE_LABEL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
134 if (is_gimple_debug (last))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
135 continue;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
136
16
kono
parents: 14
diff changeset
137 if (gimple_code (last) == GIMPLE_CALL
kono
parents: 14
diff changeset
138 && (!gimple_inexpensive_call_p (as_a <gcall *> (last))
kono
parents: 14
diff changeset
139 /* IFN_LOOP_DIST_ALIAS means that inner loop is distributed
kono
parents: 14
diff changeset
140 at current loop's header. Don't copy in this case. */
kono
parents: 14
diff changeset
141 || gimple_call_internal_p (last, IFN_LOOP_DIST_ALIAS)))
kono
parents: 14
diff changeset
142 {
kono
parents: 14
diff changeset
143 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
144 fprintf (dump_file,
kono
parents: 14
diff changeset
145 " Not duplicating bb %i: it contains call.\n",
kono
parents: 14
diff changeset
146 header->index);
kono
parents: 14
diff changeset
147 return false;
kono
parents: 14
diff changeset
148 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 *limit -= estimate_num_insns (last, &eni_size_weights);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 if (*limit < 0)
16
kono
parents: 14
diff changeset
152 {
kono
parents: 14
diff changeset
153 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
154 fprintf (dump_file,
kono
parents: 14
diff changeset
155 " Not duplicating bb %i contains too many insns.\n",
kono
parents: 14
diff changeset
156 header->index);
kono
parents: 14
diff changeset
157 return false;
kono
parents: 14
diff changeset
158 }
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
159
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
160 /* Classify the stmt based on whether its computation is based
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
161 on a IV or whether it is invariant in the loop. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
162 gimple_set_uid (last, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
163 if (!gimple_vuse (last))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
164 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
165 bool inv = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
166 bool iv = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
167 ssa_op_iter i;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
168 tree op;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
169 FOR_EACH_SSA_TREE_OPERAND (op, last, i, SSA_OP_USE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
170 if (!SSA_NAME_IS_DEFAULT_DEF (op)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
171 && flow_bb_inside_loop_p (loop,
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
172 gimple_bb (SSA_NAME_DEF_STMT (op))))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
173 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
174 if (!(gimple_uid (SSA_NAME_DEF_STMT (op)) & 2 /* INV */))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
175 inv = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
176 if (gimple_uid (SSA_NAME_DEF_STMT (op)) & 1 /* IV */)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
177 iv = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
178 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
179 gimple_set_uid (last, (iv ? 1 : 0) | (inv ? 2 : 0));
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
180 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
182
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
183 /* If the condition tests a non-IV loop variant we do not want to rotate
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
184 the loop further. Unless this is the original loop header. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
185 tree lhs = gimple_cond_lhs (last);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
186 tree rhs = gimple_cond_rhs (last);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
187 if (header != loop->header
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
188 && ((TREE_CODE (lhs) == SSA_NAME
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
189 && !SSA_NAME_IS_DEFAULT_DEF (lhs)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
190 && flow_bb_inside_loop_p (loop, gimple_bb (SSA_NAME_DEF_STMT (lhs)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
191 && gimple_uid (SSA_NAME_DEF_STMT (lhs)) == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
192 || (TREE_CODE (rhs) == SSA_NAME
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
193 && !SSA_NAME_IS_DEFAULT_DEF (rhs)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
194 && flow_bb_inside_loop_p (loop,
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
195 gimple_bb (SSA_NAME_DEF_STMT (rhs)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
196 && gimple_uid (SSA_NAME_DEF_STMT (rhs)) == 0)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
197 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
198 if (dump_file && (dump_flags & TDF_DETAILS))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
199 fprintf (dump_file,
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
200 " Not duplicating bb %i: condition based on non-IV loop"
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
201 " variant.\n", header->index);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
202 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
203 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
204
16
kono
parents: 14
diff changeset
205 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
206 fprintf (dump_file, " Will duplicate bb %i\n", header->index);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 /* Checks whether LOOP is a do-while style loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 static bool
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
213 do_while_loop_p (class loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 {
16
kono
parents: 14
diff changeset
215 gimple *stmt = last_stmt (loop->latch);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 /* If the latch of the loop is not empty, it is not a do-while loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 if (stmt
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 && gimple_code (stmt) != GIMPLE_LABEL)
16
kono
parents: 14
diff changeset
220 {
kono
parents: 14
diff changeset
221 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
222 fprintf (dump_file,
kono
parents: 14
diff changeset
223 "Loop %i is not do-while loop: latch is not empty.\n",
kono
parents: 14
diff changeset
224 loop->num);
kono
parents: 14
diff changeset
225 return false;
kono
parents: 14
diff changeset
226 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
228 /* If the latch does not have a single predecessor, it is not a
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
229 do-while loop. */
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
230 if (!single_pred_p (loop->latch))
16
kono
parents: 14
diff changeset
231 {
kono
parents: 14
diff changeset
232 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
233 fprintf (dump_file,
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
234 "Loop %i is not do-while loop: latch has multiple "
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
235 "predecessors.\n", loop->num);
16
kono
parents: 14
diff changeset
236 return false;
kono
parents: 14
diff changeset
237 }
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
238
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
239 /* If the latch predecessor doesn't exit the loop, it is not a
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
240 do-while loop. */
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
241 if (!loop_exits_from_bb_p (loop, single_pred (loop->latch)))
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
242 {
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
243 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
244 fprintf (dump_file,
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
245 "Loop %i is not do-while loop: latch predecessor "
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
246 "does not exit loop.\n", loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
247 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
248 }
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
249
16
kono
parents: 14
diff changeset
250 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
251 fprintf (dump_file, "Loop %i is do-while loop\n", loop->num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
16
kono
parents: 14
diff changeset
256 namespace {
kono
parents: 14
diff changeset
257
kono
parents: 14
diff changeset
258 /* Common superclass for both header-copying phases. */
kono
parents: 14
diff changeset
259 class ch_base : public gimple_opt_pass
kono
parents: 14
diff changeset
260 {
kono
parents: 14
diff changeset
261 protected:
kono
parents: 14
diff changeset
262 ch_base (pass_data data, gcc::context *ctxt)
kono
parents: 14
diff changeset
263 : gimple_opt_pass (data, ctxt)
kono
parents: 14
diff changeset
264 {}
kono
parents: 14
diff changeset
265
kono
parents: 14
diff changeset
266 /* Copies headers of all loops in FUN for which process_loop_p is true. */
kono
parents: 14
diff changeset
267 unsigned int copy_headers (function *fun);
kono
parents: 14
diff changeset
268
kono
parents: 14
diff changeset
269 /* Return true to copy headers of LOOP or false to skip. */
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
270 virtual bool process_loop_p (class loop *loop) = 0;
16
kono
parents: 14
diff changeset
271 };
kono
parents: 14
diff changeset
272
kono
parents: 14
diff changeset
273 const pass_data pass_data_ch =
kono
parents: 14
diff changeset
274 {
kono
parents: 14
diff changeset
275 GIMPLE_PASS, /* type */
kono
parents: 14
diff changeset
276 "ch", /* name */
kono
parents: 14
diff changeset
277 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 14
diff changeset
278 TV_TREE_CH, /* tv_id */
kono
parents: 14
diff changeset
279 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 14
diff changeset
280 0, /* properties_provided */
kono
parents: 14
diff changeset
281 0, /* properties_destroyed */
kono
parents: 14
diff changeset
282 0, /* todo_flags_start */
kono
parents: 14
diff changeset
283 0, /* todo_flags_finish */
kono
parents: 14
diff changeset
284 };
kono
parents: 14
diff changeset
285
kono
parents: 14
diff changeset
286 class pass_ch : public ch_base
kono
parents: 14
diff changeset
287 {
kono
parents: 14
diff changeset
288 public:
kono
parents: 14
diff changeset
289 pass_ch (gcc::context *ctxt)
kono
parents: 14
diff changeset
290 : ch_base (pass_data_ch, ctxt)
kono
parents: 14
diff changeset
291 {}
kono
parents: 14
diff changeset
292
kono
parents: 14
diff changeset
293 /* opt_pass methods: */
kono
parents: 14
diff changeset
294 virtual bool gate (function *) { return flag_tree_ch != 0; }
kono
parents: 14
diff changeset
295
kono
parents: 14
diff changeset
296 /* Initialize and finalize loop structures, copying headers inbetween. */
kono
parents: 14
diff changeset
297 virtual unsigned int execute (function *);
kono
parents: 14
diff changeset
298
kono
parents: 14
diff changeset
299 opt_pass * clone () { return new pass_ch (m_ctxt); }
kono
parents: 14
diff changeset
300
kono
parents: 14
diff changeset
301 protected:
kono
parents: 14
diff changeset
302 /* ch_base method: */
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
303 virtual bool process_loop_p (class loop *loop);
16
kono
parents: 14
diff changeset
304 }; // class pass_ch
kono
parents: 14
diff changeset
305
kono
parents: 14
diff changeset
306 const pass_data pass_data_ch_vect =
kono
parents: 14
diff changeset
307 {
kono
parents: 14
diff changeset
308 GIMPLE_PASS, /* type */
kono
parents: 14
diff changeset
309 "ch_vect", /* name */
kono
parents: 14
diff changeset
310 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 14
diff changeset
311 TV_TREE_CH, /* tv_id */
kono
parents: 14
diff changeset
312 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 14
diff changeset
313 0, /* properties_provided */
kono
parents: 14
diff changeset
314 0, /* properties_destroyed */
kono
parents: 14
diff changeset
315 0, /* todo_flags_start */
kono
parents: 14
diff changeset
316 0, /* todo_flags_finish */
kono
parents: 14
diff changeset
317 };
kono
parents: 14
diff changeset
318
kono
parents: 14
diff changeset
319 /* This is a more aggressive version of the same pass, designed to run just
kono
parents: 14
diff changeset
320 before if-conversion and vectorization, to put more loops into the form
kono
parents: 14
diff changeset
321 required for those phases. */
kono
parents: 14
diff changeset
322 class pass_ch_vect : public ch_base
kono
parents: 14
diff changeset
323 {
kono
parents: 14
diff changeset
324 public:
kono
parents: 14
diff changeset
325 pass_ch_vect (gcc::context *ctxt)
kono
parents: 14
diff changeset
326 : ch_base (pass_data_ch_vect, ctxt)
kono
parents: 14
diff changeset
327 {}
kono
parents: 14
diff changeset
328
kono
parents: 14
diff changeset
329 /* opt_pass methods: */
kono
parents: 14
diff changeset
330 virtual bool gate (function *fun)
kono
parents: 14
diff changeset
331 {
kono
parents: 14
diff changeset
332 return flag_tree_ch != 0
kono
parents: 14
diff changeset
333 && (flag_tree_loop_vectorize != 0 || fun->has_force_vectorize_loops);
kono
parents: 14
diff changeset
334 }
kono
parents: 14
diff changeset
335
kono
parents: 14
diff changeset
336 /* Just copy headers, no initialization/finalization of loop structures. */
kono
parents: 14
diff changeset
337 virtual unsigned int execute (function *);
kono
parents: 14
diff changeset
338
kono
parents: 14
diff changeset
339 protected:
kono
parents: 14
diff changeset
340 /* ch_base method: */
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
341 virtual bool process_loop_p (class loop *loop);
16
kono
parents: 14
diff changeset
342 }; // class pass_ch_vect
kono
parents: 14
diff changeset
343
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 /* For all loops, copy the condition at the end of the loop body in front
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 of the loop. This is beneficial since it increases efficiency of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 code motion optimizations. It also saves one jump on entry to the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
16
kono
parents: 14
diff changeset
348 unsigned int
kono
parents: 14
diff changeset
349 ch_base::copy_headers (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 {
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
351 class loop *loop;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 basic_block header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 edge exit, entry;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 basic_block *bbs, *copied_bbs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 unsigned n_bbs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 unsigned bbs_size;
16
kono
parents: 14
diff changeset
357 bool changed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358
16
kono
parents: 14
diff changeset
359 if (number_of_loops (fun) <= 1)
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
360 return 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
16
kono
parents: 14
diff changeset
362 bbs = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun));
kono
parents: 14
diff changeset
363 copied_bbs = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun));
kono
parents: 14
diff changeset
364 bbs_size = n_basic_blocks_for_fn (fun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
366 auto_vec<std::pair<edge, loop_p> > copied;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
367
16
kono
parents: 14
diff changeset
368 FOR_EACH_LOOP (loop, 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 {
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
370 int initial_limit = param_max_loop_header_insns;
16
kono
parents: 14
diff changeset
371 int remaining_limit = initial_limit;
kono
parents: 14
diff changeset
372 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 14
diff changeset
373 fprintf (dump_file,
kono
parents: 14
diff changeset
374 "Analyzing loop %i\n", loop->num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 header = loop->header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 /* If the loop is already a do-while style one (either because it was
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 written as such, or because jump threading transformed it into one),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 we might be in fact peeling the first iteration of the loop. This
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
381 in general is not a good idea. Also avoid touching infinite loops. */
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
382 if (!loop_has_exit_edges (loop)
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
383 || !process_loop_p (loop))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 /* Iterate the header copying up to limit; this takes care of the cases
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 like while (a && b) {...}, where we want to have both of the conditions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 copied. TODO -- handle while (a || b) - like cases, by not requiring
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 the header to have just a single successor and copying up to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 postdominator. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 exit = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 n_bbs = 0;
16
kono
parents: 14
diff changeset
394 while (should_duplicate_loop_header_p (header, loop, &remaining_limit))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 /* Find a successor of header that is inside a loop; i.e. the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 header after the condition is copied. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 exit = EDGE_SUCC (header, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 exit = EDGE_SUCC (header, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 bbs[n_bbs++] = header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 gcc_assert (bbs_size > n_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 header = exit->dest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 if (!exit)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 fprintf (dump_file,
16
kono
parents: 14
diff changeset
412 "Duplicating header of the loop %d up to edge %d->%d,"
kono
parents: 14
diff changeset
413 " %i insns.\n",
kono
parents: 14
diff changeset
414 loop->num, exit->src->index, exit->dest->index,
kono
parents: 14
diff changeset
415 initial_limit - remaining_limit);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 /* Ensure that the header will have just the latch as a predecessor
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 inside the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 if (!single_pred_p (exit->dest))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 exit = single_pred_edge (split_edge (exit));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 entry = loop_preheader_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423
16
kono
parents: 14
diff changeset
424 propagate_threaded_block_debug_into (exit->dest, entry->dest);
kono
parents: 14
diff changeset
425 if (!gimple_duplicate_sese_region (entry, exit, bbs, n_bbs, copied_bbs,
kono
parents: 14
diff changeset
426 true))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 fprintf (dump_file, "Duplication failed.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 }
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
431 copied.safe_push (std::make_pair (entry, loop));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 /* If the loop has the form "for (i = j; i < j + 10; i++)" then
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 this copying can introduce a case where we rely on undefined
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 signed overflow to eliminate the preheader condition, because
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 we assume that "j < j + 10" is true. We don't want to warn
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 about that case for -Wstrict-overflow, because in general we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 don't warn about overflow involving loops. Prevent the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 warning by setting the no_warning flag in the condition. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 if (warn_strict_overflow > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 unsigned int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 for (i = 0; i < n_bbs; ++i)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 gimple_stmt_iterator bsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 for (bsi = gsi_start_bb (copied_bbs[i]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 !gsi_end_p (bsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 gsi_next (&bsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 {
16
kono
parents: 14
diff changeset
452 gimple *stmt = gsi_stmt (bsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 if (gimple_code (stmt) == GIMPLE_COND)
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
454 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
455 tree lhs = gimple_cond_lhs (stmt);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
456 if (gimple_cond_code (stmt) != EQ_EXPR
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
457 && gimple_cond_code (stmt) != NE_EXPR
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
458 && INTEGRAL_TYPE_P (TREE_TYPE (lhs))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
459 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (lhs)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
460 gimple_set_no_warning (stmt, true);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
461 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 else if (is_gimple_assign (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
465 tree rhs1 = gimple_assign_rhs1 (stmt);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
466 if (TREE_CODE_CLASS (rhs_code) == tcc_comparison
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
467 && rhs_code != EQ_EXPR
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
468 && rhs_code != NE_EXPR
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
469 && INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
470 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 gimple_set_no_warning (stmt, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 /* Ensure that the latch and the preheader is simple (we know that they
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 are not now, since there was the loop exit condition. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 split_edge (loop_preheader_edge (loop));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 split_edge (loop_latch_edge (loop));
16
kono
parents: 14
diff changeset
481
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
482 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
483 {
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
484 if (do_while_loop_p (loop))
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
485 fprintf (dump_file, "Loop %d is now do-while loop.\n", loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
486 else
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
487 fprintf (dump_file, "Loop %d is still not do-while loop.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
488 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
489 }
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
490
16
kono
parents: 14
diff changeset
491 changed = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493
16
kono
parents: 14
diff changeset
494 if (changed)
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
495 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
496 update_ssa (TODO_update_ssa);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
497 /* After updating SSA form perform CSE on the loop header
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
498 copies. This is esp. required for the pass before
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
499 vectorization since nothing cleans up copied exit tests
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
500 that can now be simplified. CSE from the entry of the
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
501 region we copied till all loop exit blocks but not
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
502 entering the loop itself. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
503 for (unsigned i = 0; i < copied.length (); ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
504 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
505 edge entry = copied[i].first;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
506 loop_p loop = copied[i].second;
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
507 vec<edge> exit_edges = get_loop_exit_edges (loop);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
508 bitmap exit_bbs = BITMAP_ALLOC (NULL);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
509 for (unsigned j = 0; j < exit_edges.length (); ++j)
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
510 bitmap_set_bit (exit_bbs, exit_edges[j]->dest->index);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
511 bitmap_set_bit (exit_bbs, loop->header->index);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
512 do_rpo_vn (cfun, entry, exit_bbs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
513 BITMAP_FREE (exit_bbs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
514 exit_edges.release ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
515 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
516 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 free (bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 free (copied_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519
16
kono
parents: 14
diff changeset
520 return changed ? TODO_cleanup_cfg : 0;
kono
parents: 14
diff changeset
521 }
kono
parents: 14
diff changeset
522
kono
parents: 14
diff changeset
523 /* Initialize the loop structures we need, and finalize after. */
kono
parents: 14
diff changeset
524
kono
parents: 14
diff changeset
525 unsigned int
kono
parents: 14
diff changeset
526 pass_ch::execute (function *fun)
kono
parents: 14
diff changeset
527 {
kono
parents: 14
diff changeset
528 loop_optimizer_init (LOOPS_HAVE_PREHEADERS
17
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
529 | LOOPS_HAVE_SIMPLE_LATCHES
84e7813d76e9 gcc-8.2
mir3636
parents: 16
diff changeset
530 | LOOPS_HAVE_RECORDED_EXITS);
16
kono
parents: 14
diff changeset
531
kono
parents: 14
diff changeset
532 unsigned int res = copy_headers (fun);
kono
parents: 14
diff changeset
533
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 loop_optimizer_finalize ();
16
kono
parents: 14
diff changeset
535 return res;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537
16
kono
parents: 14
diff changeset
538 /* Assume an earlier phase has already initialized all the loop structures that
kono
parents: 14
diff changeset
539 we need here (and perhaps others too), and that these will be finalized by
kono
parents: 14
diff changeset
540 a later phase. */
kono
parents: 14
diff changeset
541
kono
parents: 14
diff changeset
542 unsigned int
kono
parents: 14
diff changeset
543 pass_ch_vect::execute (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 {
16
kono
parents: 14
diff changeset
545 return copy_headers (fun);
kono
parents: 14
diff changeset
546 }
kono
parents: 14
diff changeset
547
kono
parents: 14
diff changeset
548 /* Apply header copying according to a very simple test of do-while shape. */
kono
parents: 14
diff changeset
549
kono
parents: 14
diff changeset
550 bool
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
551 pass_ch::process_loop_p (class loop *loop)
16
kono
parents: 14
diff changeset
552 {
kono
parents: 14
diff changeset
553 return !do_while_loop_p (loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555
16
kono
parents: 14
diff changeset
556 /* Apply header-copying to loops where we might enable vectorization. */
kono
parents: 14
diff changeset
557
kono
parents: 14
diff changeset
558 bool
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
559 pass_ch_vect::process_loop_p (class loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 {
16
kono
parents: 14
diff changeset
561 if (!flag_tree_loop_vectorize && !loop->force_vectorize)
kono
parents: 14
diff changeset
562 return false;
kono
parents: 14
diff changeset
563
kono
parents: 14
diff changeset
564 if (loop->dont_vectorize)
kono
parents: 14
diff changeset
565 return false;
kono
parents: 14
diff changeset
566
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
567 /* The vectorizer won't handle anything with multiple exits, so skip. */
16
kono
parents: 14
diff changeset
568 edge exit = single_exit (loop);
kono
parents: 14
diff changeset
569 if (!exit)
kono
parents: 14
diff changeset
570 return false;
kono
parents: 14
diff changeset
571
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
572 if (!do_while_loop_p (loop))
1830386684a0 gcc-9.2.0
anatofuz
parents: 17
diff changeset
573 return true;
16
kono
parents: 14
diff changeset
574
kono
parents: 14
diff changeset
575 return false;
kono
parents: 14
diff changeset
576 }
kono
parents: 14
diff changeset
577
kono
parents: 14
diff changeset
578 } // anon namespace
kono
parents: 14
diff changeset
579
kono
parents: 14
diff changeset
580 gimple_opt_pass *
kono
parents: 14
diff changeset
581 make_pass_ch_vect (gcc::context *ctxt)
kono
parents: 14
diff changeset
582 {
kono
parents: 14
diff changeset
583 return new pass_ch_vect (ctxt);
kono
parents: 14
diff changeset
584 }
kono
parents: 14
diff changeset
585
kono
parents: 14
diff changeset
586 gimple_opt_pass *
kono
parents: 14
diff changeset
587 make_pass_ch (gcc::context *ctxt)
kono
parents: 14
diff changeset
588 {
kono
parents: 14
diff changeset
589 return new pass_ch (ctxt);
kono
parents: 14
diff changeset
590 }