1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "opto/addnode.hpp"
28 #include "opto/castnode.hpp"
29 #include "opto/cfgnode.hpp"
30 #include "opto/connode.hpp"
31 #include "opto/machnode.hpp"
32 #include "opto/movenode.hpp"
33 #include "opto/mulnode.hpp"
34 #include "opto/phaseX.hpp"
35 #include "opto/subnode.hpp"
36
37 // Portions of code courtesy of Clifford Click
38
39 // Classic Add functionality. This covers all the usual 'add' behaviors for
40 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are
41 // all inherited from this class. The various identity values are supplied
42 // by virtual functions.
43
44
45 //=============================================================================
46 //------------------------------hash-------------------------------------------
47 // Hash function over AddNodes. Needs to be commutative; i.e., I swap
48 // (commute) inputs to AddNodes willy-nilly so the hash function must return
49 // the same value in the presence of edge swapping.
hash() const50 uint AddNode::hash() const {
51 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
52 }
53
54 //------------------------------Identity---------------------------------------
55 // If either input is a constant 0, return the other input.
Identity(PhaseGVN * phase)56 Node* AddNode::Identity(PhaseGVN* phase) {
57 const Type *zero = add_id(); // The additive identity
58 if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
59 if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
60 return this;
61 }
62
63 //------------------------------commute----------------------------------------
64 // Commute operands to move loads and constants to the right.
commute(Node * add,bool con_left,bool con_right)65 static bool commute(Node *add, bool con_left, bool con_right) {
66 Node *in1 = add->in(1);
67 Node *in2 = add->in(2);
68
69 // Convert "1+x" into "x+1".
70 // Right is a constant; leave it
71 if( con_right ) return false;
72 // Left is a constant; move it right.
73 if( con_left ) {
74 add->swap_edges(1, 2);
75 return true;
76 }
77
78 // Convert "Load+x" into "x+Load".
79 // Now check for loads
80 if (in2->is_Load()) {
81 if (!in1->is_Load()) {
82 // already x+Load to return
83 return false;
84 }
85 // both are loads, so fall through to sort inputs by idx
86 } else if( in1->is_Load() ) {
87 // Left is a Load and Right is not; move it right.
88 add->swap_edges(1, 2);
89 return true;
90 }
91
92 PhiNode *phi;
93 // Check for tight loop increments: Loop-phi of Add of loop-phi
94 if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add)
95 return false;
96 if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){
97 add->swap_edges(1, 2);
98 return true;
99 }
100
101 // Otherwise, sort inputs (commutativity) to help value numbering.
102 if( in1->_idx > in2->_idx ) {
103 add->swap_edges(1, 2);
104 return true;
105 }
106 return false;
107 }
108
109 //------------------------------Idealize---------------------------------------
110 // If we get here, we assume we are associative!
Ideal(PhaseGVN * phase,bool can_reshape)111 Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {
112 const Type *t1 = phase->type( in(1) );
113 const Type *t2 = phase->type( in(2) );
114 bool con_left = t1->singleton();
115 bool con_right = t2->singleton();
116
117 // Check for commutative operation desired
118 if( commute(this,con_left,con_right) ) return this;
119
120 AddNode *progress = NULL; // Progress flag
121
122 // Convert "(x+1)+2" into "x+(1+2)". If the right input is a
123 // constant, and the left input is an add of a constant, flatten the
124 // expression tree.
125 Node *add1 = in(1);
126 Node *add2 = in(2);
127 int add1_op = add1->Opcode();
128 int this_op = Opcode();
129 if( con_right && t2 != Type::TOP && // Right input is a constant?
130 add1_op == this_op ) { // Left input is an Add?
131
132 // Type of left _in right input
133 const Type *t12 = phase->type( add1->in(2) );
134 if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
135 // Check for rare case of closed data cycle which can happen inside
136 // unreachable loops. In these cases the computation is undefined.
137 #ifdef ASSERT
138 Node *add11 = add1->in(1);
139 int add11_op = add11->Opcode();
140 if( (add1 == add1->in(1))
141 || (add11_op == this_op && add11->in(1) == add1) ) {
142 assert(false, "dead loop in AddNode::Ideal");
143 }
144 #endif
145 // The Add of the flattened expression
146 Node *x1 = add1->in(1);
147 Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 ));
148 PhaseIterGVN *igvn = phase->is_IterGVN();
149 if( igvn ) {
150 set_req_X(2,x2,igvn);
151 set_req_X(1,x1,igvn);
152 } else {
153 set_req(2,x2);
154 set_req(1,x1);
155 }
156 progress = this; // Made progress
157 add1 = in(1);
158 add1_op = add1->Opcode();
159 }
160 }
161
162 // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree.
163 if( add1_op == this_op && !con_right ) {
164 Node *a12 = add1->in(2);
165 const Type *t12 = phase->type( a12 );
166 if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
167 !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
168 assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
169 add2 = add1->clone();
170 add2->set_req(2, in(2));
171 add2 = phase->transform(add2);
172 set_req(1, add2);
173 set_req(2, a12);
174 progress = this;
175 add2 = a12;
176 }
177 }
178
179 // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree.
180 int add2_op = add2->Opcode();
181 if( add2_op == this_op && !con_left ) {
182 Node *a22 = add2->in(2);
183 const Type *t22 = phase->type( a22 );
184 if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
185 !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
186 assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
187 Node *addx = add2->clone();
188 addx->set_req(1, in(1));
189 addx->set_req(2, add2->in(1));
190 addx = phase->transform(addx);
191 set_req(1, addx);
192 set_req(2, a22);
193 progress = this;
194 PhaseIterGVN *igvn = phase->is_IterGVN();
195 if (add2->outcnt() == 0 && igvn) {
196 // add disconnected.
197 igvn->_worklist.push(add2);
198 }
199 }
200 }
201
202 return progress;
203 }
204
205 //------------------------------Value-----------------------------------------
206 // An add node sums it's two _in. If one input is an RSD, we must mixin
207 // the other input's symbols.
Value(PhaseGVN * phase) const208 const Type* AddNode::Value(PhaseGVN* phase) const {
209 // Either input is TOP ==> the result is TOP
210 const Type *t1 = phase->type( in(1) );
211 const Type *t2 = phase->type( in(2) );
212 if( t1 == Type::TOP ) return Type::TOP;
213 if( t2 == Type::TOP ) return Type::TOP;
214
215 // Either input is BOTTOM ==> the result is the local BOTTOM
216 const Type *bot = bottom_type();
217 if( (t1 == bot) || (t2 == bot) ||
218 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
219 return bot;
220
221 // Check for an addition involving the additive identity
222 const Type *tadd = add_of_identity( t1, t2 );
223 if( tadd ) return tadd;
224
225 return add_ring(t1,t2); // Local flavor of type addition
226 }
227
228 //------------------------------add_identity-----------------------------------
229 // Check for addition of the identity
add_of_identity(const Type * t1,const Type * t2) const230 const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {
231 const Type *zero = add_id(); // The additive identity
232 if( t1->higher_equal( zero ) ) return t2;
233 if( t2->higher_equal( zero ) ) return t1;
234
235 return NULL;
236 }
237
238
239 //=============================================================================
240 //------------------------------Idealize---------------------------------------
Ideal(PhaseGVN * phase,bool can_reshape)241 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
242 Node* in1 = in(1);
243 Node* in2 = in(2);
244 int op1 = in1->Opcode();
245 int op2 = in2->Opcode();
246 // Fold (con1-x)+con2 into (con1+con2)-x
247 if ( op1 == Op_AddI && op2 == Op_SubI ) {
248 // Swap edges to try optimizations below
249 in1 = in2;
250 in2 = in(1);
251 op1 = op2;
252 op2 = in2->Opcode();
253 }
254 if( op1 == Op_SubI ) {
255 const Type *t_sub1 = phase->type( in1->in(1) );
256 const Type *t_2 = phase->type( in2 );
257 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
258 return new SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
259 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
260 if( op2 == Op_SubI ) {
261 // Check for dead cycle: d = (a-b)+(c-d)
262 assert( in1->in(2) != this && in2->in(2) != this,
263 "dead loop in AddINode::Ideal" );
264 Node *sub = new SubINode(NULL, NULL);
265 sub->init_req(1, phase->transform(new AddINode(in1->in(1), in2->in(1) ) ));
266 sub->init_req(2, phase->transform(new AddINode(in1->in(2), in2->in(2) ) ));
267 return sub;
268 }
269 // Convert "(a-b)+(b+c)" into "(a+c)"
270 if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
271 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
272 return new AddINode(in1->in(1), in2->in(2));
273 }
274 // Convert "(a-b)+(c+b)" into "(a+c)"
275 if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
276 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
277 return new AddINode(in1->in(1), in2->in(1));
278 }
279 // Convert "(a-b)+(b-c)" into "(a-c)"
280 if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
281 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
282 return new SubINode(in1->in(1), in2->in(2));
283 }
284 // Convert "(a-b)+(c-a)" into "(c-b)"
285 if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
286 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
287 return new SubINode(in2->in(1), in1->in(2));
288 }
289 }
290
291 // Convert "x+(0-y)" into "(x-y)"
292 if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
293 return new SubINode(in1, in2->in(2) );
294
295 // Convert "(0-y)+x" into "(x-y)"
296 if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
297 return new SubINode( in2, in1->in(2) );
298
299 // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
300 // Helps with array allocation math constant folding
301 // See 4790063:
302 // Unrestricted transformation is unsafe for some runtime values of 'x'
303 // ( x == 0, z == 1, y == -1 ) fails
304 // ( x == -5, z == 1, y == 1 ) fails
305 // Transform works for small z and small negative y when the addition
306 // (x + (y << z)) does not cross zero.
307 // Implement support for negative y and (x >= -(y << z))
308 // Have not observed cases where type information exists to support
309 // positive y and (x <= -(y << z))
310 if( op1 == Op_URShiftI && op2 == Op_ConI &&
311 in1->in(2)->Opcode() == Op_ConI ) {
312 jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
313 jint y = phase->type( in2 )->is_int()->get_con();
314
315 if( z < 5 && -5 < y && y < 0 ) {
316 const Type *t_in11 = phase->type(in1->in(1));
317 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
318 Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );
319 return new URShiftINode( a, in1->in(2) );
320 }
321 }
322 }
323
324 return AddNode::Ideal(phase, can_reshape);
325 }
326
327
328 //------------------------------Identity---------------------------------------
329 // Fold (x-y)+y OR y+(x-y) into x
Identity(PhaseGVN * phase)330 Node* AddINode::Identity(PhaseGVN* phase) {
331 if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
332 return in(1)->in(1);
333 }
334 else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
335 return in(2)->in(1);
336 }
337 return AddNode::Identity(phase);
338 }
339
340
341 //------------------------------add_ring---------------------------------------
342 // Supplied function returns the sum of the inputs. Guaranteed never
343 // to be passed a TOP or BOTTOM type, these are filtered out by
344 // pre-check.
add_ring(const Type * t0,const Type * t1) const345 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
346 const TypeInt *r0 = t0->is_int(); // Handy access
347 const TypeInt *r1 = t1->is_int();
348 int lo = java_add(r0->_lo, r1->_lo);
349 int hi = java_add(r0->_hi, r1->_hi);
350 if( !(r0->is_con() && r1->is_con()) ) {
351 // Not both constants, compute approximate result
352 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
353 lo = min_jint; hi = max_jint; // Underflow on the low side
354 }
355 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
356 lo = min_jint; hi = max_jint; // Overflow on the high side
357 }
358 if( lo > hi ) { // Handle overflow
359 lo = min_jint; hi = max_jint;
360 }
361 } else {
362 // both constants, compute precise result using 'lo' and 'hi'
363 // Semantics define overflow and underflow for integer addition
364 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0
365 }
366 return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
367 }
368
369
370 //=============================================================================
371 //------------------------------Idealize---------------------------------------
Ideal(PhaseGVN * phase,bool can_reshape)372 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
373 Node* in1 = in(1);
374 Node* in2 = in(2);
375 int op1 = in1->Opcode();
376 int op2 = in2->Opcode();
377 // Fold (con1-x)+con2 into (con1+con2)-x
378 if ( op1 == Op_AddL && op2 == Op_SubL ) {
379 // Swap edges to try optimizations below
380 in1 = in2;
381 in2 = in(1);
382 op1 = op2;
383 op2 = in2->Opcode();
384 }
385 // Fold (con1-x)+con2 into (con1+con2)-x
386 if( op1 == Op_SubL ) {
387 const Type *t_sub1 = phase->type( in1->in(1) );
388 const Type *t_2 = phase->type( in2 );
389 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
390 return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
391 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
392 if( op2 == Op_SubL ) {
393 // Check for dead cycle: d = (a-b)+(c-d)
394 assert( in1->in(2) != this && in2->in(2) != this,
395 "dead loop in AddLNode::Ideal" );
396 Node *sub = new SubLNode(NULL, NULL);
397 sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));
398 sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));
399 return sub;
400 }
401 // Convert "(a-b)+(b+c)" into "(a+c)"
402 if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
403 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
404 return new AddLNode(in1->in(1), in2->in(2));
405 }
406 // Convert "(a-b)+(c+b)" into "(a+c)"
407 if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
408 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
409 return new AddLNode(in1->in(1), in2->in(1));
410 }
411 // Convert "(a-b)+(b-c)" into "(a-c)"
412 if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
413 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
414 return new SubLNode(in1->in(1), in2->in(2));
415 }
416 // Convert "(a-b)+(c-a)" into "(c-b)"
417 if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
418 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
419 return new SubLNode(in2->in(1), in1->in(2));
420 }
421 }
422
423 // Convert "x+(0-y)" into "(x-y)"
424 if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
425 return new SubLNode( in1, in2->in(2) );
426
427 // Convert "(0-y)+x" into "(x-y)"
428 if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
429 return new SubLNode( in2, in1->in(2) );
430
431 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
432 // into "(X<<1)+Y" and let shift-folding happen.
433 if( op2 == Op_AddL &&
434 in2->in(1) == in1 &&
435 op1 != Op_ConL &&
436 0 ) {
437 Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
438 return new AddLNode(shift,in2->in(2));
439 }
440
441 return AddNode::Ideal(phase, can_reshape);
442 }
443
444
445 //------------------------------Identity---------------------------------------
446 // Fold (x-y)+y OR y+(x-y) into x
Identity(PhaseGVN * phase)447 Node* AddLNode::Identity(PhaseGVN* phase) {
448 if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
449 return in(1)->in(1);
450 }
451 else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
452 return in(2)->in(1);
453 }
454 return AddNode::Identity(phase);
455 }
456
457
458 //------------------------------add_ring---------------------------------------
459 // Supplied function returns the sum of the inputs. Guaranteed never
460 // to be passed a TOP or BOTTOM type, these are filtered out by
461 // pre-check.
add_ring(const Type * t0,const Type * t1) const462 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
463 const TypeLong *r0 = t0->is_long(); // Handy access
464 const TypeLong *r1 = t1->is_long();
465 jlong lo = java_add(r0->_lo, r1->_lo);
466 jlong hi = java_add(r0->_hi, r1->_hi);
467 if( !(r0->is_con() && r1->is_con()) ) {
468 // Not both constants, compute approximate result
469 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
470 lo =min_jlong; hi = max_jlong; // Underflow on the low side
471 }
472 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
473 lo = min_jlong; hi = max_jlong; // Overflow on the high side
474 }
475 if( lo > hi ) { // Handle overflow
476 lo = min_jlong; hi = max_jlong;
477 }
478 } else {
479 // both constants, compute precise result using 'lo' and 'hi'
480 // Semantics define overflow and underflow for integer addition
481 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0
482 }
483 return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
484 }
485
486
487 //=============================================================================
488 //------------------------------add_of_identity--------------------------------
489 // Check for addition of the identity
add_of_identity(const Type * t1,const Type * t2) const490 const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const {
491 // x ADD 0 should return x unless 'x' is a -zero
492 //
493 // const Type *zero = add_id(); // The additive identity
494 // jfloat f1 = t1->getf();
495 // jfloat f2 = t2->getf();
496 //
497 // if( t1->higher_equal( zero ) ) return t2;
498 // if( t2->higher_equal( zero ) ) return t1;
499
500 return NULL;
501 }
502
503 //------------------------------add_ring---------------------------------------
504 // Supplied function returns the sum of the inputs.
505 // This also type-checks the inputs for sanity. Guaranteed never to
506 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
add_ring(const Type * t0,const Type * t1) const507 const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const {
508 // We must be adding 2 float constants.
509 return TypeF::make( t0->getf() + t1->getf() );
510 }
511
512 //------------------------------Ideal------------------------------------------
Ideal(PhaseGVN * phase,bool can_reshape)513 Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
514 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
515 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
516 }
517
518 // Floating point additions are not associative because of boundary conditions (infinity)
519 return commute(this,
520 phase->type( in(1) )->singleton(),
521 phase->type( in(2) )->singleton() ) ? this : NULL;
522 }
523
524
525 //=============================================================================
526 //------------------------------add_of_identity--------------------------------
527 // Check for addition of the identity
add_of_identity(const Type * t1,const Type * t2) const528 const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const {
529 // x ADD 0 should return x unless 'x' is a -zero
530 //
531 // const Type *zero = add_id(); // The additive identity
532 // jfloat f1 = t1->getf();
533 // jfloat f2 = t2->getf();
534 //
535 // if( t1->higher_equal( zero ) ) return t2;
536 // if( t2->higher_equal( zero ) ) return t1;
537
538 return NULL;
539 }
540 //------------------------------add_ring---------------------------------------
541 // Supplied function returns the sum of the inputs.
542 // This also type-checks the inputs for sanity. Guaranteed never to
543 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
add_ring(const Type * t0,const Type * t1) const544 const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const {
545 // We must be adding 2 double constants.
546 return TypeD::make( t0->getd() + t1->getd() );
547 }
548
549 //------------------------------Ideal------------------------------------------
Ideal(PhaseGVN * phase,bool can_reshape)550 Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
551 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
552 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
553 }
554
555 // Floating point additions are not associative because of boundary conditions (infinity)
556 return commute(this,
557 phase->type( in(1) )->singleton(),
558 phase->type( in(2) )->singleton() ) ? this : NULL;
559 }
560
561
562 //=============================================================================
563 //------------------------------Identity---------------------------------------
564 // If one input is a constant 0, return the other input.
Identity(PhaseGVN * phase)565 Node* AddPNode::Identity(PhaseGVN* phase) {
566 return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;
567 }
568
569 //------------------------------Idealize---------------------------------------
Ideal(PhaseGVN * phase,bool can_reshape)570 Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
571 // Bail out if dead inputs
572 if( phase->type( in(Address) ) == Type::TOP ) return NULL;
573
574 // If the left input is an add of a constant, flatten the expression tree.
575 const Node *n = in(Address);
576 if (n->is_AddP() && n->in(Base) == in(Base)) {
577 const AddPNode *addp = n->as_AddP(); // Left input is an AddP
578 assert( !addp->in(Address)->is_AddP() ||
579 addp->in(Address)->as_AddP() != addp,
580 "dead loop in AddPNode::Ideal" );
581 // Type of left input's right input
582 const Type *t = phase->type( addp->in(Offset) );
583 if( t == Type::TOP ) return NULL;
584 const TypeX *t12 = t->is_intptr_t();
585 if( t12->is_con() ) { // Left input is an add of a constant?
586 // If the right input is a constant, combine constants
587 const Type *temp_t2 = phase->type( in(Offset) );
588 if( temp_t2 == Type::TOP ) return NULL;
589 const TypeX *t2 = temp_t2->is_intptr_t();
590 Node* address;
591 Node* offset;
592 if( t2->is_con() ) {
593 // The Add of the flattened expression
594 address = addp->in(Address);
595 offset = phase->MakeConX(t2->get_con() + t12->get_con());
596 } else {
597 // Else move the constant to the right. ((A+con)+B) into ((A+B)+con)
598 address = phase->transform(new AddPNode(in(Base),addp->in(Address),in(Offset)));
599 offset = addp->in(Offset);
600 }
601 PhaseIterGVN *igvn = phase->is_IterGVN();
602 if( igvn ) {
603 set_req_X(Address,address,igvn);
604 set_req_X(Offset,offset,igvn);
605 } else {
606 set_req(Address,address);
607 set_req(Offset,offset);
608 }
609 return this;
610 }
611 }
612
613 // Raw pointers?
614 if( in(Base)->bottom_type() == Type::TOP ) {
615 // If this is a NULL+long form (from unsafe accesses), switch to a rawptr.
616 if (phase->type(in(Address)) == TypePtr::NULL_PTR) {
617 Node* offset = in(Offset);
618 return new CastX2PNode(offset);
619 }
620 }
621
622 // If the right is an add of a constant, push the offset down.
623 // Convert: (ptr + (offset+con)) into (ptr+offset)+con.
624 // The idea is to merge array_base+scaled_index groups together,
625 // and only have different constant offsets from the same base.
626 const Node *add = in(Offset);
627 if( add->Opcode() == Op_AddX && add->in(1) != add ) {
628 const Type *t22 = phase->type( add->in(2) );
629 if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant?
630 set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));
631 set_req(Offset, add->in(2));
632 PhaseIterGVN *igvn = phase->is_IterGVN();
633 if (add->outcnt() == 0 && igvn) {
634 // add disconnected.
635 igvn->_worklist.push((Node*)add);
636 }
637 return this; // Made progress
638 }
639 }
640
641 return NULL; // No progress
642 }
643
644 //------------------------------bottom_type------------------------------------
645 // Bottom-type is the pointer-type with unknown offset.
bottom_type() const646 const Type *AddPNode::bottom_type() const {
647 if (in(Address) == NULL) return TypePtr::BOTTOM;
648 const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
649 if( !tp ) return Type::TOP; // TOP input means TOP output
650 assert( in(Offset)->Opcode() != Op_ConP, "" );
651 const Type *t = in(Offset)->bottom_type();
652 if( t == Type::TOP )
653 return tp->add_offset(Type::OffsetTop);
654 const TypeX *tx = t->is_intptr_t();
655 intptr_t txoffset = Type::OffsetBot;
656 if (tx->is_con()) { // Left input is an add of a constant?
657 txoffset = tx->get_con();
658 }
659 return tp->add_offset(txoffset);
660 }
661
662 //------------------------------Value------------------------------------------
Value(PhaseGVN * phase) const663 const Type* AddPNode::Value(PhaseGVN* phase) const {
664 // Either input is TOP ==> the result is TOP
665 const Type *t1 = phase->type( in(Address) );
666 const Type *t2 = phase->type( in(Offset) );
667 if( t1 == Type::TOP ) return Type::TOP;
668 if( t2 == Type::TOP ) return Type::TOP;
669
670 // Left input is a pointer
671 const TypePtr *p1 = t1->isa_ptr();
672 // Right input is an int
673 const TypeX *p2 = t2->is_intptr_t();
674 // Add 'em
675 intptr_t p2offset = Type::OffsetBot;
676 if (p2->is_con()) { // Left input is an add of a constant?
677 p2offset = p2->get_con();
678 }
679 return p1->add_offset(p2offset);
680 }
681
682 //------------------------Ideal_base_and_offset--------------------------------
683 // Split an oop pointer into a base and offset.
684 // (The offset might be Type::OffsetBot in the case of an array.)
685 // Return the base, or NULL if failure.
Ideal_base_and_offset(Node * ptr,PhaseTransform * phase,intptr_t & offset)686 Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,
687 // second return value:
688 intptr_t& offset) {
689 if (ptr->is_AddP()) {
690 Node* base = ptr->in(AddPNode::Base);
691 Node* addr = ptr->in(AddPNode::Address);
692 Node* offs = ptr->in(AddPNode::Offset);
693 if (base == addr || base->is_top()) {
694 offset = phase->find_intptr_t_con(offs, Type::OffsetBot);
695 if (offset != Type::OffsetBot) {
696 return addr;
697 }
698 }
699 }
700 offset = Type::OffsetBot;
701 return NULL;
702 }
703
704 //------------------------------unpack_offsets----------------------------------
705 // Collect the AddP offset values into the elements array, giving up
706 // if there are more than length.
unpack_offsets(Node * elements[],int length)707 int AddPNode::unpack_offsets(Node* elements[], int length) {
708 int count = 0;
709 Node* addr = this;
710 Node* base = addr->in(AddPNode::Base);
711 while (addr->is_AddP()) {
712 if (addr->in(AddPNode::Base) != base) {
713 // give up
714 return -1;
715 }
716 elements[count++] = addr->in(AddPNode::Offset);
717 if (count == length) {
718 // give up
719 return -1;
720 }
721 addr = addr->in(AddPNode::Address);
722 }
723 if (addr != base) {
724 return -1;
725 }
726 return count;
727 }
728
729 //------------------------------match_edge-------------------------------------
730 // Do we Match on this edge index or not? Do not match base pointer edge
match_edge(uint idx) const731 uint AddPNode::match_edge(uint idx) const {
732 return idx > Base;
733 }
734
735 //=============================================================================
736 //------------------------------Identity---------------------------------------
Identity(PhaseGVN * phase)737 Node* OrINode::Identity(PhaseGVN* phase) {
738 // x | x => x
739 if (phase->eqv(in(1), in(2))) {
740 return in(1);
741 }
742
743 return AddNode::Identity(phase);
744 }
745
746 //------------------------------add_ring---------------------------------------
747 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For
748 // the logical operations the ring's ADD is really a logical OR function.
749 // This also type-checks the inputs for sanity. Guaranteed never to
750 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
add_ring(const Type * t0,const Type * t1) const751 const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {
752 const TypeInt *r0 = t0->is_int(); // Handy access
753 const TypeInt *r1 = t1->is_int();
754
755 // If both args are bool, can figure out better types
756 if ( r0 == TypeInt::BOOL ) {
757 if ( r1 == TypeInt::ONE) {
758 return TypeInt::ONE;
759 } else if ( r1 == TypeInt::BOOL ) {
760 return TypeInt::BOOL;
761 }
762 } else if ( r0 == TypeInt::ONE ) {
763 if ( r1 == TypeInt::BOOL ) {
764 return TypeInt::ONE;
765 }
766 }
767
768 // If either input is not a constant, just return all integers.
769 if( !r0->is_con() || !r1->is_con() )
770 return TypeInt::INT; // Any integer, but still no symbols.
771
772 // Otherwise just OR them bits.
773 return TypeInt::make( r0->get_con() | r1->get_con() );
774 }
775
776 //=============================================================================
777 //------------------------------Identity---------------------------------------
Identity(PhaseGVN * phase)778 Node* OrLNode::Identity(PhaseGVN* phase) {
779 // x | x => x
780 if (phase->eqv(in(1), in(2))) {
781 return in(1);
782 }
783
784 return AddNode::Identity(phase);
785 }
786
787 //------------------------------add_ring---------------------------------------
add_ring(const Type * t0,const Type * t1) const788 const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
789 const TypeLong *r0 = t0->is_long(); // Handy access
790 const TypeLong *r1 = t1->is_long();
791
792 // If either input is not a constant, just return all integers.
793 if( !r0->is_con() || !r1->is_con() )
794 return TypeLong::LONG; // Any integer, but still no symbols.
795
796 // Otherwise just OR them bits.
797 return TypeLong::make( r0->get_con() | r1->get_con() );
798 }
799
800 //=============================================================================
801 //------------------------------add_ring---------------------------------------
802 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For
803 // the logical operations the ring's ADD is really a logical OR function.
804 // This also type-checks the inputs for sanity. Guaranteed never to
805 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
add_ring(const Type * t0,const Type * t1) const806 const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const {
807 const TypeInt *r0 = t0->is_int(); // Handy access
808 const TypeInt *r1 = t1->is_int();
809
810 // Complementing a boolean?
811 if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE
812 || r1 == TypeInt::BOOL))
813 return TypeInt::BOOL;
814
815 if( !r0->is_con() || !r1->is_con() ) // Not constants
816 return TypeInt::INT; // Any integer, but still no symbols.
817
818 // Otherwise just XOR them bits.
819 return TypeInt::make( r0->get_con() ^ r1->get_con() );
820 }
821
822 //=============================================================================
823 //------------------------------add_ring---------------------------------------
add_ring(const Type * t0,const Type * t1) const824 const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
825 const TypeLong *r0 = t0->is_long(); // Handy access
826 const TypeLong *r1 = t1->is_long();
827
828 // If either input is not a constant, just return all integers.
829 if( !r0->is_con() || !r1->is_con() )
830 return TypeLong::LONG; // Any integer, but still no symbols.
831
832 // Otherwise just OR them bits.
833 return TypeLong::make( r0->get_con() ^ r1->get_con() );
834 }
835
836
build_min_max(Node * a,Node * b,bool is_max,bool is_unsigned,const Type * t,PhaseGVN & gvn)837 Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) {
838 bool is_int = gvn.type(a)->isa_int();
839 assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");
840 assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");
841 if (!is_unsigned) {
842 if (is_max) {
843 if (is_int) {
844 Node* res = gvn.transform(new MaxINode(a, b));
845 assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");
846 return res;
847 } else {
848 Node* cmp = gvn.transform(new CmpLNode(a, b));
849 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
850 return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
851 }
852 } else {
853 if (is_int) {
854 Node* res = gvn.transform(new MinINode(a, b));
855 assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");
856 return res;
857 } else {
858 Node* cmp = gvn.transform(new CmpLNode(b, a));
859 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
860 return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
861 }
862 }
863 } else {
864 if (is_max) {
865 if (is_int) {
866 Node* cmp = gvn.transform(new CmpUNode(a, b));
867 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
868 return gvn.transform(new CMoveINode(bol, a, b, t->is_int()));
869 } else {
870 Node* cmp = gvn.transform(new CmpULNode(a, b));
871 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
872 return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
873 }
874 } else {
875 if (is_int) {
876 Node* cmp = gvn.transform(new CmpUNode(b, a));
877 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
878 return gvn.transform(new CMoveINode(bol, a, b, t->is_int()));
879 } else {
880 Node* cmp = gvn.transform(new CmpULNode(b, a));
881 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
882 return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
883 }
884 }
885 }
886 }
887
build_min_max_diff_with_zero(Node * a,Node * b,bool is_max,const Type * t,PhaseGVN & gvn)888 Node* MaxNode::build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn) {
889 bool is_int = gvn.type(a)->isa_int();
890 assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");
891 assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");
892 Node* zero = NULL;
893 if (is_int) {
894 zero = gvn.intcon(0);
895 } else {
896 zero = gvn.longcon(0);
897 }
898 if (is_max) {
899 if (is_int) {
900 Node* cmp = gvn.transform(new CmpINode(a, b));
901 Node* sub = gvn.transform(new SubINode(a, b));
902 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
903 return gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));
904 } else {
905 Node* cmp = gvn.transform(new CmpLNode(a, b));
906 Node* sub = gvn.transform(new SubLNode(a, b));
907 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
908 return gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));
909 }
910 } else {
911 if (is_int) {
912 Node* cmp = gvn.transform(new CmpINode(b, a));
913 Node* sub = gvn.transform(new SubINode(a, b));
914 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
915 return gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));
916 } else {
917 Node* cmp = gvn.transform(new CmpLNode(b, a));
918 Node* sub = gvn.transform(new SubLNode(a, b));
919 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
920 return gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));
921 }
922 }
923 }
924
925 //=============================================================================
926 //------------------------------add_ring---------------------------------------
927 // Supplied function returns the sum of the inputs.
add_ring(const Type * t0,const Type * t1) const928 const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {
929 const TypeInt *r0 = t0->is_int(); // Handy access
930 const TypeInt *r1 = t1->is_int();
931
932 // Otherwise just MAX them bits.
933 return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
934 }
935
936 // Check if addition of an integer with type 't' and a constant 'c' can overflow
can_overflow(const TypeInt * t,jint c)937 static bool can_overflow(const TypeInt* t, jint c) {
938 jint t_lo = t->_lo;
939 jint t_hi = t->_hi;
940 return ((c < 0 && (java_add(t_lo, c) > t_lo)) ||
941 (c > 0 && (java_add(t_hi, c) < t_hi)));
942 }
943
944 //=============================================================================
945 //------------------------------Idealize---------------------------------------
946 // MINs show up in range-check loop limit calculations. Look for
947 // "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)"
Ideal(PhaseGVN * phase,bool can_reshape)948 Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
949 Node *progress = NULL;
950 // Force a right-spline graph
951 Node *l = in(1);
952 Node *r = in(2);
953 // Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) )
954 // to force a right-spline graph for the rest of MinINode::Ideal().
955 if( l->Opcode() == Op_MinI ) {
956 assert( l != l->in(1), "dead loop in MinINode::Ideal" );
957 r = phase->transform(new MinINode(l->in(2),r));
958 l = l->in(1);
959 set_req(1, l);
960 set_req(2, r);
961 return this;
962 }
963
964 // Get left input & constant
965 Node *x = l;
966 jint x_off = 0;
967 if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant
968 x->in(2)->is_Con() ) {
969 const Type *t = x->in(2)->bottom_type();
970 if( t == Type::TOP ) return NULL; // No progress
971 x_off = t->is_int()->get_con();
972 x = x->in(1);
973 }
974
975 // Scan a right-spline-tree for MINs
976 Node *y = r;
977 jint y_off = 0;
978 // Check final part of MIN tree
979 if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant
980 y->in(2)->is_Con() ) {
981 const Type *t = y->in(2)->bottom_type();
982 if( t == Type::TOP ) return NULL; // No progress
983 y_off = t->is_int()->get_con();
984 y = y->in(1);
985 }
986 if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {
987 swap_edges(1, 2);
988 return this;
989 }
990
991 const TypeInt* tx = phase->type(x)->isa_int();
992
993 if( r->Opcode() == Op_MinI ) {
994 assert( r != r->in(2), "dead loop in MinINode::Ideal" );
995 y = r->in(1);
996 // Check final part of MIN tree
997 if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant
998 y->in(2)->is_Con() ) {
999 const Type *t = y->in(2)->bottom_type();
1000 if( t == Type::TOP ) return NULL; // No progress
1001 y_off = t->is_int()->get_con();
1002 y = y->in(1);
1003 }
1004
1005 if( x->_idx > y->_idx )
1006 return new MinINode(r->in(1),phase->transform(new MinINode(l,r->in(2))));
1007
1008 // Transform MIN2(x + c0, MIN2(x + c1, z)) into MIN2(x + MIN2(c0, c1), z)
1009 // if x == y and the additions can't overflow.
1010 if (phase->eqv(x,y) && tx != NULL &&
1011 !can_overflow(tx, x_off) &&
1012 !can_overflow(tx, y_off)) {
1013 return new MinINode(phase->transform(new AddINode(x, phase->intcon(MIN2(x_off, y_off)))), r->in(2));
1014 }
1015 } else {
1016 // Transform MIN2(x + c0, y + c1) into x + MIN2(c0, c1)
1017 // if x == y and the additions can't overflow.
1018 if (phase->eqv(x,y) && tx != NULL &&
1019 !can_overflow(tx, x_off) &&
1020 !can_overflow(tx, y_off)) {
1021 return new AddINode(x,phase->intcon(MIN2(x_off,y_off)));
1022 }
1023 }
1024 return NULL;
1025 }
1026
1027 //------------------------------add_ring---------------------------------------
1028 // Supplied function returns the sum of the inputs.
add_ring(const Type * t0,const Type * t1) const1029 const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {
1030 const TypeInt *r0 = t0->is_int(); // Handy access
1031 const TypeInt *r1 = t1->is_int();
1032
1033 // Otherwise just MIN them bits.
1034 return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
1035 }
1036
1037 //------------------------------add_ring---------------------------------------
add_ring(const Type * t0,const Type * t1) const1038 const Type *MinFNode::add_ring( const Type *t0, const Type *t1 ) const {
1039 const TypeF *r0 = t0->is_float_constant();
1040 const TypeF *r1 = t1->is_float_constant();
1041
1042 if (r0->is_nan()) {
1043 return r0;
1044 }
1045 if (r1->is_nan()) {
1046 return r1;
1047 }
1048
1049 float f0 = r0->getf();
1050 float f1 = r1->getf();
1051 if (f0 != 0.0f || f1 != 0.0f) {
1052 return f0 < f1 ? r0 : r1;
1053 }
1054
1055 // handle min of 0.0, -0.0 case.
1056 return (jint_cast(f0) < jint_cast(f1)) ? r0 : r1;
1057 }
1058
1059 //------------------------------add_ring---------------------------------------
add_ring(const Type * t0,const Type * t1) const1060 const Type *MinDNode::add_ring( const Type *t0, const Type *t1 ) const {
1061 const TypeD *r0 = t0->is_double_constant();
1062 const TypeD *r1 = t1->is_double_constant();
1063
1064 if (r0->is_nan()) {
1065 return r0;
1066 }
1067 if (r1->is_nan()) {
1068 return r1;
1069 }
1070
1071 double d0 = r0->getd();
1072 double d1 = r1->getd();
1073 if (d0 != 0.0 || d1 != 0.0) {
1074 return d0 < d1 ? r0 : r1;
1075 }
1076
1077 // handle min of 0.0, -0.0 case.
1078 return (jlong_cast(d0) < jlong_cast(d1)) ? r0 : r1;
1079 }
1080
1081 //------------------------------add_ring---------------------------------------
add_ring(const Type * t0,const Type * t1) const1082 const Type *MaxFNode::add_ring( const Type *t0, const Type *t1 ) const {
1083 const TypeF *r0 = t0->is_float_constant();
1084 const TypeF *r1 = t1->is_float_constant();
1085
1086 if (r0->is_nan()) {
1087 return r0;
1088 }
1089 if (r1->is_nan()) {
1090 return r1;
1091 }
1092
1093 float f0 = r0->getf();
1094 float f1 = r1->getf();
1095 if (f0 != 0.0f || f1 != 0.0f) {
1096 return f0 > f1 ? r0 : r1;
1097 }
1098
1099 // handle max of 0.0,-0.0 case.
1100 return (jint_cast(f0) > jint_cast(f1)) ? r0 : r1;
1101 }
1102
1103 //------------------------------add_ring---------------------------------------
add_ring(const Type * t0,const Type * t1) const1104 const Type *MaxDNode::add_ring( const Type *t0, const Type *t1 ) const {
1105 const TypeD *r0 = t0->is_double_constant();
1106 const TypeD *r1 = t1->is_double_constant();
1107
1108 if (r0->is_nan()) {
1109 return r0;
1110 }
1111 if (r1->is_nan()) {
1112 return r1;
1113 }
1114
1115 double d0 = r0->getd();
1116 double d1 = r1->getd();
1117 if (d0 != 0.0 || d1 != 0.0) {
1118 return d0 > d1 ? r0 : r1;
1119 }
1120
1121 // handle max of 0.0, -0.0 case.
1122 return (jlong_cast(d0) > jlong_cast(d1)) ? r0 : r1;
1123 }
1124