Mercurial > hg > truffle
annotate src/share/vm/opto/addnode.cpp @ 4724:0841c0ec2ed6
7123810: new hotspot build - hs23-b10
Reviewed-by: jcoomes
author | amurillo |
---|---|
date | Fri, 23 Dec 2011 15:29:34 -0800 |
parents | a6eef545f1a2 |
children | e626685e9f6c |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1541
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1541
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1541
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "memory/allocation.inline.hpp" | |
27 #include "opto/addnode.hpp" | |
28 #include "opto/cfgnode.hpp" | |
29 #include "opto/connode.hpp" | |
30 #include "opto/machnode.hpp" | |
31 #include "opto/mulnode.hpp" | |
32 #include "opto/phaseX.hpp" | |
33 #include "opto/subnode.hpp" | |
0 | 34 |
1972 | 35 // Portions of code courtesy of Clifford Click |
0 | 36 |
37 // Classic Add functionality. This covers all the usual 'add' behaviors for | |
38 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are | |
39 // all inherited from this class. The various identity values are supplied | |
40 // by virtual functions. | |
41 | |
42 | |
43 //============================================================================= | |
44 //------------------------------hash------------------------------------------- | |
45 // Hash function over AddNodes. Needs to be commutative; i.e., I swap | |
46 // (commute) inputs to AddNodes willy-nilly so the hash function must return | |
47 // the same value in the presence of edge swapping. | |
48 uint AddNode::hash() const { | |
49 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode(); | |
50 } | |
51 | |
52 //------------------------------Identity--------------------------------------- | |
53 // If either input is a constant 0, return the other input. | |
54 Node *AddNode::Identity( PhaseTransform *phase ) { | |
55 const Type *zero = add_id(); // The additive identity | |
56 if( phase->type( in(1) )->higher_equal( zero ) ) return in(2); | |
57 if( phase->type( in(2) )->higher_equal( zero ) ) return in(1); | |
58 return this; | |
59 } | |
60 | |
61 //------------------------------commute---------------------------------------- | |
62 // Commute operands to move loads and constants to the right. | |
63 static bool commute( Node *add, int con_left, int con_right ) { | |
64 Node *in1 = add->in(1); | |
65 Node *in2 = add->in(2); | |
66 | |
67 // Convert "1+x" into "x+1". | |
68 // Right is a constant; leave it | |
69 if( con_right ) return false; | |
70 // Left is a constant; move it right. | |
71 if( con_left ) { | |
72 add->swap_edges(1, 2); | |
73 return true; | |
74 } | |
75 | |
76 // Convert "Load+x" into "x+Load". | |
77 // Now check for loads | |
99
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
78 if (in2->is_Load()) { |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
79 if (!in1->is_Load()) { |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
80 // already x+Load to return |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
81 return false; |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
82 } |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
83 // both are loads, so fall through to sort inputs by idx |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
84 } else if( in1->is_Load() ) { |
8a4ef4e001d3
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
32
diff
changeset
|
85 // Left is a Load and Right is not; move it right. |
0 | 86 add->swap_edges(1, 2); |
87 return true; | |
88 } | |
89 | |
90 PhiNode *phi; | |
91 // Check for tight loop increments: Loop-phi of Add of loop-phi | |
92 if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add) | |
93 return false; | |
94 if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){ | |
95 add->swap_edges(1, 2); | |
96 return true; | |
97 } | |
98 | |
99 // Otherwise, sort inputs (commutativity) to help value numbering. | |
100 if( in1->_idx > in2->_idx ) { | |
101 add->swap_edges(1, 2); | |
102 return true; | |
103 } | |
104 return false; | |
105 } | |
106 | |
107 //------------------------------Idealize--------------------------------------- | |
108 // If we get here, we assume we are associative! | |
109 Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
110 const Type *t1 = phase->type( in(1) ); | |
111 const Type *t2 = phase->type( in(2) ); | |
112 int con_left = t1->singleton(); | |
113 int con_right = t2->singleton(); | |
114 | |
115 // Check for commutative operation desired | |
116 if( commute(this,con_left,con_right) ) return this; | |
117 | |
118 AddNode *progress = NULL; // Progress flag | |
119 | |
120 // Convert "(x+1)+2" into "x+(1+2)". If the right input is a | |
121 // constant, and the left input is an add of a constant, flatten the | |
122 // expression tree. | |
123 Node *add1 = in(1); | |
124 Node *add2 = in(2); | |
125 int add1_op = add1->Opcode(); | |
126 int this_op = Opcode(); | |
127 if( con_right && t2 != Type::TOP && // Right input is a constant? | |
128 add1_op == this_op ) { // Left input is an Add? | |
129 | |
130 // Type of left _in right input | |
131 const Type *t12 = phase->type( add1->in(2) ); | |
132 if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant? | |
133 // Check for rare case of closed data cycle which can happen inside | |
134 // unreachable loops. In these cases the computation is undefined. | |
135 #ifdef ASSERT | |
136 Node *add11 = add1->in(1); | |
137 int add11_op = add11->Opcode(); | |
138 if( (add1 == add1->in(1)) | |
139 || (add11_op == this_op && add11->in(1) == add1) ) { | |
140 assert(false, "dead loop in AddNode::Ideal"); | |
141 } | |
142 #endif | |
143 // The Add of the flattened expression | |
144 Node *x1 = add1->in(1); | |
145 Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 )); | |
146 PhaseIterGVN *igvn = phase->is_IterGVN(); | |
147 if( igvn ) { | |
148 set_req_X(2,x2,igvn); | |
149 set_req_X(1,x1,igvn); | |
150 } else { | |
151 set_req(2,x2); | |
152 set_req(1,x1); | |
153 } | |
154 progress = this; // Made progress | |
155 add1 = in(1); | |
156 add1_op = add1->Opcode(); | |
157 } | |
158 } | |
159 | |
160 // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree. | |
161 if( add1_op == this_op && !con_right ) { | |
162 Node *a12 = add1->in(2); | |
163 const Type *t12 = phase->type( a12 ); | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
164 if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) && |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
165 !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) { |
320
2b73d212b1fd
6676462: JVM sometimes would suddenly consume significant amount of memory
kvn
parents:
306
diff
changeset
|
166 assert(add1->in(1) != this, "dead loop in AddNode::Ideal"); |
0 | 167 add2 = add1->clone(); |
168 add2->set_req(2, in(2)); | |
169 add2 = phase->transform(add2); | |
170 set_req(1, add2); | |
171 set_req(2, a12); | |
172 progress = this; | |
173 add2 = a12; | |
174 } | |
175 } | |
176 | |
177 // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree. | |
178 int add2_op = add2->Opcode(); | |
179 if( add2_op == this_op && !con_left ) { | |
180 Node *a22 = add2->in(2); | |
181 const Type *t22 = phase->type( a22 ); | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
182 if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) && |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
183 !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) { |
320
2b73d212b1fd
6676462: JVM sometimes would suddenly consume significant amount of memory
kvn
parents:
306
diff
changeset
|
184 assert(add2->in(1) != this, "dead loop in AddNode::Ideal"); |
0 | 185 Node *addx = add2->clone(); |
186 addx->set_req(1, in(1)); | |
187 addx->set_req(2, add2->in(1)); | |
188 addx = phase->transform(addx); | |
189 set_req(1, addx); | |
190 set_req(2, a22); | |
191 progress = this; | |
192 } | |
193 } | |
194 | |
195 return progress; | |
196 } | |
197 | |
198 //------------------------------Value----------------------------------------- | |
199 // An add node sums it's two _in. If one input is an RSD, we must mixin | |
200 // the other input's symbols. | |
201 const Type *AddNode::Value( PhaseTransform *phase ) const { | |
202 // Either input is TOP ==> the result is TOP | |
203 const Type *t1 = phase->type( in(1) ); | |
204 const Type *t2 = phase->type( in(2) ); | |
205 if( t1 == Type::TOP ) return Type::TOP; | |
206 if( t2 == Type::TOP ) return Type::TOP; | |
207 | |
208 // Either input is BOTTOM ==> the result is the local BOTTOM | |
209 const Type *bot = bottom_type(); | |
210 if( (t1 == bot) || (t2 == bot) || | |
211 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) | |
212 return bot; | |
213 | |
214 // Check for an addition involving the additive identity | |
215 const Type *tadd = add_of_identity( t1, t2 ); | |
216 if( tadd ) return tadd; | |
217 | |
218 return add_ring(t1,t2); // Local flavor of type addition | |
219 } | |
220 | |
221 //------------------------------add_identity----------------------------------- | |
222 // Check for addition of the identity | |
223 const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const { | |
224 const Type *zero = add_id(); // The additive identity | |
225 if( t1->higher_equal( zero ) ) return t2; | |
226 if( t2->higher_equal( zero ) ) return t1; | |
227 | |
228 return NULL; | |
229 } | |
230 | |
231 | |
232 //============================================================================= | |
233 //------------------------------Idealize--------------------------------------- | |
234 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
235 Node* in1 = in(1); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
236 Node* in2 = in(2); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
237 int op1 = in1->Opcode(); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
238 int op2 = in2->Opcode(); |
0 | 239 // Fold (con1-x)+con2 into (con1+con2)-x |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
240 if ( op1 == Op_AddI && op2 == Op_SubI ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
241 // Swap edges to try optimizations below |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
242 in1 = in2; |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
243 in2 = in(1); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
244 op1 = op2; |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
245 op2 = in2->Opcode(); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
246 } |
0 | 247 if( op1 == Op_SubI ) { |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
248 const Type *t_sub1 = phase->type( in1->in(1) ); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
249 const Type *t_2 = phase->type( in2 ); |
0 | 250 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) |
251 return new (phase->C, 3) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
252 in1->in(2) ); |
0 | 253 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" |
254 if( op2 == Op_SubI ) { | |
255 // Check for dead cycle: d = (a-b)+(c-d) | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
256 assert( in1->in(2) != this && in2->in(2) != this, |
0 | 257 "dead loop in AddINode::Ideal" ); |
258 Node *sub = new (phase->C, 3) SubINode(NULL, NULL); | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
259 sub->init_req(1, phase->transform(new (phase->C, 3) AddINode(in1->in(1), in2->in(1) ) )); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
260 sub->init_req(2, phase->transform(new (phase->C, 3) AddINode(in1->in(2), in2->in(2) ) )); |
0 | 261 return sub; |
262 } | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
263 // Convert "(a-b)+(b+c)" into "(a+c)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
264 if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
265 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
266 return new (phase->C, 3) AddINode(in1->in(1), in2->in(2)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
267 } |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
268 // Convert "(a-b)+(c+b)" into "(a+c)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
269 if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
270 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
271 return new (phase->C, 3) AddINode(in1->in(1), in2->in(1)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
272 } |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
273 // Convert "(a-b)+(b-c)" into "(a-c)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
274 if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
275 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
276 return new (phase->C, 3) SubINode(in1->in(1), in2->in(2)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
277 } |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
278 // Convert "(a-b)+(c-a)" into "(c-b)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
279 if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
280 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
281 return new (phase->C, 3) SubINode(in2->in(1), in1->in(2)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
282 } |
0 | 283 } |
284 | |
285 // Convert "x+(0-y)" into "(x-y)" | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
286 if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO ) |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
287 return new (phase->C, 3) SubINode(in1, in2->in(2) ); |
0 | 288 |
289 // Convert "(0-y)+x" into "(x-y)" | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
290 if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO ) |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
291 return new (phase->C, 3) SubINode( in2, in1->in(2) ); |
0 | 292 |
293 // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y. | |
294 // Helps with array allocation math constant folding | |
295 // See 4790063: | |
296 // Unrestricted transformation is unsafe for some runtime values of 'x' | |
297 // ( x == 0, z == 1, y == -1 ) fails | |
298 // ( x == -5, z == 1, y == 1 ) fails | |
299 // Transform works for small z and small negative y when the addition | |
300 // (x + (y << z)) does not cross zero. | |
301 // Implement support for negative y and (x >= -(y << z)) | |
302 // Have not observed cases where type information exists to support | |
303 // positive y and (x <= -(y << z)) | |
304 if( op1 == Op_URShiftI && op2 == Op_ConI && | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
305 in1->in(2)->Opcode() == Op_ConI ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
306 jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
307 jint y = phase->type( in2 )->is_int()->get_con(); |
0 | 308 |
309 if( z < 5 && -5 < y && y < 0 ) { | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
310 const Type *t_in11 = phase->type(in1->in(1)); |
0 | 311 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) { |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
312 Node *a = phase->transform( new (phase->C, 3) AddINode( in1->in(1), phase->intcon(y<<z) ) ); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
313 return new (phase->C, 3) URShiftINode( a, in1->in(2) ); |
0 | 314 } |
315 } | |
316 } | |
317 | |
318 return AddNode::Ideal(phase, can_reshape); | |
319 } | |
320 | |
321 | |
322 //------------------------------Identity--------------------------------------- | |
323 // Fold (x-y)+y OR y+(x-y) into x | |
324 Node *AddINode::Identity( PhaseTransform *phase ) { | |
325 if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) { | |
326 return in(1)->in(1); | |
327 } | |
328 else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) { | |
329 return in(2)->in(1); | |
330 } | |
331 return AddNode::Identity(phase); | |
332 } | |
333 | |
334 | |
335 //------------------------------add_ring--------------------------------------- | |
336 // Supplied function returns the sum of the inputs. Guaranteed never | |
337 // to be passed a TOP or BOTTOM type, these are filtered out by | |
338 // pre-check. | |
339 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const { | |
340 const TypeInt *r0 = t0->is_int(); // Handy access | |
341 const TypeInt *r1 = t1->is_int(); | |
342 int lo = r0->_lo + r1->_lo; | |
343 int hi = r0->_hi + r1->_hi; | |
344 if( !(r0->is_con() && r1->is_con()) ) { | |
345 // Not both constants, compute approximate result | |
346 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) { | |
347 lo = min_jint; hi = max_jint; // Underflow on the low side | |
348 } | |
349 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) { | |
350 lo = min_jint; hi = max_jint; // Overflow on the high side | |
351 } | |
352 if( lo > hi ) { // Handle overflow | |
353 lo = min_jint; hi = max_jint; | |
354 } | |
355 } else { | |
356 // both constants, compute precise result using 'lo' and 'hi' | |
357 // Semantics define overflow and underflow for integer addition | |
358 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0 | |
359 } | |
360 return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) ); | |
361 } | |
362 | |
363 | |
364 //============================================================================= | |
365 //------------------------------Idealize--------------------------------------- | |
366 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
367 Node* in1 = in(1); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
368 Node* in2 = in(2); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
369 int op1 = in1->Opcode(); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
370 int op2 = in2->Opcode(); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
371 // Fold (con1-x)+con2 into (con1+con2)-x |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
372 if ( op1 == Op_AddL && op2 == Op_SubL ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
373 // Swap edges to try optimizations below |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
374 in1 = in2; |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
375 in2 = in(1); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
376 op1 = op2; |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
377 op2 = in2->Opcode(); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
378 } |
0 | 379 // Fold (con1-x)+con2 into (con1+con2)-x |
380 if( op1 == Op_SubL ) { | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
381 const Type *t_sub1 = phase->type( in1->in(1) ); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
382 const Type *t_2 = phase->type( in2 ); |
0 | 383 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) |
384 return new (phase->C, 3) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
385 in1->in(2) ); |
0 | 386 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" |
387 if( op2 == Op_SubL ) { | |
388 // Check for dead cycle: d = (a-b)+(c-d) | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
389 assert( in1->in(2) != this && in2->in(2) != this, |
0 | 390 "dead loop in AddLNode::Ideal" ); |
391 Node *sub = new (phase->C, 3) SubLNode(NULL, NULL); | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
392 sub->init_req(1, phase->transform(new (phase->C, 3) AddLNode(in1->in(1), in2->in(1) ) )); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
393 sub->init_req(2, phase->transform(new (phase->C, 3) AddLNode(in1->in(2), in2->in(2) ) )); |
0 | 394 return sub; |
395 } | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
396 // Convert "(a-b)+(b+c)" into "(a+c)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
397 if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
398 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
399 return new (phase->C, 3) AddLNode(in1->in(1), in2->in(2)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
400 } |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
401 // Convert "(a-b)+(c+b)" into "(a+c)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
402 if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
403 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
404 return new (phase->C, 3) AddLNode(in1->in(1), in2->in(1)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
405 } |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
406 // Convert "(a-b)+(b-c)" into "(a-c)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
407 if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
408 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
409 return new (phase->C, 3) SubLNode(in1->in(1), in2->in(2)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
410 } |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
411 // Convert "(a-b)+(c-a)" into "(c-b)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
412 if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) { |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
413 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal"); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
414 return new (phase->C, 3) SubLNode(in2->in(1), in1->in(2)); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
415 } |
0 | 416 } |
417 | |
418 // Convert "x+(0-y)" into "(x-y)" | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
419 if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO ) |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
420 return new (phase->C, 3) SubLNode( in1, in2->in(2) ); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
421 |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
422 // Convert "(0-y)+x" into "(x-y)" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
423 if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO ) |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
424 return new (phase->C, 3) SubLNode( in2, in1->in(2) ); |
0 | 425 |
426 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)" | |
427 // into "(X<<1)+Y" and let shift-folding happen. | |
428 if( op2 == Op_AddL && | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
429 in2->in(1) == in1 && |
0 | 430 op1 != Op_ConL && |
431 0 ) { | |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
432 Node *shift = phase->transform(new (phase->C, 3) LShiftLNode(in1,phase->intcon(1))); |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
320
diff
changeset
|
433 return new (phase->C, 3) AddLNode(shift,in2->in(2)); |
0 | 434 } |
435 | |
436 return AddNode::Ideal(phase, can_reshape); | |
437 } | |
438 | |
439 | |
440 //------------------------------Identity--------------------------------------- | |
441 // Fold (x-y)+y OR y+(x-y) into x | |
442 Node *AddLNode::Identity( PhaseTransform *phase ) { | |
443 if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) { | |
444 return in(1)->in(1); | |
445 } | |
446 else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) { | |
447 return in(2)->in(1); | |
448 } | |
449 return AddNode::Identity(phase); | |
450 } | |
451 | |
452 | |
453 //------------------------------add_ring--------------------------------------- | |
454 // Supplied function returns the sum of the inputs. Guaranteed never | |
455 // to be passed a TOP or BOTTOM type, these are filtered out by | |
456 // pre-check. | |
457 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const { | |
458 const TypeLong *r0 = t0->is_long(); // Handy access | |
459 const TypeLong *r1 = t1->is_long(); | |
460 jlong lo = r0->_lo + r1->_lo; | |
461 jlong hi = r0->_hi + r1->_hi; | |
462 if( !(r0->is_con() && r1->is_con()) ) { | |
463 // Not both constants, compute approximate result | |
464 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) { | |
465 lo =min_jlong; hi = max_jlong; // Underflow on the low side | |
466 } | |
467 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) { | |
468 lo = min_jlong; hi = max_jlong; // Overflow on the high side | |
469 } | |
470 if( lo > hi ) { // Handle overflow | |
471 lo = min_jlong; hi = max_jlong; | |
472 } | |
473 } else { | |
474 // both constants, compute precise result using 'lo' and 'hi' | |
475 // Semantics define overflow and underflow for integer addition | |
476 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0 | |
477 } | |
478 return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) ); | |
479 } | |
480 | |
481 | |
482 //============================================================================= | |
483 //------------------------------add_of_identity-------------------------------- | |
484 // Check for addition of the identity | |
485 const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const { | |
486 // x ADD 0 should return x unless 'x' is a -zero | |
487 // | |
488 // const Type *zero = add_id(); // The additive identity | |
489 // jfloat f1 = t1->getf(); | |
490 // jfloat f2 = t2->getf(); | |
491 // | |
492 // if( t1->higher_equal( zero ) ) return t2; | |
493 // if( t2->higher_equal( zero ) ) return t1; | |
494 | |
495 return NULL; | |
496 } | |
497 | |
498 //------------------------------add_ring--------------------------------------- | |
499 // Supplied function returns the sum of the inputs. | |
500 // This also type-checks the inputs for sanity. Guaranteed never to | |
501 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. | |
502 const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const { | |
503 // We must be adding 2 float constants. | |
504 return TypeF::make( t0->getf() + t1->getf() ); | |
505 } | |
506 | |
507 //------------------------------Ideal------------------------------------------ | |
508 Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
509 if( IdealizedNumerics && !phase->C->method()->is_strict() ) { | |
510 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms | |
511 } | |
512 | |
513 // Floating point additions are not associative because of boundary conditions (infinity) | |
514 return commute(this, | |
515 phase->type( in(1) )->singleton(), | |
516 phase->type( in(2) )->singleton() ) ? this : NULL; | |
517 } | |
518 | |
519 | |
520 //============================================================================= | |
521 //------------------------------add_of_identity-------------------------------- | |
522 // Check for addition of the identity | |
523 const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const { | |
524 // x ADD 0 should return x unless 'x' is a -zero | |
525 // | |
526 // const Type *zero = add_id(); // The additive identity | |
527 // jfloat f1 = t1->getf(); | |
528 // jfloat f2 = t2->getf(); | |
529 // | |
530 // if( t1->higher_equal( zero ) ) return t2; | |
531 // if( t2->higher_equal( zero ) ) return t1; | |
532 | |
533 return NULL; | |
534 } | |
535 //------------------------------add_ring--------------------------------------- | |
536 // Supplied function returns the sum of the inputs. | |
537 // This also type-checks the inputs for sanity. Guaranteed never to | |
538 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. | |
539 const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const { | |
540 // We must be adding 2 double constants. | |
541 return TypeD::make( t0->getd() + t1->getd() ); | |
542 } | |
543 | |
544 //------------------------------Ideal------------------------------------------ | |
545 Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
546 if( IdealizedNumerics && !phase->C->method()->is_strict() ) { | |
547 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms | |
548 } | |
549 | |
550 // Floating point additions are not associative because of boundary conditions (infinity) | |
551 return commute(this, | |
552 phase->type( in(1) )->singleton(), | |
553 phase->type( in(2) )->singleton() ) ? this : NULL; | |
554 } | |
555 | |
556 | |
557 //============================================================================= | |
558 //------------------------------Identity--------------------------------------- | |
559 // If one input is a constant 0, return the other input. | |
560 Node *AddPNode::Identity( PhaseTransform *phase ) { | |
561 return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this; | |
562 } | |
563 | |
564 //------------------------------Idealize--------------------------------------- | |
565 Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
566 // Bail out if dead inputs | |
567 if( phase->type( in(Address) ) == Type::TOP ) return NULL; | |
568 | |
569 // If the left input is an add of a constant, flatten the expression tree. | |
570 const Node *n = in(Address); | |
571 if (n->is_AddP() && n->in(Base) == in(Base)) { | |
572 const AddPNode *addp = n->as_AddP(); // Left input is an AddP | |
573 assert( !addp->in(Address)->is_AddP() || | |
574 addp->in(Address)->as_AddP() != addp, | |
575 "dead loop in AddPNode::Ideal" ); | |
576 // Type of left input's right input | |
577 const Type *t = phase->type( addp->in(Offset) ); | |
578 if( t == Type::TOP ) return NULL; | |
579 const TypeX *t12 = t->is_intptr_t(); | |
580 if( t12->is_con() ) { // Left input is an add of a constant? | |
581 // If the right input is a constant, combine constants | |
582 const Type *temp_t2 = phase->type( in(Offset) ); | |
583 if( temp_t2 == Type::TOP ) return NULL; | |
584 const TypeX *t2 = temp_t2->is_intptr_t(); | |
32
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
585 Node* address; |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
586 Node* offset; |
0 | 587 if( t2->is_con() ) { |
588 // The Add of the flattened expression | |
32
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
589 address = addp->in(Address); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
590 offset = phase->MakeConX(t2->get_con() + t12->get_con()); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
591 } else { |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
592 // Else move the constant to the right. ((A+con)+B) into ((A+B)+con) |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
593 address = phase->transform(new (phase->C, 4) AddPNode(in(Base),addp->in(Address),in(Offset))); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
594 offset = addp->in(Offset); |
0 | 595 } |
32
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
596 PhaseIterGVN *igvn = phase->is_IterGVN(); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
597 if( igvn ) { |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
598 set_req_X(Address,address,igvn); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
599 set_req_X(Offset,offset,igvn); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
600 } else { |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
601 set_req(Address,address); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
602 set_req(Offset,offset); |
4d428c5b4cb3
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
17
diff
changeset
|
603 } |
0 | 604 return this; |
605 } | |
606 } | |
607 | |
608 // Raw pointers? | |
609 if( in(Base)->bottom_type() == Type::TOP ) { | |
610 // If this is a NULL+long form (from unsafe accesses), switch to a rawptr. | |
611 if (phase->type(in(Address)) == TypePtr::NULL_PTR) { | |
612 Node* offset = in(Offset); | |
613 return new (phase->C, 2) CastX2PNode(offset); | |
614 } | |
615 } | |
616 | |
617 // If the right is an add of a constant, push the offset down. | |
618 // Convert: (ptr + (offset+con)) into (ptr+offset)+con. | |
619 // The idea is to merge array_base+scaled_index groups together, | |
620 // and only have different constant offsets from the same base. | |
621 const Node *add = in(Offset); | |
622 if( add->Opcode() == Op_AddX && add->in(1) != add ) { | |
623 const Type *t22 = phase->type( add->in(2) ); | |
624 if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant? | |
625 set_req(Address, phase->transform(new (phase->C, 4) AddPNode(in(Base),in(Address),add->in(1)))); | |
626 set_req(Offset, add->in(2)); | |
627 return this; // Made progress | |
628 } | |
629 } | |
630 | |
631 return NULL; // No progress | |
632 } | |
633 | |
634 //------------------------------bottom_type------------------------------------ | |
635 // Bottom-type is the pointer-type with unknown offset. | |
636 const Type *AddPNode::bottom_type() const { | |
637 if (in(Address) == NULL) return TypePtr::BOTTOM; | |
638 const TypePtr *tp = in(Address)->bottom_type()->isa_ptr(); | |
639 if( !tp ) return Type::TOP; // TOP input means TOP output | |
640 assert( in(Offset)->Opcode() != Op_ConP, "" ); | |
641 const Type *t = in(Offset)->bottom_type(); | |
642 if( t == Type::TOP ) | |
643 return tp->add_offset(Type::OffsetTop); | |
644 const TypeX *tx = t->is_intptr_t(); | |
645 intptr_t txoffset = Type::OffsetBot; | |
646 if (tx->is_con()) { // Left input is an add of a constant? | |
647 txoffset = tx->get_con(); | |
648 } | |
649 return tp->add_offset(txoffset); | |
650 } | |
651 | |
652 //------------------------------Value------------------------------------------ | |
653 const Type *AddPNode::Value( PhaseTransform *phase ) const { | |
654 // Either input is TOP ==> the result is TOP | |
655 const Type *t1 = phase->type( in(Address) ); | |
656 const Type *t2 = phase->type( in(Offset) ); | |
657 if( t1 == Type::TOP ) return Type::TOP; | |
658 if( t2 == Type::TOP ) return Type::TOP; | |
659 | |
660 // Left input is a pointer | |
661 const TypePtr *p1 = t1->isa_ptr(); | |
662 // Right input is an int | |
663 const TypeX *p2 = t2->is_intptr_t(); | |
664 // Add 'em | |
665 intptr_t p2offset = Type::OffsetBot; | |
666 if (p2->is_con()) { // Left input is an add of a constant? | |
667 p2offset = p2->get_con(); | |
668 } | |
669 return p1->add_offset(p2offset); | |
670 } | |
671 | |
672 //------------------------Ideal_base_and_offset-------------------------------- | |
673 // Split an oop pointer into a base and offset. | |
674 // (The offset might be Type::OffsetBot in the case of an array.) | |
675 // Return the base, or NULL if failure. | |
676 Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase, | |
677 // second return value: | |
678 intptr_t& offset) { | |
679 if (ptr->is_AddP()) { | |
680 Node* base = ptr->in(AddPNode::Base); | |
681 Node* addr = ptr->in(AddPNode::Address); | |
682 Node* offs = ptr->in(AddPNode::Offset); | |
683 if (base == addr || base->is_top()) { | |
684 offset = phase->find_intptr_t_con(offs, Type::OffsetBot); | |
685 if (offset != Type::OffsetBot) { | |
686 return addr; | |
687 } | |
688 } | |
689 } | |
690 offset = Type::OffsetBot; | |
691 return NULL; | |
692 } | |
693 | |
17
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
694 //------------------------------unpack_offsets---------------------------------- |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
695 // Collect the AddP offset values into the elements array, giving up |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
696 // if there are more than length. |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
697 int AddPNode::unpack_offsets(Node* elements[], int length) { |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
698 int count = 0; |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
699 Node* addr = this; |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
700 Node* base = addr->in(AddPNode::Base); |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
701 while (addr->is_AddP()) { |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
702 if (addr->in(AddPNode::Base) != base) { |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
703 // give up |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
704 return -1; |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
705 } |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
706 elements[count++] = addr->in(AddPNode::Offset); |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
707 if (count == length) { |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
708 // give up |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
709 return -1; |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
710 } |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
711 addr = addr->in(AddPNode::Address); |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
712 } |
1763 | 713 if (addr != base) { |
714 return -1; | |
715 } | |
17
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
716 return count; |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
717 } |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
718 |
0 | 719 //------------------------------match_edge------------------------------------- |
720 // Do we Match on this edge index or not? Do not match base pointer edge | |
721 uint AddPNode::match_edge(uint idx) const { | |
722 return idx > Base; | |
723 } | |
724 | |
725 //============================================================================= | |
726 //------------------------------Identity--------------------------------------- | |
727 Node *OrINode::Identity( PhaseTransform *phase ) { | |
728 // x | x => x | |
729 if (phase->eqv(in(1), in(2))) { | |
730 return in(1); | |
731 } | |
732 | |
733 return AddNode::Identity(phase); | |
734 } | |
735 | |
736 //------------------------------add_ring--------------------------------------- | |
737 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For | |
738 // the logical operations the ring's ADD is really a logical OR function. | |
739 // This also type-checks the inputs for sanity. Guaranteed never to | |
740 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. | |
741 const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const { | |
742 const TypeInt *r0 = t0->is_int(); // Handy access | |
743 const TypeInt *r1 = t1->is_int(); | |
744 | |
745 // If both args are bool, can figure out better types | |
746 if ( r0 == TypeInt::BOOL ) { | |
747 if ( r1 == TypeInt::ONE) { | |
748 return TypeInt::ONE; | |
749 } else if ( r1 == TypeInt::BOOL ) { | |
750 return TypeInt::BOOL; | |
751 } | |
752 } else if ( r0 == TypeInt::ONE ) { | |
753 if ( r1 == TypeInt::BOOL ) { | |
754 return TypeInt::ONE; | |
755 } | |
756 } | |
757 | |
758 // If either input is not a constant, just return all integers. | |
759 if( !r0->is_con() || !r1->is_con() ) | |
760 return TypeInt::INT; // Any integer, but still no symbols. | |
761 | |
762 // Otherwise just OR them bits. | |
763 return TypeInt::make( r0->get_con() | r1->get_con() ); | |
764 } | |
765 | |
766 //============================================================================= | |
767 //------------------------------Identity--------------------------------------- | |
768 Node *OrLNode::Identity( PhaseTransform *phase ) { | |
769 // x | x => x | |
770 if (phase->eqv(in(1), in(2))) { | |
771 return in(1); | |
772 } | |
773 | |
774 return AddNode::Identity(phase); | |
775 } | |
776 | |
777 //------------------------------add_ring--------------------------------------- | |
778 const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const { | |
779 const TypeLong *r0 = t0->is_long(); // Handy access | |
780 const TypeLong *r1 = t1->is_long(); | |
781 | |
782 // If either input is not a constant, just return all integers. | |
783 if( !r0->is_con() || !r1->is_con() ) | |
784 return TypeLong::LONG; // Any integer, but still no symbols. | |
785 | |
786 // Otherwise just OR them bits. | |
787 return TypeLong::make( r0->get_con() | r1->get_con() ); | |
788 } | |
789 | |
790 //============================================================================= | |
791 //------------------------------add_ring--------------------------------------- | |
792 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For | |
793 // the logical operations the ring's ADD is really a logical OR function. | |
794 // This also type-checks the inputs for sanity. Guaranteed never to | |
795 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. | |
796 const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const { | |
797 const TypeInt *r0 = t0->is_int(); // Handy access | |
798 const TypeInt *r1 = t1->is_int(); | |
799 | |
800 // Complementing a boolean? | |
801 if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE | |
802 || r1 == TypeInt::BOOL)) | |
803 return TypeInt::BOOL; | |
804 | |
805 if( !r0->is_con() || !r1->is_con() ) // Not constants | |
806 return TypeInt::INT; // Any integer, but still no symbols. | |
807 | |
808 // Otherwise just XOR them bits. | |
809 return TypeInt::make( r0->get_con() ^ r1->get_con() ); | |
810 } | |
811 | |
812 //============================================================================= | |
813 //------------------------------add_ring--------------------------------------- | |
814 const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const { | |
815 const TypeLong *r0 = t0->is_long(); // Handy access | |
816 const TypeLong *r1 = t1->is_long(); | |
817 | |
818 // If either input is not a constant, just return all integers. | |
819 if( !r0->is_con() || !r1->is_con() ) | |
820 return TypeLong::LONG; // Any integer, but still no symbols. | |
821 | |
822 // Otherwise just OR them bits. | |
823 return TypeLong::make( r0->get_con() ^ r1->get_con() ); | |
824 } | |
825 | |
826 //============================================================================= | |
827 //------------------------------add_ring--------------------------------------- | |
828 // Supplied function returns the sum of the inputs. | |
829 const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const { | |
830 const TypeInt *r0 = t0->is_int(); // Handy access | |
831 const TypeInt *r1 = t1->is_int(); | |
832 | |
833 // Otherwise just MAX them bits. | |
834 return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) ); | |
835 } | |
836 | |
837 //============================================================================= | |
838 //------------------------------Idealize--------------------------------------- | |
839 // MINs show up in range-check loop limit calculations. Look for | |
840 // "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)" | |
841 Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
842 Node *progress = NULL; | |
843 // Force a right-spline graph | |
844 Node *l = in(1); | |
845 Node *r = in(2); | |
846 // Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) ) | |
847 // to force a right-spline graph for the rest of MinINode::Ideal(). | |
848 if( l->Opcode() == Op_MinI ) { | |
849 assert( l != l->in(1), "dead loop in MinINode::Ideal" ); | |
850 r = phase->transform(new (phase->C, 3) MinINode(l->in(2),r)); | |
851 l = l->in(1); | |
852 set_req(1, l); | |
853 set_req(2, r); | |
854 return this; | |
855 } | |
856 | |
857 // Get left input & constant | |
858 Node *x = l; | |
859 int x_off = 0; | |
860 if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant | |
861 x->in(2)->is_Con() ) { | |
862 const Type *t = x->in(2)->bottom_type(); | |
863 if( t == Type::TOP ) return NULL; // No progress | |
864 x_off = t->is_int()->get_con(); | |
865 x = x->in(1); | |
866 } | |
867 | |
868 // Scan a right-spline-tree for MINs | |
869 Node *y = r; | |
870 int y_off = 0; | |
871 // Check final part of MIN tree | |
872 if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant | |
873 y->in(2)->is_Con() ) { | |
874 const Type *t = y->in(2)->bottom_type(); | |
875 if( t == Type::TOP ) return NULL; // No progress | |
876 y_off = t->is_int()->get_con(); | |
877 y = y->in(1); | |
878 } | |
879 if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) { | |
880 swap_edges(1, 2); | |
881 return this; | |
882 } | |
883 | |
884 | |
885 if( r->Opcode() == Op_MinI ) { | |
886 assert( r != r->in(2), "dead loop in MinINode::Ideal" ); | |
887 y = r->in(1); | |
888 // Check final part of MIN tree | |
889 if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant | |
890 y->in(2)->is_Con() ) { | |
891 const Type *t = y->in(2)->bottom_type(); | |
892 if( t == Type::TOP ) return NULL; // No progress | |
893 y_off = t->is_int()->get_con(); | |
894 y = y->in(1); | |
895 } | |
896 | |
897 if( x->_idx > y->_idx ) | |
898 return new (phase->C, 3) MinINode(r->in(1),phase->transform(new (phase->C, 3) MinINode(l,r->in(2)))); | |
899 | |
900 // See if covers: MIN2(x+c0,MIN2(y+c1,z)) | |
901 if( !phase->eqv(x,y) ) return NULL; | |
902 // If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into | |
903 // MIN2(x+c0 or x+c1 which less, z). | |
904 return new (phase->C, 3) MinINode(phase->transform(new (phase->C, 3) AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2)); | |
905 } else { | |
906 // See if covers: MIN2(x+c0,y+c1) | |
907 if( !phase->eqv(x,y) ) return NULL; | |
908 // If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less. | |
909 return new (phase->C, 3) AddINode(x,phase->intcon(MIN2(x_off,y_off))); | |
910 } | |
911 | |
912 } | |
913 | |
914 //------------------------------add_ring--------------------------------------- | |
915 // Supplied function returns the sum of the inputs. | |
916 const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const { | |
917 const TypeInt *r0 = t0->is_int(); // Handy access | |
918 const TypeInt *r1 = t1->is_int(); | |
919 | |
920 // Otherwise just MIN them bits. | |
921 return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) ); | |
922 } |