1 /* 2 * Copyright (c) 1997, 2025, 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 "memory/allocation.inline.hpp" 26 #include "opto/addnode.hpp" 27 #include "opto/castnode.hpp" 28 #include "opto/cfgnode.hpp" 29 #include "opto/connode.hpp" 30 #include "opto/machnode.hpp" 31 #include "opto/movenode.hpp" 32 #include "opto/mulnode.hpp" 33 #include "opto/phaseX.hpp" 34 #include "opto/subnode.hpp" 35 #include "runtime/stubRoutines.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. 50 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. 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. 65 static bool commute(PhaseGVN* phase, Node* add) { 66 Node *in1 = add->in(1); 67 Node *in2 = add->in(2); 68 69 // convert "max(a,b) + min(a,b)" into "a+b". 70 if ((in1->Opcode() == add->as_Add()->max_opcode() && in2->Opcode() == add->as_Add()->min_opcode()) 71 || (in1->Opcode() == add->as_Add()->min_opcode() && in2->Opcode() == add->as_Add()->max_opcode())) { 72 Node *in11 = in1->in(1); 73 Node *in12 = in1->in(2); 74 75 Node *in21 = in2->in(1); 76 Node *in22 = in2->in(2); 77 78 if ((in11 == in21 && in12 == in22) || 79 (in11 == in22 && in12 == in21)) { 80 add->set_req_X(1, in11, phase); 81 add->set_req_X(2, in12, phase); 82 return true; 83 } 84 } 85 86 bool con_left = phase->type(in1)->singleton(); 87 bool con_right = phase->type(in2)->singleton(); 88 89 // Convert "1+x" into "x+1". 90 // Right is a constant; leave it 91 if( con_right ) return false; 92 // Left is a constant; move it right. 93 if( con_left ) { 94 add->swap_edges(1, 2); 95 return true; 96 } 97 98 // Convert "Load+x" into "x+Load". 99 // Now check for loads 100 if (in2->is_Load()) { 101 if (!in1->is_Load()) { 102 // already x+Load to return 103 return false; 104 } 105 // both are loads, so fall through to sort inputs by idx 106 } else if( in1->is_Load() ) { 107 // Left is a Load and Right is not; move it right. 108 add->swap_edges(1, 2); 109 return true; 110 } 111 112 PhiNode *phi; 113 // Check for tight loop increments: Loop-phi of Add of loop-phi 114 if (in1->is_Phi() && (phi = in1->as_Phi()) && phi->region()->is_Loop() && phi->in(2) == add) 115 return false; 116 if (in2->is_Phi() && (phi = in2->as_Phi()) && phi->region()->is_Loop() && phi->in(2) == add) { 117 add->swap_edges(1, 2); 118 return true; 119 } 120 121 // Otherwise, sort inputs (commutativity) to help value numbering. 122 if( in1->_idx > in2->_idx ) { 123 add->swap_edges(1, 2); 124 return true; 125 } 126 return false; 127 } 128 129 //------------------------------Idealize--------------------------------------- 130 // If we get here, we assume we are associative! 131 Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) { 132 const Type *t1 = phase->type(in(1)); 133 const Type *t2 = phase->type(in(2)); 134 bool con_left = t1->singleton(); 135 bool con_right = t2->singleton(); 136 137 // Check for commutative operation desired 138 if (commute(phase, this)) return this; 139 140 AddNode *progress = nullptr; // Progress flag 141 142 // Convert "(x+1)+2" into "x+(1+2)". If the right input is a 143 // constant, and the left input is an add of a constant, flatten the 144 // expression tree. 145 Node *add1 = in(1); 146 Node *add2 = in(2); 147 int add1_op = add1->Opcode(); 148 int this_op = Opcode(); 149 if (con_right && t2 != Type::TOP && // Right input is a constant? 150 add1_op == this_op) { // Left input is an Add? 151 152 // Type of left _in right input 153 const Type *t12 = phase->type(add1->in(2)); 154 if (t12->singleton() && t12 != Type::TOP) { // Left input is an add of a constant? 155 // Check for rare case of closed data cycle which can happen inside 156 // unreachable loops. In these cases the computation is undefined. 157 #ifdef ASSERT 158 Node *add11 = add1->in(1); 159 int add11_op = add11->Opcode(); 160 if ((add1 == add1->in(1)) 161 || (add11_op == this_op && add11->in(1) == add1)) { 162 assert(false, "dead loop in AddNode::Ideal"); 163 } 164 #endif 165 // The Add of the flattened expression 166 Node *x1 = add1->in(1); 167 Node *x2 = phase->makecon(add1->as_Add()->add_ring(t2, t12)); 168 set_req_X(2, x2, phase); 169 set_req_X(1, x1, phase); 170 progress = this; // Made progress 171 add1 = in(1); 172 add1_op = add1->Opcode(); 173 } 174 } 175 176 // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree. 177 if (add1_op == this_op && !con_right) { 178 Node *a12 = add1->in(2); 179 const Type *t12 = phase->type( a12 ); 180 if (t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) && 181 !(add1->in(1)->is_Phi() && (add1->in(1)->as_Phi()->is_tripcount(T_INT) || add1->in(1)->as_Phi()->is_tripcount(T_LONG)))) { 182 assert(add1->in(1) != this, "dead loop in AddNode::Ideal"); 183 add2 = add1->clone(); 184 add2->set_req(2, in(2)); 185 add2 = phase->transform(add2); 186 set_req_X(1, add2, phase); 187 set_req_X(2, a12, phase); 188 progress = this; 189 add2 = a12; 190 } 191 } 192 193 // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree. 194 int add2_op = add2->Opcode(); 195 if (add2_op == this_op && !con_left) { 196 Node *a22 = add2->in(2); 197 const Type *t22 = phase->type( a22 ); 198 if (t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) && 199 !(add2->in(1)->is_Phi() && (add2->in(1)->as_Phi()->is_tripcount(T_INT) || add2->in(1)->as_Phi()->is_tripcount(T_LONG)))) { 200 assert(add2->in(1) != this, "dead loop in AddNode::Ideal"); 201 Node *addx = add2->clone(); 202 addx->set_req(1, in(1)); 203 addx->set_req(2, add2->in(1)); 204 addx = phase->transform(addx); 205 set_req_X(1, addx, phase); 206 set_req_X(2, a22, phase); 207 progress = this; 208 } 209 } 210 211 return progress; 212 } 213 214 //------------------------------Value----------------------------------------- 215 // An add node sums it's two _in. If one input is an RSD, we must mixin 216 // the other input's symbols. 217 const Type* AddNode::Value(PhaseGVN* phase) const { 218 // Either input is TOP ==> the result is TOP 219 const Type* t1 = phase->type(in(1)); 220 const Type* t2 = phase->type(in(2)); 221 if (t1 == Type::TOP || t2 == Type::TOP) { 222 return Type::TOP; 223 } 224 225 // Check for an addition involving the additive identity 226 const Type* tadd = add_of_identity(t1, t2); 227 if (tadd != nullptr) { 228 return tadd; 229 } 230 231 return add_ring(t1, t2); // Local flavor of type addition 232 } 233 234 //------------------------------add_identity----------------------------------- 235 // Check for addition of the identity 236 const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const { 237 const Type *zero = add_id(); // The additive identity 238 if( t1->higher_equal( zero ) ) return t2; 239 if( t2->higher_equal( zero ) ) return t1; 240 241 return nullptr; 242 } 243 244 AddNode* AddNode::make(Node* in1, Node* in2, BasicType bt) { 245 switch (bt) { 246 case T_INT: 247 return new AddINode(in1, in2); 248 case T_LONG: 249 return new AddLNode(in1, in2); 250 default: 251 fatal("Not implemented for %s", type2name(bt)); 252 } 253 return nullptr; 254 } 255 256 bool AddNode::is_not(PhaseGVN* phase, Node* n, BasicType bt) { 257 return n->Opcode() == Op_Xor(bt) && phase->type(n->in(2)) == TypeInteger::minus_1(bt); 258 } 259 260 AddNode* AddNode::make_not(PhaseGVN* phase, Node* n, BasicType bt) { 261 switch (bt) { 262 case T_INT: 263 return new XorINode(n, phase->intcon(-1)); 264 case T_LONG: 265 return new XorLNode(n, phase->longcon(-1L)); 266 default: 267 fatal("Not implemented for %s", type2name(bt)); 268 } 269 return nullptr; 270 } 271 272 //============================================================================= 273 //------------------------------Idealize--------------------------------------- 274 Node* AddNode::IdealIL(PhaseGVN* phase, bool can_reshape, BasicType bt) { 275 Node* in1 = in(1); 276 Node* in2 = in(2); 277 int op1 = in1->Opcode(); 278 int op2 = in2->Opcode(); 279 // Fold (con1-x)+con2 into (con1+con2)-x 280 if (op1 == Op_Add(bt) && op2 == Op_Sub(bt)) { 281 // Swap edges to try optimizations below 282 in1 = in2; 283 in2 = in(1); 284 op1 = op2; 285 op2 = in2->Opcode(); 286 } 287 if (op1 == Op_Sub(bt)) { 288 const Type* t_sub1 = phase->type(in1->in(1)); 289 const Type* t_2 = phase->type(in2 ); 290 if (t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP) { 291 return SubNode::make(phase->makecon(add_ring(t_sub1, t_2)), in1->in(2), bt); 292 } 293 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" 294 if (op2 == Op_Sub(bt)) { 295 // Check for dead cycle: d = (a-b)+(c-d) 296 assert( in1->in(2) != this && in2->in(2) != this, 297 "dead loop in AddINode::Ideal" ); 298 Node* sub = SubNode::make(nullptr, nullptr, bt); 299 Node* sub_in1; 300 PhaseIterGVN* igvn = phase->is_IterGVN(); 301 // During IGVN, if both inputs of the new AddNode are a tree of SubNodes, this same transformation will be applied 302 // to every node of the tree. Calling transform() causes the transformation to be applied recursively, once per 303 // tree node whether some subtrees are identical or not. Pushing to the IGVN worklist instead, causes the transform 304 // to be applied once per unique subtrees (because all uses of a subtree are updated with the result of the 305 // transformation). In case of a large tree, this can make a difference in compilation time. 306 if (igvn != nullptr) { 307 sub_in1 = igvn->register_new_node_with_optimizer(AddNode::make(in1->in(1), in2->in(1), bt)); 308 } else { 309 sub_in1 = phase->transform(AddNode::make(in1->in(1), in2->in(1), bt)); 310 } 311 Node* sub_in2; 312 if (igvn != nullptr) { 313 sub_in2 = igvn->register_new_node_with_optimizer(AddNode::make(in1->in(2), in2->in(2), bt)); 314 } else { 315 sub_in2 = phase->transform(AddNode::make(in1->in(2), in2->in(2), bt)); 316 } 317 sub->init_req(1, sub_in1); 318 sub->init_req(2, sub_in2); 319 return sub; 320 } 321 // Convert "(a-b)+(b+c)" into "(a+c)" 322 if (op2 == Op_Add(bt) && in1->in(2) == in2->in(1)) { 323 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal/AddLNode::Ideal"); 324 return AddNode::make(in1->in(1), in2->in(2), bt); 325 } 326 // Convert "(a-b)+(c+b)" into "(a+c)" 327 if (op2 == Op_Add(bt) && in1->in(2) == in2->in(2)) { 328 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal/AddLNode::Ideal"); 329 return AddNode::make(in1->in(1), in2->in(1), bt); 330 } 331 } 332 333 // Convert (con - y) + x into "(x - y) + con" 334 if (op1 == Op_Sub(bt) && in1->in(1)->Opcode() == Op_ConIL(bt) 335 && in1 != in1->in(2) && !(in1->in(2)->is_Phi() && in1->in(2)->as_Phi()->is_tripcount(bt))) { 336 return AddNode::make(phase->transform(SubNode::make(in2, in1->in(2), bt)), in1->in(1), bt); 337 } 338 339 // Convert x + (con - y) into "(x - y) + con" 340 if (op2 == Op_Sub(bt) && in2->in(1)->Opcode() == Op_ConIL(bt) 341 && in2 != in2->in(2) && !(in2->in(2)->is_Phi() && in2->in(2)->as_Phi()->is_tripcount(bt))) { 342 return AddNode::make(phase->transform(SubNode::make(in1, in2->in(2), bt)), in2->in(1), bt); 343 } 344 345 // Associative 346 if (op1 == Op_Mul(bt) && op2 == Op_Mul(bt)) { 347 Node* add_in1 = nullptr; 348 Node* add_in2 = nullptr; 349 Node* mul_in = nullptr; 350 351 if (in1->in(1) == in2->in(1)) { 352 // Convert "a*b+a*c into a*(b+c) 353 add_in1 = in1->in(2); 354 add_in2 = in2->in(2); 355 mul_in = in1->in(1); 356 } else if (in1->in(2) == in2->in(1)) { 357 // Convert a*b+b*c into b*(a+c) 358 add_in1 = in1->in(1); 359 add_in2 = in2->in(2); 360 mul_in = in1->in(2); 361 } else if (in1->in(2) == in2->in(2)) { 362 // Convert a*c+b*c into (a+b)*c 363 add_in1 = in1->in(1); 364 add_in2 = in2->in(1); 365 mul_in = in1->in(2); 366 } else if (in1->in(1) == in2->in(2)) { 367 // Convert a*b+c*a into a*(b+c) 368 add_in1 = in1->in(2); 369 add_in2 = in2->in(1); 370 mul_in = in1->in(1); 371 } 372 373 if (mul_in != nullptr) { 374 Node* add = phase->transform(AddNode::make(add_in1, add_in2, bt)); 375 return MulNode::make(mul_in, add, bt); 376 } 377 } 378 379 // Convert (x >>> rshift) + (x << lshift) into RotateRight(x, rshift) 380 if (Matcher::match_rule_supported(Op_RotateRight) && 381 ((op1 == Op_URShift(bt) && op2 == Op_LShift(bt)) || (op1 == Op_LShift(bt) && op2 == Op_URShift(bt))) && 382 in1->in(1) != nullptr && in1->in(1) == in2->in(1)) { 383 Node* rshift = op1 == Op_URShift(bt) ? in1->in(2) : in2->in(2); 384 Node* lshift = op1 == Op_URShift(bt) ? in2->in(2) : in1->in(2); 385 if (rshift != nullptr && lshift != nullptr) { 386 const TypeInt* rshift_t = phase->type(rshift)->isa_int(); 387 const TypeInt* lshift_t = phase->type(lshift)->isa_int(); 388 int bits = bt == T_INT ? 32 : 64; 389 int mask = bt == T_INT ? 0x1F : 0x3F; 390 if (lshift_t != nullptr && lshift_t->is_con() && 391 rshift_t != nullptr && rshift_t->is_con() && 392 ((lshift_t->get_con() & mask) == (bits - (rshift_t->get_con() & mask)))) { 393 return new RotateRightNode(in1->in(1), phase->intcon(rshift_t->get_con() & mask), TypeInteger::bottom(bt)); 394 } 395 } 396 } 397 398 return AddNode::Ideal(phase, can_reshape); 399 } 400 401 402 Node* AddINode::Ideal(PhaseGVN* phase, bool can_reshape) { 403 Node* in1 = in(1); 404 Node* in2 = in(2); 405 int op1 = in1->Opcode(); 406 int op2 = in2->Opcode(); 407 408 // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y. 409 // Helps with array allocation math constant folding 410 // See 4790063: 411 // Unrestricted transformation is unsafe for some runtime values of 'x' 412 // ( x == 0, z == 1, y == -1 ) fails 413 // ( x == -5, z == 1, y == 1 ) fails 414 // Transform works for small z and small negative y when the addition 415 // (x + (y << z)) does not cross zero. 416 // Implement support for negative y and (x >= -(y << z)) 417 // Have not observed cases where type information exists to support 418 // positive y and (x <= -(y << z)) 419 if (op1 == Op_URShiftI && op2 == Op_ConI && 420 in1->in(2)->Opcode() == Op_ConI) { 421 jint z = phase->type(in1->in(2))->is_int()->get_con() & 0x1f; // only least significant 5 bits matter 422 jint y = phase->type(in2)->is_int()->get_con(); 423 424 if (z < 5 && -5 < y && y < 0) { 425 const Type* t_in11 = phase->type(in1->in(1)); 426 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z))) { 427 Node* a = phase->transform(new AddINode( in1->in(1), phase->intcon(y<<z))); 428 return new URShiftINode(a, in1->in(2)); 429 } 430 } 431 } 432 433 return AddNode::IdealIL(phase, can_reshape, T_INT); 434 } 435 436 437 //------------------------------Identity--------------------------------------- 438 // Fold (x-y)+y OR y+(x-y) into x 439 Node* AddINode::Identity(PhaseGVN* phase) { 440 if (in(1)->Opcode() == Op_SubI && in(1)->in(2) == in(2)) { 441 return in(1)->in(1); 442 } else if (in(2)->Opcode() == Op_SubI && in(2)->in(2) == in(1)) { 443 return in(2)->in(1); 444 } 445 return AddNode::Identity(phase); 446 } 447 448 449 //------------------------------add_ring--------------------------------------- 450 // Supplied function returns the sum of the inputs. Guaranteed never 451 // to be passed a TOP or BOTTOM type, these are filtered out by 452 // pre-check. 453 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const { 454 const TypeInt *r0 = t0->is_int(); // Handy access 455 const TypeInt *r1 = t1->is_int(); 456 int lo = java_add(r0->_lo, r1->_lo); 457 int hi = java_add(r0->_hi, r1->_hi); 458 if( !(r0->is_con() && r1->is_con()) ) { 459 // Not both constants, compute approximate result 460 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) { 461 lo = min_jint; hi = max_jint; // Underflow on the low side 462 } 463 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) { 464 lo = min_jint; hi = max_jint; // Overflow on the high side 465 } 466 if( lo > hi ) { // Handle overflow 467 lo = min_jint; hi = max_jint; 468 } 469 } else { 470 // both constants, compute precise result using 'lo' and 'hi' 471 // Semantics define overflow and underflow for integer addition 472 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0 473 } 474 return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) ); 475 } 476 477 478 //============================================================================= 479 //------------------------------Idealize--------------------------------------- 480 Node* AddLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 481 return AddNode::IdealIL(phase, can_reshape, T_LONG); 482 } 483 484 485 //------------------------------Identity--------------------------------------- 486 // Fold (x-y)+y OR y+(x-y) into x 487 Node* AddLNode::Identity(PhaseGVN* phase) { 488 if (in(1)->Opcode() == Op_SubL && in(1)->in(2) == in(2)) { 489 return in(1)->in(1); 490 } else if (in(2)->Opcode() == Op_SubL && in(2)->in(2) == in(1)) { 491 return in(2)->in(1); 492 } 493 return AddNode::Identity(phase); 494 } 495 496 497 //------------------------------add_ring--------------------------------------- 498 // Supplied function returns the sum of the inputs. Guaranteed never 499 // to be passed a TOP or BOTTOM type, these are filtered out by 500 // pre-check. 501 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const { 502 const TypeLong *r0 = t0->is_long(); // Handy access 503 const TypeLong *r1 = t1->is_long(); 504 jlong lo = java_add(r0->_lo, r1->_lo); 505 jlong hi = java_add(r0->_hi, r1->_hi); 506 if( !(r0->is_con() && r1->is_con()) ) { 507 // Not both constants, compute approximate result 508 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) { 509 lo =min_jlong; hi = max_jlong; // Underflow on the low side 510 } 511 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) { 512 lo = min_jlong; hi = max_jlong; // Overflow on the high side 513 } 514 if( lo > hi ) { // Handle overflow 515 lo = min_jlong; hi = max_jlong; 516 } 517 } else { 518 // both constants, compute precise result using 'lo' and 'hi' 519 // Semantics define overflow and underflow for integer addition 520 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0 521 } 522 return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) ); 523 } 524 525 526 //============================================================================= 527 //------------------------------add_of_identity-------------------------------- 528 // Check for addition of the identity 529 const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const { 530 // x ADD 0 should return x unless 'x' is a -zero 531 // 532 // const Type *zero = add_id(); // The additive identity 533 // jfloat f1 = t1->getf(); 534 // jfloat f2 = t2->getf(); 535 // 536 // if( t1->higher_equal( zero ) ) return t2; 537 // if( t2->higher_equal( zero ) ) return t1; 538 539 return nullptr; 540 } 541 542 //------------------------------add_ring--------------------------------------- 543 // Supplied function returns the sum of the inputs. 544 // This also type-checks the inputs for sanity. Guaranteed never to 545 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. 546 const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const { 547 if (!t0->isa_float_constant() || !t1->isa_float_constant()) { 548 return bottom_type(); 549 } 550 return TypeF::make( t0->getf() + t1->getf() ); 551 } 552 553 //------------------------------Ideal------------------------------------------ 554 Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) { 555 // Floating point additions are not associative because of boundary conditions (infinity) 556 return commute(phase, this) ? this : nullptr; 557 } 558 559 //============================================================================= 560 //------------------------------add_of_identity-------------------------------- 561 // Check for addition of the identity 562 const Type* AddHFNode::add_of_identity(const Type* t1, const Type* t2) const { 563 return nullptr; 564 } 565 566 // Supplied function returns the sum of the inputs. 567 // This also type-checks the inputs for sanity. Guaranteed never to 568 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. 569 const Type* AddHFNode::add_ring(const Type* t0, const Type* t1) const { 570 if (!t0->isa_half_float_constant() || !t1->isa_half_float_constant()) { 571 return bottom_type(); 572 } 573 return TypeH::make(t0->getf() + t1->getf()); 574 } 575 576 //============================================================================= 577 //------------------------------add_of_identity-------------------------------- 578 // Check for addition of the identity 579 const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const { 580 // x ADD 0 should return x unless 'x' is a -zero 581 // 582 // const Type *zero = add_id(); // The additive identity 583 // jfloat f1 = t1->getf(); 584 // jfloat f2 = t2->getf(); 585 // 586 // if( t1->higher_equal( zero ) ) return t2; 587 // if( t2->higher_equal( zero ) ) return t1; 588 589 return nullptr; 590 } 591 //------------------------------add_ring--------------------------------------- 592 // Supplied function returns the sum of the inputs. 593 // This also type-checks the inputs for sanity. Guaranteed never to 594 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. 595 const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const { 596 if (!t0->isa_double_constant() || !t1->isa_double_constant()) { 597 return bottom_type(); 598 } 599 return TypeD::make( t0->getd() + t1->getd() ); 600 } 601 602 //------------------------------Ideal------------------------------------------ 603 Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) { 604 // Floating point additions are not associative because of boundary conditions (infinity) 605 return commute(phase, this) ? this : nullptr; 606 } 607 608 609 //============================================================================= 610 //------------------------------Identity--------------------------------------- 611 // If one input is a constant 0, return the other input. 612 Node* AddPNode::Identity(PhaseGVN* phase) { 613 return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this; 614 } 615 616 //------------------------------Idealize--------------------------------------- 617 Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) { 618 // Bail out if dead inputs 619 if( phase->type( in(Address) ) == Type::TOP ) return nullptr; 620 621 // If the left input is an add of a constant, flatten the expression tree. 622 const Node *n = in(Address); 623 if (n->is_AddP() && n->in(Base) == in(Base)) { 624 const AddPNode *addp = n->as_AddP(); // Left input is an AddP 625 assert( !addp->in(Address)->is_AddP() || 626 addp->in(Address)->as_AddP() != addp, 627 "dead loop in AddPNode::Ideal" ); 628 // Type of left input's right input 629 const Type *t = phase->type( addp->in(Offset) ); 630 if( t == Type::TOP ) return nullptr; 631 const TypeX *t12 = t->is_intptr_t(); 632 if( t12->is_con() ) { // Left input is an add of a constant? 633 // If the right input is a constant, combine constants 634 const Type *temp_t2 = phase->type( in(Offset) ); 635 if( temp_t2 == Type::TOP ) return nullptr; 636 const TypeX *t2 = temp_t2->is_intptr_t(); 637 Node* address; 638 Node* offset; 639 if( t2->is_con() ) { 640 // The Add of the flattened expression 641 address = addp->in(Address); 642 offset = phase->MakeConX(t2->get_con() + t12->get_con()); 643 } else { 644 // Else move the constant to the right. ((A+con)+B) into ((A+B)+con) 645 address = phase->transform(new AddPNode(in(Base),addp->in(Address),in(Offset))); 646 offset = addp->in(Offset); 647 } 648 set_req_X(Address, address, phase); 649 set_req_X(Offset, offset, phase); 650 return this; 651 } 652 } 653 654 // Raw pointers? 655 if( in(Base)->bottom_type() == Type::TOP ) { 656 // If this is a null+long form (from unsafe accesses), switch to a rawptr. 657 if (phase->type(in(Address)) == TypePtr::NULL_PTR) { 658 Node* offset = in(Offset); 659 return new CastX2PNode(offset); 660 } 661 } 662 663 // If the right is an add of a constant, push the offset down. 664 // Convert: (ptr + (offset+con)) into (ptr+offset)+con. 665 // The idea is to merge array_base+scaled_index groups together, 666 // and only have different constant offsets from the same base. 667 const Node *add = in(Offset); 668 if( add->Opcode() == Op_AddX && add->in(1) != add ) { 669 const Type *t22 = phase->type( add->in(2) ); 670 if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant? 671 set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1)))); 672 set_req_X(Offset, add->in(2), phase); // puts add on igvn worklist if needed 673 return this; // Made progress 674 } 675 } 676 677 return nullptr; // No progress 678 } 679 680 //------------------------------bottom_type------------------------------------ 681 // Bottom-type is the pointer-type with unknown offset. 682 const Type *AddPNode::bottom_type() const { 683 if (in(Address) == nullptr) return TypePtr::BOTTOM; 684 const TypePtr *tp = in(Address)->bottom_type()->isa_ptr(); 685 if( !tp ) return Type::TOP; // TOP input means TOP output 686 assert( in(Offset)->Opcode() != Op_ConP, "" ); 687 const Type *t = in(Offset)->bottom_type(); 688 if( t == Type::TOP ) 689 return tp->add_offset(Type::OffsetTop); 690 const TypeX *tx = t->is_intptr_t(); 691 intptr_t txoffset = Type::OffsetBot; 692 if (tx->is_con()) { // Left input is an add of a constant? 693 txoffset = tx->get_con(); 694 } 695 if (tp->isa_aryptr()) { 696 // In the case of a flat inline type array, each field has its 697 // own slice so we need to extract the field being accessed from 698 // the address computation 699 return tp->is_aryptr()->add_field_offset_and_offset(txoffset); 700 } 701 return tp->add_offset(txoffset); 702 } 703 704 //------------------------------Value------------------------------------------ 705 const Type* AddPNode::Value(PhaseGVN* phase) const { 706 // Either input is TOP ==> the result is TOP 707 const Type *t1 = phase->type( in(Address) ); 708 const Type *t2 = phase->type( in(Offset) ); 709 if( t1 == Type::TOP ) return Type::TOP; 710 if( t2 == Type::TOP ) return Type::TOP; 711 712 // Left input is a pointer 713 const TypePtr *p1 = t1->isa_ptr(); 714 // Right input is an int 715 const TypeX *p2 = t2->is_intptr_t(); 716 // Add 'em 717 intptr_t p2offset = Type::OffsetBot; 718 if (p2->is_con()) { // Left input is an add of a constant? 719 p2offset = p2->get_con(); 720 } 721 if (p1->isa_aryptr()) { 722 // In the case of a flat inline type array, each field has its 723 // own slice so we need to extract the field being accessed from 724 // the address computation 725 return p1->is_aryptr()->add_field_offset_and_offset(p2offset); 726 } 727 return p1->add_offset(p2offset); 728 } 729 730 //------------------------Ideal_base_and_offset-------------------------------- 731 // Split an oop pointer into a base and offset. 732 // (The offset might be Type::OffsetBot in the case of an array.) 733 // Return the base, or null if failure. 734 Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseValues* phase, 735 // second return value: 736 intptr_t& offset) { 737 if (ptr->is_AddP()) { 738 Node* base = ptr->in(AddPNode::Base); 739 Node* addr = ptr->in(AddPNode::Address); 740 Node* offs = ptr->in(AddPNode::Offset); 741 if (base == addr || base->is_top()) { 742 offset = phase->find_intptr_t_con(offs, Type::OffsetBot); 743 if (offset != Type::OffsetBot) { 744 return addr; 745 } 746 } 747 } 748 offset = Type::OffsetBot; 749 return nullptr; 750 } 751 752 //------------------------------unpack_offsets---------------------------------- 753 // Collect the AddP offset values into the elements array, giving up 754 // if there are more than length. 755 int AddPNode::unpack_offsets(Node* elements[], int length) const { 756 int count = 0; 757 Node const* addr = this; 758 Node* base = addr->in(AddPNode::Base); 759 while (addr->is_AddP()) { 760 if (addr->in(AddPNode::Base) != base) { 761 // give up 762 return -1; 763 } 764 elements[count++] = addr->in(AddPNode::Offset); 765 if (count == length) { 766 // give up 767 return -1; 768 } 769 addr = addr->in(AddPNode::Address); 770 } 771 if (addr != base) { 772 return -1; 773 } 774 return count; 775 } 776 777 //------------------------------match_edge------------------------------------- 778 // Do we Match on this edge index or not? Do not match base pointer edge 779 uint AddPNode::match_edge(uint idx) const { 780 return idx > Base; 781 } 782 783 //============================================================================= 784 //------------------------------Identity--------------------------------------- 785 Node* OrINode::Identity(PhaseGVN* phase) { 786 // x | x => x 787 if (in(1) == in(2)) { 788 return in(1); 789 } 790 791 return AddNode::Identity(phase); 792 } 793 794 // Find shift value for Integer or Long OR. 795 static Node* rotate_shift(PhaseGVN* phase, Node* lshift, Node* rshift, int mask) { 796 // val << norm_con_shift | val >> ({32|64} - norm_con_shift) => rotate_left val, norm_con_shift 797 const TypeInt* lshift_t = phase->type(lshift)->isa_int(); 798 const TypeInt* rshift_t = phase->type(rshift)->isa_int(); 799 if (lshift_t != nullptr && lshift_t->is_con() && 800 rshift_t != nullptr && rshift_t->is_con() && 801 ((lshift_t->get_con() & mask) == ((mask + 1) - (rshift_t->get_con() & mask)))) { 802 return phase->intcon(lshift_t->get_con() & mask); 803 } 804 // val << var_shift | val >> ({0|32|64} - var_shift) => rotate_left val, var_shift 805 if (rshift->Opcode() == Op_SubI && rshift->in(2) == lshift && rshift->in(1)->is_Con()){ 806 const TypeInt* shift_t = phase->type(rshift->in(1))->isa_int(); 807 if (shift_t != nullptr && shift_t->is_con() && 808 (shift_t->get_con() == 0 || shift_t->get_con() == (mask + 1))) { 809 return lshift; 810 } 811 } 812 return nullptr; 813 } 814 815 Node* OrINode::Ideal(PhaseGVN* phase, bool can_reshape) { 816 int lopcode = in(1)->Opcode(); 817 int ropcode = in(2)->Opcode(); 818 if (Matcher::match_rule_supported(Op_RotateLeft) && 819 lopcode == Op_LShiftI && ropcode == Op_URShiftI && in(1)->in(1) == in(2)->in(1)) { 820 Node* lshift = in(1)->in(2); 821 Node* rshift = in(2)->in(2); 822 Node* shift = rotate_shift(phase, lshift, rshift, 0x1F); 823 if (shift != nullptr) { 824 return new RotateLeftNode(in(1)->in(1), shift, TypeInt::INT); 825 } 826 return nullptr; 827 } 828 if (Matcher::match_rule_supported(Op_RotateRight) && 829 lopcode == Op_URShiftI && ropcode == Op_LShiftI && in(1)->in(1) == in(2)->in(1)) { 830 Node* rshift = in(1)->in(2); 831 Node* lshift = in(2)->in(2); 832 Node* shift = rotate_shift(phase, rshift, lshift, 0x1F); 833 if (shift != nullptr) { 834 return new RotateRightNode(in(1)->in(1), shift, TypeInt::INT); 835 } 836 } 837 838 // Convert "~a | ~b" into "~(a & b)" 839 if (AddNode::is_not(phase, in(1), T_INT) && AddNode::is_not(phase, in(2), T_INT)) { 840 Node* and_a_b = new AndINode(in(1)->in(1), in(2)->in(1)); 841 Node* tn = phase->transform(and_a_b); 842 return AddNode::make_not(phase, tn, T_INT); 843 } 844 return nullptr; 845 } 846 847 //------------------------------add_ring--------------------------------------- 848 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For 849 // the logical operations the ring's ADD is really a logical OR function. 850 // This also type-checks the inputs for sanity. Guaranteed never to 851 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. 852 const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const { 853 const TypeInt *r0 = t0->is_int(); // Handy access 854 const TypeInt *r1 = t1->is_int(); 855 856 // If both args are bool, can figure out better types 857 if ( r0 == TypeInt::BOOL ) { 858 if ( r1 == TypeInt::ONE) { 859 return TypeInt::ONE; 860 } else if ( r1 == TypeInt::BOOL ) { 861 return TypeInt::BOOL; 862 } 863 } else if ( r0 == TypeInt::ONE ) { 864 if ( r1 == TypeInt::BOOL ) { 865 return TypeInt::ONE; 866 } 867 } 868 869 // If either input is all ones, the output is all ones. 870 // x | ~0 == ~0 <==> x | -1 == -1 871 if (r0 == TypeInt::MINUS_1 || r1 == TypeInt::MINUS_1) { 872 return TypeInt::MINUS_1; 873 } 874 875 // If either input is not a constant, just return all integers. 876 if( !r0->is_con() || !r1->is_con() ) 877 return TypeInt::INT; // Any integer, but still no symbols. 878 879 // Otherwise just OR them bits. 880 return TypeInt::make( r0->get_con() | r1->get_con() ); 881 } 882 883 //============================================================================= 884 //------------------------------Identity--------------------------------------- 885 Node* OrLNode::Identity(PhaseGVN* phase) { 886 // x | x => x 887 if (in(1) == in(2)) { 888 return in(1); 889 } 890 891 return AddNode::Identity(phase); 892 } 893 894 Node* OrLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 895 int lopcode = in(1)->Opcode(); 896 int ropcode = in(2)->Opcode(); 897 if (Matcher::match_rule_supported(Op_RotateLeft) && 898 lopcode == Op_LShiftL && ropcode == Op_URShiftL && in(1)->in(1) == in(2)->in(1)) { 899 Node* lshift = in(1)->in(2); 900 Node* rshift = in(2)->in(2); 901 Node* shift = rotate_shift(phase, lshift, rshift, 0x3F); 902 if (shift != nullptr) { 903 return new RotateLeftNode(in(1)->in(1), shift, TypeLong::LONG); 904 } 905 return nullptr; 906 } 907 if (Matcher::match_rule_supported(Op_RotateRight) && 908 lopcode == Op_URShiftL && ropcode == Op_LShiftL && in(1)->in(1) == in(2)->in(1)) { 909 Node* rshift = in(1)->in(2); 910 Node* lshift = in(2)->in(2); 911 Node* shift = rotate_shift(phase, rshift, lshift, 0x3F); 912 if (shift != nullptr) { 913 return new RotateRightNode(in(1)->in(1), shift, TypeLong::LONG); 914 } 915 } 916 917 // Convert "~a | ~b" into "~(a & b)" 918 if (AddNode::is_not(phase, in(1), T_LONG) && AddNode::is_not(phase, in(2), T_LONG)) { 919 Node* and_a_b = new AndLNode(in(1)->in(1), in(2)->in(1)); 920 Node* tn = phase->transform(and_a_b); 921 return AddNode::make_not(phase, tn, T_LONG); 922 } 923 924 return nullptr; 925 } 926 927 //------------------------------add_ring--------------------------------------- 928 const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const { 929 const TypeLong *r0 = t0->is_long(); // Handy access 930 const TypeLong *r1 = t1->is_long(); 931 932 // If either input is all ones, the output is all ones. 933 // x | ~0 == ~0 <==> x | -1 == -1 934 if (r0 == TypeLong::MINUS_1 || r1 == TypeLong::MINUS_1) { 935 return TypeLong::MINUS_1; 936 } 937 938 // If either input is not a constant, just return all integers. 939 if( !r0->is_con() || !r1->is_con() ) 940 return TypeLong::LONG; // Any integer, but still no symbols. 941 942 // Otherwise just OR them bits. 943 return TypeLong::make( r0->get_con() | r1->get_con() ); 944 } 945 946 //---------------------------Helper ------------------------------------------- 947 /* Decide if the given node is used only in arithmetic expressions(add or sub). 948 */ 949 static bool is_used_in_only_arithmetic(Node* n, BasicType bt) { 950 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { 951 Node* u = n->fast_out(i); 952 if (u->Opcode() != Op_Add(bt) && u->Opcode() != Op_Sub(bt)) { 953 return false; 954 } 955 } 956 return true; 957 } 958 959 //============================================================================= 960 //------------------------------Idealize--------------------------------------- 961 Node* XorINode::Ideal(PhaseGVN* phase, bool can_reshape) { 962 Node* in1 = in(1); 963 Node* in2 = in(2); 964 965 // Convert ~x into -1-x when ~x is used in an arithmetic expression 966 // or x itself is an expression. 967 if (phase->type(in2) == TypeInt::MINUS_1) { // follows LHS^(-1), i.e., ~LHS 968 if (phase->is_IterGVN()) { 969 if (is_used_in_only_arithmetic(this, T_INT) 970 // LHS is arithmetic 971 || (in1->Opcode() == Op_AddI || in1->Opcode() == Op_SubI)) { 972 return new SubINode(in2, in1); 973 } 974 } else { 975 // graph could be incomplete in GVN so we postpone to IGVN 976 phase->record_for_igvn(this); 977 } 978 } 979 980 // Propagate xor through constant cmoves. This pattern can occur after expansion of Conv2B nodes. 981 const TypeInt* in2_type = phase->type(in2)->isa_int(); 982 if (in1->Opcode() == Op_CMoveI && in2_type != nullptr && in2_type->is_con()) { 983 int in2_val = in2_type->get_con(); 984 985 // Get types of both sides of the CMove 986 const TypeInt* left = phase->type(in1->in(CMoveNode::IfFalse))->isa_int(); 987 const TypeInt* right = phase->type(in1->in(CMoveNode::IfTrue))->isa_int(); 988 989 // Ensure that both sides are int constants 990 if (left != nullptr && right != nullptr && left->is_con() && right->is_con()) { 991 Node* cond = in1->in(CMoveNode::Condition); 992 993 // Check that the comparison is a bool and that the cmp node type is correct 994 if (cond->is_Bool()) { 995 int cmp_op = cond->in(1)->Opcode(); 996 997 if (cmp_op == Op_CmpI || cmp_op == Op_CmpP) { 998 int l_val = left->get_con(); 999 int r_val = right->get_con(); 1000 1001 return new CMoveINode(cond, phase->intcon(l_val ^ in2_val), phase->intcon(r_val ^ in2_val), TypeInt::INT); 1002 } 1003 } 1004 } 1005 } 1006 1007 return AddNode::Ideal(phase, can_reshape); 1008 } 1009 1010 const Type* XorINode::Value(PhaseGVN* phase) const { 1011 Node* in1 = in(1); 1012 Node* in2 = in(2); 1013 const Type* t1 = phase->type(in1); 1014 const Type* t2 = phase->type(in2); 1015 if (t1 == Type::TOP || t2 == Type::TOP) { 1016 return Type::TOP; 1017 } 1018 // x ^ x ==> 0 1019 if (in1->eqv_uncast(in2)) { 1020 return add_id(); 1021 } 1022 // result of xor can only have bits sets where any of the 1023 // inputs have bits set. lo can always become 0. 1024 const TypeInt* t1i = t1->is_int(); 1025 const TypeInt* t2i = t2->is_int(); 1026 if ((t1i->_lo >= 0) && 1027 (t1i->_hi > 0) && 1028 (t2i->_lo >= 0) && 1029 (t2i->_hi > 0)) { 1030 // hi - set all bits below the highest bit. Using round_down to avoid overflow. 1031 const TypeInt* t1x = TypeInt::make(0, round_down_power_of_2(t1i->_hi) + (round_down_power_of_2(t1i->_hi) - 1), t1i->_widen); 1032 const TypeInt* t2x = TypeInt::make(0, round_down_power_of_2(t2i->_hi) + (round_down_power_of_2(t2i->_hi) - 1), t2i->_widen); 1033 return t1x->meet(t2x); 1034 } 1035 return AddNode::Value(phase); 1036 } 1037 1038 1039 //------------------------------add_ring--------------------------------------- 1040 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For 1041 // the logical operations the ring's ADD is really a logical OR function. 1042 // This also type-checks the inputs for sanity. Guaranteed never to 1043 // be passed a TOP or BOTTOM type, these are filtered out by pre-check. 1044 const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const { 1045 const TypeInt *r0 = t0->is_int(); // Handy access 1046 const TypeInt *r1 = t1->is_int(); 1047 1048 // Complementing a boolean? 1049 if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE 1050 || r1 == TypeInt::BOOL)) 1051 return TypeInt::BOOL; 1052 1053 if( !r0->is_con() || !r1->is_con() ) // Not constants 1054 return TypeInt::INT; // Any integer, but still no symbols. 1055 1056 // Otherwise just XOR them bits. 1057 return TypeInt::make( r0->get_con() ^ r1->get_con() ); 1058 } 1059 1060 //============================================================================= 1061 //------------------------------add_ring--------------------------------------- 1062 const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const { 1063 const TypeLong *r0 = t0->is_long(); // Handy access 1064 const TypeLong *r1 = t1->is_long(); 1065 1066 // If either input is not a constant, just return all integers. 1067 if( !r0->is_con() || !r1->is_con() ) 1068 return TypeLong::LONG; // Any integer, but still no symbols. 1069 1070 // Otherwise just OR them bits. 1071 return TypeLong::make( r0->get_con() ^ r1->get_con() ); 1072 } 1073 1074 Node* XorLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 1075 Node* in1 = in(1); 1076 Node* in2 = in(2); 1077 1078 // Convert ~x into -1-x when ~x is used in an arithmetic expression 1079 // or x itself is an arithmetic expression. 1080 if (phase->type(in2) == TypeLong::MINUS_1) { // follows LHS^(-1), i.e., ~LHS 1081 if (phase->is_IterGVN()) { 1082 if (is_used_in_only_arithmetic(this, T_LONG) 1083 // LHS is arithmetic 1084 || (in1->Opcode() == Op_AddL || in1->Opcode() == Op_SubL)) { 1085 return new SubLNode(in2, in1); 1086 } 1087 } else { 1088 // graph could be incomplete in GVN so we postpone to IGVN 1089 phase->record_for_igvn(this); 1090 } 1091 } 1092 return AddNode::Ideal(phase, can_reshape); 1093 } 1094 1095 const Type* XorLNode::Value(PhaseGVN* phase) const { 1096 Node* in1 = in(1); 1097 Node* in2 = in(2); 1098 const Type* t1 = phase->type(in1); 1099 const Type* t2 = phase->type(in2); 1100 if (t1 == Type::TOP || t2 == Type::TOP) { 1101 return Type::TOP; 1102 } 1103 // x ^ x ==> 0 1104 if (in1->eqv_uncast(in2)) { 1105 return add_id(); 1106 } 1107 // result of xor can only have bits sets where any of the 1108 // inputs have bits set. lo can always become 0. 1109 const TypeLong* t1l = t1->is_long(); 1110 const TypeLong* t2l = t2->is_long(); 1111 if ((t1l->_lo >= 0) && 1112 (t1l->_hi > 0) && 1113 (t2l->_lo >= 0) && 1114 (t2l->_hi > 0)) { 1115 // hi - set all bits below the highest bit. Using round_down to avoid overflow. 1116 const TypeLong* t1x = TypeLong::make(0, round_down_power_of_2(t1l->_hi) + (round_down_power_of_2(t1l->_hi) - 1), t1l->_widen); 1117 const TypeLong* t2x = TypeLong::make(0, round_down_power_of_2(t2l->_hi) + (round_down_power_of_2(t2l->_hi) - 1), t2l->_widen); 1118 return t1x->meet(t2x); 1119 } 1120 return AddNode::Value(phase); 1121 } 1122 1123 Node* MaxNode::build_min_max_int(Node* a, Node* b, bool is_max) { 1124 if (is_max) { 1125 return new MaxINode(a, b); 1126 } else { 1127 return new MinINode(a, b); 1128 } 1129 } 1130 1131 Node* MaxNode::build_min_max_long(PhaseGVN* phase, Node* a, Node* b, bool is_max) { 1132 if (is_max) { 1133 return new MaxLNode(phase->C, a, b); 1134 } else { 1135 return new MinLNode(phase->C, a, b); 1136 } 1137 } 1138 1139 Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) { 1140 bool is_int = gvn.type(a)->isa_int(); 1141 assert(is_int || gvn.type(a)->isa_long(), "int or long inputs"); 1142 assert(is_int == (gvn.type(b)->isa_int() != nullptr), "inconsistent inputs"); 1143 BasicType bt = is_int ? T_INT: T_LONG; 1144 Node* hook = nullptr; 1145 if (gvn.is_IterGVN()) { 1146 // Make sure a and b are not destroyed 1147 hook = new Node(2); 1148 hook->init_req(0, a); 1149 hook->init_req(1, b); 1150 } 1151 Node* res = nullptr; 1152 if (is_int && !is_unsigned) { 1153 res = gvn.transform(build_min_max_int(a, b, is_max)); 1154 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"); 1155 } else { 1156 Node* cmp = nullptr; 1157 if (is_max) { 1158 cmp = gvn.transform(CmpNode::make(a, b, bt, is_unsigned)); 1159 } else { 1160 cmp = gvn.transform(CmpNode::make(b, a, bt, is_unsigned)); 1161 } 1162 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1163 res = gvn.transform(CMoveNode::make(bol, a, b, t)); 1164 } 1165 if (hook != nullptr) { 1166 hook->destruct(&gvn); 1167 } 1168 return res; 1169 } 1170 1171 Node* MaxNode::build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn) { 1172 bool is_int = gvn.type(a)->isa_int(); 1173 assert(is_int || gvn.type(a)->isa_long(), "int or long inputs"); 1174 assert(is_int == (gvn.type(b)->isa_int() != nullptr), "inconsistent inputs"); 1175 BasicType bt = is_int ? T_INT: T_LONG; 1176 Node* zero = gvn.integercon(0, bt); 1177 Node* hook = nullptr; 1178 if (gvn.is_IterGVN()) { 1179 // Make sure a and b are not destroyed 1180 hook = new Node(2); 1181 hook->init_req(0, a); 1182 hook->init_req(1, b); 1183 } 1184 Node* cmp = nullptr; 1185 if (is_max) { 1186 cmp = gvn.transform(CmpNode::make(a, b, bt, false)); 1187 } else { 1188 cmp = gvn.transform(CmpNode::make(b, a, bt, false)); 1189 } 1190 Node* sub = gvn.transform(SubNode::make(a, b, bt)); 1191 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1192 Node* res = gvn.transform(CMoveNode::make(bol, sub, zero, t)); 1193 if (hook != nullptr) { 1194 hook->destruct(&gvn); 1195 } 1196 return res; 1197 } 1198 1199 // Check if addition of an integer with type 't' and a constant 'c' can overflow. 1200 static bool can_overflow(const TypeInt* t, jint c) { 1201 jint t_lo = t->_lo; 1202 jint t_hi = t->_hi; 1203 return ((c < 0 && (java_add(t_lo, c) > t_lo)) || 1204 (c > 0 && (java_add(t_hi, c) < t_hi))); 1205 } 1206 1207 // Let <x, x_off> = x_operands and <y, y_off> = y_operands. 1208 // If x == y and neither add(x, x_off) nor add(y, y_off) overflow, return 1209 // add(x, op(x_off, y_off)). Otherwise, return nullptr. 1210 Node* MaxNode::extract_add(PhaseGVN* phase, ConstAddOperands x_operands, ConstAddOperands y_operands) { 1211 Node* x = x_operands.first; 1212 Node* y = y_operands.first; 1213 int opcode = Opcode(); 1214 assert(opcode == Op_MaxI || opcode == Op_MinI, "Unexpected opcode"); 1215 const TypeInt* tx = phase->type(x)->isa_int(); 1216 jint x_off = x_operands.second; 1217 jint y_off = y_operands.second; 1218 if (x == y && tx != nullptr && 1219 !can_overflow(tx, x_off) && 1220 !can_overflow(tx, y_off)) { 1221 jint c = opcode == Op_MinI ? MIN2(x_off, y_off) : MAX2(x_off, y_off); 1222 return new AddINode(x, phase->intcon(c)); 1223 } 1224 return nullptr; 1225 } 1226 1227 // Try to cast n as an integer addition with a constant. Return: 1228 // <x, C>, if n == add(x, C), where 'C' is a non-TOP constant; 1229 // <nullptr, 0>, if n == add(x, C), where 'C' is a TOP constant; or 1230 // <n, 0>, otherwise. 1231 static ConstAddOperands as_add_with_constant(Node* n) { 1232 if (n->Opcode() != Op_AddI) { 1233 return ConstAddOperands(n, 0); 1234 } 1235 Node* x = n->in(1); 1236 Node* c = n->in(2); 1237 if (!c->is_Con()) { 1238 return ConstAddOperands(n, 0); 1239 } 1240 const Type* c_type = c->bottom_type(); 1241 if (c_type == Type::TOP) { 1242 return ConstAddOperands(nullptr, 0); 1243 } 1244 return ConstAddOperands(x, c_type->is_int()->get_con()); 1245 } 1246 1247 Node* MaxNode::IdealI(PhaseGVN* phase, bool can_reshape) { 1248 int opcode = Opcode(); 1249 assert(opcode == Op_MinI || opcode == Op_MaxI, "Unexpected opcode"); 1250 // Try to transform the following pattern, in any of its four possible 1251 // permutations induced by op's commutativity: 1252 // op(op(add(inner, inner_off), inner_other), add(outer, outer_off)) 1253 // into 1254 // op(add(inner, op(inner_off, outer_off)), inner_other), 1255 // where: 1256 // op is either MinI or MaxI, and 1257 // inner == outer, and 1258 // the additions cannot overflow. 1259 for (uint inner_op_index = 1; inner_op_index <= 2; inner_op_index++) { 1260 if (in(inner_op_index)->Opcode() != opcode) { 1261 continue; 1262 } 1263 Node* outer_add = in(inner_op_index == 1 ? 2 : 1); 1264 ConstAddOperands outer_add_operands = as_add_with_constant(outer_add); 1265 if (outer_add_operands.first == nullptr) { 1266 return nullptr; // outer_add has a TOP input, no need to continue. 1267 } 1268 // One operand is a MinI/MaxI and the other is an integer addition with 1269 // constant. Test the operands of the inner MinI/MaxI. 1270 for (uint inner_add_index = 1; inner_add_index <= 2; inner_add_index++) { 1271 Node* inner_op = in(inner_op_index); 1272 Node* inner_add = inner_op->in(inner_add_index); 1273 ConstAddOperands inner_add_operands = as_add_with_constant(inner_add); 1274 if (inner_add_operands.first == nullptr) { 1275 return nullptr; // inner_add has a TOP input, no need to continue. 1276 } 1277 // Try to extract the inner add. 1278 Node* add_extracted = extract_add(phase, inner_add_operands, outer_add_operands); 1279 if (add_extracted == nullptr) { 1280 continue; 1281 } 1282 Node* add_transformed = phase->transform(add_extracted); 1283 Node* inner_other = inner_op->in(inner_add_index == 1 ? 2 : 1); 1284 return build_min_max_int(add_transformed, inner_other, opcode == Op_MaxI); 1285 } 1286 } 1287 // Try to transform 1288 // op(add(x, x_off), add(y, y_off)) 1289 // into 1290 // add(x, op(x_off, y_off)), 1291 // where: 1292 // op is either MinI or MaxI, and 1293 // inner == outer, and 1294 // the additions cannot overflow. 1295 ConstAddOperands xC = as_add_with_constant(in(1)); 1296 ConstAddOperands yC = as_add_with_constant(in(2)); 1297 if (xC.first == nullptr || yC.first == nullptr) return nullptr; 1298 return extract_add(phase, xC, yC); 1299 } 1300 1301 // Ideal transformations for MaxINode 1302 Node* MaxINode::Ideal(PhaseGVN* phase, bool can_reshape) { 1303 return IdealI(phase, can_reshape); 1304 } 1305 1306 Node* MaxINode::Identity(PhaseGVN* phase) { 1307 const TypeInt* t1 = phase->type(in(1))->is_int(); 1308 const TypeInt* t2 = phase->type(in(2))->is_int(); 1309 1310 // Can we determine the maximum statically? 1311 if (t1->_lo >= t2->_hi) { 1312 return in(1); 1313 } else if (t2->_lo >= t1->_hi) { 1314 return in(2); 1315 } 1316 1317 return MaxNode::Identity(phase); 1318 } 1319 1320 //============================================================================= 1321 //------------------------------add_ring--------------------------------------- 1322 // Supplied function returns the sum of the inputs. 1323 const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const { 1324 const TypeInt *r0 = t0->is_int(); // Handy access 1325 const TypeInt *r1 = t1->is_int(); 1326 1327 // Otherwise just MAX them bits. 1328 return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) ); 1329 } 1330 1331 //============================================================================= 1332 //------------------------------Idealize--------------------------------------- 1333 // MINs show up in range-check loop limit calculations. Look for 1334 // "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)" 1335 Node* MinINode::Ideal(PhaseGVN* phase, bool can_reshape) { 1336 return IdealI(phase, can_reshape); 1337 } 1338 1339 Node* MinINode::Identity(PhaseGVN* phase) { 1340 const TypeInt* t1 = phase->type(in(1))->is_int(); 1341 const TypeInt* t2 = phase->type(in(2))->is_int(); 1342 1343 // Can we determine the minimum statically? 1344 if (t1->_lo >= t2->_hi) { 1345 return in(2); 1346 } else if (t2->_lo >= t1->_hi) { 1347 return in(1); 1348 } 1349 1350 return MaxNode::Identity(phase); 1351 } 1352 1353 //------------------------------add_ring--------------------------------------- 1354 // Supplied function returns the sum of the inputs. 1355 const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const { 1356 const TypeInt *r0 = t0->is_int(); // Handy access 1357 const TypeInt *r1 = t1->is_int(); 1358 1359 // Otherwise just MIN them bits. 1360 return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) ); 1361 } 1362 1363 // Collapse the "addition with overflow-protection" pattern, and the symmetrical 1364 // "subtraction with underflow-protection" pattern. These are created during the 1365 // unrolling, when we have to adjust the limit by subtracting the stride, but want 1366 // to protect against underflow: MaxL(SubL(limit, stride), min_jint). 1367 // If we have more than one of those in a sequence: 1368 // 1369 // x con2 1370 // | | 1371 // AddL clamp2 1372 // | | 1373 // Max/MinL con1 1374 // | | 1375 // AddL clamp1 1376 // | | 1377 // Max/MinL (n) 1378 // 1379 // We want to collapse it to: 1380 // 1381 // x con1 con2 1382 // | | | 1383 // | AddLNode (new_con) 1384 // | | 1385 // AddLNode clamp1 1386 // | | 1387 // Max/MinL (n) 1388 // 1389 // Note: we assume that SubL was already replaced by an AddL, and that the stride 1390 // has its sign flipped: SubL(limit, stride) -> AddL(limit, -stride). 1391 static Node* fold_subI_no_underflow_pattern(Node* n, PhaseGVN* phase) { 1392 assert(n->Opcode() == Op_MaxL || n->Opcode() == Op_MinL, "sanity"); 1393 // Check that the two clamps have the correct values. 1394 jlong clamp = (n->Opcode() == Op_MaxL) ? min_jint : max_jint; 1395 auto is_clamp = [&](Node* c) { 1396 const TypeLong* t = phase->type(c)->isa_long(); 1397 return t != nullptr && t->is_con() && 1398 t->get_con() == clamp; 1399 }; 1400 // Check that the constants are negative if MaxL, and positive if MinL. 1401 auto is_sub_con = [&](Node* c) { 1402 const TypeLong* t = phase->type(c)->isa_long(); 1403 return t != nullptr && t->is_con() && 1404 t->get_con() < max_jint && t->get_con() > min_jint && 1405 (t->get_con() < 0) == (n->Opcode() == Op_MaxL); 1406 }; 1407 // Verify the graph level by level: 1408 Node* add1 = n->in(1); 1409 Node* clamp1 = n->in(2); 1410 if (add1->Opcode() == Op_AddL && is_clamp(clamp1)) { 1411 Node* max2 = add1->in(1); 1412 Node* con1 = add1->in(2); 1413 if (max2->Opcode() == n->Opcode() && is_sub_con(con1)) { 1414 Node* add2 = max2->in(1); 1415 Node* clamp2 = max2->in(2); 1416 if (add2->Opcode() == Op_AddL && is_clamp(clamp2)) { 1417 Node* x = add2->in(1); 1418 Node* con2 = add2->in(2); 1419 if (is_sub_con(con2)) { 1420 Node* new_con = phase->transform(new AddLNode(con1, con2)); 1421 Node* new_sub = phase->transform(new AddLNode(x, new_con)); 1422 n->set_req_X(1, new_sub, phase); 1423 return n; 1424 } 1425 } 1426 } 1427 } 1428 return nullptr; 1429 } 1430 1431 const Type* MaxLNode::add_ring(const Type* t0, const Type* t1) const { 1432 const TypeLong* r0 = t0->is_long(); 1433 const TypeLong* r1 = t1->is_long(); 1434 1435 return TypeLong::make(MAX2(r0->_lo, r1->_lo), MAX2(r0->_hi, r1->_hi), MAX2(r0->_widen, r1->_widen)); 1436 } 1437 1438 Node* MaxLNode::Identity(PhaseGVN* phase) { 1439 const TypeLong* t1 = phase->type(in(1))->is_long(); 1440 const TypeLong* t2 = phase->type(in(2))->is_long(); 1441 1442 // Can we determine maximum statically? 1443 if (t1->_lo >= t2->_hi) { 1444 return in(1); 1445 } else if (t2->_lo >= t1->_hi) { 1446 return in(2); 1447 } 1448 1449 return MaxNode::Identity(phase); 1450 } 1451 1452 Node* MaxLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 1453 Node* n = AddNode::Ideal(phase, can_reshape); 1454 if (n != nullptr) { 1455 return n; 1456 } 1457 if (can_reshape) { 1458 return fold_subI_no_underflow_pattern(this, phase); 1459 } 1460 return nullptr; 1461 } 1462 1463 const Type* MinLNode::add_ring(const Type* t0, const Type* t1) const { 1464 const TypeLong* r0 = t0->is_long(); 1465 const TypeLong* r1 = t1->is_long(); 1466 1467 return TypeLong::make(MIN2(r0->_lo, r1->_lo), MIN2(r0->_hi, r1->_hi), MAX2(r0->_widen, r1->_widen)); 1468 } 1469 1470 Node* MinLNode::Identity(PhaseGVN* phase) { 1471 const TypeLong* t1 = phase->type(in(1))->is_long(); 1472 const TypeLong* t2 = phase->type(in(2))->is_long(); 1473 1474 // Can we determine minimum statically? 1475 if (t1->_lo >= t2->_hi) { 1476 return in(2); 1477 } else if (t2->_lo >= t1->_hi) { 1478 return in(1); 1479 } 1480 1481 return MaxNode::Identity(phase); 1482 } 1483 1484 Node* MinLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 1485 Node* n = AddNode::Ideal(phase, can_reshape); 1486 if (n != nullptr) { 1487 return n; 1488 } 1489 if (can_reshape) { 1490 return fold_subI_no_underflow_pattern(this, phase); 1491 } 1492 return nullptr; 1493 } 1494 1495 int MaxNode::opposite_opcode() const { 1496 if (Opcode() == max_opcode()) { 1497 return min_opcode(); 1498 } else { 1499 assert(Opcode() == min_opcode(), "Caller should be either %s or %s, but is %s", NodeClassNames[max_opcode()], NodeClassNames[min_opcode()], NodeClassNames[Opcode()]); 1500 return max_opcode(); 1501 } 1502 } 1503 1504 // Given a redundant structure such as Max/Min(A, Max/Min(B, C)) where A == B or A == C, return the useful part of the structure. 1505 // 'operation' is the node expected to be the inner 'Max/Min(B, C)', and 'operand' is the node expected to be the 'A' operand of the outer node. 1506 Node* MaxNode::find_identity_operation(Node* operation, Node* operand) { 1507 if (operation->Opcode() == Opcode() || operation->Opcode() == opposite_opcode()) { 1508 Node* n1 = operation->in(1); 1509 Node* n2 = operation->in(2); 1510 1511 // Given Op(A, Op(B, C)), see if either A == B or A == C is true. 1512 if (n1 == operand || n2 == operand) { 1513 // If the operations are the same return the inner operation, as Max(A, Max(A, B)) == Max(A, B). 1514 if (operation->Opcode() == Opcode()) { 1515 return operation; 1516 } 1517 1518 // If the operations are different return the operand 'A', as Max(A, Min(A, B)) == A if the value isn't floating point. 1519 // With floating point values, the identity doesn't hold if B == NaN. 1520 const Type* type = bottom_type(); 1521 if (type->isa_int() || type->isa_long()) { 1522 return operand; 1523 } 1524 } 1525 } 1526 1527 return nullptr; 1528 } 1529 1530 Node* MaxNode::Identity(PhaseGVN* phase) { 1531 if (in(1) == in(2)) { 1532 return in(1); 1533 } 1534 1535 Node* identity_1 = MaxNode::find_identity_operation(in(2), in(1)); 1536 if (identity_1 != nullptr) { 1537 return identity_1; 1538 } 1539 1540 Node* identity_2 = MaxNode::find_identity_operation(in(1), in(2)); 1541 if (identity_2 != nullptr) { 1542 return identity_2; 1543 } 1544 1545 return AddNode::Identity(phase); 1546 } 1547 1548 //------------------------------add_ring--------------------------------------- 1549 const Type* MinHFNode::add_ring(const Type* t0, const Type* t1) const { 1550 const TypeH* r0 = t0->isa_half_float_constant(); 1551 const TypeH* r1 = t1->isa_half_float_constant(); 1552 if (r0 == nullptr || r1 == nullptr) { 1553 return bottom_type(); 1554 } 1555 1556 if (r0->is_nan()) { 1557 return r0; 1558 } 1559 if (r1->is_nan()) { 1560 return r1; 1561 } 1562 1563 float f0 = r0->getf(); 1564 float f1 = r1->getf(); 1565 if (f0 != 0.0f || f1 != 0.0f) { 1566 return f0 < f1 ? r0 : r1; 1567 } 1568 1569 // As per IEEE 754 specification, floating point comparison consider +ve and -ve 1570 // zeros as equals. Thus, performing signed integral comparison for min value 1571 // detection. 1572 return (jint_cast(f0) < jint_cast(f1)) ? r0 : r1; 1573 } 1574 1575 //------------------------------add_ring--------------------------------------- 1576 const Type* MinFNode::add_ring(const Type* t0, const Type* t1 ) const { 1577 const TypeF* r0 = t0->isa_float_constant(); 1578 const TypeF* r1 = t1->isa_float_constant(); 1579 if (r0 == nullptr || r1 == nullptr) { 1580 return bottom_type(); 1581 } 1582 1583 if (r0->is_nan()) { 1584 return r0; 1585 } 1586 if (r1->is_nan()) { 1587 return r1; 1588 } 1589 1590 float f0 = r0->getf(); 1591 float f1 = r1->getf(); 1592 if (f0 != 0.0f || f1 != 0.0f) { 1593 return f0 < f1 ? r0 : r1; 1594 } 1595 1596 // handle min of 0.0, -0.0 case. 1597 return (jint_cast(f0) < jint_cast(f1)) ? r0 : r1; 1598 } 1599 1600 //------------------------------add_ring--------------------------------------- 1601 const Type* MinDNode::add_ring(const Type* t0, const Type* t1) const { 1602 const TypeD* r0 = t0->isa_double_constant(); 1603 const TypeD* r1 = t1->isa_double_constant(); 1604 if (r0 == nullptr || r1 == nullptr) { 1605 return bottom_type(); 1606 } 1607 1608 if (r0->is_nan()) { 1609 return r0; 1610 } 1611 if (r1->is_nan()) { 1612 return r1; 1613 } 1614 1615 double d0 = r0->getd(); 1616 double d1 = r1->getd(); 1617 if (d0 != 0.0 || d1 != 0.0) { 1618 return d0 < d1 ? r0 : r1; 1619 } 1620 1621 // handle min of 0.0, -0.0 case. 1622 return (jlong_cast(d0) < jlong_cast(d1)) ? r0 : r1; 1623 } 1624 1625 //------------------------------add_ring--------------------------------------- 1626 const Type* MaxHFNode::add_ring(const Type* t0, const Type* t1) const { 1627 const TypeH* r0 = t0->isa_half_float_constant(); 1628 const TypeH* r1 = t1->isa_half_float_constant(); 1629 if (r0 == nullptr || r1 == nullptr) { 1630 return bottom_type(); 1631 } 1632 1633 if (r0->is_nan()) { 1634 return r0; 1635 } 1636 if (r1->is_nan()) { 1637 return r1; 1638 } 1639 1640 float f0 = r0->getf(); 1641 float f1 = r1->getf(); 1642 if (f0 != 0.0f || f1 != 0.0f) { 1643 return f0 > f1 ? r0 : r1; 1644 } 1645 1646 // As per IEEE 754 specification, floating point comparison consider +ve and -ve 1647 // zeros as equals. Thus, performing signed integral comparison for max value 1648 // detection. 1649 return (jint_cast(f0) > jint_cast(f1)) ? r0 : r1; 1650 } 1651 1652 1653 //------------------------------add_ring--------------------------------------- 1654 const Type* MaxFNode::add_ring(const Type* t0, const Type* t1) const { 1655 const TypeF* r0 = t0->isa_float_constant(); 1656 const TypeF* r1 = t1->isa_float_constant(); 1657 if (r0 == nullptr || r1 == nullptr) { 1658 return bottom_type(); 1659 } 1660 1661 if (r0->is_nan()) { 1662 return r0; 1663 } 1664 if (r1->is_nan()) { 1665 return r1; 1666 } 1667 1668 float f0 = r0->getf(); 1669 float f1 = r1->getf(); 1670 if (f0 != 0.0f || f1 != 0.0f) { 1671 return f0 > f1 ? r0 : r1; 1672 } 1673 1674 // handle max of 0.0,-0.0 case. 1675 return (jint_cast(f0) > jint_cast(f1)) ? r0 : r1; 1676 } 1677 1678 //------------------------------add_ring--------------------------------------- 1679 const Type* MaxDNode::add_ring(const Type* t0, const Type* t1) const { 1680 const TypeD* r0 = t0->isa_double_constant(); 1681 const TypeD* r1 = t1->isa_double_constant(); 1682 if (r0 == nullptr || r1 == nullptr) { 1683 return bottom_type(); 1684 } 1685 1686 if (r0->is_nan()) { 1687 return r0; 1688 } 1689 if (r1->is_nan()) { 1690 return r1; 1691 } 1692 1693 double d0 = r0->getd(); 1694 double d1 = r1->getd(); 1695 if (d0 != 0.0 || d1 != 0.0) { 1696 return d0 > d1 ? r0 : r1; 1697 } 1698 1699 // handle max of 0.0, -0.0 case. 1700 return (jlong_cast(d0) > jlong_cast(d1)) ? r0 : r1; 1701 }