annotate gcc/tree-ssa-forwprop.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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 /* Forward propagation of expressions for single use variables.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
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,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 GNU General Public License for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
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"
111
kono
parents: 67
diff changeset
23 #include "backend.h"
kono
parents: 67
diff changeset
24 #include "rtl.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "tree.h"
111
kono
parents: 67
diff changeset
26 #include "gimple.h"
kono
parents: 67
diff changeset
27 #include "cfghooks.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "tree-pass.h"
111
kono
parents: 67
diff changeset
29 #include "ssa.h"
kono
parents: 67
diff changeset
30 #include "expmed.h"
kono
parents: 67
diff changeset
31 #include "optabs-query.h"
kono
parents: 67
diff changeset
32 #include "gimple-pretty-print.h"
kono
parents: 67
diff changeset
33 #include "fold-const.h"
kono
parents: 67
diff changeset
34 #include "stor-layout.h"
kono
parents: 67
diff changeset
35 #include "gimple-fold.h"
kono
parents: 67
diff changeset
36 #include "tree-eh.h"
kono
parents: 67
diff changeset
37 #include "gimplify.h"
kono
parents: 67
diff changeset
38 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
39 #include "gimplify-me.h"
kono
parents: 67
diff changeset
40 #include "tree-cfg.h"
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
41 #include "expr.h"
111
kono
parents: 67
diff changeset
42 #include "tree-dfa.h"
kono
parents: 67
diff changeset
43 #include "tree-ssa-propagate.h"
kono
parents: 67
diff changeset
44 #include "tree-ssa-dom.h"
kono
parents: 67
diff changeset
45 #include "builtins.h"
kono
parents: 67
diff changeset
46 #include "tree-cfgcleanup.h"
kono
parents: 67
diff changeset
47 #include "cfganal.h"
kono
parents: 67
diff changeset
48 #include "optabs-tree.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
49 #include "tree-vector-builder.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
50 #include "vec-perm-indices.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 /* This pass propagates the RHS of assignment statements into use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 sites of the LHS of the assignment. It's basically a specialized
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 form of tree combination. It is hoped all of this can disappear
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 when we have a generalized tree combiner.
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 One class of common cases we handle is forward propagating a single use
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
58 variable into a COND_EXPR.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 x = a COND b;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 if (x) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 Will be transformed into:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 if (a COND b) goto ... else goto ...
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
68
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 Similarly for the tests (x == 0), (x != 0), (x == 1) and (x != 1).
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 Or (assuming c1 and c2 are constants):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 bb0:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
74 x = a + c1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 if (x EQ/NEQ c2) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 Will be transformed into:
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 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 if (a EQ/NEQ (c2 - c1)) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 Similarly for x = a - c1.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
83
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 Or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 x = !a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 if (x) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 Will be transformed into:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 if (a == 0) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 Similarly for the tests (x == 0), (x != 0), (x == 1) and (x != 1).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 For these cases, we propagate A into all, possibly more than one,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 COND_EXPRs that use X.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 Or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 x = (typecast) a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 if (x) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 Will be transformed into:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 bb0:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 if (a != 0) goto ... else goto ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 (Assuming a is an integral type and x is a boolean or x is an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 integral and a is a boolean.)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 Similarly for the tests (x == 0), (x != 0), (x == 1) and (x != 1).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 For these cases, we propagate A into all, possibly more than one,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 COND_EXPRs that use X.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 In addition to eliminating the variable and the statement which assigns
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 a value to the variable, we may be able to later thread the jump without
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 adding insane complexity in the dominator optimizer.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 Also note these transformations can cascade. We handle this by having
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 a worklist of COND_EXPR statements to examine. As we make a change to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 a statement, we put it back on the worklist to examine on the next
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 iteration of the main loop.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 A second class of propagation opportunities arises for ADDR_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 nodes.
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 ptr = &x->y->z;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 res = *ptr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 Will get turned into
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 res = x->y->z;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 Or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 ptr = (type1*)&type2var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 res = *ptr
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 Will get turned into (if type1 and type2 are the same size
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 and neither have volatile on them):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 res = VIEW_CONVERT_EXPR<type1>(type2var)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 Or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 ptr = &x[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 ptr2 = ptr + <constant>;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 Will get turned into
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 ptr2 = &x[constant/elementsize];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 Or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 ptr = &x[0];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 offset = index * element_size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 offset_p = (pointer) offset;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 ptr2 = ptr + offset_p
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 Will get turned into:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 ptr2 = &x[index];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
164 Or
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
165 ssa = (int) decl
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
166 res = ssa & 1
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
167
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
168 Provided that decl has known alignment >= 2, will get turned into
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
169
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
170 res = 0
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
171
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 We also propagate casts into SWITCH_EXPR and COND_EXPR conditions to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 allow us to remove the cast and {NOT_EXPR,NEG_EXPR} into a subsequent
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 {NOT_EXPR,NEG_EXPR}.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 This will (of course) be extended as other needs arise. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
111
kono
parents: 67
diff changeset
178 static bool forward_propagate_addr_expr (tree, tree, bool);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
111
kono
parents: 67
diff changeset
180 /* Set to true if we delete dead edges during the optimization. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 static bool cfg_changed;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
111
kono
parents: 67
diff changeset
183 static tree rhs_to_tree (tree type, gimple *stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
111
kono
parents: 67
diff changeset
185 static bitmap to_purge;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
111
kono
parents: 67
diff changeset
187 /* Const-and-copy lattice. */
kono
parents: 67
diff changeset
188 static vec<tree> lattice;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
111
kono
parents: 67
diff changeset
190 /* Set the lattice entry for NAME to VAL. */
kono
parents: 67
diff changeset
191 static void
kono
parents: 67
diff changeset
192 fwprop_set_lattice_val (tree name, tree val)
kono
parents: 67
diff changeset
193 {
kono
parents: 67
diff changeset
194 if (TREE_CODE (name) == SSA_NAME)
kono
parents: 67
diff changeset
195 {
kono
parents: 67
diff changeset
196 if (SSA_NAME_VERSION (name) >= lattice.length ())
kono
parents: 67
diff changeset
197 {
kono
parents: 67
diff changeset
198 lattice.reserve (num_ssa_names - lattice.length ());
kono
parents: 67
diff changeset
199 lattice.quick_grow_cleared (num_ssa_names);
kono
parents: 67
diff changeset
200 }
kono
parents: 67
diff changeset
201 lattice[SSA_NAME_VERSION (name)] = val;
kono
parents: 67
diff changeset
202 }
kono
parents: 67
diff changeset
203 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204
111
kono
parents: 67
diff changeset
205 /* Invalidate the lattice entry for NAME, done when releasing SSA names. */
kono
parents: 67
diff changeset
206 static void
kono
parents: 67
diff changeset
207 fwprop_invalidate_lattice (tree name)
kono
parents: 67
diff changeset
208 {
kono
parents: 67
diff changeset
209 if (name
kono
parents: 67
diff changeset
210 && TREE_CODE (name) == SSA_NAME
kono
parents: 67
diff changeset
211 && SSA_NAME_VERSION (name) < lattice.length ())
kono
parents: 67
diff changeset
212 lattice[SSA_NAME_VERSION (name)] = NULL_TREE;
kono
parents: 67
diff changeset
213 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 /* Get the statement we can propagate from into NAME skipping
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 trivial copies. Returns the statement which defines the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 propagation source or NULL_TREE if there is no such one.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 If SINGLE_USE_ONLY is set considers only sources which have
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 a single use chain up to NAME. If SINGLE_USE_P is non-null,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 it is set to whether the chain to NAME is a single use chain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 or not. SINGLE_USE_P is not written to if SINGLE_USE_ONLY is set. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
111
kono
parents: 67
diff changeset
224 static gimple *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 get_prop_source_stmt (tree name, bool single_use_only, bool *single_use_p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 bool single_use = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 do {
111
kono
parents: 67
diff changeset
230 gimple *def_stmt = SSA_NAME_DEF_STMT (name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 if (!has_single_use (name))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 single_use = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 if (single_use_only)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 /* If name is defined by a PHI node or is the default def, bail out. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
240 if (!is_gimple_assign (def_stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
111
kono
parents: 67
diff changeset
243 /* If def_stmt is a simple copy, continue looking. */
kono
parents: 67
diff changeset
244 if (gimple_assign_rhs_code (def_stmt) == SSA_NAME)
kono
parents: 67
diff changeset
245 name = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
246 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 if (!single_use_only && single_use_p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 *single_use_p = single_use;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
111
kono
parents: 67
diff changeset
251 return def_stmt;
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 } while (1);
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 /* Checks if the destination ssa name in DEF_STMT can be used as
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 propagation source. Returns true if so, otherwise false. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 static bool
111
kono
parents: 67
diff changeset
260 can_propagate_from (gimple *def_stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 gcc_assert (is_gimple_assign (def_stmt));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
263
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 /* If the rhs has side-effects we cannot propagate from it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 if (gimple_has_volatile_ops (def_stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 /* If the rhs is a load we cannot propagate from it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 if (TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) == tcc_reference
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) == tcc_declaration)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 /* Constants can be always propagated. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
274 if (gimple_assign_single_p (def_stmt)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
275 && is_gimple_min_invariant (gimple_assign_rhs1 (def_stmt)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 /* We cannot propagate ssa names that occur in abnormal phi nodes. */
111
kono
parents: 67
diff changeset
279 if (stmt_references_abnormal_ssa_name (def_stmt))
kono
parents: 67
diff changeset
280 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 /* If the definition is a conversion of a pointer to a function type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 then we can not apply optimizations as some targets require
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 function pointers to be canonicalized and in this case this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 optimization could eliminate a necessary canonicalization. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
286 if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 tree rhs = gimple_assign_rhs1 (def_stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 if (POINTER_TYPE_P (TREE_TYPE (rhs))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 && TREE_CODE (TREE_TYPE (TREE_TYPE (rhs))) == FUNCTION_TYPE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
293
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
111
kono
parents: 67
diff changeset
297 /* Remove a chain of dead statements starting at the definition of
kono
parents: 67
diff changeset
298 NAME. The chain is linked via the first operand of the defining statements.
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
299 If NAME was replaced in its only use then this function can be used
111
kono
parents: 67
diff changeset
300 to clean up dead stmts. The function handles already released SSA
kono
parents: 67
diff changeset
301 names gracefully.
kono
parents: 67
diff changeset
302 Returns true if cleanup-cfg has to run. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 static bool
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
305 remove_prop_source_from_use (tree name)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 gimple_stmt_iterator gsi;
111
kono
parents: 67
diff changeset
308 gimple *stmt;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
309 bool cfg_changed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 do {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
312 basic_block bb;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
313
111
kono
parents: 67
diff changeset
314 if (SSA_NAME_IN_FREE_LIST (name)
kono
parents: 67
diff changeset
315 || SSA_NAME_IS_DEFAULT_DEF (name)
kono
parents: 67
diff changeset
316 || !has_zero_uses (name))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
317 return cfg_changed;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 stmt = SSA_NAME_DEF_STMT (name);
111
kono
parents: 67
diff changeset
320 if (gimple_code (stmt) == GIMPLE_PHI
kono
parents: 67
diff changeset
321 || gimple_has_side_effects (stmt))
kono
parents: 67
diff changeset
322 return cfg_changed;
kono
parents: 67
diff changeset
323
kono
parents: 67
diff changeset
324 bb = gimple_bb (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 gsi = gsi_for_stmt (stmt);
111
kono
parents: 67
diff changeset
326 unlink_stmt_vdef (stmt);
kono
parents: 67
diff changeset
327 if (gsi_remove (&gsi, true))
kono
parents: 67
diff changeset
328 bitmap_set_bit (to_purge, bb->index);
kono
parents: 67
diff changeset
329 fwprop_invalidate_lattice (gimple_get_lhs (stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 release_defs (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331
111
kono
parents: 67
diff changeset
332 name = is_gimple_assign (stmt) ? gimple_assign_rhs1 (stmt) : NULL_TREE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 } while (name && TREE_CODE (name) == SSA_NAME);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
335 return cfg_changed;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
111
kono
parents: 67
diff changeset
338 /* Return the rhs of a gassign *STMT in a form of a single tree,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 converted to type TYPE.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
340
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 This should disappear, but is needed so we can combine expressions and use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 the fold() interfaces. Long term, we need to develop folding and combine
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 routines that deal with gimple exclusively . */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 static tree
111
kono
parents: 67
diff changeset
346 rhs_to_tree (tree type, gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
348 location_t loc = gimple_location (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 enum tree_code code = gimple_assign_rhs_code (stmt);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
350 if (get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
351 return fold_build3_loc (loc, code, type, gimple_assign_rhs1 (stmt),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
352 gimple_assign_rhs2 (stmt),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
353 gimple_assign_rhs3 (stmt));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
354 else if (get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
355 return fold_build2_loc (loc, code, type, gimple_assign_rhs1 (stmt),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 gimple_assign_rhs2 (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 else if (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 return build1 (code, type, gimple_assign_rhs1 (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 else if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 return gimple_assign_rhs1 (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 /* Combine OP0 CODE OP1 in the context of a COND_EXPR. Returns
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 the folded result in a form suitable for COND_EXPR_COND or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 NULL_TREE, if there is no suitable simplified form. If
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 INVARIANT_ONLY is true only gimple_min_invariant results are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 considered simplified. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 static tree
111
kono
parents: 67
diff changeset
372 combine_cond_expr_cond (gimple *stmt, enum tree_code code, tree type,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 tree op0, tree op1, bool invariant_only)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 tree t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 gcc_assert (TREE_CODE_CLASS (code) == tcc_comparison);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378
111
kono
parents: 67
diff changeset
379 fold_defer_overflow_warnings ();
kono
parents: 67
diff changeset
380 t = fold_binary_loc (gimple_location (stmt), code, type, op0, op1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 if (!t)
111
kono
parents: 67
diff changeset
382 {
kono
parents: 67
diff changeset
383 fold_undefer_overflow_warnings (false, NULL, 0);
kono
parents: 67
diff changeset
384 return NULL_TREE;
kono
parents: 67
diff changeset
385 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 /* Require that we got a boolean type out if we put one in. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 gcc_assert (TREE_CODE (TREE_TYPE (t)) == TREE_CODE (type));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 /* Canonicalize the combined condition for use in a COND_EXPR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 t = canonicalize_cond_expr_cond (t);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 /* Bail out if we required an invariant but didn't get one. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 if (!t || (invariant_only && !is_gimple_min_invariant (t)))
111
kono
parents: 67
diff changeset
395 {
kono
parents: 67
diff changeset
396 fold_undefer_overflow_warnings (false, NULL, 0);
kono
parents: 67
diff changeset
397 return NULL_TREE;
kono
parents: 67
diff changeset
398 }
kono
parents: 67
diff changeset
399
kono
parents: 67
diff changeset
400 fold_undefer_overflow_warnings (!gimple_no_warning_p (stmt), stmt, 0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 return t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
111
kono
parents: 67
diff changeset
405 /* Combine the comparison OP0 CODE OP1 at LOC with the defining statements
kono
parents: 67
diff changeset
406 of its operand. Return a new comparison tree or NULL_TREE if there
kono
parents: 67
diff changeset
407 were no simplifying combines. */
kono
parents: 67
diff changeset
408
kono
parents: 67
diff changeset
409 static tree
kono
parents: 67
diff changeset
410 forward_propagate_into_comparison_1 (gimple *stmt,
kono
parents: 67
diff changeset
411 enum tree_code code, tree type,
kono
parents: 67
diff changeset
412 tree op0, tree op1)
kono
parents: 67
diff changeset
413 {
kono
parents: 67
diff changeset
414 tree tmp = NULL_TREE;
kono
parents: 67
diff changeset
415 tree rhs0 = NULL_TREE, rhs1 = NULL_TREE;
kono
parents: 67
diff changeset
416 bool single_use0_p = false, single_use1_p = false;
kono
parents: 67
diff changeset
417
kono
parents: 67
diff changeset
418 /* For comparisons use the first operand, that is likely to
kono
parents: 67
diff changeset
419 simplify comparisons against constants. */
kono
parents: 67
diff changeset
420 if (TREE_CODE (op0) == SSA_NAME)
kono
parents: 67
diff changeset
421 {
kono
parents: 67
diff changeset
422 gimple *def_stmt = get_prop_source_stmt (op0, false, &single_use0_p);
kono
parents: 67
diff changeset
423 if (def_stmt && can_propagate_from (def_stmt))
kono
parents: 67
diff changeset
424 {
kono
parents: 67
diff changeset
425 enum tree_code def_code = gimple_assign_rhs_code (def_stmt);
kono
parents: 67
diff changeset
426 bool invariant_only_p = !single_use0_p;
kono
parents: 67
diff changeset
427
kono
parents: 67
diff changeset
428 rhs0 = rhs_to_tree (TREE_TYPE (op1), def_stmt);
kono
parents: 67
diff changeset
429
kono
parents: 67
diff changeset
430 /* Always combine comparisons or conversions from booleans. */
kono
parents: 67
diff changeset
431 if (TREE_CODE (op1) == INTEGER_CST
kono
parents: 67
diff changeset
432 && ((CONVERT_EXPR_CODE_P (def_code)
kono
parents: 67
diff changeset
433 && TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs0, 0)))
kono
parents: 67
diff changeset
434 == BOOLEAN_TYPE)
kono
parents: 67
diff changeset
435 || TREE_CODE_CLASS (def_code) == tcc_comparison))
kono
parents: 67
diff changeset
436 invariant_only_p = false;
kono
parents: 67
diff changeset
437
kono
parents: 67
diff changeset
438 tmp = combine_cond_expr_cond (stmt, code, type,
kono
parents: 67
diff changeset
439 rhs0, op1, invariant_only_p);
kono
parents: 67
diff changeset
440 if (tmp)
kono
parents: 67
diff changeset
441 return tmp;
kono
parents: 67
diff changeset
442 }
kono
parents: 67
diff changeset
443 }
kono
parents: 67
diff changeset
444
kono
parents: 67
diff changeset
445 /* If that wasn't successful, try the second operand. */
kono
parents: 67
diff changeset
446 if (TREE_CODE (op1) == SSA_NAME)
kono
parents: 67
diff changeset
447 {
kono
parents: 67
diff changeset
448 gimple *def_stmt = get_prop_source_stmt (op1, false, &single_use1_p);
kono
parents: 67
diff changeset
449 if (def_stmt && can_propagate_from (def_stmt))
kono
parents: 67
diff changeset
450 {
kono
parents: 67
diff changeset
451 rhs1 = rhs_to_tree (TREE_TYPE (op0), def_stmt);
kono
parents: 67
diff changeset
452 tmp = combine_cond_expr_cond (stmt, code, type,
kono
parents: 67
diff changeset
453 op0, rhs1, !single_use1_p);
kono
parents: 67
diff changeset
454 if (tmp)
kono
parents: 67
diff changeset
455 return tmp;
kono
parents: 67
diff changeset
456 }
kono
parents: 67
diff changeset
457 }
kono
parents: 67
diff changeset
458
kono
parents: 67
diff changeset
459 /* If that wasn't successful either, try both operands. */
kono
parents: 67
diff changeset
460 if (rhs0 != NULL_TREE
kono
parents: 67
diff changeset
461 && rhs1 != NULL_TREE)
kono
parents: 67
diff changeset
462 tmp = combine_cond_expr_cond (stmt, code, type,
kono
parents: 67
diff changeset
463 rhs0, rhs1,
kono
parents: 67
diff changeset
464 !(single_use0_p && single_use1_p));
kono
parents: 67
diff changeset
465
kono
parents: 67
diff changeset
466 return tmp;
kono
parents: 67
diff changeset
467 }
kono
parents: 67
diff changeset
468
kono
parents: 67
diff changeset
469 /* Propagate from the ssa name definition statements of the assignment
kono
parents: 67
diff changeset
470 from a comparison at *GSI into the conditional if that simplifies it.
kono
parents: 67
diff changeset
471 Returns 1 if the stmt was modified and 2 if the CFG needs cleanup,
kono
parents: 67
diff changeset
472 otherwise returns 0. */
kono
parents: 67
diff changeset
473
kono
parents: 67
diff changeset
474 static int
kono
parents: 67
diff changeset
475 forward_propagate_into_comparison (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
476 {
kono
parents: 67
diff changeset
477 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
478 tree tmp;
kono
parents: 67
diff changeset
479 bool cfg_changed = false;
kono
parents: 67
diff changeset
480 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
kono
parents: 67
diff changeset
481 tree rhs1 = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
482 tree rhs2 = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
483
kono
parents: 67
diff changeset
484 /* Combine the comparison with defining statements. */
kono
parents: 67
diff changeset
485 tmp = forward_propagate_into_comparison_1 (stmt,
kono
parents: 67
diff changeset
486 gimple_assign_rhs_code (stmt),
kono
parents: 67
diff changeset
487 type, rhs1, rhs2);
kono
parents: 67
diff changeset
488 if (tmp && useless_type_conversion_p (type, TREE_TYPE (tmp)))
kono
parents: 67
diff changeset
489 {
kono
parents: 67
diff changeset
490 gimple_assign_set_rhs_from_tree (gsi, tmp);
kono
parents: 67
diff changeset
491 fold_stmt (gsi);
kono
parents: 67
diff changeset
492 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
493
kono
parents: 67
diff changeset
494 if (TREE_CODE (rhs1) == SSA_NAME)
kono
parents: 67
diff changeset
495 cfg_changed |= remove_prop_source_from_use (rhs1);
kono
parents: 67
diff changeset
496 if (TREE_CODE (rhs2) == SSA_NAME)
kono
parents: 67
diff changeset
497 cfg_changed |= remove_prop_source_from_use (rhs2);
kono
parents: 67
diff changeset
498 return cfg_changed ? 2 : 1;
kono
parents: 67
diff changeset
499 }
kono
parents: 67
diff changeset
500
kono
parents: 67
diff changeset
501 return 0;
kono
parents: 67
diff changeset
502 }
kono
parents: 67
diff changeset
503
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 /* Propagate from the ssa name definition statements of COND_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 in GIMPLE_COND statement STMT into the conditional if that simplifies it.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 Returns zero if no statement was changed, one if there were
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 changes and two if cfg_cleanup needs to run.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
508
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 This must be kept in sync with forward_propagate_into_cond. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 static int
111
kono
parents: 67
diff changeset
512 forward_propagate_into_gimple_cond (gcond *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 {
111
kono
parents: 67
diff changeset
514 tree tmp;
kono
parents: 67
diff changeset
515 enum tree_code code = gimple_cond_code (stmt);
kono
parents: 67
diff changeset
516 bool cfg_changed = false;
kono
parents: 67
diff changeset
517 tree rhs1 = gimple_cond_lhs (stmt);
kono
parents: 67
diff changeset
518 tree rhs2 = gimple_cond_rhs (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519
111
kono
parents: 67
diff changeset
520 /* We can do tree combining on SSA_NAME and comparison expressions. */
kono
parents: 67
diff changeset
521 if (TREE_CODE_CLASS (gimple_cond_code (stmt)) != tcc_comparison)
kono
parents: 67
diff changeset
522 return 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523
111
kono
parents: 67
diff changeset
524 tmp = forward_propagate_into_comparison_1 (stmt, code,
kono
parents: 67
diff changeset
525 boolean_type_node,
kono
parents: 67
diff changeset
526 rhs1, rhs2);
kono
parents: 67
diff changeset
527 if (tmp)
kono
parents: 67
diff changeset
528 {
kono
parents: 67
diff changeset
529 if (dump_file && tmp)
kono
parents: 67
diff changeset
530 {
kono
parents: 67
diff changeset
531 fprintf (dump_file, " Replaced '");
kono
parents: 67
diff changeset
532 print_gimple_expr (dump_file, stmt, 0);
kono
parents: 67
diff changeset
533 fprintf (dump_file, "' with '");
kono
parents: 67
diff changeset
534 print_generic_expr (dump_file, tmp);
kono
parents: 67
diff changeset
535 fprintf (dump_file, "'\n");
kono
parents: 67
diff changeset
536 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537
111
kono
parents: 67
diff changeset
538 gimple_cond_set_condition_from_tree (stmt, unshare_expr (tmp));
kono
parents: 67
diff changeset
539 update_stmt (stmt);
kono
parents: 67
diff changeset
540
kono
parents: 67
diff changeset
541 if (TREE_CODE (rhs1) == SSA_NAME)
kono
parents: 67
diff changeset
542 cfg_changed |= remove_prop_source_from_use (rhs1);
kono
parents: 67
diff changeset
543 if (TREE_CODE (rhs2) == SSA_NAME)
kono
parents: 67
diff changeset
544 cfg_changed |= remove_prop_source_from_use (rhs2);
kono
parents: 67
diff changeset
545 return (cfg_changed || is_gimple_min_invariant (tmp)) ? 2 : 1;
kono
parents: 67
diff changeset
546 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547
111
kono
parents: 67
diff changeset
548 /* Canonicalize _Bool == 0 and _Bool != 1 to _Bool != 0 by swapping edges. */
kono
parents: 67
diff changeset
549 if ((TREE_CODE (TREE_TYPE (rhs1)) == BOOLEAN_TYPE
kono
parents: 67
diff changeset
550 || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
kono
parents: 67
diff changeset
551 && TYPE_PRECISION (TREE_TYPE (rhs1)) == 1))
kono
parents: 67
diff changeset
552 && ((code == EQ_EXPR
kono
parents: 67
diff changeset
553 && integer_zerop (rhs2))
kono
parents: 67
diff changeset
554 || (code == NE_EXPR
kono
parents: 67
diff changeset
555 && integer_onep (rhs2))))
kono
parents: 67
diff changeset
556 {
kono
parents: 67
diff changeset
557 basic_block bb = gimple_bb (stmt);
kono
parents: 67
diff changeset
558 gimple_cond_set_code (stmt, NE_EXPR);
kono
parents: 67
diff changeset
559 gimple_cond_set_rhs (stmt, build_zero_cst (TREE_TYPE (rhs1)));
kono
parents: 67
diff changeset
560 EDGE_SUCC (bb, 0)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
kono
parents: 67
diff changeset
561 EDGE_SUCC (bb, 1)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
kono
parents: 67
diff changeset
562 return 1;
kono
parents: 67
diff changeset
563 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564
111
kono
parents: 67
diff changeset
565 return 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 /* Propagate from the ssa name definition statements of COND_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 in the rhs of statement STMT into the conditional if that simplifies it.
111
kono
parents: 67
diff changeset
571 Returns true zero if the stmt was changed. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572
111
kono
parents: 67
diff changeset
573 static bool
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 forward_propagate_into_cond (gimple_stmt_iterator *gsi_p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 {
111
kono
parents: 67
diff changeset
576 gimple *stmt = gsi_stmt (*gsi_p);
kono
parents: 67
diff changeset
577 tree tmp = NULL_TREE;
kono
parents: 67
diff changeset
578 tree cond = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
579 enum tree_code code = gimple_assign_rhs_code (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580
111
kono
parents: 67
diff changeset
581 /* We can do tree combining on SSA_NAME and comparison expressions. */
kono
parents: 67
diff changeset
582 if (COMPARISON_CLASS_P (cond))
kono
parents: 67
diff changeset
583 tmp = forward_propagate_into_comparison_1 (stmt, TREE_CODE (cond),
kono
parents: 67
diff changeset
584 TREE_TYPE (cond),
kono
parents: 67
diff changeset
585 TREE_OPERAND (cond, 0),
kono
parents: 67
diff changeset
586 TREE_OPERAND (cond, 1));
kono
parents: 67
diff changeset
587 else if (TREE_CODE (cond) == SSA_NAME)
kono
parents: 67
diff changeset
588 {
kono
parents: 67
diff changeset
589 enum tree_code def_code;
kono
parents: 67
diff changeset
590 tree name = cond;
kono
parents: 67
diff changeset
591 gimple *def_stmt = get_prop_source_stmt (name, true, NULL);
kono
parents: 67
diff changeset
592 if (!def_stmt || !can_propagate_from (def_stmt))
kono
parents: 67
diff changeset
593 return 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594
111
kono
parents: 67
diff changeset
595 def_code = gimple_assign_rhs_code (def_stmt);
kono
parents: 67
diff changeset
596 if (TREE_CODE_CLASS (def_code) == tcc_comparison)
kono
parents: 67
diff changeset
597 tmp = fold_build2_loc (gimple_location (def_stmt),
kono
parents: 67
diff changeset
598 def_code,
kono
parents: 67
diff changeset
599 TREE_TYPE (cond),
kono
parents: 67
diff changeset
600 gimple_assign_rhs1 (def_stmt),
kono
parents: 67
diff changeset
601 gimple_assign_rhs2 (def_stmt));
kono
parents: 67
diff changeset
602 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603
111
kono
parents: 67
diff changeset
604 if (tmp
kono
parents: 67
diff changeset
605 && is_gimple_condexpr (tmp))
kono
parents: 67
diff changeset
606 {
kono
parents: 67
diff changeset
607 if (dump_file && tmp)
kono
parents: 67
diff changeset
608 {
kono
parents: 67
diff changeset
609 fprintf (dump_file, " Replaced '");
kono
parents: 67
diff changeset
610 print_generic_expr (dump_file, cond);
kono
parents: 67
diff changeset
611 fprintf (dump_file, "' with '");
kono
parents: 67
diff changeset
612 print_generic_expr (dump_file, tmp);
kono
parents: 67
diff changeset
613 fprintf (dump_file, "'\n");
kono
parents: 67
diff changeset
614 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615
111
kono
parents: 67
diff changeset
616 if ((code == VEC_COND_EXPR) ? integer_all_onesp (tmp)
kono
parents: 67
diff changeset
617 : integer_onep (tmp))
kono
parents: 67
diff changeset
618 gimple_assign_set_rhs_from_tree (gsi_p, gimple_assign_rhs2 (stmt));
kono
parents: 67
diff changeset
619 else if (integer_zerop (tmp))
kono
parents: 67
diff changeset
620 gimple_assign_set_rhs_from_tree (gsi_p, gimple_assign_rhs3 (stmt));
kono
parents: 67
diff changeset
621 else
kono
parents: 67
diff changeset
622 gimple_assign_set_rhs1 (stmt, unshare_expr (tmp));
kono
parents: 67
diff changeset
623 stmt = gsi_stmt (*gsi_p);
kono
parents: 67
diff changeset
624 update_stmt (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625
111
kono
parents: 67
diff changeset
626 return true;
kono
parents: 67
diff changeset
627 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628
111
kono
parents: 67
diff changeset
629 return 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
632 /* We've just substituted an ADDR_EXPR into stmt. Update all the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 relevant data structures to match. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 static void
111
kono
parents: 67
diff changeset
636 tidy_after_forward_propagate_addr (gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 /* We may have turned a trapping insn into a non-trapping insn. */
111
kono
parents: 67
diff changeset
639 if (maybe_clean_or_replace_eh_stmt (stmt, stmt))
kono
parents: 67
diff changeset
640 bitmap_set_bit (to_purge, gimple_bb (stmt)->index);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 if (TREE_CODE (gimple_assign_rhs1 (stmt)) == ADDR_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 /* NAME is a SSA_NAME representing DEF_RHS which is of the form
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 ADDR_EXPR <whatever>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 Try to forward propagate the ADDR_EXPR into the use USE_STMT.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 Often this will allow for removal of an ADDR_EXPR and INDIRECT_REF
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 node or for recovery of array indexing from pointer arithmetic.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 Return true if the propagation was successful (the propagation can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 be not totally successful, yet things may have been changed). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 forward_propagate_addr_expr_1 (tree name, tree def_rhs,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 gimple_stmt_iterator *use_stmt_gsi,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 bool single_use_p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 tree lhs, rhs, rhs2, array_ref;
111
kono
parents: 67
diff changeset
662 gimple *use_stmt = gsi_stmt (*use_stmt_gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 enum tree_code rhs_code;
19
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
664 bool res = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 gcc_assert (TREE_CODE (def_rhs) == ADDR_EXPR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 lhs = gimple_assign_lhs (use_stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 rhs_code = gimple_assign_rhs_code (use_stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 rhs = gimple_assign_rhs1 (use_stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671
111
kono
parents: 67
diff changeset
672 /* Do not perform copy-propagation but recurse through copy chains. */
kono
parents: 67
diff changeset
673 if (TREE_CODE (lhs) == SSA_NAME
kono
parents: 67
diff changeset
674 && rhs_code == SSA_NAME)
kono
parents: 67
diff changeset
675 return forward_propagate_addr_expr (lhs, def_rhs, single_use_p);
kono
parents: 67
diff changeset
676
kono
parents: 67
diff changeset
677 /* The use statement could be a conversion. Recurse to the uses of the
kono
parents: 67
diff changeset
678 lhs as copyprop does not copy through pointer to integer to pointer
kono
parents: 67
diff changeset
679 conversions and FRE does not catch all cases either.
kono
parents: 67
diff changeset
680 Treat the case of a single-use name and
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 a conversion to def_rhs type separate, though. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 if (TREE_CODE (lhs) == SSA_NAME
111
kono
parents: 67
diff changeset
683 && CONVERT_EXPR_CODE_P (rhs_code))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 {
111
kono
parents: 67
diff changeset
685 /* If there is a point in a conversion chain where the types match
kono
parents: 67
diff changeset
686 so we can remove a conversion re-materialize the address here
kono
parents: 67
diff changeset
687 and stop. */
kono
parents: 67
diff changeset
688 if (single_use_p
kono
parents: 67
diff changeset
689 && useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (def_rhs)))
kono
parents: 67
diff changeset
690 {
kono
parents: 67
diff changeset
691 gimple_assign_set_rhs1 (use_stmt, unshare_expr (def_rhs));
kono
parents: 67
diff changeset
692 gimple_assign_set_rhs_code (use_stmt, TREE_CODE (def_rhs));
kono
parents: 67
diff changeset
693 return true;
kono
parents: 67
diff changeset
694 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695
111
kono
parents: 67
diff changeset
696 /* Else recurse if the conversion preserves the address value. */
kono
parents: 67
diff changeset
697 if ((INTEGRAL_TYPE_P (TREE_TYPE (lhs))
kono
parents: 67
diff changeset
698 || POINTER_TYPE_P (TREE_TYPE (lhs)))
kono
parents: 67
diff changeset
699 && (TYPE_PRECISION (TREE_TYPE (lhs))
kono
parents: 67
diff changeset
700 >= TYPE_PRECISION (TREE_TYPE (def_rhs))))
kono
parents: 67
diff changeset
701 return forward_propagate_addr_expr (lhs, def_rhs, single_use_p);
kono
parents: 67
diff changeset
702
kono
parents: 67
diff changeset
703 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705
111
kono
parents: 67
diff changeset
706 /* If this isn't a conversion chain from this on we only can propagate
kono
parents: 67
diff changeset
707 into compatible pointer contexts. */
kono
parents: 67
diff changeset
708 if (!types_compatible_p (TREE_TYPE (name), TREE_TYPE (def_rhs)))
kono
parents: 67
diff changeset
709 return false;
kono
parents: 67
diff changeset
710
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
711 /* Propagate through constant pointer adjustments. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
712 if (TREE_CODE (lhs) == SSA_NAME
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
713 && rhs_code == POINTER_PLUS_EXPR
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
714 && rhs == name
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
715 && TREE_CODE (gimple_assign_rhs2 (use_stmt)) == INTEGER_CST)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
716 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
717 tree new_def_rhs;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
718 /* As we come here with non-invariant addresses in def_rhs we need
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
719 to make sure we can build a valid constant offsetted address
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
720 for further propagation. Simply rely on fold building that
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
721 and check after the fact. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
722 new_def_rhs = fold_build2 (MEM_REF, TREE_TYPE (TREE_TYPE (rhs)),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
723 def_rhs,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
724 fold_convert (ptr_type_node,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
725 gimple_assign_rhs2 (use_stmt)));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
726 if (TREE_CODE (new_def_rhs) == MEM_REF
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
727 && !is_gimple_mem_ref_addr (TREE_OPERAND (new_def_rhs, 0)))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
728 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
729 new_def_rhs = build_fold_addr_expr_with_type (new_def_rhs,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
730 TREE_TYPE (rhs));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
731
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
732 /* Recurse. If we could propagate into all uses of lhs do not
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
733 bother to replace into the current use but just pretend we did. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
734 if (TREE_CODE (new_def_rhs) == ADDR_EXPR
111
kono
parents: 67
diff changeset
735 && forward_propagate_addr_expr (lhs, new_def_rhs, single_use_p))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
736 return true;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
737
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
738 if (useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (new_def_rhs)))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
739 gimple_assign_set_rhs_with_ops (use_stmt_gsi, TREE_CODE (new_def_rhs),
111
kono
parents: 67
diff changeset
740 new_def_rhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
741 else if (is_gimple_min_invariant (new_def_rhs))
111
kono
parents: 67
diff changeset
742 gimple_assign_set_rhs_with_ops (use_stmt_gsi, NOP_EXPR, new_def_rhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
743 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
744 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
745 gcc_assert (gsi_stmt (*use_stmt_gsi) == use_stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
746 update_stmt (use_stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
747 return true;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
748 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
749
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
750 /* Now strip away any outer COMPONENT_REF/ARRAY_REF nodes from the LHS.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 ADDR_EXPR will not appear on the LHS. */
111
kono
parents: 67
diff changeset
752 tree *lhsp = gimple_assign_lhs_ptr (use_stmt);
kono
parents: 67
diff changeset
753 while (handled_component_p (*lhsp))
kono
parents: 67
diff changeset
754 lhsp = &TREE_OPERAND (*lhsp, 0);
kono
parents: 67
diff changeset
755 lhs = *lhsp;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
757 /* Now see if the LHS node is a MEM_REF using NAME. If so,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 propagate the ADDR_EXPR into the use of NAME and fold the result. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
759 if (TREE_CODE (lhs) == MEM_REF
19
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
760 && TREE_OPERAND (lhs, 0) == name)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
762 tree def_rhs_base;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
763 poly_int64 def_rhs_offset;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
764 /* If the address is invariant we can always fold it. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
765 if ((def_rhs_base = get_addr_base_and_unit_offset (TREE_OPERAND (def_rhs, 0),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
766 &def_rhs_offset)))
19
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
767 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
768 poly_offset_int off = mem_ref_offset (lhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
769 tree new_ptr;
111
kono
parents: 67
diff changeset
770 off += def_rhs_offset;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
771 if (TREE_CODE (def_rhs_base) == MEM_REF)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
772 {
111
kono
parents: 67
diff changeset
773 off += mem_ref_offset (def_rhs_base);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
774 new_ptr = TREE_OPERAND (def_rhs_base, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
775 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
776 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
777 new_ptr = build_fold_addr_expr (def_rhs_base);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
778 TREE_OPERAND (lhs, 0) = new_ptr;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
779 TREE_OPERAND (lhs, 1)
111
kono
parents: 67
diff changeset
780 = wide_int_to_tree (TREE_TYPE (TREE_OPERAND (lhs, 1)), off);
19
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
781 tidy_after_forward_propagate_addr (use_stmt);
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
782 /* Continue propagating into the RHS if this was not the only use. */
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
783 if (single_use_p)
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
784 return true;
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
785 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
786 /* If the LHS is a plain dereference and the value type is the same as
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
787 that of the pointed-to type of the address we can put the
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
788 dereferenced address on the LHS preserving the original alias-type. */
111
kono
parents: 67
diff changeset
789 else if (integer_zerop (TREE_OPERAND (lhs, 1))
kono
parents: 67
diff changeset
790 && ((gimple_assign_lhs (use_stmt) == lhs
kono
parents: 67
diff changeset
791 && useless_type_conversion_p
kono
parents: 67
diff changeset
792 (TREE_TYPE (TREE_OPERAND (def_rhs, 0)),
kono
parents: 67
diff changeset
793 TREE_TYPE (gimple_assign_rhs1 (use_stmt))))
kono
parents: 67
diff changeset
794 || types_compatible_p (TREE_TYPE (lhs),
kono
parents: 67
diff changeset
795 TREE_TYPE (TREE_OPERAND (def_rhs, 0))))
kono
parents: 67
diff changeset
796 /* Don't forward anything into clobber stmts if it would result
kono
parents: 67
diff changeset
797 in the lhs no longer being a MEM_REF. */
kono
parents: 67
diff changeset
798 && (!gimple_clobber_p (use_stmt)
kono
parents: 67
diff changeset
799 || TREE_CODE (TREE_OPERAND (def_rhs, 0)) == MEM_REF))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
800 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
801 tree *def_rhs_basep = &TREE_OPERAND (def_rhs, 0);
111
kono
parents: 67
diff changeset
802 tree new_offset, new_base, saved, new_lhs;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
803 while (handled_component_p (*def_rhs_basep))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
804 def_rhs_basep = &TREE_OPERAND (*def_rhs_basep, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
805 saved = *def_rhs_basep;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
806 if (TREE_CODE (*def_rhs_basep) == MEM_REF)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
807 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
808 new_base = TREE_OPERAND (*def_rhs_basep, 0);
111
kono
parents: 67
diff changeset
809 new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (lhs, 1)),
kono
parents: 67
diff changeset
810 TREE_OPERAND (*def_rhs_basep, 1));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
811 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
812 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
813 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
814 new_base = build_fold_addr_expr (*def_rhs_basep);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
815 new_offset = TREE_OPERAND (lhs, 1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
816 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
817 *def_rhs_basep = build2 (MEM_REF, TREE_TYPE (*def_rhs_basep),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
818 new_base, new_offset);
111
kono
parents: 67
diff changeset
819 TREE_THIS_VOLATILE (*def_rhs_basep) = TREE_THIS_VOLATILE (lhs);
kono
parents: 67
diff changeset
820 TREE_SIDE_EFFECTS (*def_rhs_basep) = TREE_SIDE_EFFECTS (lhs);
kono
parents: 67
diff changeset
821 TREE_THIS_NOTRAP (*def_rhs_basep) = TREE_THIS_NOTRAP (lhs);
kono
parents: 67
diff changeset
822 new_lhs = unshare_expr (TREE_OPERAND (def_rhs, 0));
kono
parents: 67
diff changeset
823 *lhsp = new_lhs;
kono
parents: 67
diff changeset
824 TREE_THIS_VOLATILE (new_lhs) = TREE_THIS_VOLATILE (lhs);
kono
parents: 67
diff changeset
825 TREE_SIDE_EFFECTS (new_lhs) = TREE_SIDE_EFFECTS (lhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
826 *def_rhs_basep = saved;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
827 tidy_after_forward_propagate_addr (use_stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
828 /* Continue propagating into the RHS if this was not the
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
829 only use. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
830 if (single_use_p)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
831 return true;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
832 }
19
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
833 else
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
834 /* We can have a struct assignment dereferencing our name twice.
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
835 Note that we didn't propagate into the lhs to not falsely
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
836 claim we did when propagating into the rhs. */
58ad6c70ea60 update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents: 0
diff changeset
837 res = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 nodes from the RHS. */
111
kono
parents: 67
diff changeset
842 tree *rhsp = gimple_assign_rhs1_ptr (use_stmt);
kono
parents: 67
diff changeset
843 if (TREE_CODE (*rhsp) == ADDR_EXPR)
kono
parents: 67
diff changeset
844 rhsp = &TREE_OPERAND (*rhsp, 0);
kono
parents: 67
diff changeset
845 while (handled_component_p (*rhsp))
kono
parents: 67
diff changeset
846 rhsp = &TREE_OPERAND (*rhsp, 0);
kono
parents: 67
diff changeset
847 rhs = *rhsp;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
849 /* Now see if the RHS node is a MEM_REF using NAME. If so,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
850 propagate the ADDR_EXPR into the use of NAME and fold the result. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
851 if (TREE_CODE (rhs) == MEM_REF
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
852 && TREE_OPERAND (rhs, 0) == name)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
853 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
854 tree def_rhs_base;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
855 poly_int64 def_rhs_offset;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
856 if ((def_rhs_base = get_addr_base_and_unit_offset (TREE_OPERAND (def_rhs, 0),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
857 &def_rhs_offset)))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
858 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
859 poly_offset_int off = mem_ref_offset (rhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
860 tree new_ptr;
111
kono
parents: 67
diff changeset
861 off += def_rhs_offset;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
862 if (TREE_CODE (def_rhs_base) == MEM_REF)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
863 {
111
kono
parents: 67
diff changeset
864 off += mem_ref_offset (def_rhs_base);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
865 new_ptr = TREE_OPERAND (def_rhs_base, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
866 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
867 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
868 new_ptr = build_fold_addr_expr (def_rhs_base);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
869 TREE_OPERAND (rhs, 0) = new_ptr;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
870 TREE_OPERAND (rhs, 1)
111
kono
parents: 67
diff changeset
871 = wide_int_to_tree (TREE_TYPE (TREE_OPERAND (rhs, 1)), off);
kono
parents: 67
diff changeset
872 fold_stmt_inplace (use_stmt_gsi);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
873 tidy_after_forward_propagate_addr (use_stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
874 return res;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
875 }
111
kono
parents: 67
diff changeset
876 /* If the RHS is a plain dereference and the value type is the same as
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
877 that of the pointed-to type of the address we can put the
111
kono
parents: 67
diff changeset
878 dereferenced address on the RHS preserving the original alias-type. */
kono
parents: 67
diff changeset
879 else if (integer_zerop (TREE_OPERAND (rhs, 1))
kono
parents: 67
diff changeset
880 && ((gimple_assign_rhs1 (use_stmt) == rhs
kono
parents: 67
diff changeset
881 && useless_type_conversion_p
kono
parents: 67
diff changeset
882 (TREE_TYPE (gimple_assign_lhs (use_stmt)),
kono
parents: 67
diff changeset
883 TREE_TYPE (TREE_OPERAND (def_rhs, 0))))
kono
parents: 67
diff changeset
884 || types_compatible_p (TREE_TYPE (rhs),
kono
parents: 67
diff changeset
885 TREE_TYPE (TREE_OPERAND (def_rhs, 0)))))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
886 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
887 tree *def_rhs_basep = &TREE_OPERAND (def_rhs, 0);
111
kono
parents: 67
diff changeset
888 tree new_offset, new_base, saved, new_rhs;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
889 while (handled_component_p (*def_rhs_basep))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
890 def_rhs_basep = &TREE_OPERAND (*def_rhs_basep, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
891 saved = *def_rhs_basep;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
892 if (TREE_CODE (*def_rhs_basep) == MEM_REF)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
893 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
894 new_base = TREE_OPERAND (*def_rhs_basep, 0);
111
kono
parents: 67
diff changeset
895 new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (rhs, 1)),
kono
parents: 67
diff changeset
896 TREE_OPERAND (*def_rhs_basep, 1));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
897 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
898 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
899 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
900 new_base = build_fold_addr_expr (*def_rhs_basep);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
901 new_offset = TREE_OPERAND (rhs, 1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
902 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
903 *def_rhs_basep = build2 (MEM_REF, TREE_TYPE (*def_rhs_basep),
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
904 new_base, new_offset);
111
kono
parents: 67
diff changeset
905 TREE_THIS_VOLATILE (*def_rhs_basep) = TREE_THIS_VOLATILE (rhs);
kono
parents: 67
diff changeset
906 TREE_SIDE_EFFECTS (*def_rhs_basep) = TREE_SIDE_EFFECTS (rhs);
kono
parents: 67
diff changeset
907 TREE_THIS_NOTRAP (*def_rhs_basep) = TREE_THIS_NOTRAP (rhs);
kono
parents: 67
diff changeset
908 new_rhs = unshare_expr (TREE_OPERAND (def_rhs, 0));
kono
parents: 67
diff changeset
909 *rhsp = new_rhs;
kono
parents: 67
diff changeset
910 TREE_THIS_VOLATILE (new_rhs) = TREE_THIS_VOLATILE (rhs);
kono
parents: 67
diff changeset
911 TREE_SIDE_EFFECTS (new_rhs) = TREE_SIDE_EFFECTS (rhs);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
912 *def_rhs_basep = saved;
111
kono
parents: 67
diff changeset
913 fold_stmt_inplace (use_stmt_gsi);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
914 tidy_after_forward_propagate_addr (use_stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
915 return res;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
916 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
917 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 /* If the use of the ADDR_EXPR is not a POINTER_PLUS_EXPR, there
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 is nothing to do. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 if (gimple_assign_rhs_code (use_stmt) != POINTER_PLUS_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 || gimple_assign_rhs1 (use_stmt) != name)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 return false;
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 /* The remaining cases are all for turning pointer arithmetic into
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 array indexing. They only apply when we have the address of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 element zero in an array. If that is not the case then there
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 is nothing to do. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 array_ref = TREE_OPERAND (def_rhs, 0);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
930 if ((TREE_CODE (array_ref) != ARRAY_REF
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
931 || TREE_CODE (TREE_TYPE (TREE_OPERAND (array_ref, 0))) != ARRAY_TYPE
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
932 || TREE_CODE (TREE_OPERAND (array_ref, 1)) != INTEGER_CST)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
933 && TREE_CODE (TREE_TYPE (array_ref)) != ARRAY_TYPE)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 rhs2 = gimple_assign_rhs2 (use_stmt);
111
kono
parents: 67
diff changeset
937 /* Optimize &x[C1] p+ C2 to &x p+ C3 with C3 = C1 * element_size + C2. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 if (TREE_CODE (rhs2) == INTEGER_CST)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 {
111
kono
parents: 67
diff changeset
940 tree new_rhs = build1_loc (gimple_location (use_stmt),
kono
parents: 67
diff changeset
941 ADDR_EXPR, TREE_TYPE (def_rhs),
kono
parents: 67
diff changeset
942 fold_build2 (MEM_REF,
kono
parents: 67
diff changeset
943 TREE_TYPE (TREE_TYPE (def_rhs)),
kono
parents: 67
diff changeset
944 unshare_expr (def_rhs),
kono
parents: 67
diff changeset
945 fold_convert (ptr_type_node,
kono
parents: 67
diff changeset
946 rhs2)));
kono
parents: 67
diff changeset
947 gimple_assign_set_rhs_from_tree (use_stmt_gsi, new_rhs);
kono
parents: 67
diff changeset
948 use_stmt = gsi_stmt (*use_stmt_gsi);
kono
parents: 67
diff changeset
949 update_stmt (use_stmt);
kono
parents: 67
diff changeset
950 tidy_after_forward_propagate_addr (use_stmt);
kono
parents: 67
diff changeset
951 return true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 /* STMT is a statement of the form SSA_NAME = ADDR_EXPR <whatever>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 Try to forward propagate the ADDR_EXPR into all uses of the SSA_NAME.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 Often this will allow for removal of an ADDR_EXPR and INDIRECT_REF
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 node or for recovery of array indexing from pointer arithmetic.
111
kono
parents: 67
diff changeset
962
kono
parents: 67
diff changeset
963 PARENT_SINGLE_USE_P tells if, when in a recursive invocation, NAME was
kono
parents: 67
diff changeset
964 the single use in the previous invocation. Pass true when calling
kono
parents: 67
diff changeset
965 this as toplevel.
kono
parents: 67
diff changeset
966
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 Returns true, if all uses have been propagated into. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 static bool
111
kono
parents: 67
diff changeset
970 forward_propagate_addr_expr (tree name, tree rhs, bool parent_single_use_p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 imm_use_iterator iter;
111
kono
parents: 67
diff changeset
973 gimple *use_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 bool all = true;
111
kono
parents: 67
diff changeset
975 bool single_use_p = parent_single_use_p && has_single_use (name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 FOR_EACH_IMM_USE_STMT (use_stmt, iter, name)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 bool result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980 tree use_rhs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 /* If the use is not in a simple assignment statement, then
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 there is nothing we can do. */
111
kono
parents: 67
diff changeset
984 if (!is_gimple_assign (use_stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
986 if (!is_gimple_debug (use_stmt))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
987 all = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990
111
kono
parents: 67
diff changeset
991 gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
kono
parents: 67
diff changeset
992 result = forward_propagate_addr_expr_1 (name, rhs, &gsi,
kono
parents: 67
diff changeset
993 single_use_p);
kono
parents: 67
diff changeset
994 /* If the use has moved to a different statement adjust
kono
parents: 67
diff changeset
995 the update machinery for the old statement too. */
kono
parents: 67
diff changeset
996 if (use_stmt != gsi_stmt (gsi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 {
111
kono
parents: 67
diff changeset
998 update_stmt (use_stmt);
kono
parents: 67
diff changeset
999 use_stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 }
111
kono
parents: 67
diff changeset
1001 update_stmt (use_stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 all &= result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 /* Remove intermediate now unused copy and conversion chains. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 use_rhs = gimple_assign_rhs1 (use_stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 if (result
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 && TREE_CODE (gimple_assign_lhs (use_stmt)) == SSA_NAME
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1008 && TREE_CODE (use_rhs) == SSA_NAME
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1009 && has_zero_uses (gimple_assign_lhs (use_stmt)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
111
kono
parents: 67
diff changeset
1012 fwprop_invalidate_lattice (gimple_get_lhs (use_stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 release_defs (use_stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014 gsi_remove (&gsi, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1018 return all && has_zero_uses (name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020
111
kono
parents: 67
diff changeset
1021
kono
parents: 67
diff changeset
1022 /* Helper function for simplify_gimple_switch. Remove case labels that
kono
parents: 67
diff changeset
1023 have values outside the range of the new type. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024
111
kono
parents: 67
diff changeset
1025 static void
kono
parents: 67
diff changeset
1026 simplify_gimple_switch_label_vec (gswitch *stmt, tree index_type)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 {
111
kono
parents: 67
diff changeset
1028 unsigned int branch_num = gimple_switch_num_labels (stmt);
kono
parents: 67
diff changeset
1029 auto_vec<tree> labels (branch_num);
kono
parents: 67
diff changeset
1030 unsigned int i, len;
kono
parents: 67
diff changeset
1031
kono
parents: 67
diff changeset
1032 /* Collect the existing case labels in a VEC, and preprocess it as if
kono
parents: 67
diff changeset
1033 we are gimplifying a GENERIC SWITCH_EXPR. */
kono
parents: 67
diff changeset
1034 for (i = 1; i < branch_num; i++)
kono
parents: 67
diff changeset
1035 labels.quick_push (gimple_switch_label (stmt, i));
kono
parents: 67
diff changeset
1036 preprocess_case_label_vec_for_gimple (labels, index_type, NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037
111
kono
parents: 67
diff changeset
1038 /* If any labels were removed, replace the existing case labels
kono
parents: 67
diff changeset
1039 in the GIMPLE_SWITCH statement with the correct ones.
kono
parents: 67
diff changeset
1040 Note that the type updates were done in-place on the case labels,
kono
parents: 67
diff changeset
1041 so we only have to replace the case labels in the GIMPLE_SWITCH
kono
parents: 67
diff changeset
1042 if the number of labels changed. */
kono
parents: 67
diff changeset
1043 len = labels.length ();
kono
parents: 67
diff changeset
1044 if (len < branch_num - 1)
kono
parents: 67
diff changeset
1045 {
kono
parents: 67
diff changeset
1046 bitmap target_blocks;
kono
parents: 67
diff changeset
1047 edge_iterator ei;
kono
parents: 67
diff changeset
1048 edge e;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049
111
kono
parents: 67
diff changeset
1050 /* Corner case: *all* case labels have been removed as being
kono
parents: 67
diff changeset
1051 out-of-range for INDEX_TYPE. Push one label and let the
kono
parents: 67
diff changeset
1052 CFG cleanups deal with this further. */
kono
parents: 67
diff changeset
1053 if (len == 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 {
111
kono
parents: 67
diff changeset
1055 tree label, elt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056
111
kono
parents: 67
diff changeset
1057 label = CASE_LABEL (gimple_switch_default_label (stmt));
kono
parents: 67
diff changeset
1058 elt = build_case_label (build_int_cst (index_type, 0), NULL, label);
kono
parents: 67
diff changeset
1059 labels.quick_push (elt);
kono
parents: 67
diff changeset
1060 len = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062
111
kono
parents: 67
diff changeset
1063 for (i = 0; i < labels.length (); i++)
kono
parents: 67
diff changeset
1064 gimple_switch_set_label (stmt, i + 1, labels[i]);
kono
parents: 67
diff changeset
1065 for (i++ ; i < branch_num; i++)
kono
parents: 67
diff changeset
1066 gimple_switch_set_label (stmt, i, NULL_TREE);
kono
parents: 67
diff changeset
1067 gimple_switch_set_num_labels (stmt, len + 1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068
111
kono
parents: 67
diff changeset
1069 /* Cleanup any edges that are now dead. */
kono
parents: 67
diff changeset
1070 target_blocks = BITMAP_ALLOC (NULL);
kono
parents: 67
diff changeset
1071 for (i = 0; i < gimple_switch_num_labels (stmt); i++)
kono
parents: 67
diff changeset
1072 {
kono
parents: 67
diff changeset
1073 tree elt = gimple_switch_label (stmt, i);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1074 basic_block target = label_to_block (cfun, CASE_LABEL (elt));
111
kono
parents: 67
diff changeset
1075 bitmap_set_bit (target_blocks, target->index);
kono
parents: 67
diff changeset
1076 }
kono
parents: 67
diff changeset
1077 for (ei = ei_start (gimple_bb (stmt)->succs); (e = ei_safe_edge (ei)); )
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 {
111
kono
parents: 67
diff changeset
1079 if (! bitmap_bit_p (target_blocks, e->dest->index))
kono
parents: 67
diff changeset
1080 {
kono
parents: 67
diff changeset
1081 remove_edge (e);
kono
parents: 67
diff changeset
1082 cfg_changed = true;
kono
parents: 67
diff changeset
1083 free_dominance_info (CDI_DOMINATORS);
kono
parents: 67
diff changeset
1084 }
kono
parents: 67
diff changeset
1085 else
kono
parents: 67
diff changeset
1086 ei_next (&ei);
kono
parents: 67
diff changeset
1087 }
kono
parents: 67
diff changeset
1088 BITMAP_FREE (target_blocks);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 /* STMT is a SWITCH_EXPR for which we attempt to find equivalent forms of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 the condition which we may be able to optimize better. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094
111
kono
parents: 67
diff changeset
1095 static bool
kono
parents: 67
diff changeset
1096 simplify_gimple_switch (gswitch *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 /* The optimization that we really care about is removing unnecessary
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099 casts. That will let us do much better in propagating the inferred
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 constant at the switch target. */
111
kono
parents: 67
diff changeset
1101 tree cond = gimple_switch_index (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 if (TREE_CODE (cond) == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 {
111
kono
parents: 67
diff changeset
1104 gimple *def_stmt = SSA_NAME_DEF_STMT (cond);
kono
parents: 67
diff changeset
1105 if (gimple_assign_cast_p (def_stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 {
111
kono
parents: 67
diff changeset
1107 tree def = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
1108 if (TREE_CODE (def) != SSA_NAME)
kono
parents: 67
diff changeset
1109 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110
111
kono
parents: 67
diff changeset
1111 /* If we have an extension or sign-change that preserves the
kono
parents: 67
diff changeset
1112 values we check against then we can copy the source value into
kono
parents: 67
diff changeset
1113 the switch. */
kono
parents: 67
diff changeset
1114 tree ti = TREE_TYPE (def);
kono
parents: 67
diff changeset
1115 if (INTEGRAL_TYPE_P (ti)
kono
parents: 67
diff changeset
1116 && TYPE_PRECISION (ti) <= TYPE_PRECISION (TREE_TYPE (cond)))
kono
parents: 67
diff changeset
1117 {
kono
parents: 67
diff changeset
1118 size_t n = gimple_switch_num_labels (stmt);
kono
parents: 67
diff changeset
1119 tree min = NULL_TREE, max = NULL_TREE;
kono
parents: 67
diff changeset
1120 if (n > 1)
kono
parents: 67
diff changeset
1121 {
kono
parents: 67
diff changeset
1122 min = CASE_LOW (gimple_switch_label (stmt, 1));
kono
parents: 67
diff changeset
1123 if (CASE_HIGH (gimple_switch_label (stmt, n - 1)))
kono
parents: 67
diff changeset
1124 max = CASE_HIGH (gimple_switch_label (stmt, n - 1));
kono
parents: 67
diff changeset
1125 else
kono
parents: 67
diff changeset
1126 max = CASE_LOW (gimple_switch_label (stmt, n - 1));
kono
parents: 67
diff changeset
1127 }
kono
parents: 67
diff changeset
1128 if ((!min || int_fits_type_p (min, ti))
kono
parents: 67
diff changeset
1129 && (!max || int_fits_type_p (max, ti)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 gimple_switch_set_index (stmt, def);
111
kono
parents: 67
diff changeset
1132 simplify_gimple_switch_label_vec (stmt, ti);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 update_stmt (stmt);
111
kono
parents: 67
diff changeset
1134 return true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 }
111
kono
parents: 67
diff changeset
1139
kono
parents: 67
diff changeset
1140 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1143 /* For pointers p2 and p1 return p2 - p1 if the
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1144 difference is known and constant, otherwise return NULL. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1145
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1146 static tree
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1147 constant_pointer_difference (tree p1, tree p2)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1148 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1149 int i, j;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1150 #define CPD_ITERATIONS 5
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1151 tree exps[2][CPD_ITERATIONS];
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1152 tree offs[2][CPD_ITERATIONS];
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1153 int cnt[2];
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1154
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1155 for (i = 0; i < 2; i++)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1156 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1157 tree p = i ? p1 : p2;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1158 tree off = size_zero_node;
111
kono
parents: 67
diff changeset
1159 gimple *stmt;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1160 enum tree_code code;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1161
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1162 /* For each of p1 and p2 we need to iterate at least
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1163 twice, to handle ADDR_EXPR directly in p1/p2,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1164 SSA_NAME with ADDR_EXPR or POINTER_PLUS_EXPR etc.
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1165 on definition's stmt RHS. Iterate a few extra times. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1166 j = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1167 do
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1168 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1169 if (!POINTER_TYPE_P (TREE_TYPE (p)))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1170 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1171 if (TREE_CODE (p) == ADDR_EXPR)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1172 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1173 tree q = TREE_OPERAND (p, 0);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1174 poly_int64 offset;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1175 tree base = get_addr_base_and_unit_offset (q, &offset);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1176 if (base)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1177 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1178 q = base;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1179 if (maybe_ne (offset, 0))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1180 off = size_binop (PLUS_EXPR, off, size_int (offset));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1181 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1182 if (TREE_CODE (q) == MEM_REF
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1183 && TREE_CODE (TREE_OPERAND (q, 0)) == SSA_NAME)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1184 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1185 p = TREE_OPERAND (q, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1186 off = size_binop (PLUS_EXPR, off,
111
kono
parents: 67
diff changeset
1187 wide_int_to_tree (sizetype,
kono
parents: 67
diff changeset
1188 mem_ref_offset (q)));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1189 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1190 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1191 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1192 exps[i][j] = q;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1193 offs[i][j++] = off;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1194 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1195 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1196 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1197 if (TREE_CODE (p) != SSA_NAME)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1198 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1199 exps[i][j] = p;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1200 offs[i][j++] = off;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1201 if (j == CPD_ITERATIONS)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1202 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1203 stmt = SSA_NAME_DEF_STMT (p);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1204 if (!is_gimple_assign (stmt) || gimple_assign_lhs (stmt) != p)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1205 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1206 code = gimple_assign_rhs_code (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1207 if (code == POINTER_PLUS_EXPR)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1208 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1209 if (TREE_CODE (gimple_assign_rhs2 (stmt)) != INTEGER_CST)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1210 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1211 off = size_binop (PLUS_EXPR, off, gimple_assign_rhs2 (stmt));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1212 p = gimple_assign_rhs1 (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1213 }
111
kono
parents: 67
diff changeset
1214 else if (code == ADDR_EXPR || CONVERT_EXPR_CODE_P (code))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1215 p = gimple_assign_rhs1 (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1216 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1217 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1218 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1219 while (1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1220 cnt[i] = j;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1221 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1222
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1223 for (i = 0; i < cnt[0]; i++)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1224 for (j = 0; j < cnt[1]; j++)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1225 if (exps[0][i] == exps[1][j])
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1226 return size_binop (MINUS_EXPR, offs[0][i], offs[1][j]);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1227
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1228 return NULL_TREE;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1229 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1230
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1231 /* *GSI_P is a GIMPLE_CALL to a builtin function.
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1232 Optimize
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1233 memcpy (p, "abcd", 4);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1234 memset (p + 4, ' ', 3);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1235 into
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1236 memcpy (p, "abcd ", 7);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1237 call if the latter can be stored by pieces during expansion. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1238
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1239 static bool
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1240 simplify_builtin_call (gimple_stmt_iterator *gsi_p, tree callee2)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1241 {
111
kono
parents: 67
diff changeset
1242 gimple *stmt1, *stmt2 = gsi_stmt (*gsi_p);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1243 tree vuse = gimple_vuse (stmt2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1244 if (vuse == NULL)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1245 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1246 stmt1 = SSA_NAME_DEF_STMT (vuse);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1247
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1248 switch (DECL_FUNCTION_CODE (callee2))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1249 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1250 case BUILT_IN_MEMSET:
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1251 if (gimple_call_num_args (stmt2) != 3
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1252 || gimple_call_lhs (stmt2)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1253 || CHAR_BIT != 8
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1254 || BITS_PER_UNIT != 8)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1255 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1256 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1257 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1258 tree callee1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1259 tree ptr1, src1, str1, off1, len1, lhs1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1260 tree ptr2 = gimple_call_arg (stmt2, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1261 tree val2 = gimple_call_arg (stmt2, 1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1262 tree len2 = gimple_call_arg (stmt2, 2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1263 tree diff, vdef, new_str_cst;
111
kono
parents: 67
diff changeset
1264 gimple *use_stmt;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1265 unsigned int ptr1_align;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1266 unsigned HOST_WIDE_INT src_len;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1267 char *src_buf;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1268 use_operand_p use_p;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1269
111
kono
parents: 67
diff changeset
1270 if (!tree_fits_shwi_p (val2)
kono
parents: 67
diff changeset
1271 || !tree_fits_uhwi_p (len2)
kono
parents: 67
diff changeset
1272 || compare_tree_int (len2, 1024) == 1)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1273 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1274 if (is_gimple_call (stmt1))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1275 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1276 /* If first stmt is a call, it needs to be memcpy
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1277 or mempcpy, with string literal as second argument and
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1278 constant length. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1279 callee1 = gimple_call_fndecl (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1280 if (callee1 == NULL_TREE
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1281 || !fndecl_built_in_p (callee1, BUILT_IN_NORMAL)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1282 || gimple_call_num_args (stmt1) != 3)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1283 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1284 if (DECL_FUNCTION_CODE (callee1) != BUILT_IN_MEMCPY
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1285 && DECL_FUNCTION_CODE (callee1) != BUILT_IN_MEMPCPY)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1286 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1287 ptr1 = gimple_call_arg (stmt1, 0);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1288 src1 = gimple_call_arg (stmt1, 1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1289 len1 = gimple_call_arg (stmt1, 2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1290 lhs1 = gimple_call_lhs (stmt1);
111
kono
parents: 67
diff changeset
1291 if (!tree_fits_uhwi_p (len1))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1292 break;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1293 str1 = string_constant (src1, &off1, NULL, NULL);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1294 if (str1 == NULL_TREE)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1295 break;
111
kono
parents: 67
diff changeset
1296 if (!tree_fits_uhwi_p (off1)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1297 || compare_tree_int (off1, TREE_STRING_LENGTH (str1) - 1) > 0
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1298 || compare_tree_int (len1, TREE_STRING_LENGTH (str1)
111
kono
parents: 67
diff changeset
1299 - tree_to_uhwi (off1)) > 0
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1300 || TREE_CODE (TREE_TYPE (str1)) != ARRAY_TYPE
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1301 || TYPE_MODE (TREE_TYPE (TREE_TYPE (str1)))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1302 != TYPE_MODE (char_type_node))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1303 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1304 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1305 else if (gimple_assign_single_p (stmt1))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1306 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1307 /* Otherwise look for length 1 memcpy optimized into
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1308 assignment. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1309 ptr1 = gimple_assign_lhs (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1310 src1 = gimple_assign_rhs1 (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1311 if (TREE_CODE (ptr1) != MEM_REF
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1312 || TYPE_MODE (TREE_TYPE (ptr1)) != TYPE_MODE (char_type_node)
111
kono
parents: 67
diff changeset
1313 || !tree_fits_shwi_p (src1))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1314 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1315 ptr1 = build_fold_addr_expr (ptr1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1316 callee1 = NULL_TREE;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1317 len1 = size_one_node;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1318 lhs1 = NULL_TREE;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1319 off1 = size_zero_node;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1320 str1 = NULL_TREE;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1321 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1322 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1323 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1324
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1325 diff = constant_pointer_difference (ptr1, ptr2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1326 if (diff == NULL && lhs1 != NULL)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1327 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1328 diff = constant_pointer_difference (lhs1, ptr2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1329 if (DECL_FUNCTION_CODE (callee1) == BUILT_IN_MEMPCPY
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1330 && diff != NULL)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1331 diff = size_binop (PLUS_EXPR, diff,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1332 fold_convert (sizetype, len1));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1333 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1334 /* If the difference between the second and first destination pointer
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1335 is not constant, or is bigger than memcpy length, bail out. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1336 if (diff == NULL
111
kono
parents: 67
diff changeset
1337 || !tree_fits_uhwi_p (diff)
kono
parents: 67
diff changeset
1338 || tree_int_cst_lt (len1, diff)
kono
parents: 67
diff changeset
1339 || compare_tree_int (diff, 1024) == 1)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1340 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1341
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1342 /* Use maximum of difference plus memset length and memcpy length
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1343 as the new memcpy length, if it is too big, bail out. */
111
kono
parents: 67
diff changeset
1344 src_len = tree_to_uhwi (diff);
kono
parents: 67
diff changeset
1345 src_len += tree_to_uhwi (len2);
kono
parents: 67
diff changeset
1346 if (src_len < tree_to_uhwi (len1))
kono
parents: 67
diff changeset
1347 src_len = tree_to_uhwi (len1);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1348 if (src_len > 1024)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1349 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1350
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1351 /* If mempcpy value is used elsewhere, bail out, as mempcpy
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1352 with bigger length will return different result. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1353 if (lhs1 != NULL_TREE
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1354 && DECL_FUNCTION_CODE (callee1) == BUILT_IN_MEMPCPY
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1355 && (TREE_CODE (lhs1) != SSA_NAME
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1356 || !single_imm_use (lhs1, &use_p, &use_stmt)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1357 || use_stmt != stmt2))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1358 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1359
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1360 /* If anything reads memory in between memcpy and memset
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1361 call, the modified memcpy call might change it. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1362 vdef = gimple_vdef (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1363 if (vdef != NULL
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1364 && (!single_imm_use (vdef, &use_p, &use_stmt)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1365 || use_stmt != stmt2))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1366 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1367
111
kono
parents: 67
diff changeset
1368 ptr1_align = get_pointer_alignment (ptr1);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1369 /* Construct the new source string literal. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1370 src_buf = XALLOCAVEC (char, src_len + 1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1371 if (callee1)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1372 memcpy (src_buf,
111
kono
parents: 67
diff changeset
1373 TREE_STRING_POINTER (str1) + tree_to_uhwi (off1),
kono
parents: 67
diff changeset
1374 tree_to_uhwi (len1));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1375 else
111
kono
parents: 67
diff changeset
1376 src_buf[0] = tree_to_shwi (src1);
kono
parents: 67
diff changeset
1377 memset (src_buf + tree_to_uhwi (diff),
kono
parents: 67
diff changeset
1378 tree_to_shwi (val2), tree_to_uhwi (len2));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1379 src_buf[src_len] = '\0';
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1380 /* Neither builtin_strncpy_read_str nor builtin_memcpy_read_str
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1381 handle embedded '\0's. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1382 if (strlen (src_buf) != src_len)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1383 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1384 rtl_profile_for_bb (gimple_bb (stmt2));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1385 /* If the new memcpy wouldn't be emitted by storing the literal
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1386 by pieces, this optimization might enlarge .rodata too much,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1387 as commonly used string literals couldn't be shared any
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1388 longer. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1389 if (!can_store_by_pieces (src_len,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1390 builtin_strncpy_read_str,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1391 src_buf, ptr1_align, false))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1392 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1393
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1394 new_str_cst = build_string_literal (src_len, src_buf);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1395 if (callee1)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1396 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1397 /* If STMT1 is a mem{,p}cpy call, adjust it and remove
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1398 memset call. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1399 if (lhs1 && DECL_FUNCTION_CODE (callee1) == BUILT_IN_MEMPCPY)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1400 gimple_call_set_lhs (stmt1, NULL_TREE);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1401 gimple_call_set_arg (stmt1, 1, new_str_cst);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1402 gimple_call_set_arg (stmt1, 2,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1403 build_int_cst (TREE_TYPE (len1), src_len));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1404 update_stmt (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1405 unlink_stmt_vdef (stmt2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1406 gsi_remove (gsi_p, true);
111
kono
parents: 67
diff changeset
1407 fwprop_invalidate_lattice (gimple_get_lhs (stmt2));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1408 release_defs (stmt2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1409 if (lhs1 && DECL_FUNCTION_CODE (callee1) == BUILT_IN_MEMPCPY)
111
kono
parents: 67
diff changeset
1410 {
kono
parents: 67
diff changeset
1411 fwprop_invalidate_lattice (lhs1);
kono
parents: 67
diff changeset
1412 release_ssa_name (lhs1);
kono
parents: 67
diff changeset
1413 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1414 return true;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1415 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1416 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1417 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1418 /* Otherwise, if STMT1 is length 1 memcpy optimized into
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1419 assignment, remove STMT1 and change memset call into
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1420 memcpy call. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1421 gimple_stmt_iterator gsi = gsi_for_stmt (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1422
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1423 if (!is_gimple_val (ptr1))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1424 ptr1 = force_gimple_operand_gsi (gsi_p, ptr1, true, NULL_TREE,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1425 true, GSI_SAME_STMT);
111
kono
parents: 67
diff changeset
1426 gimple_call_set_fndecl (stmt2,
kono
parents: 67
diff changeset
1427 builtin_decl_explicit (BUILT_IN_MEMCPY));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1428 gimple_call_set_arg (stmt2, 0, ptr1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1429 gimple_call_set_arg (stmt2, 1, new_str_cst);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1430 gimple_call_set_arg (stmt2, 2,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1431 build_int_cst (TREE_TYPE (len2), src_len));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1432 unlink_stmt_vdef (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1433 gsi_remove (&gsi, true);
111
kono
parents: 67
diff changeset
1434 fwprop_invalidate_lattice (gimple_get_lhs (stmt1));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1435 release_defs (stmt1);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1436 update_stmt (stmt2);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1437 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1438 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1439 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1440 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1441 default:
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1442 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1443 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1444 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1445 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1446
111
kono
parents: 67
diff changeset
1447 /* Given a ssa_name in NAME see if it was defined by an assignment and
kono
parents: 67
diff changeset
1448 set CODE to be the code and ARG1 to the first operand on the rhs and ARG2
kono
parents: 67
diff changeset
1449 to the second operand on the rhs. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1450
111
kono
parents: 67
diff changeset
1451 static inline void
kono
parents: 67
diff changeset
1452 defcodefor_name (tree name, enum tree_code *code, tree *arg1, tree *arg2)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1453 {
111
kono
parents: 67
diff changeset
1454 gimple *def;
kono
parents: 67
diff changeset
1455 enum tree_code code1;
kono
parents: 67
diff changeset
1456 tree arg11;
kono
parents: 67
diff changeset
1457 tree arg21;
kono
parents: 67
diff changeset
1458 tree arg31;
kono
parents: 67
diff changeset
1459 enum gimple_rhs_class grhs_class;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1460
111
kono
parents: 67
diff changeset
1461 code1 = TREE_CODE (name);
kono
parents: 67
diff changeset
1462 arg11 = name;
kono
parents: 67
diff changeset
1463 arg21 = NULL_TREE;
kono
parents: 67
diff changeset
1464 arg31 = NULL_TREE;
kono
parents: 67
diff changeset
1465 grhs_class = get_gimple_rhs_class (code1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1466
111
kono
parents: 67
diff changeset
1467 if (code1 == SSA_NAME)
kono
parents: 67
diff changeset
1468 {
kono
parents: 67
diff changeset
1469 def = SSA_NAME_DEF_STMT (name);
kono
parents: 67
diff changeset
1470
kono
parents: 67
diff changeset
1471 if (def && is_gimple_assign (def)
kono
parents: 67
diff changeset
1472 && can_propagate_from (def))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1473 {
111
kono
parents: 67
diff changeset
1474 code1 = gimple_assign_rhs_code (def);
kono
parents: 67
diff changeset
1475 arg11 = gimple_assign_rhs1 (def);
kono
parents: 67
diff changeset
1476 arg21 = gimple_assign_rhs2 (def);
kono
parents: 67
diff changeset
1477 arg31 = gimple_assign_rhs3 (def);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1478 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1479 }
111
kono
parents: 67
diff changeset
1480 else if (grhs_class != GIMPLE_SINGLE_RHS)
kono
parents: 67
diff changeset
1481 code1 = ERROR_MARK;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1482
111
kono
parents: 67
diff changeset
1483 *code = code1;
kono
parents: 67
diff changeset
1484 *arg1 = arg11;
kono
parents: 67
diff changeset
1485 if (arg2)
kono
parents: 67
diff changeset
1486 *arg2 = arg21;
kono
parents: 67
diff changeset
1487 if (arg31)
kono
parents: 67
diff changeset
1488 *code = ERROR_MARK;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1489 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
1490
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1491
111
kono
parents: 67
diff changeset
1492 /* Recognize rotation patterns. Return true if a transformation
kono
parents: 67
diff changeset
1493 applied, otherwise return false.
kono
parents: 67
diff changeset
1494
kono
parents: 67
diff changeset
1495 We are looking for X with unsigned type T with bitsize B, OP being
kono
parents: 67
diff changeset
1496 +, | or ^, some type T2 wider than T. For:
kono
parents: 67
diff changeset
1497 (X << CNT1) OP (X >> CNT2) iff CNT1 + CNT2 == B
kono
parents: 67
diff changeset
1498 ((T) ((T2) X << CNT1)) OP ((T) ((T2) X >> CNT2)) iff CNT1 + CNT2 == B
kono
parents: 67
diff changeset
1499
kono
parents: 67
diff changeset
1500 transform these into:
kono
parents: 67
diff changeset
1501 X r<< CNT1
kono
parents: 67
diff changeset
1502
kono
parents: 67
diff changeset
1503 Or for:
kono
parents: 67
diff changeset
1504 (X << Y) OP (X >> (B - Y))
kono
parents: 67
diff changeset
1505 (X << (int) Y) OP (X >> (int) (B - Y))
kono
parents: 67
diff changeset
1506 ((T) ((T2) X << Y)) OP ((T) ((T2) X >> (B - Y)))
kono
parents: 67
diff changeset
1507 ((T) ((T2) X << (int) Y)) OP ((T) ((T2) X >> (int) (B - Y)))
kono
parents: 67
diff changeset
1508 (X << Y) | (X >> ((-Y) & (B - 1)))
kono
parents: 67
diff changeset
1509 (X << (int) Y) | (X >> (int) ((-Y) & (B - 1)))
kono
parents: 67
diff changeset
1510 ((T) ((T2) X << Y)) | ((T) ((T2) X >> ((-Y) & (B - 1))))
kono
parents: 67
diff changeset
1511 ((T) ((T2) X << (int) Y)) | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))
kono
parents: 67
diff changeset
1512
kono
parents: 67
diff changeset
1513 transform these into:
kono
parents: 67
diff changeset
1514 X r<< Y
kono
parents: 67
diff changeset
1515
kono
parents: 67
diff changeset
1516 Or for:
kono
parents: 67
diff changeset
1517 (X << (Y & (B - 1))) | (X >> ((-Y) & (B - 1)))
kono
parents: 67
diff changeset
1518 (X << (int) (Y & (B - 1))) | (X >> (int) ((-Y) & (B - 1)))
kono
parents: 67
diff changeset
1519 ((T) ((T2) X << (Y & (B - 1)))) | ((T) ((T2) X >> ((-Y) & (B - 1))))
kono
parents: 67
diff changeset
1520 ((T) ((T2) X << (int) (Y & (B - 1)))) \
kono
parents: 67
diff changeset
1521 | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))
kono
parents: 67
diff changeset
1522
kono
parents: 67
diff changeset
1523 transform these into:
kono
parents: 67
diff changeset
1524 X r<< (Y & (B - 1))
kono
parents: 67
diff changeset
1525
kono
parents: 67
diff changeset
1526 Note, in the patterns with T2 type, the type of OP operands
kono
parents: 67
diff changeset
1527 might be even a signed type, but should have precision B.
kono
parents: 67
diff changeset
1528 Expressions with & (B - 1) should be recognized only if B is
kono
parents: 67
diff changeset
1529 a power of 2. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1530
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1531 static bool
111
kono
parents: 67
diff changeset
1532 simplify_rotate (gimple_stmt_iterator *gsi)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1533 {
111
kono
parents: 67
diff changeset
1534 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
1535 tree arg[2], rtype, rotcnt = NULL_TREE;
kono
parents: 67
diff changeset
1536 tree def_arg1[2], def_arg2[2];
kono
parents: 67
diff changeset
1537 enum tree_code def_code[2];
kono
parents: 67
diff changeset
1538 tree lhs;
kono
parents: 67
diff changeset
1539 int i;
kono
parents: 67
diff changeset
1540 bool swapped_p = false;
kono
parents: 67
diff changeset
1541 gimple *g;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1542
111
kono
parents: 67
diff changeset
1543 arg[0] = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1544 arg[1] = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
1545 rtype = TREE_TYPE (arg[0]);
kono
parents: 67
diff changeset
1546
kono
parents: 67
diff changeset
1547 /* Only create rotates in complete modes. Other cases are not
kono
parents: 67
diff changeset
1548 expanded properly. */
kono
parents: 67
diff changeset
1549 if (!INTEGRAL_TYPE_P (rtype)
kono
parents: 67
diff changeset
1550 || !type_has_mode_precision_p (rtype))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1551 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1552
111
kono
parents: 67
diff changeset
1553 for (i = 0; i < 2; i++)
kono
parents: 67
diff changeset
1554 defcodefor_name (arg[i], &def_code[i], &def_arg1[i], &def_arg2[i]);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1555
111
kono
parents: 67
diff changeset
1556 /* Look through narrowing conversions. */
kono
parents: 67
diff changeset
1557 if (CONVERT_EXPR_CODE_P (def_code[0])
kono
parents: 67
diff changeset
1558 && CONVERT_EXPR_CODE_P (def_code[1])
kono
parents: 67
diff changeset
1559 && INTEGRAL_TYPE_P (TREE_TYPE (def_arg1[0]))
kono
parents: 67
diff changeset
1560 && INTEGRAL_TYPE_P (TREE_TYPE (def_arg1[1]))
kono
parents: 67
diff changeset
1561 && TYPE_PRECISION (TREE_TYPE (def_arg1[0]))
kono
parents: 67
diff changeset
1562 == TYPE_PRECISION (TREE_TYPE (def_arg1[1]))
kono
parents: 67
diff changeset
1563 && TYPE_PRECISION (TREE_TYPE (def_arg1[0])) > TYPE_PRECISION (rtype)
kono
parents: 67
diff changeset
1564 && has_single_use (arg[0])
kono
parents: 67
diff changeset
1565 && has_single_use (arg[1]))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1566 {
111
kono
parents: 67
diff changeset
1567 for (i = 0; i < 2; i++)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1568 {
111
kono
parents: 67
diff changeset
1569 arg[i] = def_arg1[i];
kono
parents: 67
diff changeset
1570 defcodefor_name (arg[i], &def_code[i], &def_arg1[i], &def_arg2[i]);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1571 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1572 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1573
111
kono
parents: 67
diff changeset
1574 /* One operand has to be LSHIFT_EXPR and one RSHIFT_EXPR. */
kono
parents: 67
diff changeset
1575 for (i = 0; i < 2; i++)
kono
parents: 67
diff changeset
1576 if (def_code[i] != LSHIFT_EXPR && def_code[i] != RSHIFT_EXPR)
kono
parents: 67
diff changeset
1577 return false;
kono
parents: 67
diff changeset
1578 else if (!has_single_use (arg[i]))
kono
parents: 67
diff changeset
1579 return false;
kono
parents: 67
diff changeset
1580 if (def_code[0] == def_code[1])
kono
parents: 67
diff changeset
1581 return false;
kono
parents: 67
diff changeset
1582
kono
parents: 67
diff changeset
1583 /* If we've looked through narrowing conversions before, look through
kono
parents: 67
diff changeset
1584 widening conversions from unsigned type with the same precision
kono
parents: 67
diff changeset
1585 as rtype here. */
kono
parents: 67
diff changeset
1586 if (TYPE_PRECISION (TREE_TYPE (def_arg1[0])) != TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1587 for (i = 0; i < 2; i++)
kono
parents: 67
diff changeset
1588 {
kono
parents: 67
diff changeset
1589 tree tem;
kono
parents: 67
diff changeset
1590 enum tree_code code;
kono
parents: 67
diff changeset
1591 defcodefor_name (def_arg1[i], &code, &tem, NULL);
kono
parents: 67
diff changeset
1592 if (!CONVERT_EXPR_CODE_P (code)
kono
parents: 67
diff changeset
1593 || !INTEGRAL_TYPE_P (TREE_TYPE (tem))
kono
parents: 67
diff changeset
1594 || TYPE_PRECISION (TREE_TYPE (tem)) != TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1595 return false;
kono
parents: 67
diff changeset
1596 def_arg1[i] = tem;
kono
parents: 67
diff changeset
1597 }
kono
parents: 67
diff changeset
1598 /* Both shifts have to use the same first operand. */
kono
parents: 67
diff changeset
1599 if (!operand_equal_for_phi_arg_p (def_arg1[0], def_arg1[1])
kono
parents: 67
diff changeset
1600 || !types_compatible_p (TREE_TYPE (def_arg1[0]),
kono
parents: 67
diff changeset
1601 TREE_TYPE (def_arg1[1])))
kono
parents: 67
diff changeset
1602 return false;
kono
parents: 67
diff changeset
1603 if (!TYPE_UNSIGNED (TREE_TYPE (def_arg1[0])))
kono
parents: 67
diff changeset
1604 return false;
kono
parents: 67
diff changeset
1605
kono
parents: 67
diff changeset
1606 /* CNT1 + CNT2 == B case above. */
kono
parents: 67
diff changeset
1607 if (tree_fits_uhwi_p (def_arg2[0])
kono
parents: 67
diff changeset
1608 && tree_fits_uhwi_p (def_arg2[1])
kono
parents: 67
diff changeset
1609 && tree_to_uhwi (def_arg2[0])
kono
parents: 67
diff changeset
1610 + tree_to_uhwi (def_arg2[1]) == TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1611 rotcnt = def_arg2[0];
kono
parents: 67
diff changeset
1612 else if (TREE_CODE (def_arg2[0]) != SSA_NAME
kono
parents: 67
diff changeset
1613 || TREE_CODE (def_arg2[1]) != SSA_NAME)
kono
parents: 67
diff changeset
1614 return false;
kono
parents: 67
diff changeset
1615 else
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1616 {
111
kono
parents: 67
diff changeset
1617 tree cdef_arg1[2], cdef_arg2[2], def_arg2_alt[2];
kono
parents: 67
diff changeset
1618 enum tree_code cdef_code[2];
kono
parents: 67
diff changeset
1619 /* Look through conversion of the shift count argument.
kono
parents: 67
diff changeset
1620 The C/C++ FE cast any shift count argument to integer_type_node.
kono
parents: 67
diff changeset
1621 The only problem might be if the shift count type maximum value
kono
parents: 67
diff changeset
1622 is equal or smaller than number of bits in rtype. */
kono
parents: 67
diff changeset
1623 for (i = 0; i < 2; i++)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1624 {
111
kono
parents: 67
diff changeset
1625 def_arg2_alt[i] = def_arg2[i];
kono
parents: 67
diff changeset
1626 defcodefor_name (def_arg2[i], &cdef_code[i],
kono
parents: 67
diff changeset
1627 &cdef_arg1[i], &cdef_arg2[i]);
kono
parents: 67
diff changeset
1628 if (CONVERT_EXPR_CODE_P (cdef_code[i])
kono
parents: 67
diff changeset
1629 && INTEGRAL_TYPE_P (TREE_TYPE (cdef_arg1[i]))
kono
parents: 67
diff changeset
1630 && TYPE_PRECISION (TREE_TYPE (cdef_arg1[i]))
kono
parents: 67
diff changeset
1631 > floor_log2 (TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1632 && type_has_mode_precision_p (TREE_TYPE (cdef_arg1[i])))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1633 {
111
kono
parents: 67
diff changeset
1634 def_arg2_alt[i] = cdef_arg1[i];
kono
parents: 67
diff changeset
1635 defcodefor_name (def_arg2_alt[i], &cdef_code[i],
kono
parents: 67
diff changeset
1636 &cdef_arg1[i], &cdef_arg2[i]);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1637 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1638 }
111
kono
parents: 67
diff changeset
1639 for (i = 0; i < 2; i++)
kono
parents: 67
diff changeset
1640 /* Check for one shift count being Y and the other B - Y,
kono
parents: 67
diff changeset
1641 with optional casts. */
kono
parents: 67
diff changeset
1642 if (cdef_code[i] == MINUS_EXPR
kono
parents: 67
diff changeset
1643 && tree_fits_shwi_p (cdef_arg1[i])
kono
parents: 67
diff changeset
1644 && tree_to_shwi (cdef_arg1[i]) == TYPE_PRECISION (rtype)
kono
parents: 67
diff changeset
1645 && TREE_CODE (cdef_arg2[i]) == SSA_NAME)
kono
parents: 67
diff changeset
1646 {
kono
parents: 67
diff changeset
1647 tree tem;
kono
parents: 67
diff changeset
1648 enum tree_code code;
kono
parents: 67
diff changeset
1649
kono
parents: 67
diff changeset
1650 if (cdef_arg2[i] == def_arg2[1 - i]
kono
parents: 67
diff changeset
1651 || cdef_arg2[i] == def_arg2_alt[1 - i])
kono
parents: 67
diff changeset
1652 {
kono
parents: 67
diff changeset
1653 rotcnt = cdef_arg2[i];
kono
parents: 67
diff changeset
1654 break;
kono
parents: 67
diff changeset
1655 }
kono
parents: 67
diff changeset
1656 defcodefor_name (cdef_arg2[i], &code, &tem, NULL);
kono
parents: 67
diff changeset
1657 if (CONVERT_EXPR_CODE_P (code)
kono
parents: 67
diff changeset
1658 && INTEGRAL_TYPE_P (TREE_TYPE (tem))
kono
parents: 67
diff changeset
1659 && TYPE_PRECISION (TREE_TYPE (tem))
kono
parents: 67
diff changeset
1660 > floor_log2 (TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1661 && type_has_mode_precision_p (TREE_TYPE (tem))
kono
parents: 67
diff changeset
1662 && (tem == def_arg2[1 - i]
kono
parents: 67
diff changeset
1663 || tem == def_arg2_alt[1 - i]))
kono
parents: 67
diff changeset
1664 {
kono
parents: 67
diff changeset
1665 rotcnt = tem;
kono
parents: 67
diff changeset
1666 break;
kono
parents: 67
diff changeset
1667 }
kono
parents: 67
diff changeset
1668 }
kono
parents: 67
diff changeset
1669 /* The above sequence isn't safe for Y being 0,
kono
parents: 67
diff changeset
1670 because then one of the shifts triggers undefined behavior.
kono
parents: 67
diff changeset
1671 This alternative is safe even for rotation count of 0.
kono
parents: 67
diff changeset
1672 One shift count is Y and the other (-Y) & (B - 1).
kono
parents: 67
diff changeset
1673 Or one shift count is Y & (B - 1) and the other (-Y) & (B - 1). */
kono
parents: 67
diff changeset
1674 else if (cdef_code[i] == BIT_AND_EXPR
kono
parents: 67
diff changeset
1675 && pow2p_hwi (TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1676 && tree_fits_shwi_p (cdef_arg2[i])
kono
parents: 67
diff changeset
1677 && tree_to_shwi (cdef_arg2[i])
kono
parents: 67
diff changeset
1678 == TYPE_PRECISION (rtype) - 1
kono
parents: 67
diff changeset
1679 && TREE_CODE (cdef_arg1[i]) == SSA_NAME
kono
parents: 67
diff changeset
1680 && gimple_assign_rhs_code (stmt) == BIT_IOR_EXPR)
kono
parents: 67
diff changeset
1681 {
kono
parents: 67
diff changeset
1682 tree tem;
kono
parents: 67
diff changeset
1683 enum tree_code code;
kono
parents: 67
diff changeset
1684
kono
parents: 67
diff changeset
1685 defcodefor_name (cdef_arg1[i], &code, &tem, NULL);
kono
parents: 67
diff changeset
1686 if (CONVERT_EXPR_CODE_P (code)
kono
parents: 67
diff changeset
1687 && INTEGRAL_TYPE_P (TREE_TYPE (tem))
kono
parents: 67
diff changeset
1688 && TYPE_PRECISION (TREE_TYPE (tem))
kono
parents: 67
diff changeset
1689 > floor_log2 (TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1690 && type_has_mode_precision_p (TREE_TYPE (tem)))
kono
parents: 67
diff changeset
1691 defcodefor_name (tem, &code, &tem, NULL);
kono
parents: 67
diff changeset
1692
kono
parents: 67
diff changeset
1693 if (code == NEGATE_EXPR)
kono
parents: 67
diff changeset
1694 {
kono
parents: 67
diff changeset
1695 if (tem == def_arg2[1 - i] || tem == def_arg2_alt[1 - i])
kono
parents: 67
diff changeset
1696 {
kono
parents: 67
diff changeset
1697 rotcnt = tem;
kono
parents: 67
diff changeset
1698 break;
kono
parents: 67
diff changeset
1699 }
kono
parents: 67
diff changeset
1700 tree tem2;
kono
parents: 67
diff changeset
1701 defcodefor_name (tem, &code, &tem2, NULL);
kono
parents: 67
diff changeset
1702 if (CONVERT_EXPR_CODE_P (code)
kono
parents: 67
diff changeset
1703 && INTEGRAL_TYPE_P (TREE_TYPE (tem2))
kono
parents: 67
diff changeset
1704 && TYPE_PRECISION (TREE_TYPE (tem2))
kono
parents: 67
diff changeset
1705 > floor_log2 (TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1706 && type_has_mode_precision_p (TREE_TYPE (tem2)))
kono
parents: 67
diff changeset
1707 {
kono
parents: 67
diff changeset
1708 if (tem2 == def_arg2[1 - i]
kono
parents: 67
diff changeset
1709 || tem2 == def_arg2_alt[1 - i])
kono
parents: 67
diff changeset
1710 {
kono
parents: 67
diff changeset
1711 rotcnt = tem2;
kono
parents: 67
diff changeset
1712 break;
kono
parents: 67
diff changeset
1713 }
kono
parents: 67
diff changeset
1714 }
kono
parents: 67
diff changeset
1715 else
kono
parents: 67
diff changeset
1716 tem2 = NULL_TREE;
kono
parents: 67
diff changeset
1717
kono
parents: 67
diff changeset
1718 if (cdef_code[1 - i] == BIT_AND_EXPR
kono
parents: 67
diff changeset
1719 && tree_fits_shwi_p (cdef_arg2[1 - i])
kono
parents: 67
diff changeset
1720 && tree_to_shwi (cdef_arg2[1 - i])
kono
parents: 67
diff changeset
1721 == TYPE_PRECISION (rtype) - 1
kono
parents: 67
diff changeset
1722 && TREE_CODE (cdef_arg1[1 - i]) == SSA_NAME)
kono
parents: 67
diff changeset
1723 {
kono
parents: 67
diff changeset
1724 if (tem == cdef_arg1[1 - i]
kono
parents: 67
diff changeset
1725 || tem2 == cdef_arg1[1 - i])
kono
parents: 67
diff changeset
1726 {
kono
parents: 67
diff changeset
1727 rotcnt = def_arg2[1 - i];
kono
parents: 67
diff changeset
1728 break;
kono
parents: 67
diff changeset
1729 }
kono
parents: 67
diff changeset
1730 tree tem3;
kono
parents: 67
diff changeset
1731 defcodefor_name (cdef_arg1[1 - i], &code, &tem3, NULL);
kono
parents: 67
diff changeset
1732 if (CONVERT_EXPR_CODE_P (code)
kono
parents: 67
diff changeset
1733 && INTEGRAL_TYPE_P (TREE_TYPE (tem3))
kono
parents: 67
diff changeset
1734 && TYPE_PRECISION (TREE_TYPE (tem3))
kono
parents: 67
diff changeset
1735 > floor_log2 (TYPE_PRECISION (rtype))
kono
parents: 67
diff changeset
1736 && type_has_mode_precision_p (TREE_TYPE (tem3)))
kono
parents: 67
diff changeset
1737 {
kono
parents: 67
diff changeset
1738 if (tem == tem3 || tem2 == tem3)
kono
parents: 67
diff changeset
1739 {
kono
parents: 67
diff changeset
1740 rotcnt = def_arg2[1 - i];
kono
parents: 67
diff changeset
1741 break;
kono
parents: 67
diff changeset
1742 }
kono
parents: 67
diff changeset
1743 }
kono
parents: 67
diff changeset
1744 }
kono
parents: 67
diff changeset
1745 }
kono
parents: 67
diff changeset
1746 }
kono
parents: 67
diff changeset
1747 if (rotcnt == NULL_TREE)
kono
parents: 67
diff changeset
1748 return false;
kono
parents: 67
diff changeset
1749 swapped_p = i != 1;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1750 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1751
111
kono
parents: 67
diff changeset
1752 if (!useless_type_conversion_p (TREE_TYPE (def_arg2[0]),
kono
parents: 67
diff changeset
1753 TREE_TYPE (rotcnt)))
kono
parents: 67
diff changeset
1754 {
kono
parents: 67
diff changeset
1755 g = gimple_build_assign (make_ssa_name (TREE_TYPE (def_arg2[0])),
kono
parents: 67
diff changeset
1756 NOP_EXPR, rotcnt);
kono
parents: 67
diff changeset
1757 gsi_insert_before (gsi, g, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1758 rotcnt = gimple_assign_lhs (g);
kono
parents: 67
diff changeset
1759 }
kono
parents: 67
diff changeset
1760 lhs = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
1761 if (!useless_type_conversion_p (rtype, TREE_TYPE (def_arg1[0])))
kono
parents: 67
diff changeset
1762 lhs = make_ssa_name (TREE_TYPE (def_arg1[0]));
kono
parents: 67
diff changeset
1763 g = gimple_build_assign (lhs,
kono
parents: 67
diff changeset
1764 ((def_code[0] == LSHIFT_EXPR) ^ swapped_p)
kono
parents: 67
diff changeset
1765 ? LROTATE_EXPR : RROTATE_EXPR, def_arg1[0], rotcnt);
kono
parents: 67
diff changeset
1766 if (!useless_type_conversion_p (rtype, TREE_TYPE (def_arg1[0])))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1767 {
111
kono
parents: 67
diff changeset
1768 gsi_insert_before (gsi, g, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1769 g = gimple_build_assign (gimple_assign_lhs (stmt), NOP_EXPR, lhs);
kono
parents: 67
diff changeset
1770 }
kono
parents: 67
diff changeset
1771 gsi_replace (gsi, g, false);
kono
parents: 67
diff changeset
1772 return true;
kono
parents: 67
diff changeset
1773 }
kono
parents: 67
diff changeset
1774
kono
parents: 67
diff changeset
1775 /* Combine an element access with a shuffle. Returns true if there were
kono
parents: 67
diff changeset
1776 any changes made, else it returns false. */
kono
parents: 67
diff changeset
1777
kono
parents: 67
diff changeset
1778 static bool
kono
parents: 67
diff changeset
1779 simplify_bitfield_ref (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
1780 {
kono
parents: 67
diff changeset
1781 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
1782 gimple *def_stmt;
kono
parents: 67
diff changeset
1783 tree op, op0, op1, op2;
kono
parents: 67
diff changeset
1784 tree elem_type;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1785 unsigned idx, size;
111
kono
parents: 67
diff changeset
1786 enum tree_code code;
kono
parents: 67
diff changeset
1787
kono
parents: 67
diff changeset
1788 op = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1789 gcc_checking_assert (TREE_CODE (op) == BIT_FIELD_REF);
kono
parents: 67
diff changeset
1790
kono
parents: 67
diff changeset
1791 op0 = TREE_OPERAND (op, 0);
kono
parents: 67
diff changeset
1792 if (TREE_CODE (op0) != SSA_NAME
kono
parents: 67
diff changeset
1793 || TREE_CODE (TREE_TYPE (op0)) != VECTOR_TYPE)
kono
parents: 67
diff changeset
1794 return false;
kono
parents: 67
diff changeset
1795
kono
parents: 67
diff changeset
1796 def_stmt = get_prop_source_stmt (op0, false, NULL);
kono
parents: 67
diff changeset
1797 if (!def_stmt || !can_propagate_from (def_stmt))
kono
parents: 67
diff changeset
1798 return false;
kono
parents: 67
diff changeset
1799
kono
parents: 67
diff changeset
1800 op1 = TREE_OPERAND (op, 1);
kono
parents: 67
diff changeset
1801 op2 = TREE_OPERAND (op, 2);
kono
parents: 67
diff changeset
1802 code = gimple_assign_rhs_code (def_stmt);
kono
parents: 67
diff changeset
1803
kono
parents: 67
diff changeset
1804 if (code == CONSTRUCTOR)
kono
parents: 67
diff changeset
1805 {
kono
parents: 67
diff changeset
1806 tree tem = fold_ternary (BIT_FIELD_REF, TREE_TYPE (op),
kono
parents: 67
diff changeset
1807 gimple_assign_rhs1 (def_stmt), op1, op2);
kono
parents: 67
diff changeset
1808 if (!tem || !valid_gimple_rhs_p (tem))
kono
parents: 67
diff changeset
1809 return false;
kono
parents: 67
diff changeset
1810 gimple_assign_set_rhs_from_tree (gsi, tem);
kono
parents: 67
diff changeset
1811 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1812 return true;
kono
parents: 67
diff changeset
1813 }
kono
parents: 67
diff changeset
1814
kono
parents: 67
diff changeset
1815 elem_type = TREE_TYPE (TREE_TYPE (op0));
kono
parents: 67
diff changeset
1816 if (TREE_TYPE (op) != elem_type)
kono
parents: 67
diff changeset
1817 return false;
kono
parents: 67
diff changeset
1818
kono
parents: 67
diff changeset
1819 size = TREE_INT_CST_LOW (TYPE_SIZE (elem_type));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1820 if (maybe_ne (bit_field_size (op), size))
111
kono
parents: 67
diff changeset
1821 return false;
kono
parents: 67
diff changeset
1822
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1823 if (code == VEC_PERM_EXPR
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1824 && constant_multiple_p (bit_field_offset (op), size, &idx))
111
kono
parents: 67
diff changeset
1825 {
kono
parents: 67
diff changeset
1826 tree p, m, tem;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1827 unsigned HOST_WIDE_INT nelts;
111
kono
parents: 67
diff changeset
1828 m = gimple_assign_rhs3 (def_stmt);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1829 if (TREE_CODE (m) != VECTOR_CST
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1830 || !VECTOR_CST_NELTS (m).is_constant (&nelts))
111
kono
parents: 67
diff changeset
1831 return false;
kono
parents: 67
diff changeset
1832 idx = TREE_INT_CST_LOW (VECTOR_CST_ELT (m, idx));
kono
parents: 67
diff changeset
1833 idx %= 2 * nelts;
kono
parents: 67
diff changeset
1834 if (idx < nelts)
kono
parents: 67
diff changeset
1835 {
kono
parents: 67
diff changeset
1836 p = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
1837 }
kono
parents: 67
diff changeset
1838 else
kono
parents: 67
diff changeset
1839 {
kono
parents: 67
diff changeset
1840 p = gimple_assign_rhs2 (def_stmt);
kono
parents: 67
diff changeset
1841 idx -= nelts;
kono
parents: 67
diff changeset
1842 }
kono
parents: 67
diff changeset
1843 tem = build3 (BIT_FIELD_REF, TREE_TYPE (op),
kono
parents: 67
diff changeset
1844 unshare_expr (p), op1, bitsize_int (idx * size));
kono
parents: 67
diff changeset
1845 gimple_assign_set_rhs1 (stmt, tem);
kono
parents: 67
diff changeset
1846 fold_stmt (gsi);
kono
parents: 67
diff changeset
1847 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1848 return true;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1849 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1850
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1851 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1852 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1853
111
kono
parents: 67
diff changeset
1854 /* Determine whether applying the 2 permutations (mask1 then mask2)
kono
parents: 67
diff changeset
1855 gives back one of the input. */
kono
parents: 67
diff changeset
1856
kono
parents: 67
diff changeset
1857 static int
kono
parents: 67
diff changeset
1858 is_combined_permutation_identity (tree mask1, tree mask2)
kono
parents: 67
diff changeset
1859 {
kono
parents: 67
diff changeset
1860 tree mask;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1861 unsigned HOST_WIDE_INT nelts, i, j;
111
kono
parents: 67
diff changeset
1862 bool maybe_identity1 = true;
kono
parents: 67
diff changeset
1863 bool maybe_identity2 = true;
kono
parents: 67
diff changeset
1864
kono
parents: 67
diff changeset
1865 gcc_checking_assert (TREE_CODE (mask1) == VECTOR_CST
kono
parents: 67
diff changeset
1866 && TREE_CODE (mask2) == VECTOR_CST);
kono
parents: 67
diff changeset
1867 mask = fold_ternary (VEC_PERM_EXPR, TREE_TYPE (mask1), mask1, mask1, mask2);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1868 if (mask == NULL_TREE || TREE_CODE (mask) != VECTOR_CST)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1869 return 0;
111
kono
parents: 67
diff changeset
1870
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1871 if (!VECTOR_CST_NELTS (mask).is_constant (&nelts))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1872 return 0;
111
kono
parents: 67
diff changeset
1873 for (i = 0; i < nelts; i++)
kono
parents: 67
diff changeset
1874 {
kono
parents: 67
diff changeset
1875 tree val = VECTOR_CST_ELT (mask, i);
kono
parents: 67
diff changeset
1876 gcc_assert (TREE_CODE (val) == INTEGER_CST);
kono
parents: 67
diff changeset
1877 j = TREE_INT_CST_LOW (val) & (2 * nelts - 1);
kono
parents: 67
diff changeset
1878 if (j == i)
kono
parents: 67
diff changeset
1879 maybe_identity2 = false;
kono
parents: 67
diff changeset
1880 else if (j == i + nelts)
kono
parents: 67
diff changeset
1881 maybe_identity1 = false;
kono
parents: 67
diff changeset
1882 else
kono
parents: 67
diff changeset
1883 return 0;
kono
parents: 67
diff changeset
1884 }
kono
parents: 67
diff changeset
1885 return maybe_identity1 ? 1 : maybe_identity2 ? 2 : 0;
kono
parents: 67
diff changeset
1886 }
kono
parents: 67
diff changeset
1887
kono
parents: 67
diff changeset
1888 /* Combine a shuffle with its arguments. Returns 1 if there were any
kono
parents: 67
diff changeset
1889 changes made, 2 if cfg-cleanup needs to run. Else it returns 0. */
kono
parents: 67
diff changeset
1890
kono
parents: 67
diff changeset
1891 static int
kono
parents: 67
diff changeset
1892 simplify_permutation (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
1893 {
kono
parents: 67
diff changeset
1894 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
1895 gimple *def_stmt;
kono
parents: 67
diff changeset
1896 tree op0, op1, op2, op3, arg0, arg1;
kono
parents: 67
diff changeset
1897 enum tree_code code;
kono
parents: 67
diff changeset
1898 bool single_use_op0 = false;
kono
parents: 67
diff changeset
1899
kono
parents: 67
diff changeset
1900 gcc_checking_assert (gimple_assign_rhs_code (stmt) == VEC_PERM_EXPR);
kono
parents: 67
diff changeset
1901
kono
parents: 67
diff changeset
1902 op0 = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1903 op1 = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
1904 op2 = gimple_assign_rhs3 (stmt);
kono
parents: 67
diff changeset
1905
kono
parents: 67
diff changeset
1906 if (TREE_CODE (op2) != VECTOR_CST)
kono
parents: 67
diff changeset
1907 return 0;
kono
parents: 67
diff changeset
1908
kono
parents: 67
diff changeset
1909 if (TREE_CODE (op0) == VECTOR_CST)
kono
parents: 67
diff changeset
1910 {
kono
parents: 67
diff changeset
1911 code = VECTOR_CST;
kono
parents: 67
diff changeset
1912 arg0 = op0;
kono
parents: 67
diff changeset
1913 }
kono
parents: 67
diff changeset
1914 else if (TREE_CODE (op0) == SSA_NAME)
kono
parents: 67
diff changeset
1915 {
kono
parents: 67
diff changeset
1916 def_stmt = get_prop_source_stmt (op0, false, &single_use_op0);
kono
parents: 67
diff changeset
1917 if (!def_stmt || !can_propagate_from (def_stmt))
kono
parents: 67
diff changeset
1918 return 0;
kono
parents: 67
diff changeset
1919
kono
parents: 67
diff changeset
1920 code = gimple_assign_rhs_code (def_stmt);
kono
parents: 67
diff changeset
1921 arg0 = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
1922 }
kono
parents: 67
diff changeset
1923 else
kono
parents: 67
diff changeset
1924 return 0;
kono
parents: 67
diff changeset
1925
kono
parents: 67
diff changeset
1926 /* Two consecutive shuffles. */
kono
parents: 67
diff changeset
1927 if (code == VEC_PERM_EXPR)
kono
parents: 67
diff changeset
1928 {
kono
parents: 67
diff changeset
1929 tree orig;
kono
parents: 67
diff changeset
1930 int ident;
kono
parents: 67
diff changeset
1931
kono
parents: 67
diff changeset
1932 if (op0 != op1)
kono
parents: 67
diff changeset
1933 return 0;
kono
parents: 67
diff changeset
1934 op3 = gimple_assign_rhs3 (def_stmt);
kono
parents: 67
diff changeset
1935 if (TREE_CODE (op3) != VECTOR_CST)
kono
parents: 67
diff changeset
1936 return 0;
kono
parents: 67
diff changeset
1937 ident = is_combined_permutation_identity (op3, op2);
kono
parents: 67
diff changeset
1938 if (!ident)
kono
parents: 67
diff changeset
1939 return 0;
kono
parents: 67
diff changeset
1940 orig = (ident == 1) ? gimple_assign_rhs1 (def_stmt)
kono
parents: 67
diff changeset
1941 : gimple_assign_rhs2 (def_stmt);
kono
parents: 67
diff changeset
1942 gimple_assign_set_rhs1 (stmt, unshare_expr (orig));
kono
parents: 67
diff changeset
1943 gimple_assign_set_rhs_code (stmt, TREE_CODE (orig));
kono
parents: 67
diff changeset
1944 gimple_set_num_ops (stmt, 2);
kono
parents: 67
diff changeset
1945 update_stmt (stmt);
kono
parents: 67
diff changeset
1946 return remove_prop_source_from_use (op0) ? 2 : 1;
kono
parents: 67
diff changeset
1947 }
kono
parents: 67
diff changeset
1948
kono
parents: 67
diff changeset
1949 /* Shuffle of a constructor. */
kono
parents: 67
diff changeset
1950 else if (code == CONSTRUCTOR || code == VECTOR_CST)
kono
parents: 67
diff changeset
1951 {
kono
parents: 67
diff changeset
1952 tree opt;
kono
parents: 67
diff changeset
1953 bool ret = false;
kono
parents: 67
diff changeset
1954 if (op0 != op1)
kono
parents: 67
diff changeset
1955 {
kono
parents: 67
diff changeset
1956 if (TREE_CODE (op0) == SSA_NAME && !single_use_op0)
kono
parents: 67
diff changeset
1957 return 0;
kono
parents: 67
diff changeset
1958
kono
parents: 67
diff changeset
1959 if (TREE_CODE (op1) == VECTOR_CST)
kono
parents: 67
diff changeset
1960 arg1 = op1;
kono
parents: 67
diff changeset
1961 else if (TREE_CODE (op1) == SSA_NAME)
kono
parents: 67
diff changeset
1962 {
kono
parents: 67
diff changeset
1963 enum tree_code code2;
kono
parents: 67
diff changeset
1964
kono
parents: 67
diff changeset
1965 gimple *def_stmt2 = get_prop_source_stmt (op1, true, NULL);
kono
parents: 67
diff changeset
1966 if (!def_stmt2 || !can_propagate_from (def_stmt2))
kono
parents: 67
diff changeset
1967 return 0;
kono
parents: 67
diff changeset
1968
kono
parents: 67
diff changeset
1969 code2 = gimple_assign_rhs_code (def_stmt2);
kono
parents: 67
diff changeset
1970 if (code2 != CONSTRUCTOR && code2 != VECTOR_CST)
kono
parents: 67
diff changeset
1971 return 0;
kono
parents: 67
diff changeset
1972 arg1 = gimple_assign_rhs1 (def_stmt2);
kono
parents: 67
diff changeset
1973 }
kono
parents: 67
diff changeset
1974 else
kono
parents: 67
diff changeset
1975 return 0;
kono
parents: 67
diff changeset
1976 }
kono
parents: 67
diff changeset
1977 else
kono
parents: 67
diff changeset
1978 {
kono
parents: 67
diff changeset
1979 /* Already used twice in this statement. */
kono
parents: 67
diff changeset
1980 if (TREE_CODE (op0) == SSA_NAME && num_imm_uses (op0) > 2)
kono
parents: 67
diff changeset
1981 return 0;
kono
parents: 67
diff changeset
1982 arg1 = arg0;
kono
parents: 67
diff changeset
1983 }
kono
parents: 67
diff changeset
1984 opt = fold_ternary (VEC_PERM_EXPR, TREE_TYPE (op0), arg0, arg1, op2);
kono
parents: 67
diff changeset
1985 if (!opt
kono
parents: 67
diff changeset
1986 || (TREE_CODE (opt) != CONSTRUCTOR && TREE_CODE (opt) != VECTOR_CST))
kono
parents: 67
diff changeset
1987 return 0;
kono
parents: 67
diff changeset
1988 gimple_assign_set_rhs_from_tree (gsi, opt);
kono
parents: 67
diff changeset
1989 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
1990 if (TREE_CODE (op0) == SSA_NAME)
kono
parents: 67
diff changeset
1991 ret = remove_prop_source_from_use (op0);
kono
parents: 67
diff changeset
1992 if (op0 != op1 && TREE_CODE (op1) == SSA_NAME)
kono
parents: 67
diff changeset
1993 ret |= remove_prop_source_from_use (op1);
kono
parents: 67
diff changeset
1994 return ret ? 2 : 1;
kono
parents: 67
diff changeset
1995 }
kono
parents: 67
diff changeset
1996
kono
parents: 67
diff changeset
1997 return 0;
kono
parents: 67
diff changeset
1998 }
kono
parents: 67
diff changeset
1999
kono
parents: 67
diff changeset
2000 /* Recognize a VEC_PERM_EXPR. Returns true if there were any changes. */
kono
parents: 67
diff changeset
2001
kono
parents: 67
diff changeset
2002 static bool
kono
parents: 67
diff changeset
2003 simplify_vector_constructor (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
2004 {
kono
parents: 67
diff changeset
2005 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
2006 gimple *def_stmt;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2007 tree op, op2, orig[2], type, elem_type;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2008 unsigned elem_size, i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2009 unsigned HOST_WIDE_INT nelts;
111
kono
parents: 67
diff changeset
2010 enum tree_code code, conv_code;
kono
parents: 67
diff changeset
2011 constructor_elt *elt;
kono
parents: 67
diff changeset
2012 bool maybe_ident;
kono
parents: 67
diff changeset
2013
kono
parents: 67
diff changeset
2014 gcc_checking_assert (gimple_assign_rhs_code (stmt) == CONSTRUCTOR);
kono
parents: 67
diff changeset
2015
kono
parents: 67
diff changeset
2016 op = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
2017 type = TREE_TYPE (op);
kono
parents: 67
diff changeset
2018 gcc_checking_assert (TREE_CODE (type) == VECTOR_TYPE);
kono
parents: 67
diff changeset
2019
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2020 if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2021 return false;
111
kono
parents: 67
diff changeset
2022 elem_type = TREE_TYPE (type);
kono
parents: 67
diff changeset
2023 elem_size = TREE_INT_CST_LOW (TYPE_SIZE (elem_type));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2024
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2025 vec_perm_builder sel (nelts, nelts, 1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2026 orig[0] = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2027 orig[1] = NULL;
111
kono
parents: 67
diff changeset
2028 conv_code = ERROR_MARK;
kono
parents: 67
diff changeset
2029 maybe_ident = true;
kono
parents: 67
diff changeset
2030 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (op), i, elt)
kono
parents: 67
diff changeset
2031 {
kono
parents: 67
diff changeset
2032 tree ref, op1;
kono
parents: 67
diff changeset
2033
kono
parents: 67
diff changeset
2034 if (i >= nelts)
kono
parents: 67
diff changeset
2035 return false;
kono
parents: 67
diff changeset
2036
kono
parents: 67
diff changeset
2037 if (TREE_CODE (elt->value) != SSA_NAME)
kono
parents: 67
diff changeset
2038 return false;
kono
parents: 67
diff changeset
2039 def_stmt = get_prop_source_stmt (elt->value, false, NULL);
kono
parents: 67
diff changeset
2040 if (!def_stmt)
kono
parents: 67
diff changeset
2041 return false;
kono
parents: 67
diff changeset
2042 code = gimple_assign_rhs_code (def_stmt);
kono
parents: 67
diff changeset
2043 if (code == FLOAT_EXPR
kono
parents: 67
diff changeset
2044 || code == FIX_TRUNC_EXPR)
kono
parents: 67
diff changeset
2045 {
kono
parents: 67
diff changeset
2046 op1 = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
2047 if (conv_code == ERROR_MARK)
kono
parents: 67
diff changeset
2048 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2049 if (maybe_ne (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (elt->value))),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2050 GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))))
111
kono
parents: 67
diff changeset
2051 return false;
kono
parents: 67
diff changeset
2052 conv_code = code;
kono
parents: 67
diff changeset
2053 }
kono
parents: 67
diff changeset
2054 else if (conv_code != code)
kono
parents: 67
diff changeset
2055 return false;
kono
parents: 67
diff changeset
2056 if (TREE_CODE (op1) != SSA_NAME)
kono
parents: 67
diff changeset
2057 return false;
kono
parents: 67
diff changeset
2058 def_stmt = SSA_NAME_DEF_STMT (op1);
kono
parents: 67
diff changeset
2059 if (! is_gimple_assign (def_stmt))
kono
parents: 67
diff changeset
2060 return false;
kono
parents: 67
diff changeset
2061 code = gimple_assign_rhs_code (def_stmt);
kono
parents: 67
diff changeset
2062 }
kono
parents: 67
diff changeset
2063 if (code != BIT_FIELD_REF)
kono
parents: 67
diff changeset
2064 return false;
kono
parents: 67
diff changeset
2065 op1 = gimple_assign_rhs1 (def_stmt);
kono
parents: 67
diff changeset
2066 ref = TREE_OPERAND (op1, 0);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2067 unsigned int j;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2068 for (j = 0; j < 2; ++j)
111
kono
parents: 67
diff changeset
2069 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2070 if (!orig[j])
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2071 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2072 if (TREE_CODE (ref) != SSA_NAME)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2073 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2074 if (! VECTOR_TYPE_P (TREE_TYPE (ref))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2075 || ! useless_type_conversion_p (TREE_TYPE (op1),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2076 TREE_TYPE (TREE_TYPE (ref))))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2077 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2078 if (j && !useless_type_conversion_p (TREE_TYPE (orig[0]),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2079 TREE_TYPE (ref)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2080 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2081 orig[j] = ref;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2082 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2083 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2084 else if (ref == orig[j])
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2085 break;
111
kono
parents: 67
diff changeset
2086 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2087 if (j == 2)
111
kono
parents: 67
diff changeset
2088 return false;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2089
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2090 unsigned int elt;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2091 if (maybe_ne (bit_field_size (op1), elem_size)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2092 || !constant_multiple_p (bit_field_offset (op1), elem_size, &elt))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2093 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2094 if (j)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2095 elt += nelts;
111
kono
parents: 67
diff changeset
2096 if (elt != i)
kono
parents: 67
diff changeset
2097 maybe_ident = false;
kono
parents: 67
diff changeset
2098 sel.quick_push (elt);
kono
parents: 67
diff changeset
2099 }
kono
parents: 67
diff changeset
2100 if (i < nelts)
kono
parents: 67
diff changeset
2101 return false;
kono
parents: 67
diff changeset
2102
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2103 if (! VECTOR_TYPE_P (TREE_TYPE (orig[0]))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2104 || maybe_ne (TYPE_VECTOR_SUBPARTS (type),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2105 TYPE_VECTOR_SUBPARTS (TREE_TYPE (orig[0]))))
111
kono
parents: 67
diff changeset
2106 return false;
kono
parents: 67
diff changeset
2107
kono
parents: 67
diff changeset
2108 tree tem;
kono
parents: 67
diff changeset
2109 if (conv_code != ERROR_MARK
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2110 && (! supportable_convert_operation (conv_code, type,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2111 TREE_TYPE (orig[0]),
111
kono
parents: 67
diff changeset
2112 &tem, &conv_code)
kono
parents: 67
diff changeset
2113 || conv_code == CALL_EXPR))
kono
parents: 67
diff changeset
2114 return false;
kono
parents: 67
diff changeset
2115
kono
parents: 67
diff changeset
2116 if (maybe_ident)
kono
parents: 67
diff changeset
2117 {
kono
parents: 67
diff changeset
2118 if (conv_code == ERROR_MARK)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2119 gimple_assign_set_rhs_from_tree (gsi, orig[0]);
111
kono
parents: 67
diff changeset
2120 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2121 gimple_assign_set_rhs_with_ops (gsi, conv_code, orig[0],
111
kono
parents: 67
diff changeset
2122 NULL_TREE, NULL_TREE);
kono
parents: 67
diff changeset
2123 }
kono
parents: 67
diff changeset
2124 else
kono
parents: 67
diff changeset
2125 {
kono
parents: 67
diff changeset
2126 tree mask_type;
kono
parents: 67
diff changeset
2127
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2128 vec_perm_indices indices (sel, orig[1] ? 2 : 1, nelts);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2129 if (!can_vec_perm_const_p (TYPE_MODE (type), indices))
111
kono
parents: 67
diff changeset
2130 return false;
kono
parents: 67
diff changeset
2131 mask_type
kono
parents: 67
diff changeset
2132 = build_vector_type (build_nonstandard_integer_type (elem_size, 1),
kono
parents: 67
diff changeset
2133 nelts);
kono
parents: 67
diff changeset
2134 if (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2135 || maybe_ne (GET_MODE_SIZE (TYPE_MODE (mask_type)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2136 GET_MODE_SIZE (TYPE_MODE (type))))
111
kono
parents: 67
diff changeset
2137 return false;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2138 op2 = vec_perm_indices_to_tree (mask_type, indices);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2139 if (!orig[1])
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2140 orig[1] = orig[0];
111
kono
parents: 67
diff changeset
2141 if (conv_code == ERROR_MARK)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2142 gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig[0],
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2143 orig[1], op2);
111
kono
parents: 67
diff changeset
2144 else
kono
parents: 67
diff changeset
2145 {
kono
parents: 67
diff changeset
2146 gimple *perm
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2147 = gimple_build_assign (make_ssa_name (TREE_TYPE (orig[0])),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2148 VEC_PERM_EXPR, orig[0], orig[1], op2);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2149 orig[0] = gimple_assign_lhs (perm);
111
kono
parents: 67
diff changeset
2150 gsi_insert_before (gsi, perm, GSI_SAME_STMT);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2151 gimple_assign_set_rhs_with_ops (gsi, conv_code, orig[0],
111
kono
parents: 67
diff changeset
2152 NULL_TREE, NULL_TREE);
kono
parents: 67
diff changeset
2153 }
kono
parents: 67
diff changeset
2154 }
kono
parents: 67
diff changeset
2155 update_stmt (gsi_stmt (*gsi));
kono
parents: 67
diff changeset
2156 return true;
kono
parents: 67
diff changeset
2157 }
kono
parents: 67
diff changeset
2158
kono
parents: 67
diff changeset
2159
kono
parents: 67
diff changeset
2160 /* Primitive "lattice" function for gimple_simplify. */
kono
parents: 67
diff changeset
2161
kono
parents: 67
diff changeset
2162 static tree
kono
parents: 67
diff changeset
2163 fwprop_ssa_val (tree name)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2164 {
111
kono
parents: 67
diff changeset
2165 /* First valueize NAME. */
kono
parents: 67
diff changeset
2166 if (TREE_CODE (name) == SSA_NAME
kono
parents: 67
diff changeset
2167 && SSA_NAME_VERSION (name) < lattice.length ())
kono
parents: 67
diff changeset
2168 {
kono
parents: 67
diff changeset
2169 tree val = lattice[SSA_NAME_VERSION (name)];
kono
parents: 67
diff changeset
2170 if (val)
kono
parents: 67
diff changeset
2171 name = val;
kono
parents: 67
diff changeset
2172 }
kono
parents: 67
diff changeset
2173 /* We continue matching along SSA use-def edges for SSA names
kono
parents: 67
diff changeset
2174 that are not single-use. Currently there are no patterns
kono
parents: 67
diff changeset
2175 that would cause any issues with that. */
kono
parents: 67
diff changeset
2176 return name;
kono
parents: 67
diff changeset
2177 }
kono
parents: 67
diff changeset
2178
kono
parents: 67
diff changeset
2179 /* Main entry point for the forward propagation and statement combine
kono
parents: 67
diff changeset
2180 optimizer. */
kono
parents: 67
diff changeset
2181
kono
parents: 67
diff changeset
2182 namespace {
kono
parents: 67
diff changeset
2183
kono
parents: 67
diff changeset
2184 const pass_data pass_data_forwprop =
kono
parents: 67
diff changeset
2185 {
kono
parents: 67
diff changeset
2186 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
2187 "forwprop", /* name */
kono
parents: 67
diff changeset
2188 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 67
diff changeset
2189 TV_TREE_FORWPROP, /* tv_id */
kono
parents: 67
diff changeset
2190 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
2191 0, /* properties_provided */
kono
parents: 67
diff changeset
2192 0, /* properties_destroyed */
kono
parents: 67
diff changeset
2193 0, /* todo_flags_start */
kono
parents: 67
diff changeset
2194 TODO_update_ssa, /* todo_flags_finish */
kono
parents: 67
diff changeset
2195 };
kono
parents: 67
diff changeset
2196
kono
parents: 67
diff changeset
2197 class pass_forwprop : public gimple_opt_pass
kono
parents: 67
diff changeset
2198 {
kono
parents: 67
diff changeset
2199 public:
kono
parents: 67
diff changeset
2200 pass_forwprop (gcc::context *ctxt)
kono
parents: 67
diff changeset
2201 : gimple_opt_pass (pass_data_forwprop, ctxt)
kono
parents: 67
diff changeset
2202 {}
kono
parents: 67
diff changeset
2203
kono
parents: 67
diff changeset
2204 /* opt_pass methods: */
kono
parents: 67
diff changeset
2205 opt_pass * clone () { return new pass_forwprop (m_ctxt); }
kono
parents: 67
diff changeset
2206 virtual bool gate (function *) { return flag_tree_forwprop; }
kono
parents: 67
diff changeset
2207 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
2208
kono
parents: 67
diff changeset
2209 }; // class pass_forwprop
kono
parents: 67
diff changeset
2210
kono
parents: 67
diff changeset
2211 unsigned int
kono
parents: 67
diff changeset
2212 pass_forwprop::execute (function *fun)
kono
parents: 67
diff changeset
2213 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2214 unsigned int todoflags = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2215
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2216 cfg_changed = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2217
111
kono
parents: 67
diff changeset
2218 /* Combine stmts with the stmts defining their operands. Do that
kono
parents: 67
diff changeset
2219 in an order that guarantees visiting SSA defs before SSA uses. */
kono
parents: 67
diff changeset
2220 lattice.create (num_ssa_names);
kono
parents: 67
diff changeset
2221 lattice.quick_grow_cleared (num_ssa_names);
kono
parents: 67
diff changeset
2222 int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (fun));
kono
parents: 67
diff changeset
2223 int postorder_num = pre_and_rev_post_order_compute_fn (cfun, NULL,
kono
parents: 67
diff changeset
2224 postorder, false);
kono
parents: 67
diff changeset
2225 auto_vec<gimple *, 4> to_fixup;
kono
parents: 67
diff changeset
2226 to_purge = BITMAP_ALLOC (NULL);
kono
parents: 67
diff changeset
2227 for (int i = 0; i < postorder_num; ++i)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2228 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2229 gimple_stmt_iterator gsi;
111
kono
parents: 67
diff changeset
2230 basic_block bb = BASIC_BLOCK_FOR_FN (fun, postorder[i]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2231
111
kono
parents: 67
diff changeset
2232 /* Propagate into PHIs and record degenerate ones in the lattice. */
kono
parents: 67
diff changeset
2233 for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
kono
parents: 67
diff changeset
2234 gsi_next (&si))
kono
parents: 67
diff changeset
2235 {
kono
parents: 67
diff changeset
2236 gphi *phi = si.phi ();
kono
parents: 67
diff changeset
2237 tree res = gimple_phi_result (phi);
kono
parents: 67
diff changeset
2238 if (virtual_operand_p (res))
kono
parents: 67
diff changeset
2239 continue;
kono
parents: 67
diff changeset
2240
kono
parents: 67
diff changeset
2241 use_operand_p use_p;
kono
parents: 67
diff changeset
2242 ssa_op_iter it;
kono
parents: 67
diff changeset
2243 tree first = NULL_TREE;
kono
parents: 67
diff changeset
2244 bool all_same = true;
kono
parents: 67
diff changeset
2245 FOR_EACH_PHI_ARG (use_p, phi, it, SSA_OP_USE)
kono
parents: 67
diff changeset
2246 {
kono
parents: 67
diff changeset
2247 tree use = USE_FROM_PTR (use_p);
kono
parents: 67
diff changeset
2248 tree tem = fwprop_ssa_val (use);
kono
parents: 67
diff changeset
2249 if (! first)
kono
parents: 67
diff changeset
2250 first = tem;
kono
parents: 67
diff changeset
2251 else if (! operand_equal_p (first, tem, 0))
kono
parents: 67
diff changeset
2252 all_same = false;
kono
parents: 67
diff changeset
2253 if (tem != use
kono
parents: 67
diff changeset
2254 && may_propagate_copy (use, tem))
kono
parents: 67
diff changeset
2255 propagate_value (use_p, tem);
kono
parents: 67
diff changeset
2256 }
kono
parents: 67
diff changeset
2257 if (all_same)
kono
parents: 67
diff changeset
2258 fwprop_set_lattice_val (res, first);
kono
parents: 67
diff changeset
2259 }
kono
parents: 67
diff changeset
2260
kono
parents: 67
diff changeset
2261 /* Apply forward propagation to all stmts in the basic-block.
kono
parents: 67
diff changeset
2262 Note we update GSI within the loop as necessary. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2263 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2264 {
111
kono
parents: 67
diff changeset
2265 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
2266 tree lhs, rhs;
kono
parents: 67
diff changeset
2267 enum tree_code code;
kono
parents: 67
diff changeset
2268
kono
parents: 67
diff changeset
2269 if (!is_gimple_assign (stmt))
kono
parents: 67
diff changeset
2270 {
kono
parents: 67
diff changeset
2271 gsi_next (&gsi);
kono
parents: 67
diff changeset
2272 continue;
kono
parents: 67
diff changeset
2273 }
kono
parents: 67
diff changeset
2274
kono
parents: 67
diff changeset
2275 lhs = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
2276 rhs = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
2277 code = gimple_assign_rhs_code (stmt);
kono
parents: 67
diff changeset
2278 if (TREE_CODE (lhs) != SSA_NAME
kono
parents: 67
diff changeset
2279 || has_zero_uses (lhs))
kono
parents: 67
diff changeset
2280 {
kono
parents: 67
diff changeset
2281 gsi_next (&gsi);
kono
parents: 67
diff changeset
2282 continue;
kono
parents: 67
diff changeset
2283 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2284
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2285 /* If this statement sets an SSA_NAME to an address,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2286 try to propagate the address into the uses of the SSA_NAME. */
111
kono
parents: 67
diff changeset
2287 if (code == ADDR_EXPR
kono
parents: 67
diff changeset
2288 /* Handle pointer conversions on invariant addresses
kono
parents: 67
diff changeset
2289 as well, as this is valid gimple. */
kono
parents: 67
diff changeset
2290 || (CONVERT_EXPR_CODE_P (code)
kono
parents: 67
diff changeset
2291 && TREE_CODE (rhs) == ADDR_EXPR
kono
parents: 67
diff changeset
2292 && POINTER_TYPE_P (TREE_TYPE (lhs))))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2293 {
111
kono
parents: 67
diff changeset
2294 tree base = get_base_address (TREE_OPERAND (rhs, 0));
kono
parents: 67
diff changeset
2295 if ((!base
kono
parents: 67
diff changeset
2296 || !DECL_P (base)
kono
parents: 67
diff changeset
2297 || decl_address_invariant_p (base))
kono
parents: 67
diff changeset
2298 && !stmt_references_abnormal_ssa_name (stmt)
kono
parents: 67
diff changeset
2299 && forward_propagate_addr_expr (lhs, rhs, true))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
2300 {
111
kono
parents: 67
diff changeset
2301 fwprop_invalidate_lattice (gimple_get_lhs (stmt));
kono
parents: 67
diff changeset
2302 release_defs (stmt);
kono
parents: 67
diff changeset
2303 gsi_remove (&gsi, true);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2304 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2305 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2306 gsi_next (&gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2307 }
111
kono
parents: 67
diff changeset
2308 else if (code == POINTER_PLUS_EXPR)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2309 {
111
kono
parents: 67
diff changeset
2310 tree off = gimple_assign_rhs2 (stmt);
kono
parents: 67
diff changeset
2311 if (TREE_CODE (off) == INTEGER_CST
kono
parents: 67
diff changeset
2312 && can_propagate_from (stmt)
kono
parents: 67
diff changeset
2313 && !simple_iv_increment_p (stmt)
kono
parents: 67
diff changeset
2314 /* ??? Better adjust the interface to that function
kono
parents: 67
diff changeset
2315 instead of building new trees here. */
kono
parents: 67
diff changeset
2316 && forward_propagate_addr_expr
kono
parents: 67
diff changeset
2317 (lhs,
kono
parents: 67
diff changeset
2318 build1_loc (gimple_location (stmt),
kono
parents: 67
diff changeset
2319 ADDR_EXPR, TREE_TYPE (rhs),
kono
parents: 67
diff changeset
2320 fold_build2 (MEM_REF,
kono
parents: 67
diff changeset
2321 TREE_TYPE (TREE_TYPE (rhs)),
kono
parents: 67
diff changeset
2322 rhs,
kono
parents: 67
diff changeset
2323 fold_convert (ptr_type_node,
kono
parents: 67
diff changeset
2324 off))), true))
kono
parents: 67
diff changeset
2325 {
kono
parents: 67
diff changeset
2326 fwprop_invalidate_lattice (gimple_get_lhs (stmt));
kono
parents: 67
diff changeset
2327 release_defs (stmt);
kono
parents: 67
diff changeset
2328 gsi_remove (&gsi, true);
kono
parents: 67
diff changeset
2329 }
kono
parents: 67
diff changeset
2330 else if (is_gimple_min_invariant (rhs))
kono
parents: 67
diff changeset
2331 {
kono
parents: 67
diff changeset
2332 /* Make sure to fold &a[0] + off_1 here. */
kono
parents: 67
diff changeset
2333 fold_stmt_inplace (&gsi);
kono
parents: 67
diff changeset
2334 update_stmt (stmt);
kono
parents: 67
diff changeset
2335 if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR)
kono
parents: 67
diff changeset
2336 gsi_next (&gsi);
kono
parents: 67
diff changeset
2337 }
kono
parents: 67
diff changeset
2338 else
kono
parents: 67
diff changeset
2339 gsi_next (&gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2340 }
111
kono
parents: 67
diff changeset
2341 else if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE
kono
parents: 67
diff changeset
2342 && gimple_assign_load_p (stmt)
kono
parents: 67
diff changeset
2343 && !gimple_has_volatile_ops (stmt)
kono
parents: 67
diff changeset
2344 && (TREE_CODE (gimple_assign_rhs1 (stmt))
kono
parents: 67
diff changeset
2345 != TARGET_MEM_REF)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2346 && !stmt_can_throw_internal (cfun, stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2347 {
111
kono
parents: 67
diff changeset
2348 /* Rewrite loads used only in real/imagpart extractions to
kono
parents: 67
diff changeset
2349 component-wise loads. */
kono
parents: 67
diff changeset
2350 use_operand_p use_p;
kono
parents: 67
diff changeset
2351 imm_use_iterator iter;
kono
parents: 67
diff changeset
2352 bool rewrite = true;
kono
parents: 67
diff changeset
2353 FOR_EACH_IMM_USE_FAST (use_p, iter, lhs)
kono
parents: 67
diff changeset
2354 {
kono
parents: 67
diff changeset
2355 gimple *use_stmt = USE_STMT (use_p);
kono
parents: 67
diff changeset
2356 if (is_gimple_debug (use_stmt))
kono
parents: 67
diff changeset
2357 continue;
kono
parents: 67
diff changeset
2358 if (!is_gimple_assign (use_stmt)
kono
parents: 67
diff changeset
2359 || (gimple_assign_rhs_code (use_stmt) != REALPART_EXPR
kono
parents: 67
diff changeset
2360 && gimple_assign_rhs_code (use_stmt) != IMAGPART_EXPR))
kono
parents: 67
diff changeset
2361 {
kono
parents: 67
diff changeset
2362 rewrite = false;
kono
parents: 67
diff changeset
2363 break;
kono
parents: 67
diff changeset
2364 }
kono
parents: 67
diff changeset
2365 }
kono
parents: 67
diff changeset
2366 if (rewrite)
kono
parents: 67
diff changeset
2367 {
kono
parents: 67
diff changeset
2368 gimple *use_stmt;
kono
parents: 67
diff changeset
2369 FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
kono
parents: 67
diff changeset
2370 {
kono
parents: 67
diff changeset
2371 if (is_gimple_debug (use_stmt))
kono
parents: 67
diff changeset
2372 {
kono
parents: 67
diff changeset
2373 if (gimple_debug_bind_p (use_stmt))
kono
parents: 67
diff changeset
2374 {
kono
parents: 67
diff changeset
2375 gimple_debug_bind_reset_value (use_stmt);
kono
parents: 67
diff changeset
2376 update_stmt (use_stmt);
kono
parents: 67
diff changeset
2377 }
kono
parents: 67
diff changeset
2378 continue;
kono
parents: 67
diff changeset
2379 }
kono
parents: 67
diff changeset
2380
kono
parents: 67
diff changeset
2381 tree new_rhs = build1 (gimple_assign_rhs_code (use_stmt),
kono
parents: 67
diff changeset
2382 TREE_TYPE (TREE_TYPE (rhs)),
kono
parents: 67
diff changeset
2383 unshare_expr (rhs));
kono
parents: 67
diff changeset
2384 gimple *new_stmt
kono
parents: 67
diff changeset
2385 = gimple_build_assign (gimple_assign_lhs (use_stmt),
kono
parents: 67
diff changeset
2386 new_rhs);
kono
parents: 67
diff changeset
2387
kono
parents: 67
diff changeset
2388 location_t loc = gimple_location (use_stmt);
kono
parents: 67
diff changeset
2389 gimple_set_location (new_stmt, loc);
kono
parents: 67
diff changeset
2390 gimple_stmt_iterator gsi2 = gsi_for_stmt (use_stmt);
kono
parents: 67
diff changeset
2391 unlink_stmt_vdef (use_stmt);
kono
parents: 67
diff changeset
2392 gsi_remove (&gsi2, true);
kono
parents: 67
diff changeset
2393
kono
parents: 67
diff changeset
2394 gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT);
kono
parents: 67
diff changeset
2395 }
kono
parents: 67
diff changeset
2396
kono
parents: 67
diff changeset
2397 release_defs (stmt);
kono
parents: 67
diff changeset
2398 gsi_remove (&gsi, true);
kono
parents: 67
diff changeset
2399 }
kono
parents: 67
diff changeset
2400 else
kono
parents: 67
diff changeset
2401 gsi_next (&gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2402 }
111
kono
parents: 67
diff changeset
2403 else if (code == COMPLEX_EXPR)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2404 {
111
kono
parents: 67
diff changeset
2405 /* Rewrite stores of a single-use complex build expression
kono
parents: 67
diff changeset
2406 to component-wise stores. */
kono
parents: 67
diff changeset
2407 use_operand_p use_p;
kono
parents: 67
diff changeset
2408 gimple *use_stmt;
kono
parents: 67
diff changeset
2409 if (single_imm_use (lhs, &use_p, &use_stmt)
kono
parents: 67
diff changeset
2410 && gimple_store_p (use_stmt)
kono
parents: 67
diff changeset
2411 && !gimple_has_volatile_ops (use_stmt)
kono
parents: 67
diff changeset
2412 && is_gimple_assign (use_stmt)
kono
parents: 67
diff changeset
2413 && (TREE_CODE (gimple_assign_lhs (use_stmt))
kono
parents: 67
diff changeset
2414 != TARGET_MEM_REF))
kono
parents: 67
diff changeset
2415 {
kono
parents: 67
diff changeset
2416 tree use_lhs = gimple_assign_lhs (use_stmt);
kono
parents: 67
diff changeset
2417 tree new_lhs = build1 (REALPART_EXPR,
kono
parents: 67
diff changeset
2418 TREE_TYPE (TREE_TYPE (use_lhs)),
kono
parents: 67
diff changeset
2419 unshare_expr (use_lhs));
kono
parents: 67
diff changeset
2420 gimple *new_stmt = gimple_build_assign (new_lhs, rhs);
kono
parents: 67
diff changeset
2421 location_t loc = gimple_location (use_stmt);
kono
parents: 67
diff changeset
2422 gimple_set_location (new_stmt, loc);
kono
parents: 67
diff changeset
2423 gimple_set_vuse (new_stmt, gimple_vuse (use_stmt));
kono
parents: 67
diff changeset
2424 gimple_set_vdef (new_stmt, make_ssa_name (gimple_vop (cfun)));
kono
parents: 67
diff changeset
2425 SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
kono
parents: 67
diff changeset
2426 gimple_set_vuse (use_stmt, gimple_vdef (new_stmt));
kono
parents: 67
diff changeset
2427 gimple_stmt_iterator gsi2 = gsi_for_stmt (use_stmt);
kono
parents: 67
diff changeset
2428 gsi_insert_before (&gsi2, new_stmt, GSI_SAME_STMT);
kono
parents: 67
diff changeset
2429
kono
parents: 67
diff changeset
2430 new_lhs = build1 (IMAGPART_EXPR,
kono
parents: 67
diff changeset
2431 TREE_TYPE (TREE_TYPE (use_lhs)),
kono
parents: 67
diff changeset
2432 unshare_expr (use_lhs));
kono
parents: 67
diff changeset
2433 gimple_assign_set_lhs (use_stmt, new_lhs);
kono
parents: 67
diff changeset
2434 gimple_assign_set_rhs1 (use_stmt, gimple_assign_rhs2 (stmt));
kono
parents: 67
diff changeset
2435 update_stmt (use_stmt);
kono
parents: 67
diff changeset
2436
kono
parents: 67
diff changeset
2437 release_defs (stmt);
kono
parents: 67
diff changeset
2438 gsi_remove (&gsi, true);
kono
parents: 67
diff changeset
2439 }
kono
parents: 67
diff changeset
2440 else
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2441 gsi_next (&gsi);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2442 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2443 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2444 gsi_next (&gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2445 }
111
kono
parents: 67
diff changeset
2446
kono
parents: 67
diff changeset
2447 /* Combine stmts with the stmts defining their operands.
kono
parents: 67
diff changeset
2448 Note we update GSI within the loop as necessary. */
kono
parents: 67
diff changeset
2449 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
kono
parents: 67
diff changeset
2450 {
kono
parents: 67
diff changeset
2451 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
2452 gimple *orig_stmt = stmt;
kono
parents: 67
diff changeset
2453 bool changed = false;
kono
parents: 67
diff changeset
2454 bool was_noreturn = (is_gimple_call (stmt)
kono
parents: 67
diff changeset
2455 && gimple_call_noreturn_p (stmt));
kono
parents: 67
diff changeset
2456
kono
parents: 67
diff changeset
2457 /* Mark stmt as potentially needing revisiting. */
kono
parents: 67
diff changeset
2458 gimple_set_plf (stmt, GF_PLF_1, false);
kono
parents: 67
diff changeset
2459
kono
parents: 67
diff changeset
2460 if (fold_stmt (&gsi, fwprop_ssa_val))
kono
parents: 67
diff changeset
2461 {
kono
parents: 67
diff changeset
2462 changed = true;
kono
parents: 67
diff changeset
2463 stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
2464 if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
kono
parents: 67
diff changeset
2465 bitmap_set_bit (to_purge, bb->index);
kono
parents: 67
diff changeset
2466 if (!was_noreturn
kono
parents: 67
diff changeset
2467 && is_gimple_call (stmt) && gimple_call_noreturn_p (stmt))
kono
parents: 67
diff changeset
2468 to_fixup.safe_push (stmt);
kono
parents: 67
diff changeset
2469 /* Cleanup the CFG if we simplified a condition to
kono
parents: 67
diff changeset
2470 true or false. */
kono
parents: 67
diff changeset
2471 if (gcond *cond = dyn_cast <gcond *> (stmt))
kono
parents: 67
diff changeset
2472 if (gimple_cond_true_p (cond)
kono
parents: 67
diff changeset
2473 || gimple_cond_false_p (cond))
kono
parents: 67
diff changeset
2474 cfg_changed = true;
kono
parents: 67
diff changeset
2475 update_stmt (stmt);
kono
parents: 67
diff changeset
2476 }
kono
parents: 67
diff changeset
2477
kono
parents: 67
diff changeset
2478 switch (gimple_code (stmt))
kono
parents: 67
diff changeset
2479 {
kono
parents: 67
diff changeset
2480 case GIMPLE_ASSIGN:
kono
parents: 67
diff changeset
2481 {
kono
parents: 67
diff changeset
2482 tree rhs1 = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
2483 enum tree_code code = gimple_assign_rhs_code (stmt);
kono
parents: 67
diff changeset
2484
kono
parents: 67
diff changeset
2485 if (code == COND_EXPR
kono
parents: 67
diff changeset
2486 || code == VEC_COND_EXPR)
kono
parents: 67
diff changeset
2487 {
kono
parents: 67
diff changeset
2488 /* In this case the entire COND_EXPR is in rhs1. */
kono
parents: 67
diff changeset
2489 if (forward_propagate_into_cond (&gsi))
kono
parents: 67
diff changeset
2490 {
kono
parents: 67
diff changeset
2491 changed = true;
kono
parents: 67
diff changeset
2492 stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
2493 }
kono
parents: 67
diff changeset
2494 }
kono
parents: 67
diff changeset
2495 else if (TREE_CODE_CLASS (code) == tcc_comparison)
kono
parents: 67
diff changeset
2496 {
kono
parents: 67
diff changeset
2497 int did_something;
kono
parents: 67
diff changeset
2498 did_something = forward_propagate_into_comparison (&gsi);
kono
parents: 67
diff changeset
2499 if (did_something == 2)
kono
parents: 67
diff changeset
2500 cfg_changed = true;
kono
parents: 67
diff changeset
2501 changed = did_something != 0;
kono
parents: 67
diff changeset
2502 }
kono
parents: 67
diff changeset
2503 else if ((code == PLUS_EXPR
kono
parents: 67
diff changeset
2504 || code == BIT_IOR_EXPR
kono
parents: 67
diff changeset
2505 || code == BIT_XOR_EXPR)
kono
parents: 67
diff changeset
2506 && simplify_rotate (&gsi))
kono
parents: 67
diff changeset
2507 changed = true;
kono
parents: 67
diff changeset
2508 else if (code == VEC_PERM_EXPR)
kono
parents: 67
diff changeset
2509 {
kono
parents: 67
diff changeset
2510 int did_something = simplify_permutation (&gsi);
kono
parents: 67
diff changeset
2511 if (did_something == 2)
kono
parents: 67
diff changeset
2512 cfg_changed = true;
kono
parents: 67
diff changeset
2513 changed = did_something != 0;
kono
parents: 67
diff changeset
2514 }
kono
parents: 67
diff changeset
2515 else if (code == BIT_FIELD_REF)
kono
parents: 67
diff changeset
2516 changed = simplify_bitfield_ref (&gsi);
kono
parents: 67
diff changeset
2517 else if (code == CONSTRUCTOR
kono
parents: 67
diff changeset
2518 && TREE_CODE (TREE_TYPE (rhs1)) == VECTOR_TYPE)
kono
parents: 67
diff changeset
2519 changed = simplify_vector_constructor (&gsi);
kono
parents: 67
diff changeset
2520 break;
kono
parents: 67
diff changeset
2521 }
kono
parents: 67
diff changeset
2522
kono
parents: 67
diff changeset
2523 case GIMPLE_SWITCH:
kono
parents: 67
diff changeset
2524 changed = simplify_gimple_switch (as_a <gswitch *> (stmt));
kono
parents: 67
diff changeset
2525 break;
kono
parents: 67
diff changeset
2526
kono
parents: 67
diff changeset
2527 case GIMPLE_COND:
kono
parents: 67
diff changeset
2528 {
kono
parents: 67
diff changeset
2529 int did_something
kono
parents: 67
diff changeset
2530 = forward_propagate_into_gimple_cond (as_a <gcond *> (stmt));
kono
parents: 67
diff changeset
2531 if (did_something == 2)
kono
parents: 67
diff changeset
2532 cfg_changed = true;
kono
parents: 67
diff changeset
2533 changed = did_something != 0;
kono
parents: 67
diff changeset
2534 break;
kono
parents: 67
diff changeset
2535 }
kono
parents: 67
diff changeset
2536
kono
parents: 67
diff changeset
2537 case GIMPLE_CALL:
kono
parents: 67
diff changeset
2538 {
kono
parents: 67
diff changeset
2539 tree callee = gimple_call_fndecl (stmt);
kono
parents: 67
diff changeset
2540 if (callee != NULL_TREE
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2541 && fndecl_built_in_p (callee, BUILT_IN_NORMAL))
111
kono
parents: 67
diff changeset
2542 changed = simplify_builtin_call (&gsi, callee);
kono
parents: 67
diff changeset
2543 break;
kono
parents: 67
diff changeset
2544 }
kono
parents: 67
diff changeset
2545
kono
parents: 67
diff changeset
2546 default:;
kono
parents: 67
diff changeset
2547 }
kono
parents: 67
diff changeset
2548
kono
parents: 67
diff changeset
2549 if (changed)
kono
parents: 67
diff changeset
2550 {
kono
parents: 67
diff changeset
2551 /* If the stmt changed then re-visit it and the statements
kono
parents: 67
diff changeset
2552 inserted before it. */
kono
parents: 67
diff changeset
2553 for (; !gsi_end_p (gsi); gsi_prev (&gsi))
kono
parents: 67
diff changeset
2554 if (gimple_plf (gsi_stmt (gsi), GF_PLF_1))
kono
parents: 67
diff changeset
2555 break;
kono
parents: 67
diff changeset
2556 if (gsi_end_p (gsi))
kono
parents: 67
diff changeset
2557 gsi = gsi_start_bb (bb);
kono
parents: 67
diff changeset
2558 else
kono
parents: 67
diff changeset
2559 gsi_next (&gsi);
kono
parents: 67
diff changeset
2560 }
kono
parents: 67
diff changeset
2561 else
kono
parents: 67
diff changeset
2562 {
kono
parents: 67
diff changeset
2563 /* Stmt no longer needs to be revisited. */
kono
parents: 67
diff changeset
2564 gimple_set_plf (stmt, GF_PLF_1, true);
kono
parents: 67
diff changeset
2565
kono
parents: 67
diff changeset
2566 /* Fill up the lattice. */
kono
parents: 67
diff changeset
2567 if (gimple_assign_single_p (stmt))
kono
parents: 67
diff changeset
2568 {
kono
parents: 67
diff changeset
2569 tree lhs = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
2570 tree rhs = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
2571 if (TREE_CODE (lhs) == SSA_NAME)
kono
parents: 67
diff changeset
2572 {
kono
parents: 67
diff changeset
2573 tree val = lhs;
kono
parents: 67
diff changeset
2574 if (TREE_CODE (rhs) == SSA_NAME)
kono
parents: 67
diff changeset
2575 val = fwprop_ssa_val (rhs);
kono
parents: 67
diff changeset
2576 else if (is_gimple_min_invariant (rhs))
kono
parents: 67
diff changeset
2577 val = rhs;
kono
parents: 67
diff changeset
2578 fwprop_set_lattice_val (lhs, val);
kono
parents: 67
diff changeset
2579 }
kono
parents: 67
diff changeset
2580 }
kono
parents: 67
diff changeset
2581
kono
parents: 67
diff changeset
2582 gsi_next (&gsi);
kono
parents: 67
diff changeset
2583 }
kono
parents: 67
diff changeset
2584 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2585 }
111
kono
parents: 67
diff changeset
2586 free (postorder);
kono
parents: 67
diff changeset
2587 lattice.release ();
kono
parents: 67
diff changeset
2588
kono
parents: 67
diff changeset
2589 /* Fixup stmts that became noreturn calls. This may require splitting
kono
parents: 67
diff changeset
2590 blocks and thus isn't possible during the walk. Do this
kono
parents: 67
diff changeset
2591 in reverse order so we don't inadvertedly remove a stmt we want to
kono
parents: 67
diff changeset
2592 fixup by visiting a dominating now noreturn call first. */
kono
parents: 67
diff changeset
2593 while (!to_fixup.is_empty ())
kono
parents: 67
diff changeset
2594 {
kono
parents: 67
diff changeset
2595 gimple *stmt = to_fixup.pop ();
kono
parents: 67
diff changeset
2596 if (dump_file && dump_flags & TDF_DETAILS)
kono
parents: 67
diff changeset
2597 {
kono
parents: 67
diff changeset
2598 fprintf (dump_file, "Fixing up noreturn call ");
kono
parents: 67
diff changeset
2599 print_gimple_stmt (dump_file, stmt, 0);
kono
parents: 67
diff changeset
2600 fprintf (dump_file, "\n");
kono
parents: 67
diff changeset
2601 }
kono
parents: 67
diff changeset
2602 cfg_changed |= fixup_noreturn_call (stmt);
kono
parents: 67
diff changeset
2603 }
kono
parents: 67
diff changeset
2604
kono
parents: 67
diff changeset
2605 cfg_changed |= gimple_purge_all_dead_eh_edges (to_purge);
kono
parents: 67
diff changeset
2606 BITMAP_FREE (to_purge);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2607
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2608 if (cfg_changed)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2609 todoflags |= TODO_cleanup_cfg;
111
kono
parents: 67
diff changeset
2610
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2611 return todoflags;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2612 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2613
111
kono
parents: 67
diff changeset
2614 } // anon namespace
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2615
111
kono
parents: 67
diff changeset
2616 gimple_opt_pass *
kono
parents: 67
diff changeset
2617 make_pass_forwprop (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2618 {
111
kono
parents: 67
diff changeset
2619 return new pass_forwprop (ctxt);
kono
parents: 67
diff changeset
2620 }