1 /* 2 * Copyright (c) 1997, 2024, 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 "compiler/compileLog.hpp" 27 #include "gc/shared/barrierSet.hpp" 28 #include "gc/shared/c2/barrierSetC2.hpp" 29 #include "memory/allocation.inline.hpp" 30 #include "opto/addnode.hpp" 31 #include "opto/callnode.hpp" 32 #include "opto/cfgnode.hpp" 33 #include "opto/inlinetypenode.hpp" 34 #include "opto/loopnode.hpp" 35 #include "opto/matcher.hpp" 36 #include "opto/movenode.hpp" 37 #include "opto/mulnode.hpp" 38 #include "opto/opaquenode.hpp" 39 #include "opto/opcodes.hpp" 40 #include "opto/phaseX.hpp" 41 #include "opto/subnode.hpp" 42 #include "runtime/sharedRuntime.hpp" 43 #include "utilities/reverse_bits.hpp" 44 45 // Portions of code courtesy of Clifford Click 46 47 // Optimization - Graph Style 48 49 #include "math.h" 50 51 //============================================================================= 52 //------------------------------Identity--------------------------------------- 53 // If right input is a constant 0, return the left input. 54 Node* SubNode::Identity(PhaseGVN* phase) { 55 assert(in(1) != this, "Must already have called Value"); 56 assert(in(2) != this, "Must already have called Value"); 57 58 // Remove double negation 59 const Type *zero = add_id(); 60 if( phase->type( in(1) )->higher_equal( zero ) && 61 in(2)->Opcode() == Opcode() && 62 phase->type( in(2)->in(1) )->higher_equal( zero ) ) { 63 return in(2)->in(2); 64 } 65 66 // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y 67 if (in(1)->Opcode() == Op_AddI || in(1)->Opcode() == Op_AddL) { 68 if (in(1)->in(2) == in(2)) { 69 return in(1)->in(1); 70 } 71 if (in(1)->in(1) == in(2)) { 72 return in(1)->in(2); 73 } 74 } 75 76 return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this; 77 } 78 79 //------------------------------Value------------------------------------------ 80 // A subtract node differences it's two inputs. 81 const Type* SubNode::Value_common(PhaseValues* phase) const { 82 const Node* in1 = in(1); 83 const Node* in2 = in(2); 84 // Either input is TOP ==> the result is TOP 85 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 86 if( t1 == Type::TOP ) return Type::TOP; 87 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 88 if( t2 == Type::TOP ) return Type::TOP; 89 90 // Not correct for SubFnode and AddFNode (must check for infinity) 91 // Equal? Subtract is zero 92 if (in1->eqv_uncast(in2)) return add_id(); 93 94 // Either input is BOTTOM ==> the result is the local BOTTOM 95 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM ) 96 return bottom_type(); 97 98 return nullptr; 99 } 100 101 const Type* SubNode::Value(PhaseGVN* phase) const { 102 const Type* t = Value_common(phase); 103 if (t != nullptr) { 104 return t; 105 } 106 const Type* t1 = phase->type(in(1)); 107 const Type* t2 = phase->type(in(2)); 108 return sub(t1,t2); // Local flavor of type subtraction 109 110 } 111 112 SubNode* SubNode::make(Node* in1, Node* in2, BasicType bt) { 113 switch (bt) { 114 case T_INT: 115 return new SubINode(in1, in2); 116 case T_LONG: 117 return new SubLNode(in1, in2); 118 default: 119 fatal("Not implemented for %s", type2name(bt)); 120 } 121 return nullptr; 122 } 123 124 //============================================================================= 125 //------------------------------Helper function-------------------------------- 126 127 static bool is_cloop_increment(Node* inc) { 128 precond(inc->Opcode() == Op_AddI || inc->Opcode() == Op_AddL); 129 130 if (!inc->in(1)->is_Phi()) { 131 return false; 132 } 133 const PhiNode* phi = inc->in(1)->as_Phi(); 134 135 if (!phi->region()->is_CountedLoop()) { 136 return false; 137 } 138 139 return inc == phi->region()->as_CountedLoop()->incr(); 140 } 141 142 // Given the expression '(x + C) - v', or 143 // 'v - (x + C)', we examine nodes '+' and 'v': 144 // 145 // 1. Do not convert if '+' is a counted-loop increment, because the '-' is 146 // loop invariant and converting extends the live-range of 'x' to overlap 147 // with the '+', forcing another register to be used in the loop. 148 // 149 // 2. Do not convert if 'v' is a counted-loop induction variable, because 150 // 'x' might be invariant. 151 // 152 static bool ok_to_convert(Node* inc, Node* var) { 153 return !(is_cloop_increment(inc) || var->is_cloop_ind_var()); 154 } 155 156 static bool is_cloop_condition(BoolNode* bol) { 157 for (DUIterator_Fast imax, i = bol->fast_outs(imax); i < imax; i++) { 158 Node* out = bol->fast_out(i); 159 if (out->is_BaseCountedLoopEnd()) { 160 return true; 161 } 162 } 163 return false; 164 } 165 166 //------------------------------Ideal------------------------------------------ 167 Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){ 168 Node *in1 = in(1); 169 Node *in2 = in(2); 170 uint op1 = in1->Opcode(); 171 uint op2 = in2->Opcode(); 172 173 #ifdef ASSERT 174 // Check for dead loop 175 if ((in1 == this) || (in2 == this) || 176 ((op1 == Op_AddI || op1 == Op_SubI) && 177 ((in1->in(1) == this) || (in1->in(2) == this) || 178 (in1->in(1) == in1) || (in1->in(2) == in1)))) { 179 assert(false, "dead loop in SubINode::Ideal"); 180 } 181 #endif 182 183 const Type *t2 = phase->type( in2 ); 184 if( t2 == Type::TOP ) return nullptr; 185 // Convert "x-c0" into "x+ -c0". 186 if( t2->base() == Type::Int ){ // Might be bottom or top... 187 const TypeInt *i = t2->is_int(); 188 if( i->is_con() ) 189 return new AddINode(in1, phase->intcon(java_negate(i->get_con()))); 190 } 191 192 // Convert "(x+c0) - y" into (x-y) + c0" 193 // Do not collapse (x+c0)-y if "+" is a loop increment or 194 // if "y" is a loop induction variable. 195 if( op1 == Op_AddI && ok_to_convert(in1, in2) ) { 196 const Type *tadd = phase->type( in1->in(2) ); 197 if( tadd->singleton() && tadd != Type::TOP ) { 198 Node *sub2 = phase->transform( new SubINode( in1->in(1), in2 )); 199 return new AddINode( sub2, in1->in(2) ); 200 } 201 } 202 203 // Convert "x - (y+c0)" into "(x-y) - c0" AND 204 // Convert "c1 - (y+c0)" into "(c1-c0) - y" 205 // Need the same check as in above optimization but reversed. 206 if (op2 == Op_AddI 207 && ok_to_convert(in2, in1) 208 && in2->in(2)->Opcode() == Op_ConI) { 209 jint c0 = phase->type(in2->in(2))->isa_int()->get_con(); 210 Node* in21 = in2->in(1); 211 if (in1->Opcode() == Op_ConI) { 212 // Match c1 213 jint c1 = phase->type(in1)->isa_int()->get_con(); 214 Node* sub2 = phase->intcon(java_subtract(c1, c0)); 215 return new SubINode(sub2, in21); 216 } else { 217 // Match x 218 Node* sub2 = phase->transform(new SubINode(in1, in21)); 219 Node* neg_c0 = phase->intcon(java_negate(c0)); 220 return new AddINode(sub2, neg_c0); 221 } 222 } 223 224 const Type *t1 = phase->type( in1 ); 225 if( t1 == Type::TOP ) return nullptr; 226 227 #ifdef ASSERT 228 // Check for dead loop 229 if ((op2 == Op_AddI || op2 == Op_SubI) && 230 ((in2->in(1) == this) || (in2->in(2) == this) || 231 (in2->in(1) == in2) || (in2->in(2) == in2))) { 232 assert(false, "dead loop in SubINode::Ideal"); 233 } 234 #endif 235 236 // Convert "x - (x+y)" into "-y" 237 if (op2 == Op_AddI && in1 == in2->in(1)) { 238 return new SubINode(phase->intcon(0), in2->in(2)); 239 } 240 // Convert "(x-y) - x" into "-y" 241 if (op1 == Op_SubI && in1->in(1) == in2) { 242 return new SubINode(phase->intcon(0), in1->in(2)); 243 } 244 // Convert "x - (y+x)" into "-y" 245 if (op2 == Op_AddI && in1 == in2->in(2)) { 246 return new SubINode(phase->intcon(0), in2->in(1)); 247 } 248 249 // Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity(). 250 if (t1 == TypeInt::ZERO && op2 == Op_SubI && phase->type(in2->in(1)) != TypeInt::ZERO) { 251 return new SubINode(in2->in(2), in2->in(1)); 252 } 253 254 // Convert "0 - (x+con)" into "-con-x" 255 jint con; 256 if( t1 == TypeInt::ZERO && op2 == Op_AddI && 257 (con = in2->in(2)->find_int_con(0)) != 0 ) 258 return new SubINode( phase->intcon(-con), in2->in(1) ); 259 260 // Convert "(X+A) - (X+B)" into "A - B" 261 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) ) 262 return new SubINode( in1->in(2), in2->in(2) ); 263 264 // Convert "(A+X) - (B+X)" into "A - B" 265 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) ) 266 return new SubINode( in1->in(1), in2->in(1) ); 267 268 // Convert "(A+X) - (X+B)" into "A - B" 269 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) ) 270 return new SubINode( in1->in(1), in2->in(2) ); 271 272 // Convert "(X+A) - (B+X)" into "A - B" 273 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) 274 return new SubINode( in1->in(2), in2->in(1) ); 275 276 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally 277 // nicer to optimize than subtract. 278 if( op2 == Op_SubI && in2->outcnt() == 1) { 279 Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) ); 280 return new SubINode( add1, in2->in(1) ); 281 } 282 283 // Associative 284 if (op1 == Op_MulI && op2 == Op_MulI) { 285 Node* sub_in1 = nullptr; 286 Node* sub_in2 = nullptr; 287 Node* mul_in = nullptr; 288 289 if (in1->in(1) == in2->in(1)) { 290 // Convert "a*b-a*c into a*(b-c) 291 sub_in1 = in1->in(2); 292 sub_in2 = in2->in(2); 293 mul_in = in1->in(1); 294 } else if (in1->in(2) == in2->in(1)) { 295 // Convert a*b-b*c into b*(a-c) 296 sub_in1 = in1->in(1); 297 sub_in2 = in2->in(2); 298 mul_in = in1->in(2); 299 } else if (in1->in(2) == in2->in(2)) { 300 // Convert a*c-b*c into (a-b)*c 301 sub_in1 = in1->in(1); 302 sub_in2 = in2->in(1); 303 mul_in = in1->in(2); 304 } else if (in1->in(1) == in2->in(2)) { 305 // Convert a*b-c*a into a*(b-c) 306 sub_in1 = in1->in(2); 307 sub_in2 = in2->in(1); 308 mul_in = in1->in(1); 309 } 310 311 if (mul_in != nullptr) { 312 Node* sub = phase->transform(new SubINode(sub_in1, sub_in2)); 313 return new MulINode(mul_in, sub); 314 } 315 } 316 317 // Convert "0-(A>>31)" into "(A>>>31)" 318 if ( op2 == Op_RShiftI ) { 319 Node *in21 = in2->in(1); 320 Node *in22 = in2->in(2); 321 const TypeInt *zero = phase->type(in1)->isa_int(); 322 const TypeInt *t21 = phase->type(in21)->isa_int(); 323 const TypeInt *t22 = phase->type(in22)->isa_int(); 324 if ( t21 && t22 && zero == TypeInt::ZERO && t22->is_con(31) ) { 325 return new URShiftINode(in21, in22); 326 } 327 } 328 329 return nullptr; 330 } 331 332 //------------------------------sub-------------------------------------------- 333 // A subtract node differences it's two inputs. 334 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { 335 const TypeInt *r0 = t1->is_int(); // Handy access 336 const TypeInt *r1 = t2->is_int(); 337 int32_t lo = java_subtract(r0->_lo, r1->_hi); 338 int32_t hi = java_subtract(r0->_hi, r1->_lo); 339 340 // We next check for 32-bit overflow. 341 // If that happens, we just assume all integers are possible. 342 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 343 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 344 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 345 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 346 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 347 else // Overflow; assume all integers 348 return TypeInt::INT; 349 } 350 351 //============================================================================= 352 //------------------------------Ideal------------------------------------------ 353 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 354 Node *in1 = in(1); 355 Node *in2 = in(2); 356 uint op1 = in1->Opcode(); 357 uint op2 = in2->Opcode(); 358 359 #ifdef ASSERT 360 // Check for dead loop 361 if ((in1 == this) || (in2 == this) || 362 ((op1 == Op_AddL || op1 == Op_SubL) && 363 ((in1->in(1) == this) || (in1->in(2) == this) || 364 (in1->in(1) == in1) || (in1->in(2) == in1)))) { 365 assert(false, "dead loop in SubLNode::Ideal"); 366 } 367 #endif 368 369 if( phase->type( in2 ) == Type::TOP ) return nullptr; 370 const TypeLong *i = phase->type( in2 )->isa_long(); 371 // Convert "x-c0" into "x+ -c0". 372 if( i && // Might be bottom or top... 373 i->is_con() ) 374 return new AddLNode(in1, phase->longcon(java_negate(i->get_con()))); 375 376 // Convert "(x+c0) - y" into (x-y) + c0" 377 // Do not collapse (x+c0)-y if "+" is a loop increment or 378 // if "y" is a loop induction variable. 379 if( op1 == Op_AddL && ok_to_convert(in1, in2) ) { 380 Node *in11 = in1->in(1); 381 const Type *tadd = phase->type( in1->in(2) ); 382 if( tadd->singleton() && tadd != Type::TOP ) { 383 Node *sub2 = phase->transform( new SubLNode( in11, in2 )); 384 return new AddLNode( sub2, in1->in(2) ); 385 } 386 } 387 388 // Convert "x - (y+c0)" into "(x-y) - c0" AND 389 // Convert "c1 - (y+c0)" into "(c1-c0) - y" 390 // Need the same check as in above optimization but reversed. 391 if (op2 == Op_AddL 392 && ok_to_convert(in2, in1) 393 && in2->in(2)->Opcode() == Op_ConL) { 394 jlong c0 = phase->type(in2->in(2))->isa_long()->get_con(); 395 Node* in21 = in2->in(1); 396 if (in1->Opcode() == Op_ConL) { 397 // Match c1 398 jlong c1 = phase->type(in1)->isa_long()->get_con(); 399 Node* sub2 = phase->longcon(java_subtract(c1, c0)); 400 return new SubLNode(sub2, in21); 401 } else { 402 Node* sub2 = phase->transform(new SubLNode(in1, in21)); 403 Node* neg_c0 = phase->longcon(-c0); 404 return new AddLNode(sub2, neg_c0); 405 } 406 } 407 408 const Type *t1 = phase->type( in1 ); 409 if( t1 == Type::TOP ) return nullptr; 410 411 #ifdef ASSERT 412 // Check for dead loop 413 if ((op2 == Op_AddL || op2 == Op_SubL) && 414 ((in2->in(1) == this) || (in2->in(2) == this) || 415 (in2->in(1) == in2) || (in2->in(2) == in2))) { 416 assert(false, "dead loop in SubLNode::Ideal"); 417 } 418 #endif 419 420 // Convert "x - (x+y)" into "-y" 421 if (op2 == Op_AddL && in1 == in2->in(1)) { 422 return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(2)); 423 } 424 // Convert "(x-y) - x" into "-y" 425 if (op1 == Op_SubL && in1->in(1) == in2) { 426 return new SubLNode(phase->makecon(TypeLong::ZERO), in1->in(2)); 427 } 428 // Convert "x - (y+x)" into "-y" 429 if (op2 == Op_AddL && in1 == in2->in(2)) { 430 return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(1)); 431 } 432 433 // Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity. 434 if (t1 == TypeLong::ZERO && op2 == Op_SubL && phase->type(in2->in(1)) != TypeLong::ZERO) { 435 return new SubLNode(in2->in(2), in2->in(1)); 436 } 437 438 // Convert "(X+A) - (X+B)" into "A - B" 439 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) ) 440 return new SubLNode( in1->in(2), in2->in(2) ); 441 442 // Convert "(A+X) - (B+X)" into "A - B" 443 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) ) 444 return new SubLNode( in1->in(1), in2->in(1) ); 445 446 // Convert "(A+X) - (X+B)" into "A - B" 447 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(1) ) 448 return new SubLNode( in1->in(1), in2->in(2) ); 449 450 // Convert "(X+A) - (B+X)" into "A - B" 451 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(2) ) 452 return new SubLNode( in1->in(2), in2->in(1) ); 453 454 // Convert "A-(B-C)" into (A+C)-B" 455 if( op2 == Op_SubL && in2->outcnt() == 1) { 456 Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) ); 457 return new SubLNode( add1, in2->in(1) ); 458 } 459 460 // Associative 461 if (op1 == Op_MulL && op2 == Op_MulL) { 462 Node* sub_in1 = nullptr; 463 Node* sub_in2 = nullptr; 464 Node* mul_in = nullptr; 465 466 if (in1->in(1) == in2->in(1)) { 467 // Convert "a*b-a*c into a*(b+c) 468 sub_in1 = in1->in(2); 469 sub_in2 = in2->in(2); 470 mul_in = in1->in(1); 471 } else if (in1->in(2) == in2->in(1)) { 472 // Convert a*b-b*c into b*(a-c) 473 sub_in1 = in1->in(1); 474 sub_in2 = in2->in(2); 475 mul_in = in1->in(2); 476 } else if (in1->in(2) == in2->in(2)) { 477 // Convert a*c-b*c into (a-b)*c 478 sub_in1 = in1->in(1); 479 sub_in2 = in2->in(1); 480 mul_in = in1->in(2); 481 } else if (in1->in(1) == in2->in(2)) { 482 // Convert a*b-c*a into a*(b-c) 483 sub_in1 = in1->in(2); 484 sub_in2 = in2->in(1); 485 mul_in = in1->in(1); 486 } 487 488 if (mul_in != nullptr) { 489 Node* sub = phase->transform(new SubLNode(sub_in1, sub_in2)); 490 return new MulLNode(mul_in, sub); 491 } 492 } 493 494 // Convert "0L-(A>>63)" into "(A>>>63)" 495 if ( op2 == Op_RShiftL ) { 496 Node *in21 = in2->in(1); 497 Node *in22 = in2->in(2); 498 const TypeLong *zero = phase->type(in1)->isa_long(); 499 const TypeLong *t21 = phase->type(in21)->isa_long(); 500 const TypeInt *t22 = phase->type(in22)->isa_int(); 501 if ( t21 && t22 && zero == TypeLong::ZERO && t22->is_con(63) ) { 502 return new URShiftLNode(in21, in22); 503 } 504 } 505 506 return nullptr; 507 } 508 509 //------------------------------sub-------------------------------------------- 510 // A subtract node differences it's two inputs. 511 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const { 512 const TypeLong *r0 = t1->is_long(); // Handy access 513 const TypeLong *r1 = t2->is_long(); 514 jlong lo = java_subtract(r0->_lo, r1->_hi); 515 jlong hi = java_subtract(r0->_hi, r1->_lo); 516 517 // We next check for 32-bit overflow. 518 // If that happens, we just assume all integers are possible. 519 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 520 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 521 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 522 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 523 return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 524 else // Overflow; assume all integers 525 return TypeLong::LONG; 526 } 527 528 //============================================================================= 529 //------------------------------Value------------------------------------------ 530 // A subtract node differences its two inputs. 531 const Type* SubFPNode::Value(PhaseGVN* phase) const { 532 const Node* in1 = in(1); 533 const Node* in2 = in(2); 534 // Either input is TOP ==> the result is TOP 535 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 536 if( t1 == Type::TOP ) return Type::TOP; 537 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 538 if( t2 == Type::TOP ) return Type::TOP; 539 540 // if both operands are infinity of same sign, the result is NaN; do 541 // not replace with zero 542 if (t1->is_finite() && t2->is_finite() && in1 == in2) { 543 return add_id(); 544 } 545 546 // Either input is BOTTOM ==> the result is the local BOTTOM 547 const Type *bot = bottom_type(); 548 if( (t1 == bot) || (t2 == bot) || 549 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) 550 return bot; 551 552 return sub(t1,t2); // Local flavor of type subtraction 553 } 554 555 556 //============================================================================= 557 //------------------------------Ideal------------------------------------------ 558 Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) { 559 const Type *t2 = phase->type( in(2) ); 560 // Convert "x-c0" into "x+ -c0". 561 if( t2->base() == Type::FloatCon ) { // Might be bottom or top... 562 // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) ); 563 } 564 565 // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes 566 // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0. 567 //if( phase->type(in(1)) == TypeF::ZERO ) 568 //return new (phase->C, 2) NegFNode(in(2)); 569 570 return nullptr; 571 } 572 573 //------------------------------sub-------------------------------------------- 574 // A subtract node differences its two inputs. 575 const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const { 576 // no folding if one of operands is infinity or NaN, do not do constant folding 577 if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) { 578 return TypeF::make( t1->getf() - t2->getf() ); 579 } 580 else if( g_isnan(t1->getf()) ) { 581 return t1; 582 } 583 else if( g_isnan(t2->getf()) ) { 584 return t2; 585 } 586 else { 587 return Type::FLOAT; 588 } 589 } 590 591 //============================================================================= 592 //------------------------------Ideal------------------------------------------ 593 Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){ 594 const Type *t2 = phase->type( in(2) ); 595 // Convert "x-c0" into "x+ -c0". 596 if( t2->base() == Type::DoubleCon ) { // Might be bottom or top... 597 // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) ); 598 } 599 600 // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes 601 // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0. 602 //if( phase->type(in(1)) == TypeD::ZERO ) 603 //return new (phase->C, 2) NegDNode(in(2)); 604 605 return nullptr; 606 } 607 608 //------------------------------sub-------------------------------------------- 609 // A subtract node differences its two inputs. 610 const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const { 611 // no folding if one of operands is infinity or NaN, do not do constant folding 612 if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) { 613 return TypeD::make( t1->getd() - t2->getd() ); 614 } 615 else if( g_isnan(t1->getd()) ) { 616 return t1; 617 } 618 else if( g_isnan(t2->getd()) ) { 619 return t2; 620 } 621 else { 622 return Type::DOUBLE; 623 } 624 } 625 626 //============================================================================= 627 //------------------------------Idealize--------------------------------------- 628 // Unlike SubNodes, compare must still flatten return value to the 629 // range -1, 0, 1. 630 // And optimizations like those for (X + Y) - X fail if overflow happens. 631 Node* CmpNode::Identity(PhaseGVN* phase) { 632 return this; 633 } 634 635 CmpNode *CmpNode::make(Node *in1, Node *in2, BasicType bt, bool unsigned_comp) { 636 switch (bt) { 637 case T_INT: 638 if (unsigned_comp) { 639 return new CmpUNode(in1, in2); 640 } 641 return new CmpINode(in1, in2); 642 case T_LONG: 643 if (unsigned_comp) { 644 return new CmpULNode(in1, in2); 645 } 646 return new CmpLNode(in1, in2); 647 case T_OBJECT: 648 case T_ARRAY: 649 case T_ADDRESS: 650 case T_METADATA: 651 return new CmpPNode(in1, in2); 652 case T_NARROWOOP: 653 case T_NARROWKLASS: 654 return new CmpNNode(in1, in2); 655 default: 656 fatal("Not implemented for %s", type2name(bt)); 657 } 658 return nullptr; 659 } 660 661 //============================================================================= 662 //------------------------------cmp-------------------------------------------- 663 // Simplify a CmpI (compare 2 integers) node, based on local information. 664 // If both inputs are constants, compare them. 665 const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const { 666 const TypeInt *r0 = t1->is_int(); // Handy access 667 const TypeInt *r1 = t2->is_int(); 668 669 if( r0->_hi < r1->_lo ) // Range is always low? 670 return TypeInt::CC_LT; 671 else if( r0->_lo > r1->_hi ) // Range is always high? 672 return TypeInt::CC_GT; 673 674 else if( r0->is_con() && r1->is_con() ) { // comparing constants? 675 assert(r0->get_con() == r1->get_con(), "must be equal"); 676 return TypeInt::CC_EQ; // Equal results. 677 } else if( r0->_hi == r1->_lo ) // Range is never high? 678 return TypeInt::CC_LE; 679 else if( r0->_lo == r1->_hi ) // Range is never low? 680 return TypeInt::CC_GE; 681 return TypeInt::CC; // else use worst case results 682 } 683 684 const Type* CmpINode::Value(PhaseGVN* phase) const { 685 Node* in1 = in(1); 686 Node* in2 = in(2); 687 // If this test is the zero trip guard for a main or post loop, check whether, with the opaque node removed, the test 688 // would constant fold so the loop is never entered. If so return the type of the test without the opaque node removed: 689 // make the loop unreachable. 690 // The reason for this is that the iv phi captures the bounds of the loop and if the loop becomes unreachable, it can 691 // become top. In that case, the loop must be removed. 692 // This is safe because: 693 // - as optimizations proceed, the range of iterations executed by the main loop narrows. If no iterations remain, then 694 // we're done with optimizations for that loop. 695 // - the post loop is initially not reachable but as long as there's a main loop, the zero trip guard for the post 696 // loop takes a phi that merges the pre and main loop's iv and can't constant fold the zero trip guard. Once, the main 697 // loop is removed, there's no need to preserve the zero trip guard for the post loop anymore. 698 if (in1 != nullptr && in2 != nullptr) { 699 uint input = 0; 700 Node* cmp = nullptr; 701 BoolTest::mask test; 702 if (in1->Opcode() == Op_OpaqueZeroTripGuard && phase->type(in1) != Type::TOP) { 703 cmp = new CmpINode(in1->in(1), in2); 704 test = ((OpaqueZeroTripGuardNode*)in1)->_loop_entered_mask; 705 } 706 if (in2->Opcode() == Op_OpaqueZeroTripGuard && phase->type(in2) != Type::TOP) { 707 assert(cmp == nullptr, "A cmp with 2 OpaqueZeroTripGuard inputs"); 708 cmp = new CmpINode(in1, in2->in(1)); 709 test = ((OpaqueZeroTripGuardNode*)in2)->_loop_entered_mask; 710 } 711 if (cmp != nullptr) { 712 const Type* cmp_t = cmp->Value(phase); 713 const Type* t = BoolTest(test).cc2logical(cmp_t); 714 cmp->destruct(phase); 715 if (t == TypeInt::ZERO) { 716 return cmp_t; 717 } 718 } 719 } 720 721 return SubNode::Value(phase); 722 } 723 724 725 // Simplify a CmpU (compare 2 integers) node, based on local information. 726 // If both inputs are constants, compare them. 727 const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { 728 assert(!t1->isa_ptr(), "obsolete usage of CmpU"); 729 730 // comparing two unsigned ints 731 const TypeInt *r0 = t1->is_int(); // Handy access 732 const TypeInt *r1 = t2->is_int(); 733 734 // Current installed version 735 // Compare ranges for non-overlap 736 juint lo0 = r0->_lo; 737 juint hi0 = r0->_hi; 738 juint lo1 = r1->_lo; 739 juint hi1 = r1->_hi; 740 741 // If either one has both negative and positive values, 742 // it therefore contains both 0 and -1, and since [0..-1] is the 743 // full unsigned range, the type must act as an unsigned bottom. 744 bool bot0 = ((jint)(lo0 ^ hi0) < 0); 745 bool bot1 = ((jint)(lo1 ^ hi1) < 0); 746 747 if (bot0 || bot1) { 748 // All unsigned values are LE -1 and GE 0. 749 if (lo0 == 0 && hi0 == 0) { 750 return TypeInt::CC_LE; // 0 <= bot 751 } else if ((jint)lo0 == -1 && (jint)hi0 == -1) { 752 return TypeInt::CC_GE; // -1 >= bot 753 } else if (lo1 == 0 && hi1 == 0) { 754 return TypeInt::CC_GE; // bot >= 0 755 } else if ((jint)lo1 == -1 && (jint)hi1 == -1) { 756 return TypeInt::CC_LE; // bot <= -1 757 } 758 } else { 759 // We can use ranges of the form [lo..hi] if signs are the same. 760 assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); 761 // results are reversed, '-' > '+' for unsigned compare 762 if (hi0 < lo1) { 763 return TypeInt::CC_LT; // smaller 764 } else if (lo0 > hi1) { 765 return TypeInt::CC_GT; // greater 766 } else if (hi0 == lo1 && lo0 == hi1) { 767 return TypeInt::CC_EQ; // Equal results 768 } else if (lo0 >= hi1) { 769 return TypeInt::CC_GE; 770 } else if (hi0 <= lo1) { 771 // Check for special case in Hashtable::get. (See below.) 772 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) 773 return TypeInt::CC_LT; 774 return TypeInt::CC_LE; 775 } 776 } 777 // Check for special case in Hashtable::get - the hash index is 778 // mod'ed to the table size so the following range check is useless. 779 // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have 780 // to be positive. 781 // (This is a gross hack, since the sub method never 782 // looks at the structure of the node in any other case.) 783 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) 784 return TypeInt::CC_LT; 785 return TypeInt::CC; // else use worst case results 786 } 787 788 const Type* CmpUNode::Value(PhaseGVN* phase) const { 789 const Type* t = SubNode::Value_common(phase); 790 if (t != nullptr) { 791 return t; 792 } 793 const Node* in1 = in(1); 794 const Node* in2 = in(2); 795 const Type* t1 = phase->type(in1); 796 const Type* t2 = phase->type(in2); 797 assert(t1->isa_int(), "CmpU has only Int type inputs"); 798 if (t2 == TypeInt::INT) { // Compare to bottom? 799 return bottom_type(); 800 } 801 802 const Type* t_sub = sub(t1, t2); // compare based on immediate inputs 803 804 uint in1_op = in1->Opcode(); 805 if (in1_op == Op_AddI || in1_op == Op_SubI) { 806 // The problem rise when result of AddI(SubI) may overflow 807 // signed integer value. Let say the input type is 808 // [256, maxint] then +128 will create 2 ranges due to 809 // overflow: [minint, minint+127] and [384, maxint]. 810 // But C2 type system keep only 1 type range and as result 811 // it use general [minint, maxint] for this case which we 812 // can't optimize. 813 // 814 // Make 2 separate type ranges based on types of AddI(SubI) inputs 815 // and compare results of their compare. If results are the same 816 // CmpU node can be optimized. 817 const Node* in11 = in1->in(1); 818 const Node* in12 = in1->in(2); 819 const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11); 820 const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12); 821 // Skip cases when input types are top or bottom. 822 if ((t11 != Type::TOP) && (t11 != TypeInt::INT) && 823 (t12 != Type::TOP) && (t12 != TypeInt::INT)) { 824 const TypeInt *r0 = t11->is_int(); 825 const TypeInt *r1 = t12->is_int(); 826 jlong lo_r0 = r0->_lo; 827 jlong hi_r0 = r0->_hi; 828 jlong lo_r1 = r1->_lo; 829 jlong hi_r1 = r1->_hi; 830 if (in1_op == Op_SubI) { 831 jlong tmp = hi_r1; 832 hi_r1 = -lo_r1; 833 lo_r1 = -tmp; 834 // Note, for substructing [minint,x] type range 835 // long arithmetic provides correct overflow answer. 836 // The confusion come from the fact that in 32-bit 837 // -minint == minint but in 64-bit -minint == maxint+1. 838 } 839 jlong lo_long = lo_r0 + lo_r1; 840 jlong hi_long = hi_r0 + hi_r1; 841 int lo_tr1 = min_jint; 842 int hi_tr1 = (int)hi_long; 843 int lo_tr2 = (int)lo_long; 844 int hi_tr2 = max_jint; 845 bool underflow = lo_long != (jlong)lo_tr2; 846 bool overflow = hi_long != (jlong)hi_tr1; 847 // Use sub(t1, t2) when there is no overflow (one type range) 848 // or when both overflow and underflow (too complex). 849 if ((underflow != overflow) && (hi_tr1 < lo_tr2)) { 850 // Overflow only on one boundary, compare 2 separate type ranges. 851 int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here 852 const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w); 853 const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w); 854 const TypeInt* cmp1 = sub(tr1, t2)->is_int(); 855 const TypeInt* cmp2 = sub(tr2, t2)->is_int(); 856 // Compute union, so that cmp handles all possible results from the two cases 857 const Type* t_cmp = cmp1->meet(cmp2); 858 // Pick narrowest type, based on overflow computation and on immediate inputs 859 return t_sub->filter(t_cmp); 860 } 861 } 862 } 863 864 return t_sub; 865 } 866 867 bool CmpUNode::is_index_range_check() const { 868 // Check for the "(X ModI Y) CmpU Y" shape 869 return (in(1)->Opcode() == Op_ModI && 870 in(1)->in(2)->eqv_uncast(in(2))); 871 } 872 873 //------------------------------Idealize--------------------------------------- 874 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) { 875 if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) { 876 switch (in(1)->Opcode()) { 877 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU 878 return new CmpUNode(in(1)->in(1),in(1)->in(2)); 879 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL 880 return new CmpLNode(in(1)->in(1),in(1)->in(2)); 881 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL 882 return new CmpULNode(in(1)->in(1),in(1)->in(2)); 883 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF 884 return new CmpFNode(in(1)->in(1),in(1)->in(2)); 885 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD 886 return new CmpDNode(in(1)->in(1),in(1)->in(2)); 887 //case Op_SubI: 888 // If (x - y) cannot overflow, then ((x - y) <?> 0) 889 // can be turned into (x <?> y). 890 // This is handled (with more general cases) by Ideal_sub_algebra. 891 } 892 } 893 return nullptr; // No change 894 } 895 896 //------------------------------Ideal------------------------------------------ 897 Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 898 Node* a = nullptr; 899 Node* b = nullptr; 900 if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) { 901 // Degraded to a simple null check, use old acmp 902 return new CmpPNode(a, b); 903 } 904 const TypeLong *t2 = phase->type(in(2))->isa_long(); 905 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) { 906 const jlong con = t2->get_con(); 907 if (con >= min_jint && con <= max_jint) { 908 return new CmpINode(in(1)->in(1), phase->intcon((jint)con)); 909 } 910 } 911 return nullptr; 912 } 913 914 // Match double null check emitted by Compile::optimize_acmp() 915 bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const { 916 if (in(1)->Opcode() == Op_OrL && 917 in(1)->in(1)->Opcode() == Op_CastP2X && 918 in(1)->in(2)->Opcode() == Op_CastP2X && 919 in(2)->bottom_type()->is_zero_type()) { 920 assert(EnableValhalla, "unexpected double null check"); 921 a = in(1)->in(1)->in(1); 922 b = in(1)->in(2)->in(1); 923 return true; 924 } 925 return false; 926 } 927 928 //------------------------------Value------------------------------------------ 929 const Type* CmpLNode::Value(PhaseGVN* phase) const { 930 Node* a = nullptr; 931 Node* b = nullptr; 932 if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) { 933 // One operand is never nullptr, emit constant false 934 return TypeInt::CC_GT; 935 } 936 return SubNode::Value(phase); 937 } 938 939 //============================================================================= 940 // Simplify a CmpL (compare 2 longs ) node, based on local information. 941 // If both inputs are constants, compare them. 942 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { 943 const TypeLong *r0 = t1->is_long(); // Handy access 944 const TypeLong *r1 = t2->is_long(); 945 946 if( r0->_hi < r1->_lo ) // Range is always low? 947 return TypeInt::CC_LT; 948 else if( r0->_lo > r1->_hi ) // Range is always high? 949 return TypeInt::CC_GT; 950 951 else if( r0->is_con() && r1->is_con() ) { // comparing constants? 952 assert(r0->get_con() == r1->get_con(), "must be equal"); 953 return TypeInt::CC_EQ; // Equal results. 954 } else if( r0->_hi == r1->_lo ) // Range is never high? 955 return TypeInt::CC_LE; 956 else if( r0->_lo == r1->_hi ) // Range is never low? 957 return TypeInt::CC_GE; 958 return TypeInt::CC; // else use worst case results 959 } 960 961 962 // Simplify a CmpUL (compare 2 unsigned longs) node, based on local information. 963 // If both inputs are constants, compare them. 964 const Type* CmpULNode::sub(const Type* t1, const Type* t2) const { 965 assert(!t1->isa_ptr(), "obsolete usage of CmpUL"); 966 967 // comparing two unsigned longs 968 const TypeLong* r0 = t1->is_long(); // Handy access 969 const TypeLong* r1 = t2->is_long(); 970 971 // Current installed version 972 // Compare ranges for non-overlap 973 julong lo0 = r0->_lo; 974 julong hi0 = r0->_hi; 975 julong lo1 = r1->_lo; 976 julong hi1 = r1->_hi; 977 978 // If either one has both negative and positive values, 979 // it therefore contains both 0 and -1, and since [0..-1] is the 980 // full unsigned range, the type must act as an unsigned bottom. 981 bool bot0 = ((jlong)(lo0 ^ hi0) < 0); 982 bool bot1 = ((jlong)(lo1 ^ hi1) < 0); 983 984 if (bot0 || bot1) { 985 // All unsigned values are LE -1 and GE 0. 986 if (lo0 == 0 && hi0 == 0) { 987 return TypeInt::CC_LE; // 0 <= bot 988 } else if ((jlong)lo0 == -1 && (jlong)hi0 == -1) { 989 return TypeInt::CC_GE; // -1 >= bot 990 } else if (lo1 == 0 && hi1 == 0) { 991 return TypeInt::CC_GE; // bot >= 0 992 } else if ((jlong)lo1 == -1 && (jlong)hi1 == -1) { 993 return TypeInt::CC_LE; // bot <= -1 994 } 995 } else { 996 // We can use ranges of the form [lo..hi] if signs are the same. 997 assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); 998 // results are reversed, '-' > '+' for unsigned compare 999 if (hi0 < lo1) { 1000 return TypeInt::CC_LT; // smaller 1001 } else if (lo0 > hi1) { 1002 return TypeInt::CC_GT; // greater 1003 } else if (hi0 == lo1 && lo0 == hi1) { 1004 return TypeInt::CC_EQ; // Equal results 1005 } else if (lo0 >= hi1) { 1006 return TypeInt::CC_GE; 1007 } else if (hi0 <= lo1) { 1008 return TypeInt::CC_LE; 1009 } 1010 } 1011 1012 return TypeInt::CC; // else use worst case results 1013 } 1014 1015 //============================================================================= 1016 //------------------------------sub-------------------------------------------- 1017 // Simplify an CmpP (compare 2 pointers) node, based on local information. 1018 // If both inputs are constants, compare them. 1019 const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { 1020 const TypePtr *r0 = t1->is_ptr(); // Handy access 1021 const TypePtr *r1 = t2->is_ptr(); 1022 1023 // Undefined inputs makes for an undefined result 1024 if( TypePtr::above_centerline(r0->_ptr) || 1025 TypePtr::above_centerline(r1->_ptr) ) 1026 return Type::TOP; 1027 1028 if (r0 == r1 && r0->singleton()) { 1029 // Equal pointer constants (klasses, nulls, etc.) 1030 return TypeInt::CC_EQ; 1031 } 1032 1033 // See if it is 2 unrelated classes. 1034 const TypeOopPtr* p0 = r0->isa_oopptr(); 1035 const TypeOopPtr* p1 = r1->isa_oopptr(); 1036 const TypeKlassPtr* k0 = r0->isa_klassptr(); 1037 const TypeKlassPtr* k1 = r1->isa_klassptr(); 1038 if ((p0 && p1) || (k0 && k1)) { 1039 if (p0 && p1) { 1040 Node* in1 = in(1)->uncast(); 1041 Node* in2 = in(2)->uncast(); 1042 AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1); 1043 AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2); 1044 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) { 1045 return TypeInt::CC_GT; // different pointers 1046 } 1047 } 1048 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact(); 1049 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact(); 1050 bool unrelated_classes = false; 1051 1052 if ((p0 && p0->is_same_java_type_as(p1)) || 1053 (k0 && k0->is_same_java_type_as(k1))) { 1054 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) || 1055 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) { 1056 unrelated_classes = true; 1057 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) || 1058 (k0 && !k1->maybe_java_subtype_of(k0))) { 1059 unrelated_classes = xklass1; 1060 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) || 1061 (k0 && !k0->maybe_java_subtype_of(k1))) { 1062 unrelated_classes = xklass0; 1063 } 1064 if (!unrelated_classes) { 1065 // Handle inline type arrays 1066 if ((r0->flat_in_array() && r1->not_flat_in_array()) || 1067 (r1->flat_in_array() && r0->not_flat_in_array())) { 1068 // One type is in flat arrays but the other type is not. Must be unrelated. 1069 unrelated_classes = true; 1070 } else if ((r0->is_not_flat() && r1->is_flat()) || 1071 (r1->is_not_flat() && r0->is_flat())) { 1072 // One type is a non-flat array and the other type is a flat array. Must be unrelated. 1073 unrelated_classes = true; 1074 } else if ((r0->is_not_null_free() && r1->is_null_free()) || 1075 (r1->is_not_null_free() && r0->is_null_free())) { 1076 // One type is a nullable array and the other type is a null-free array. Must be unrelated. 1077 unrelated_classes = true; 1078 } 1079 } 1080 if (unrelated_classes) { 1081 // The oops classes are known to be unrelated. If the joined PTRs of 1082 // two oops is not Null and not Bottom, then we are sure that one 1083 // of the two oops is non-null, and the comparison will always fail. 1084 TypePtr::PTR jp = r0->join_ptr(r1->_ptr); 1085 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { 1086 return TypeInt::CC_GT; 1087 } 1088 } 1089 } 1090 1091 // Known constants can be compared exactly 1092 // Null can be distinguished from any NotNull pointers 1093 // Unknown inputs makes an unknown result 1094 if( r0->singleton() ) { 1095 intptr_t bits0 = r0->get_con(); 1096 if( r1->singleton() ) 1097 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; 1098 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1099 } else if( r1->singleton() ) { 1100 intptr_t bits1 = r1->get_con(); 1101 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1102 } else 1103 return TypeInt::CC; 1104 } 1105 1106 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) { 1107 // Return the klass node for (indirect load from OopHandle) 1108 // LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror)))) 1109 // or null if not matching. 1110 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 1111 n = bs->step_over_gc_barrier(n); 1112 1113 if (n->Opcode() != Op_LoadP) return nullptr; 1114 1115 const TypeInstPtr* tp = phase->type(n)->isa_instptr(); 1116 if (!tp || tp->instance_klass() != phase->C->env()->Class_klass()) return nullptr; 1117 1118 Node* adr = n->in(MemNode::Address); 1119 // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier. 1120 if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return nullptr; 1121 adr = adr->in(MemNode::Address); 1122 1123 intptr_t off = 0; 1124 Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off); 1125 if (k == nullptr) return nullptr; 1126 const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr(); 1127 if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return nullptr; 1128 1129 // We've found the klass node of a Java mirror load. 1130 return k; 1131 } 1132 1133 static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) { 1134 // for ConP(Foo.class) return ConP(Foo.klass) 1135 // otherwise return null 1136 if (!n->is_Con()) return nullptr; 1137 1138 const TypeInstPtr* tp = phase->type(n)->isa_instptr(); 1139 if (!tp) return nullptr; 1140 1141 ciType* mirror_type = tp->java_mirror_type(); 1142 // TypeInstPtr::java_mirror_type() returns non-null for compile- 1143 // time Class constants only. 1144 if (!mirror_type) return nullptr; 1145 1146 // x.getClass() == int.class can never be true (for all primitive types) 1147 // Return a ConP(null) node for this case. 1148 if (mirror_type->is_classless()) { 1149 return phase->makecon(TypePtr::NULL_PTR); 1150 } 1151 1152 // return the ConP(Foo.klass) 1153 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*"); 1154 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces)); 1155 } 1156 1157 //------------------------------Ideal------------------------------------------ 1158 // Normalize comparisons between Java mirror loads to compare the klass instead. 1159 // 1160 // Also check for the case of comparing an unknown klass loaded from the primary 1161 // super-type array vs a known klass with no subtypes. This amounts to 1162 // checking to see an unknown klass subtypes a known klass with no subtypes; 1163 // this only happens on an exact match. We can shorten this test by 1 load. 1164 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1165 // TODO 8284443 in(1) could be cast? 1166 if (in(1)->is_InlineType() && phase->type(in(2))->is_zero_type()) { 1167 // Null checking a scalarized but nullable inline type. Check the IsInit 1168 // input instead of the oop input to avoid keeping buffer allocations alive. 1169 return new CmpINode(in(1)->as_InlineType()->get_is_init(), phase->intcon(0)); 1170 } 1171 1172 // Normalize comparisons between Java mirrors into comparisons of the low- 1173 // level klass, where a dependent load could be shortened. 1174 // 1175 // The new pattern has a nice effect of matching the same pattern used in the 1176 // fast path of instanceof/checkcast/Class.isInstance(), which allows 1177 // redundant exact type check be optimized away by GVN. 1178 // For example, in 1179 // if (x.getClass() == Foo.class) { 1180 // Foo foo = (Foo) x; 1181 // // ... use a ... 1182 // } 1183 // a CmpPNode could be shared between if_acmpne and checkcast 1184 { 1185 Node* k1 = isa_java_mirror_load(phase, in(1)); 1186 Node* k2 = isa_java_mirror_load(phase, in(2)); 1187 Node* conk2 = isa_const_java_mirror(phase, in(2)); 1188 1189 if (k1 && (k2 || conk2)) { 1190 Node* lhs = k1; 1191 Node* rhs = (k2 != nullptr) ? k2 : conk2; 1192 set_req_X(1, lhs, phase); 1193 set_req_X(2, rhs, phase); 1194 return this; 1195 } 1196 } 1197 1198 // Constant pointer on right? 1199 const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr(); 1200 if (t2 == nullptr || !t2->klass_is_exact()) 1201 return nullptr; 1202 // Get the constant klass we are comparing to. 1203 ciKlass* superklass = t2->exact_klass(); 1204 1205 // Now check for LoadKlass on left. 1206 Node* ldk1 = in(1); 1207 if (ldk1->is_DecodeNKlass()) { 1208 ldk1 = ldk1->in(1); 1209 if (ldk1->Opcode() != Op_LoadNKlass ) 1210 return nullptr; 1211 } else if (ldk1->Opcode() != Op_LoadKlass ) 1212 return nullptr; 1213 // Take apart the address of the LoadKlass: 1214 Node* adr1 = ldk1->in(MemNode::Address); 1215 intptr_t con2 = 0; 1216 Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2); 1217 if (ldk2 == nullptr) 1218 return nullptr; 1219 if (con2 == oopDesc::klass_offset_in_bytes()) { 1220 // We are inspecting an object's concrete class. 1221 // Short-circuit the check if the query is abstract. 1222 if (superklass->is_interface() || 1223 superklass->is_abstract()) { 1224 // Make it come out always false: 1225 this->set_req(2, phase->makecon(TypePtr::NULL_PTR)); 1226 return this; 1227 } 1228 } 1229 1230 // Check for a LoadKlass from primary supertype array. 1231 // Any nested loadklass from loadklass+con must be from the p.s. array. 1232 if (ldk2->is_DecodeNKlass()) { 1233 // Keep ldk2 as DecodeN since it could be used in CmpP below. 1234 if (ldk2->in(1)->Opcode() != Op_LoadNKlass ) 1235 return nullptr; 1236 } else if (ldk2->Opcode() != Op_LoadKlass) 1237 return nullptr; 1238 1239 // Verify that we understand the situation 1240 if (con2 != (intptr_t) superklass->super_check_offset()) 1241 return nullptr; // Might be element-klass loading from array klass 1242 1243 // Do not fold the subtype check to an array klass pointer comparison for null-able inline type arrays 1244 // because null-free [LMyValue <: null-able [LMyValue but the klasses are different. Perform a full test. 1245 if (superklass->is_obj_array_klass() && !superklass->as_array_klass()->is_elem_null_free() && 1246 superklass->as_array_klass()->element_klass()->is_inlinetype()) { 1247 return nullptr; 1248 } 1249 1250 // If 'superklass' has no subklasses and is not an interface, then we are 1251 // assured that the only input which will pass the type check is 1252 // 'superklass' itself. 1253 // 1254 // We could be more liberal here, and allow the optimization on interfaces 1255 // which have a single implementor. This would require us to increase the 1256 // expressiveness of the add_dependency() mechanism. 1257 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. 1258 1259 // Object arrays must have their base element have no subtypes 1260 while (superklass->is_obj_array_klass()) { 1261 ciType* elem = superklass->as_obj_array_klass()->element_type(); 1262 superklass = elem->as_klass(); 1263 } 1264 if (superklass->is_instance_klass()) { 1265 ciInstanceKlass* ik = superklass->as_instance_klass(); 1266 if (ik->has_subklass() || ik->is_interface()) return nullptr; 1267 // Add a dependency if there is a chance that a subclass will be added later. 1268 if (!ik->is_final()) { 1269 phase->C->dependencies()->assert_leaf_type(ik); 1270 } 1271 } 1272 1273 // Bypass the dependent load, and compare directly 1274 this->set_req_X(1, ldk2, phase); 1275 1276 return this; 1277 } 1278 1279 //============================================================================= 1280 //------------------------------sub-------------------------------------------- 1281 // Simplify an CmpN (compare 2 pointers) node, based on local information. 1282 // If both inputs are constants, compare them. 1283 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { 1284 ShouldNotReachHere(); 1285 return bottom_type(); 1286 } 1287 1288 //------------------------------Ideal------------------------------------------ 1289 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) { 1290 return nullptr; 1291 } 1292 1293 //============================================================================= 1294 //------------------------------Value------------------------------------------ 1295 // Simplify an CmpF (compare 2 floats ) node, based on local information. 1296 // If both inputs are constants, compare them. 1297 const Type* CmpFNode::Value(PhaseGVN* phase) const { 1298 const Node* in1 = in(1); 1299 const Node* in2 = in(2); 1300 // Either input is TOP ==> the result is TOP 1301 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1302 if( t1 == Type::TOP ) return Type::TOP; 1303 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1304 if( t2 == Type::TOP ) return Type::TOP; 1305 1306 // Not constants? Don't know squat - even if they are the same 1307 // value! If they are NaN's they compare to LT instead of EQ. 1308 const TypeF *tf1 = t1->isa_float_constant(); 1309 const TypeF *tf2 = t2->isa_float_constant(); 1310 if( !tf1 || !tf2 ) return TypeInt::CC; 1311 1312 // This implements the Java bytecode fcmpl, so unordered returns -1. 1313 if( tf1->is_nan() || tf2->is_nan() ) 1314 return TypeInt::CC_LT; 1315 1316 if( tf1->_f < tf2->_f ) return TypeInt::CC_LT; 1317 if( tf1->_f > tf2->_f ) return TypeInt::CC_GT; 1318 assert( tf1->_f == tf2->_f, "do not understand FP behavior" ); 1319 return TypeInt::CC_EQ; 1320 } 1321 1322 1323 //============================================================================= 1324 //------------------------------Value------------------------------------------ 1325 // Simplify an CmpD (compare 2 doubles ) node, based on local information. 1326 // If both inputs are constants, compare them. 1327 const Type* CmpDNode::Value(PhaseGVN* phase) const { 1328 const Node* in1 = in(1); 1329 const Node* in2 = in(2); 1330 // Either input is TOP ==> the result is TOP 1331 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1332 if( t1 == Type::TOP ) return Type::TOP; 1333 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1334 if( t2 == Type::TOP ) return Type::TOP; 1335 1336 // Not constants? Don't know squat - even if they are the same 1337 // value! If they are NaN's they compare to LT instead of EQ. 1338 const TypeD *td1 = t1->isa_double_constant(); 1339 const TypeD *td2 = t2->isa_double_constant(); 1340 if( !td1 || !td2 ) return TypeInt::CC; 1341 1342 // This implements the Java bytecode dcmpl, so unordered returns -1. 1343 if( td1->is_nan() || td2->is_nan() ) 1344 return TypeInt::CC_LT; 1345 1346 if( td1->_d < td2->_d ) return TypeInt::CC_LT; 1347 if( td1->_d > td2->_d ) return TypeInt::CC_GT; 1348 assert( td1->_d == td2->_d, "do not understand FP behavior" ); 1349 return TypeInt::CC_EQ; 1350 } 1351 1352 //------------------------------Ideal------------------------------------------ 1353 Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){ 1354 // Check if we can change this to a CmpF and remove a ConvD2F operation. 1355 // Change (CMPD (F2D (float)) (ConD value)) 1356 // To (CMPF (float) (ConF value)) 1357 // Valid when 'value' does not lose precision as a float. 1358 // Benefits: eliminates conversion, does not require 24-bit mode 1359 1360 // NaNs prevent commuting operands. This transform works regardless of the 1361 // order of ConD and ConvF2D inputs by preserving the original order. 1362 int idx_f2d = 1; // ConvF2D on left side? 1363 if( in(idx_f2d)->Opcode() != Op_ConvF2D ) 1364 idx_f2d = 2; // No, swap to check for reversed args 1365 int idx_con = 3-idx_f2d; // Check for the constant on other input 1366 1367 if( ConvertCmpD2CmpF && 1368 in(idx_f2d)->Opcode() == Op_ConvF2D && 1369 in(idx_con)->Opcode() == Op_ConD ) { 1370 const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant(); 1371 double t2_value_as_double = t2->_d; 1372 float t2_value_as_float = (float)t2_value_as_double; 1373 if( t2_value_as_double == (double)t2_value_as_float ) { 1374 // Test value can be represented as a float 1375 // Eliminate the conversion to double and create new comparison 1376 Node *new_in1 = in(idx_f2d)->in(1); 1377 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) ); 1378 if( idx_f2d != 1 ) { // Must flip args to match original order 1379 Node *tmp = new_in1; 1380 new_in1 = new_in2; 1381 new_in2 = tmp; 1382 } 1383 CmpFNode *new_cmp = (Opcode() == Op_CmpD3) 1384 ? new CmpF3Node( new_in1, new_in2 ) 1385 : new CmpFNode ( new_in1, new_in2 ) ; 1386 return new_cmp; // Changed to CmpFNode 1387 } 1388 // Testing value required the precision of a double 1389 } 1390 return nullptr; // No change 1391 } 1392 1393 //============================================================================= 1394 //------------------------------Value------------------------------------------ 1395 const Type* FlatArrayCheckNode::Value(PhaseGVN* phase) const { 1396 bool all_not_flat = true; 1397 for (uint i = ArrayOrKlass; i < req(); ++i) { 1398 const Type* t = phase->type(in(i)); 1399 if (t == Type::TOP) { 1400 return Type::TOP; 1401 } 1402 if (t->is_ptr()->is_flat()) { 1403 // One of the input arrays is flat, check always passes 1404 return TypeInt::CC_EQ; 1405 } else if (!t->is_ptr()->is_not_flat()) { 1406 // One of the input arrays might be flat 1407 all_not_flat = false; 1408 } 1409 } 1410 if (all_not_flat) { 1411 // None of the input arrays can be flat, check always fails 1412 return TypeInt::CC_GT; 1413 } 1414 return TypeInt::CC; 1415 } 1416 1417 //------------------------------Ideal------------------------------------------ 1418 Node* FlatArrayCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) { 1419 bool changed = false; 1420 // Remove inputs that are known to be non-flat 1421 for (uint i = ArrayOrKlass; i < req(); ++i) { 1422 const Type* t = phase->type(in(i)); 1423 if (t->isa_ptr() && t->is_ptr()->is_not_flat()) { 1424 del_req(i--); 1425 changed = true; 1426 } 1427 } 1428 return changed ? this : nullptr; 1429 } 1430 1431 //============================================================================= 1432 //------------------------------cc2logical------------------------------------- 1433 // Convert a condition code type to a logical type 1434 const Type *BoolTest::cc2logical( const Type *CC ) const { 1435 if( CC == Type::TOP ) return Type::TOP; 1436 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse 1437 const TypeInt *ti = CC->is_int(); 1438 if( ti->is_con() ) { // Only 1 kind of condition codes set? 1439 // Match low order 2 bits 1440 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0; 1441 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result 1442 return TypeInt::make(tmp); // Boolean result 1443 } 1444 1445 if( CC == TypeInt::CC_GE ) { 1446 if( _test == ge ) return TypeInt::ONE; 1447 if( _test == lt ) return TypeInt::ZERO; 1448 } 1449 if( CC == TypeInt::CC_LE ) { 1450 if( _test == le ) return TypeInt::ONE; 1451 if( _test == gt ) return TypeInt::ZERO; 1452 } 1453 1454 return TypeInt::BOOL; 1455 } 1456 1457 //------------------------------dump_spec------------------------------------- 1458 // Print special per-node info 1459 void BoolTest::dump_on(outputStream *st) const { 1460 const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"}; 1461 st->print("%s", msg[_test]); 1462 } 1463 1464 // Returns the logical AND of two tests (or 'never' if both tests can never be true). 1465 // For example, a test for 'le' followed by a test for 'lt' is equivalent with 'lt'. 1466 BoolTest::mask BoolTest::merge(BoolTest other) const { 1467 const mask res[illegal+1][illegal+1] = { 1468 // eq, gt, of, lt, ne, le, nof, ge, never, illegal 1469 {eq, never, illegal, never, never, eq, illegal, eq, never, illegal}, // eq 1470 {never, gt, illegal, never, gt, never, illegal, gt, never, illegal}, // gt 1471 {illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, never, illegal}, // of 1472 {never, never, illegal, lt, lt, lt, illegal, never, never, illegal}, // lt 1473 {never, gt, illegal, lt, ne, lt, illegal, gt, never, illegal}, // ne 1474 {eq, never, illegal, lt, lt, le, illegal, eq, never, illegal}, // le 1475 {illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, never, illegal}, // nof 1476 {eq, gt, illegal, never, gt, eq, illegal, ge, never, illegal}, // ge 1477 {never, never, never, never, never, never, never, never, never, illegal}, // never 1478 {illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal}}; // illegal 1479 return res[_test][other._test]; 1480 } 1481 1482 //============================================================================= 1483 uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); } 1484 uint BoolNode::size_of() const { return sizeof(BoolNode); } 1485 1486 //------------------------------operator==------------------------------------- 1487 bool BoolNode::cmp( const Node &n ) const { 1488 const BoolNode *b = (const BoolNode *)&n; // Cast up 1489 return (_test._test == b->_test._test); 1490 } 1491 1492 //-------------------------------make_predicate-------------------------------- 1493 Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) { 1494 if (test_value->is_Con()) return test_value; 1495 if (test_value->is_Bool()) return test_value; 1496 if (test_value->is_CMove() && 1497 test_value->in(CMoveNode::Condition)->is_Bool()) { 1498 BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool(); 1499 const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse)); 1500 const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue)); 1501 if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) { 1502 return bol; 1503 } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) { 1504 return phase->transform( bol->negate(phase) ); 1505 } 1506 // Else fall through. The CMove gets in the way of the test. 1507 // It should be the case that make_predicate(bol->as_int_value()) == bol. 1508 } 1509 Node* cmp = new CmpINode(test_value, phase->intcon(0)); 1510 cmp = phase->transform(cmp); 1511 Node* bol = new BoolNode(cmp, BoolTest::ne); 1512 return phase->transform(bol); 1513 } 1514 1515 //--------------------------------as_int_value--------------------------------- 1516 Node* BoolNode::as_int_value(PhaseGVN* phase) { 1517 // Inverse to make_predicate. The CMove probably boils down to a Conv2B. 1518 Node* cmov = CMoveNode::make(nullptr, this, 1519 phase->intcon(0), phase->intcon(1), 1520 TypeInt::BOOL); 1521 return phase->transform(cmov); 1522 } 1523 1524 //----------------------------------negate------------------------------------- 1525 BoolNode* BoolNode::negate(PhaseGVN* phase) { 1526 return new BoolNode(in(1), _test.negate()); 1527 } 1528 1529 // Change "bool eq/ne (cmp (add/sub A B) C)" into false/true if add/sub 1530 // overflows and we can prove that C is not in the two resulting ranges. 1531 // This optimization is similar to the one performed by CmpUNode::Value(). 1532 Node* BoolNode::fold_cmpI(PhaseGVN* phase, SubNode* cmp, Node* cmp1, int cmp_op, 1533 int cmp1_op, const TypeInt* cmp2_type) { 1534 // Only optimize eq/ne integer comparison of add/sub 1535 if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1536 (cmp_op == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) { 1537 // Skip cases were inputs of add/sub are not integers or of bottom type 1538 const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int(); 1539 const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int(); 1540 if ((r0 != nullptr) && (r0 != TypeInt::INT) && 1541 (r1 != nullptr) && (r1 != TypeInt::INT) && 1542 (cmp2_type != TypeInt::INT)) { 1543 // Compute exact (long) type range of add/sub result 1544 jlong lo_long = r0->_lo; 1545 jlong hi_long = r0->_hi; 1546 if (cmp1_op == Op_AddI) { 1547 lo_long += r1->_lo; 1548 hi_long += r1->_hi; 1549 } else { 1550 lo_long -= r1->_hi; 1551 hi_long -= r1->_lo; 1552 } 1553 // Check for over-/underflow by casting to integer 1554 int lo_int = (int)lo_long; 1555 int hi_int = (int)hi_long; 1556 bool underflow = lo_long != (jlong)lo_int; 1557 bool overflow = hi_long != (jlong)hi_int; 1558 if ((underflow != overflow) && (hi_int < lo_int)) { 1559 // Overflow on one boundary, compute resulting type ranges: 1560 // tr1 [MIN_INT, hi_int] and tr2 [lo_int, MAX_INT] 1561 int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here 1562 const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w); 1563 const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w); 1564 // Compare second input of cmp to both type ranges 1565 const Type* sub_tr1 = cmp->sub(tr1, cmp2_type); 1566 const Type* sub_tr2 = cmp->sub(tr2, cmp2_type); 1567 if (sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) { 1568 // The result of the add/sub will never equal cmp2. Replace BoolNode 1569 // by false (0) if it tests for equality and by true (1) otherwise. 1570 return ConINode::make((_test._test == BoolTest::eq) ? 0 : 1); 1571 } 1572 } 1573 } 1574 } 1575 return nullptr; 1576 } 1577 1578 static bool is_counted_loop_cmp(Node *cmp) { 1579 Node *n = cmp->in(1)->in(1); 1580 return n != nullptr && 1581 n->is_Phi() && 1582 n->in(0) != nullptr && 1583 n->in(0)->is_CountedLoop() && 1584 n->in(0)->as_CountedLoop()->phi() == n; 1585 } 1586 1587 //------------------------------Ideal------------------------------------------ 1588 Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1589 // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)". 1590 // This moves the constant to the right. Helps value-numbering. 1591 Node *cmp = in(1); 1592 if( !cmp->is_Sub() ) return nullptr; 1593 int cop = cmp->Opcode(); 1594 if( cop == Op_FastLock || cop == Op_FastUnlock || 1595 cmp->is_SubTypeCheck() || cop == Op_VectorTest ) { 1596 return nullptr; 1597 } 1598 Node *cmp1 = cmp->in(1); 1599 Node *cmp2 = cmp->in(2); 1600 if( !cmp1 ) return nullptr; 1601 1602 if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) { 1603 return nullptr; 1604 } 1605 1606 const int cmp1_op = cmp1->Opcode(); 1607 const int cmp2_op = cmp2->Opcode(); 1608 1609 // Constant on left? 1610 Node *con = cmp1; 1611 // Move constants to the right of compare's to canonicalize. 1612 // Do not muck with Opaque1 nodes, as this indicates a loop 1613 // guard that cannot change shape. 1614 if (con->is_Con() && !cmp2->is_Con() && cmp2_op != Op_OpaqueZeroTripGuard && 1615 // Because of NaN's, CmpD and CmpF are not commutative 1616 cop != Op_CmpD && cop != Op_CmpF && 1617 // Protect against swapping inputs to a compare when it is used by a 1618 // counted loop exit, which requires maintaining the loop-limit as in(2) 1619 !is_counted_loop_exit_test() ) { 1620 // Ok, commute the constant to the right of the cmp node. 1621 // Clone the Node, getting a new Node of the same class 1622 cmp = cmp->clone(); 1623 // Swap inputs to the clone 1624 cmp->swap_edges(1, 2); 1625 cmp = phase->transform( cmp ); 1626 return new BoolNode( cmp, _test.commute() ); 1627 } 1628 1629 // Change "bool eq/ne (cmp (cmove (bool tst (cmp2)) 1 0) 0)" into "bool tst/~tst (cmp2)" 1630 if (cop == Op_CmpI && 1631 (_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1632 cmp1_op == Op_CMoveI && cmp2->find_int_con(1) == 0) { 1633 // 0 should be on the true branch 1634 if (cmp1->in(CMoveNode::Condition)->is_Bool() && 1635 cmp1->in(CMoveNode::IfTrue)->find_int_con(1) == 0 && 1636 cmp1->in(CMoveNode::IfFalse)->find_int_con(0) != 0) { 1637 BoolNode* target = cmp1->in(CMoveNode::Condition)->as_Bool(); 1638 return new BoolNode(target->in(1), 1639 (_test._test == BoolTest::eq) ? target->_test._test : 1640 target->_test.negate()); 1641 } 1642 } 1643 1644 // Change "bool eq/ne (cmp (and X 16) 16)" into "bool ne/eq (cmp (and X 16) 0)". 1645 if (cop == Op_CmpI && 1646 (_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1647 cmp1_op == Op_AndI && cmp2_op == Op_ConI && 1648 cmp1->in(2)->Opcode() == Op_ConI) { 1649 const TypeInt *t12 = phase->type(cmp2)->isa_int(); 1650 const TypeInt *t112 = phase->type(cmp1->in(2))->isa_int(); 1651 if (t12 && t12->is_con() && t112 && t112->is_con() && 1652 t12->get_con() == t112->get_con() && is_power_of_2(t12->get_con())) { 1653 Node *ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0))); 1654 return new BoolNode(ncmp, _test.negate()); 1655 } 1656 } 1657 1658 // Same for long type: change "bool eq/ne (cmp (and X 16) 16)" into "bool ne/eq (cmp (and X 16) 0)". 1659 if (cop == Op_CmpL && 1660 (_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1661 cmp1_op == Op_AndL && cmp2_op == Op_ConL && 1662 cmp1->in(2)->Opcode() == Op_ConL) { 1663 const TypeLong *t12 = phase->type(cmp2)->isa_long(); 1664 const TypeLong *t112 = phase->type(cmp1->in(2))->isa_long(); 1665 if (t12 && t12->is_con() && t112 && t112->is_con() && 1666 t12->get_con() == t112->get_con() && is_power_of_2(t12->get_con())) { 1667 Node *ncmp = phase->transform(new CmpLNode(cmp1, phase->longcon(0))); 1668 return new BoolNode(ncmp, _test.negate()); 1669 } 1670 } 1671 1672 // Change "cmp (add X min_jint) (add Y min_jint)" into "cmpu X Y" 1673 // and "cmp (add X min_jint) c" into "cmpu X (c + min_jint)" 1674 if (cop == Op_CmpI && 1675 cmp1_op == Op_AddI && 1676 phase->type(cmp1->in(2)) == TypeInt::MIN && 1677 !is_cloop_condition(this)) { 1678 if (cmp2_op == Op_ConI) { 1679 Node* ncmp2 = phase->intcon(java_add(cmp2->get_int(), min_jint)); 1680 Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), ncmp2)); 1681 return new BoolNode(ncmp, _test._test); 1682 } else if (cmp2_op == Op_AddI && 1683 phase->type(cmp2->in(2)) == TypeInt::MIN && 1684 !is_cloop_condition(this)) { 1685 Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), cmp2->in(1))); 1686 return new BoolNode(ncmp, _test._test); 1687 } 1688 } 1689 1690 // Change "cmp (add X min_jlong) (add Y min_jlong)" into "cmpu X Y" 1691 // and "cmp (add X min_jlong) c" into "cmpu X (c + min_jlong)" 1692 if (cop == Op_CmpL && 1693 cmp1_op == Op_AddL && 1694 phase->type(cmp1->in(2)) == TypeLong::MIN && 1695 !is_cloop_condition(this)) { 1696 if (cmp2_op == Op_ConL) { 1697 Node* ncmp2 = phase->longcon(java_add(cmp2->get_long(), min_jlong)); 1698 Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), ncmp2)); 1699 return new BoolNode(ncmp, _test._test); 1700 } else if (cmp2_op == Op_AddL && 1701 phase->type(cmp2->in(2)) == TypeLong::MIN && 1702 !is_cloop_condition(this)) { 1703 Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), cmp2->in(1))); 1704 return new BoolNode(ncmp, _test._test); 1705 } 1706 } 1707 1708 // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)". 1709 // The XOR-1 is an idiom used to flip the sense of a bool. We flip the 1710 // test instead. 1711 const TypeInt* cmp2_type = phase->type(cmp2)->isa_int(); 1712 if (cmp2_type == nullptr) return nullptr; 1713 Node* j_xor = cmp1; 1714 if( cmp2_type == TypeInt::ZERO && 1715 cmp1_op == Op_XorI && 1716 j_xor->in(1) != j_xor && // An xor of itself is dead 1717 phase->type( j_xor->in(1) ) == TypeInt::BOOL && 1718 phase->type( j_xor->in(2) ) == TypeInt::ONE && 1719 (_test._test == BoolTest::eq || 1720 _test._test == BoolTest::ne) ) { 1721 Node *ncmp = phase->transform(new CmpINode(j_xor->in(1),cmp2)); 1722 return new BoolNode( ncmp, _test.negate() ); 1723 } 1724 1725 // Change ((x & (m - 1)) u< m) into (m > 0) 1726 // This is the off-by-one variant of ((x & m) u<= m) 1727 if (cop == Op_CmpU && 1728 _test._test == BoolTest::lt && 1729 cmp1_op == Op_AndI) { 1730 Node* l = cmp1->in(1); 1731 Node* r = cmp1->in(2); 1732 for (int repeat = 0; repeat < 2; repeat++) { 1733 bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 && 1734 r->in(1) == cmp2; 1735 if (match) { 1736 // arraylength known to be non-negative, so a (arraylength != 0) is sufficient, 1737 // but to be compatible with the array range check pattern, use (arraylength u> 0) 1738 Node* ncmp = cmp2->Opcode() == Op_LoadRange 1739 ? phase->transform(new CmpUNode(cmp2, phase->intcon(0))) 1740 : phase->transform(new CmpINode(cmp2, phase->intcon(0))); 1741 return new BoolNode(ncmp, BoolTest::gt); 1742 } else { 1743 // commute and try again 1744 l = cmp1->in(2); 1745 r = cmp1->in(1); 1746 } 1747 } 1748 } 1749 1750 // Change x u< 1 or x u<= 0 to x == 0 1751 // and x u> 0 or u>= 1 to x != 0 1752 if (cop == Op_CmpU && 1753 cmp1_op != Op_LoadRange && 1754 (((_test._test == BoolTest::lt || _test._test == BoolTest::ge) && 1755 cmp2->find_int_con(-1) == 1) || 1756 ((_test._test == BoolTest::le || _test._test == BoolTest::gt) && 1757 cmp2->find_int_con(-1) == 0))) { 1758 Node* ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0))); 1759 return new BoolNode(ncmp, _test.is_less() ? BoolTest::eq : BoolTest::ne); 1760 } 1761 1762 // Change (arraylength <= 0) or (arraylength == 0) 1763 // into (arraylength u<= 0) 1764 // Also change (arraylength != 0) into (arraylength u> 0) 1765 // The latter version matches the code pattern generated for 1766 // array range checks, which will more likely be optimized later. 1767 if (cop == Op_CmpI && 1768 cmp1_op == Op_LoadRange && 1769 cmp2->find_int_con(-1) == 0) { 1770 if (_test._test == BoolTest::le || _test._test == BoolTest::eq) { 1771 Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2)); 1772 return new BoolNode(ncmp, BoolTest::le); 1773 } else if (_test._test == BoolTest::ne) { 1774 Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2)); 1775 return new BoolNode(ncmp, BoolTest::gt); 1776 } 1777 } 1778 1779 // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)". 1780 // This is a standard idiom for branching on a boolean value. 1781 Node *c2b = cmp1; 1782 if( cmp2_type == TypeInt::ZERO && 1783 cmp1_op == Op_Conv2B && 1784 (_test._test == BoolTest::eq || 1785 _test._test == BoolTest::ne) ) { 1786 Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int() 1787 ? (Node*)new CmpINode(c2b->in(1),cmp2) 1788 : (Node*)new CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR)) 1789 ); 1790 return new BoolNode( ncmp, _test._test ); 1791 } 1792 1793 // Comparing a SubI against a zero is equal to comparing the SubI 1794 // arguments directly. This only works for eq and ne comparisons 1795 // due to possible integer overflow. 1796 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1797 (cop == Op_CmpI) && 1798 (cmp1_op == Op_SubI) && 1799 ( cmp2_type == TypeInt::ZERO ) ) { 1800 Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2))); 1801 return new BoolNode( ncmp, _test._test ); 1802 } 1803 1804 // Same as above but with and AddI of a constant 1805 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1806 cop == Op_CmpI && 1807 cmp1_op == Op_AddI && 1808 cmp1->in(2) != nullptr && 1809 phase->type(cmp1->in(2))->isa_int() && 1810 phase->type(cmp1->in(2))->is_int()->is_con() && 1811 cmp2_type == TypeInt::ZERO && 1812 !is_counted_loop_cmp(cmp) // modifying the exit test of a counted loop messes the counted loop shape 1813 ) { 1814 const TypeInt* cmp1_in2 = phase->type(cmp1->in(2))->is_int(); 1815 Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),phase->intcon(-cmp1_in2->_hi))); 1816 return new BoolNode( ncmp, _test._test ); 1817 } 1818 1819 // Change "bool eq/ne (cmp (phi (X -X) 0))" into "bool eq/ne (cmp X 0)" 1820 // since zero check of conditional negation of an integer is equal to 1821 // zero check of the integer directly. 1822 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1823 (cop == Op_CmpI) && 1824 (cmp2_type == TypeInt::ZERO) && 1825 (cmp1_op == Op_Phi)) { 1826 // There should be a diamond phi with true path at index 1 or 2 1827 PhiNode *phi = cmp1->as_Phi(); 1828 int idx_true = phi->is_diamond_phi(); 1829 if (idx_true != 0) { 1830 // True input is in(idx_true) while false input is in(3 - idx_true) 1831 Node *tin = phi->in(idx_true); 1832 Node *fin = phi->in(3 - idx_true); 1833 if ((tin->Opcode() == Op_SubI) && 1834 (phase->type(tin->in(1)) == TypeInt::ZERO) && 1835 (tin->in(2) == fin)) { 1836 // Found conditional negation at true path, create a new CmpINode without that 1837 Node *ncmp = phase->transform(new CmpINode(fin, cmp2)); 1838 return new BoolNode(ncmp, _test._test); 1839 } 1840 if ((fin->Opcode() == Op_SubI) && 1841 (phase->type(fin->in(1)) == TypeInt::ZERO) && 1842 (fin->in(2) == tin)) { 1843 // Found conditional negation at false path, create a new CmpINode without that 1844 Node *ncmp = phase->transform(new CmpINode(tin, cmp2)); 1845 return new BoolNode(ncmp, _test._test); 1846 } 1847 } 1848 } 1849 1850 // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the 1851 // most general case because negating 0x80000000 does nothing. Needed for 1852 // the CmpF3/SubI/CmpI idiom. 1853 if( cop == Op_CmpI && 1854 cmp1_op == Op_SubI && 1855 cmp2_type == TypeInt::ZERO && 1856 phase->type( cmp1->in(1) ) == TypeInt::ZERO && 1857 phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) { 1858 Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2)); 1859 return new BoolNode( ncmp, _test.commute() ); 1860 } 1861 1862 // Try to optimize signed integer comparison 1863 return fold_cmpI(phase, cmp->as_Sub(), cmp1, cop, cmp1_op, cmp2_type); 1864 1865 // The transformation below is not valid for either signed or unsigned 1866 // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE. 1867 // This transformation can be resurrected when we are able to 1868 // make inferences about the range of values being subtracted from 1869 // (or added to) relative to the wraparound point. 1870 // 1871 // // Remove +/-1's if possible. 1872 // // "X <= Y-1" becomes "X < Y" 1873 // // "X+1 <= Y" becomes "X < Y" 1874 // // "X < Y+1" becomes "X <= Y" 1875 // // "X-1 < Y" becomes "X <= Y" 1876 // // Do not this to compares off of the counted-loop-end. These guys are 1877 // // checking the trip counter and they want to use the post-incremented 1878 // // counter. If they use the PRE-incremented counter, then the counter has 1879 // // to be incremented in a private block on a loop backedge. 1880 // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd ) 1881 // return nullptr; 1882 // #ifndef PRODUCT 1883 // // Do not do this in a wash GVN pass during verification. 1884 // // Gets triggered by too many simple optimizations to be bothered with 1885 // // re-trying it again and again. 1886 // if( !phase->allow_progress() ) return nullptr; 1887 // #endif 1888 // // Not valid for unsigned compare because of corner cases in involving zero. 1889 // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an 1890 // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but 1891 // // "0 <=u Y" is always true). 1892 // if( cmp->Opcode() == Op_CmpU ) return nullptr; 1893 // int cmp2_op = cmp2->Opcode(); 1894 // if( _test._test == BoolTest::le ) { 1895 // if( cmp1_op == Op_AddI && 1896 // phase->type( cmp1->in(2) ) == TypeInt::ONE ) 1897 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt ); 1898 // else if( cmp2_op == Op_AddI && 1899 // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 ) 1900 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt ); 1901 // } else if( _test._test == BoolTest::lt ) { 1902 // if( cmp1_op == Op_AddI && 1903 // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 ) 1904 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le ); 1905 // else if( cmp2_op == Op_AddI && 1906 // phase->type( cmp2->in(2) ) == TypeInt::ONE ) 1907 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le ); 1908 // } 1909 } 1910 1911 //------------------------------Value------------------------------------------ 1912 // Change ((x & m) u<= m) or ((m & x) u<= m) to always true 1913 // Same with ((x & m) u< m+1) and ((m & x) u< m+1) 1914 const Type* BoolNode::Value_cmpu_and_mask(PhaseValues* phase) const { 1915 Node* cmp = in(1); 1916 if (cmp != nullptr && cmp->Opcode() == Op_CmpU) { 1917 Node* cmp1 = cmp->in(1); 1918 Node* cmp2 = cmp->in(2); 1919 1920 if (cmp1->Opcode() == Op_AndI) { 1921 Node* bound = nullptr; 1922 if (_test._test == BoolTest::le) { 1923 bound = cmp2; 1924 } else if (_test._test == BoolTest::lt && cmp2->Opcode() == Op_AddI && cmp2->in(2)->find_int_con(0) == 1) { 1925 bound = cmp2->in(1); 1926 } 1927 1928 if (cmp1->in(2) == bound || cmp1->in(1) == bound) { 1929 return TypeInt::ONE; 1930 } 1931 } 1932 } 1933 1934 return nullptr; 1935 } 1936 1937 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node, 1938 // based on local information. If the input is constant, do it. 1939 const Type* BoolNode::Value(PhaseGVN* phase) const { 1940 const Type* t = Value_cmpu_and_mask(phase); 1941 if (t != nullptr) { 1942 return t; 1943 } 1944 1945 return _test.cc2logical( phase->type( in(1) ) ); 1946 } 1947 1948 #ifndef PRODUCT 1949 //------------------------------dump_spec-------------------------------------- 1950 // Dump special per-node info 1951 void BoolNode::dump_spec(outputStream *st) const { 1952 st->print("["); 1953 _test.dump_on(st); 1954 st->print("]"); 1955 } 1956 #endif 1957 1958 //----------------------is_counted_loop_exit_test------------------------------ 1959 // Returns true if node is used by a counted loop node. 1960 bool BoolNode::is_counted_loop_exit_test() { 1961 for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { 1962 Node* use = fast_out(i); 1963 if (use->is_CountedLoopEnd()) { 1964 return true; 1965 } 1966 } 1967 return false; 1968 } 1969 1970 //============================================================================= 1971 //------------------------------Value------------------------------------------ 1972 const Type* AbsNode::Value(PhaseGVN* phase) const { 1973 const Type* t1 = phase->type(in(1)); 1974 if (t1 == Type::TOP) return Type::TOP; 1975 1976 switch (t1->base()) { 1977 case Type::Int: { 1978 const TypeInt* ti = t1->is_int(); 1979 if (ti->is_con()) { 1980 return TypeInt::make(uabs(ti->get_con())); 1981 } 1982 break; 1983 } 1984 case Type::Long: { 1985 const TypeLong* tl = t1->is_long(); 1986 if (tl->is_con()) { 1987 return TypeLong::make(uabs(tl->get_con())); 1988 } 1989 break; 1990 } 1991 case Type::FloatCon: 1992 return TypeF::make(abs(t1->getf())); 1993 case Type::DoubleCon: 1994 return TypeD::make(abs(t1->getd())); 1995 default: 1996 break; 1997 } 1998 1999 return bottom_type(); 2000 } 2001 2002 //------------------------------Identity---------------------------------------- 2003 Node* AbsNode::Identity(PhaseGVN* phase) { 2004 Node* in1 = in(1); 2005 // No need to do abs for non-negative values 2006 if (phase->type(in1)->higher_equal(TypeInt::POS) || 2007 phase->type(in1)->higher_equal(TypeLong::POS)) { 2008 return in1; 2009 } 2010 // Convert "abs(abs(x))" into "abs(x)" 2011 if (in1->Opcode() == Opcode()) { 2012 return in1; 2013 } 2014 return this; 2015 } 2016 2017 //------------------------------Ideal------------------------------------------ 2018 Node* AbsNode::Ideal(PhaseGVN* phase, bool can_reshape) { 2019 Node* in1 = in(1); 2020 // Convert "abs(0-x)" into "abs(x)" 2021 if (in1->is_Sub() && phase->type(in1->in(1))->is_zero_type()) { 2022 set_req_X(1, in1->in(2), phase); 2023 return this; 2024 } 2025 return nullptr; 2026 } 2027 2028 //============================================================================= 2029 //------------------------------Value------------------------------------------ 2030 // Compute sqrt 2031 const Type* SqrtDNode::Value(PhaseGVN* phase) const { 2032 const Type *t1 = phase->type( in(1) ); 2033 if( t1 == Type::TOP ) return Type::TOP; 2034 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 2035 double d = t1->getd(); 2036 if( d < 0.0 ) return Type::DOUBLE; 2037 return TypeD::make( sqrt( d ) ); 2038 } 2039 2040 const Type* SqrtFNode::Value(PhaseGVN* phase) const { 2041 const Type *t1 = phase->type( in(1) ); 2042 if( t1 == Type::TOP ) return Type::TOP; 2043 if( t1->base() != Type::FloatCon ) return Type::FLOAT; 2044 float f = t1->getf(); 2045 if( f < 0.0f ) return Type::FLOAT; 2046 return TypeF::make( (float)sqrt( (double)f ) ); 2047 } 2048 2049 const Type* ReverseINode::Value(PhaseGVN* phase) const { 2050 const Type *t1 = phase->type( in(1) ); 2051 if (t1 == Type::TOP) { 2052 return Type::TOP; 2053 } 2054 const TypeInt* t1int = t1->isa_int(); 2055 if (t1int && t1int->is_con()) { 2056 jint res = reverse_bits(t1int->get_con()); 2057 return TypeInt::make(res); 2058 } 2059 return bottom_type(); 2060 } 2061 2062 const Type* ReverseLNode::Value(PhaseGVN* phase) const { 2063 const Type *t1 = phase->type( in(1) ); 2064 if (t1 == Type::TOP) { 2065 return Type::TOP; 2066 } 2067 const TypeLong* t1long = t1->isa_long(); 2068 if (t1long && t1long->is_con()) { 2069 jlong res = reverse_bits(t1long->get_con()); 2070 return TypeLong::make(res); 2071 } 2072 return bottom_type(); 2073 } 2074 2075 Node* ReverseINode::Identity(PhaseGVN* phase) { 2076 if (in(1)->Opcode() == Op_ReverseI) { 2077 return in(1)->in(1); 2078 } 2079 return this; 2080 } 2081 2082 Node* ReverseLNode::Identity(PhaseGVN* phase) { 2083 if (in(1)->Opcode() == Op_ReverseL) { 2084 return in(1)->in(1); 2085 } 2086 return this; 2087 }