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