1 /* 2 * Copyright (c) 1997, 2015, 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 "memory/allocation.inline.hpp" 28 #include "opto/addnode.hpp" 29 #include "opto/callnode.hpp" 30 #include "opto/cfgnode.hpp" 31 #include "opto/loopnode.hpp" 32 #include "opto/matcher.hpp" 33 #include "opto/movenode.hpp" 34 #include "opto/mulnode.hpp" 35 #include "opto/opcodes.hpp" 36 #include "opto/phaseX.hpp" 37 #include "opto/subnode.hpp" 38 #include "runtime/sharedRuntime.hpp" 39 40 // Portions of code courtesy of Clifford Click 41 42 // Optimization - Graph Style 43 44 #include "math.h" 45 46 //============================================================================= 47 //------------------------------Identity--------------------------------------- 48 // If right input is a constant 0, return the left input. 49 Node* SubNode::Identity(PhaseGVN* phase) { 50 assert(in(1) != this, "Must already have called Value"); 51 assert(in(2) != this, "Must already have called Value"); 52 53 // Remove double negation 54 const Type *zero = add_id(); 55 if( phase->type( in(1) )->higher_equal( zero ) && 56 in(2)->Opcode() == Opcode() && 57 phase->type( in(2)->in(1) )->higher_equal( zero ) ) { 58 return in(2)->in(2); 59 } 60 61 // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y 62 if( in(1)->Opcode() == Op_AddI ) { 63 if( phase->eqv(in(1)->in(2),in(2)) ) 64 return in(1)->in(1); 65 if (phase->eqv(in(1)->in(1),in(2))) 66 return in(1)->in(2); 67 68 // Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying 69 // trip counter and X is likely to be loop-invariant (that's how O2 Nodes 70 // are originally used, although the optimizer sometimes jiggers things). 71 // This folding through an O2 removes a loop-exit use of a loop-varying 72 // value and generally lowers register pressure in and around the loop. 73 if( in(1)->in(2)->Opcode() == Op_Opaque2 && 74 phase->eqv(in(1)->in(2)->in(1),in(2)) ) 75 return in(1)->in(1); 76 } 77 78 return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this; 79 } 80 81 //------------------------------Value------------------------------------------ 82 // A subtract node differences it's two inputs. 83 const Type* SubNode::Value_common(PhaseTransform *phase) const { 84 const Node* in1 = in(1); 85 const Node* in2 = in(2); 86 // Either input is TOP ==> the result is TOP 87 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 88 if( t1 == Type::TOP ) return Type::TOP; 89 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 90 if( t2 == Type::TOP ) return Type::TOP; 91 92 // Not correct for SubFnode and AddFNode (must check for infinity) 93 // Equal? Subtract is zero 94 if (in1->eqv_uncast(in2)) return add_id(); 95 96 // Either input is BOTTOM ==> the result is the local BOTTOM 97 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM ) 98 return bottom_type(); 99 100 return NULL; 101 } 102 103 const Type* SubNode::Value(PhaseGVN* phase) const { 104 const Type* t = Value_common(phase); 105 if (t != NULL) { 106 return t; 107 } 108 const Type* t1 = phase->type(in(1)); 109 const Type* t2 = phase->type(in(2)); 110 return sub(t1,t2); // Local flavor of type subtraction 111 112 } 113 114 SubNode* SubNode::make(BasicType bt, Node *in1, Node *in2) { 115 switch(bt) { 116 case T_INT: return new SubINode(in1, in2); 117 case T_LONG: return new SubLNode(in1, in2); 118 case T_FLOAT: return new SubFNode(in1, in2); 119 case T_DOUBLE: return new SubDNode(in1, in2); 120 } 121 fatal("Bad basic type %s", type2name(bt)); 122 return NULL; 123 } 124 125 //============================================================================= 126 127 //------------------------------Helper function-------------------------------- 128 static bool ok_to_convert(Node* inc, Node* iv) { 129 // Do not collapse (x+c0)-y if "+" is a loop increment, because the 130 // "-" is loop invariant and collapsing extends the live-range of "x" 131 // to overlap with the "+", forcing another register to be used in 132 // the loop. 133 // This test will be clearer with '&&' (apply DeMorgan's rule) 134 // but I like the early cutouts that happen here. 135 const PhiNode *phi; 136 if( ( !inc->in(1)->is_Phi() || 137 !(phi=inc->in(1)->as_Phi()) || 138 phi->is_copy() || 139 !phi->region()->is_CountedLoop() || 140 inc != phi->region()->as_CountedLoop()->incr() ) 141 && 142 // Do not collapse (x+c0)-iv if "iv" is a loop induction variable, 143 // because "x" maybe invariant. 144 ( !iv->is_loop_iv() ) 145 ) { 146 return true; 147 } else { 148 return false; 149 } 150 } 151 //------------------------------Ideal------------------------------------------ 152 Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){ 153 Node *in1 = in(1); 154 Node *in2 = in(2); 155 uint op1 = in1->Opcode(); 156 uint op2 = in2->Opcode(); 157 158 #ifdef ASSERT 159 // Check for dead loop 160 if( phase->eqv( in1, this ) || phase->eqv( in2, this ) || 161 ( op1 == Op_AddI || op1 == Op_SubI ) && 162 ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) || 163 phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) ) 164 assert(false, "dead loop in SubINode::Ideal"); 165 #endif 166 167 const Type *t2 = phase->type( in2 ); 168 if( t2 == Type::TOP ) return NULL; 169 // Convert "x-c0" into "x+ -c0". 170 if( t2->base() == Type::Int ){ // Might be bottom or top... 171 const TypeInt *i = t2->is_int(); 172 if( i->is_con() ) 173 return new AddINode(in1, phase->intcon(-i->get_con())); 174 } 175 176 // Convert "(x+c0) - y" into (x-y) + c0" 177 // Do not collapse (x+c0)-y if "+" is a loop increment or 178 // if "y" is a loop induction variable. 179 if( op1 == Op_AddI && ok_to_convert(in1, in2) ) { 180 const Type *tadd = phase->type( in1->in(2) ); 181 if( tadd->singleton() && tadd != Type::TOP ) { 182 Node *sub2 = phase->transform( new SubINode( in1->in(1), in2 )); 183 return new AddINode( sub2, in1->in(2) ); 184 } 185 } 186 187 188 // Convert "x - (y+c0)" into "(x-y) - c0" 189 // Need the same check as in above optimization but reversed. 190 if (op2 == Op_AddI && ok_to_convert(in2, in1)) { 191 Node* in21 = in2->in(1); 192 Node* in22 = in2->in(2); 193 const TypeInt* tcon = phase->type(in22)->isa_int(); 194 if (tcon != NULL && tcon->is_con()) { 195 Node* sub2 = phase->transform( new SubINode(in1, in21) ); 196 Node* neg_c0 = phase->intcon(- tcon->get_con()); 197 return new AddINode(sub2, neg_c0); 198 } 199 } 200 201 const Type *t1 = phase->type( in1 ); 202 if( t1 == Type::TOP ) return NULL; 203 204 #ifdef ASSERT 205 // Check for dead loop 206 if( ( op2 == Op_AddI || op2 == Op_SubI ) && 207 ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) || 208 phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) ) 209 assert(false, "dead loop in SubINode::Ideal"); 210 #endif 211 212 // Convert "x - (x+y)" into "-y" 213 if( op2 == Op_AddI && 214 phase->eqv( in1, in2->in(1) ) ) 215 return new SubINode( phase->intcon(0),in2->in(2)); 216 // Convert "(x-y) - x" into "-y" 217 if( op1 == Op_SubI && 218 phase->eqv( in1->in(1), in2 ) ) 219 return new SubINode( phase->intcon(0),in1->in(2)); 220 // Convert "x - (y+x)" into "-y" 221 if( op2 == Op_AddI && 222 phase->eqv( in1, in2->in(2) ) ) 223 return new SubINode( phase->intcon(0),in2->in(1)); 224 225 // Convert "0 - (x-y)" into "y-x" 226 if( t1 == TypeInt::ZERO && op2 == Op_SubI ) 227 return new SubINode( in2->in(2), in2->in(1) ); 228 229 // Convert "0 - (x+con)" into "-con-x" 230 jint con; 231 if( t1 == TypeInt::ZERO && op2 == Op_AddI && 232 (con = in2->in(2)->find_int_con(0)) != 0 ) 233 return new SubINode( phase->intcon(-con), in2->in(1) ); 234 235 // Convert "(X+A) - (X+B)" into "A - B" 236 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) ) 237 return new SubINode( in1->in(2), in2->in(2) ); 238 239 // Convert "(A+X) - (B+X)" into "A - B" 240 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) ) 241 return new SubINode( in1->in(1), in2->in(1) ); 242 243 // Convert "(A+X) - (X+B)" into "A - B" 244 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) ) 245 return new SubINode( in1->in(1), in2->in(2) ); 246 247 // Convert "(X+A) - (B+X)" into "A - B" 248 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) 249 return new SubINode( in1->in(2), in2->in(1) ); 250 251 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally 252 // nicer to optimize than subtract. 253 if( op2 == Op_SubI && in2->outcnt() == 1) { 254 Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) ); 255 return new SubINode( add1, in2->in(1) ); 256 } 257 258 return NULL; 259 } 260 261 //------------------------------sub-------------------------------------------- 262 // A subtract node differences it's two inputs. 263 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { 264 const TypeInt *r0 = t1->is_int(); // Handy access 265 const TypeInt *r1 = t2->is_int(); 266 int32_t lo = java_subtract(r0->_lo, r1->_hi); 267 int32_t hi = java_subtract(r0->_hi, r1->_lo); 268 269 // We next check for 32-bit overflow. 270 // If that happens, we just assume all integers are possible. 271 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 272 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 273 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 274 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 275 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 276 else // Overflow; assume all integers 277 return TypeInt::INT; 278 } 279 280 //============================================================================= 281 //------------------------------Ideal------------------------------------------ 282 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 283 Node *in1 = in(1); 284 Node *in2 = in(2); 285 uint op1 = in1->Opcode(); 286 uint op2 = in2->Opcode(); 287 288 #ifdef ASSERT 289 // Check for dead loop 290 if( phase->eqv( in1, this ) || phase->eqv( in2, this ) || 291 ( op1 == Op_AddL || op1 == Op_SubL ) && 292 ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) || 293 phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) ) 294 assert(false, "dead loop in SubLNode::Ideal"); 295 #endif 296 297 if( phase->type( in2 ) == Type::TOP ) return NULL; 298 const TypeLong *i = phase->type( in2 )->isa_long(); 299 // Convert "x-c0" into "x+ -c0". 300 if( i && // Might be bottom or top... 301 i->is_con() ) 302 return new AddLNode(in1, phase->longcon(-i->get_con())); 303 304 // Convert "(x+c0) - y" into (x-y) + c0" 305 // Do not collapse (x+c0)-y if "+" is a loop increment or 306 // if "y" is a loop induction variable. 307 if( op1 == Op_AddL && ok_to_convert(in1, in2) ) { 308 Node *in11 = in1->in(1); 309 const Type *tadd = phase->type( in1->in(2) ); 310 if( tadd->singleton() && tadd != Type::TOP ) { 311 Node *sub2 = phase->transform( new SubLNode( in11, in2 )); 312 return new AddLNode( sub2, in1->in(2) ); 313 } 314 } 315 316 // Convert "x - (y+c0)" into "(x-y) - c0" 317 // Need the same check as in above optimization but reversed. 318 if (op2 == Op_AddL && ok_to_convert(in2, in1)) { 319 Node* in21 = in2->in(1); 320 Node* in22 = in2->in(2); 321 const TypeLong* tcon = phase->type(in22)->isa_long(); 322 if (tcon != NULL && tcon->is_con()) { 323 Node* sub2 = phase->transform( new SubLNode(in1, in21) ); 324 Node* neg_c0 = phase->longcon(- tcon->get_con()); 325 return new AddLNode(sub2, neg_c0); 326 } 327 } 328 329 const Type *t1 = phase->type( in1 ); 330 if( t1 == Type::TOP ) return NULL; 331 332 #ifdef ASSERT 333 // Check for dead loop 334 if( ( op2 == Op_AddL || op2 == Op_SubL ) && 335 ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) || 336 phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) ) 337 assert(false, "dead loop in SubLNode::Ideal"); 338 #endif 339 340 // Convert "x - (x+y)" into "-y" 341 if( op2 == Op_AddL && 342 phase->eqv( in1, in2->in(1) ) ) 343 return new SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2)); 344 // Convert "x - (y+x)" into "-y" 345 if( op2 == Op_AddL && 346 phase->eqv( in1, in2->in(2) ) ) 347 return new SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1)); 348 349 // Convert "0 - (x-y)" into "y-x" 350 if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL ) 351 return new SubLNode( in2->in(2), in2->in(1) ); 352 353 // Convert "(X+A) - (X+B)" into "A - B" 354 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) ) 355 return new SubLNode( in1->in(2), in2->in(2) ); 356 357 // Convert "(A+X) - (B+X)" into "A - B" 358 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) ) 359 return new SubLNode( in1->in(1), in2->in(1) ); 360 361 // Convert "A-(B-C)" into (A+C)-B" 362 if( op2 == Op_SubL && in2->outcnt() == 1) { 363 Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) ); 364 return new SubLNode( add1, in2->in(1) ); 365 } 366 367 return NULL; 368 } 369 370 //------------------------------sub-------------------------------------------- 371 // A subtract node differences it's two inputs. 372 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const { 373 const TypeLong *r0 = t1->is_long(); // Handy access 374 const TypeLong *r1 = t2->is_long(); 375 jlong lo = java_subtract(r0->_lo, r1->_hi); 376 jlong hi = java_subtract(r0->_hi, r1->_lo); 377 378 // We next check for 32-bit overflow. 379 // If that happens, we just assume all integers are possible. 380 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 381 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 382 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 383 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 384 return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 385 else // Overflow; assume all integers 386 return TypeLong::LONG; 387 } 388 389 //============================================================================= 390 //------------------------------Value------------------------------------------ 391 // A subtract node differences its two inputs. 392 const Type* SubFPNode::Value(PhaseGVN* phase) const { 393 const Node* in1 = in(1); 394 const Node* in2 = in(2); 395 // Either input is TOP ==> the result is TOP 396 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 397 if( t1 == Type::TOP ) return Type::TOP; 398 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 399 if( t2 == Type::TOP ) return Type::TOP; 400 401 // if both operands are infinity of same sign, the result is NaN; do 402 // not replace with zero 403 if( (t1->is_finite() && t2->is_finite()) ) { 404 if( phase->eqv(in1, in2) ) return add_id(); 405 } 406 407 // Either input is BOTTOM ==> the result is the local BOTTOM 408 const Type *bot = bottom_type(); 409 if( (t1 == bot) || (t2 == bot) || 410 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) 411 return bot; 412 413 return sub(t1,t2); // Local flavor of type subtraction 414 } 415 416 417 //============================================================================= 418 //------------------------------Ideal------------------------------------------ 419 Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) { 420 const Type *t2 = phase->type( in(2) ); 421 // Convert "x-c0" into "x+ -c0". 422 if( t2->base() == Type::FloatCon ) { // Might be bottom or top... 423 // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) ); 424 } 425 426 // Not associative because of boundary conditions (infinity) 427 if( IdealizedNumerics && !phase->C->method()->is_strict() ) { 428 // Convert "x - (x+y)" into "-y" 429 if( in(2)->is_Add() && 430 phase->eqv(in(1),in(2)->in(1) ) ) 431 return new SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2)); 432 } 433 434 // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes 435 // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0. 436 //if( phase->type(in(1)) == TypeF::ZERO ) 437 //return new (phase->C, 2) NegFNode(in(2)); 438 439 return NULL; 440 } 441 442 //------------------------------sub-------------------------------------------- 443 // A subtract node differences its two inputs. 444 const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const { 445 // no folding if one of operands is infinity or NaN, do not do constant folding 446 if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) { 447 return TypeF::make( t1->getf() - t2->getf() ); 448 } 449 else if( g_isnan(t1->getf()) ) { 450 return t1; 451 } 452 else if( g_isnan(t2->getf()) ) { 453 return t2; 454 } 455 else { 456 return Type::FLOAT; 457 } 458 } 459 460 //============================================================================= 461 //------------------------------Ideal------------------------------------------ 462 Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){ 463 const Type *t2 = phase->type( in(2) ); 464 // Convert "x-c0" into "x+ -c0". 465 if( t2->base() == Type::DoubleCon ) { // Might be bottom or top... 466 // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) ); 467 } 468 469 // Not associative because of boundary conditions (infinity) 470 if( IdealizedNumerics && !phase->C->method()->is_strict() ) { 471 // Convert "x - (x+y)" into "-y" 472 if( in(2)->is_Add() && 473 phase->eqv(in(1),in(2)->in(1) ) ) 474 return new SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2)); 475 } 476 477 // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes 478 // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0. 479 //if( phase->type(in(1)) == TypeD::ZERO ) 480 //return new (phase->C, 2) NegDNode(in(2)); 481 482 return NULL; 483 } 484 485 //------------------------------sub-------------------------------------------- 486 // A subtract node differences its two inputs. 487 const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const { 488 // no folding if one of operands is infinity or NaN, do not do constant folding 489 if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) { 490 return TypeD::make( t1->getd() - t2->getd() ); 491 } 492 else if( g_isnan(t1->getd()) ) { 493 return t1; 494 } 495 else if( g_isnan(t2->getd()) ) { 496 return t2; 497 } 498 else { 499 return Type::DOUBLE; 500 } 501 } 502 503 //============================================================================= 504 //------------------------------Idealize--------------------------------------- 505 // Unlike SubNodes, compare must still flatten return value to the 506 // range -1, 0, 1. 507 // And optimizations like those for (X + Y) - X fail if overflow happens. 508 Node* CmpNode::Identity(PhaseGVN* phase) { 509 return this; 510 } 511 512 #ifndef PRODUCT 513 //----------------------------related------------------------------------------ 514 // Related nodes of comparison nodes include all data inputs (until hitting a 515 // control boundary) as well as all outputs until and including control nodes 516 // as well as their projections. In compact mode, data inputs till depth 1 and 517 // all outputs till depth 1 are considered. 518 void CmpNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const { 519 if (compact) { 520 this->collect_nodes(in_rel, 1, false, true); 521 this->collect_nodes(out_rel, -1, false, false); 522 } else { 523 this->collect_nodes_in_all_data(in_rel, false); 524 this->collect_nodes_out_all_ctrl_boundary(out_rel); 525 // Now, find all control nodes in out_rel, and include their projections 526 // and projection targets (if any) in the result. 527 GrowableArray<Node*> proj(Compile::current()->unique()); 528 for (GrowableArrayIterator<Node*> it = out_rel->begin(); it != out_rel->end(); ++it) { 529 Node* n = *it; 530 if (n->is_CFG() && !n->is_Proj()) { 531 // Assume projections and projection targets are found at levels 1 and 2. 532 n->collect_nodes(&proj, -2, false, false); 533 for (GrowableArrayIterator<Node*> p = proj.begin(); p != proj.end(); ++p) { 534 out_rel->append_if_missing(*p); 535 } 536 proj.clear(); 537 } 538 } 539 } 540 } 541 #endif 542 543 //============================================================================= 544 //------------------------------cmp-------------------------------------------- 545 // Simplify a CmpI (compare 2 integers) node, based on local information. 546 // If both inputs are constants, compare them. 547 const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const { 548 const TypeInt *r0 = t1->is_int(); // Handy access 549 const TypeInt *r1 = t2->is_int(); 550 551 if( r0->_hi < r1->_lo ) // Range is always low? 552 return TypeInt::CC_LT; 553 else if( r0->_lo > r1->_hi ) // Range is always high? 554 return TypeInt::CC_GT; 555 556 else if( r0->is_con() && r1->is_con() ) { // comparing constants? 557 assert(r0->get_con() == r1->get_con(), "must be equal"); 558 return TypeInt::CC_EQ; // Equal results. 559 } else if( r0->_hi == r1->_lo ) // Range is never high? 560 return TypeInt::CC_LE; 561 else if( r0->_lo == r1->_hi ) // Range is never low? 562 return TypeInt::CC_GE; 563 return TypeInt::CC; // else use worst case results 564 } 565 566 // Simplify a CmpU (compare 2 integers) node, based on local information. 567 // If both inputs are constants, compare them. 568 const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { 569 assert(!t1->isa_ptr(), "obsolete usage of CmpU"); 570 571 // comparing two unsigned ints 572 const TypeInt *r0 = t1->is_int(); // Handy access 573 const TypeInt *r1 = t2->is_int(); 574 575 // Current installed version 576 // Compare ranges for non-overlap 577 juint lo0 = r0->_lo; 578 juint hi0 = r0->_hi; 579 juint lo1 = r1->_lo; 580 juint hi1 = r1->_hi; 581 582 // If either one has both negative and positive values, 583 // it therefore contains both 0 and -1, and since [0..-1] is the 584 // full unsigned range, the type must act as an unsigned bottom. 585 bool bot0 = ((jint)(lo0 ^ hi0) < 0); 586 bool bot1 = ((jint)(lo1 ^ hi1) < 0); 587 588 if (bot0 || bot1) { 589 // All unsigned values are LE -1 and GE 0. 590 if (lo0 == 0 && hi0 == 0) { 591 return TypeInt::CC_LE; // 0 <= bot 592 } else if (lo1 == 0 && hi1 == 0) { 593 return TypeInt::CC_GE; // bot >= 0 594 } 595 } else { 596 // We can use ranges of the form [lo..hi] if signs are the same. 597 assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); 598 // results are reversed, '-' > '+' for unsigned compare 599 if (hi0 < lo1) { 600 return TypeInt::CC_LT; // smaller 601 } else if (lo0 > hi1) { 602 return TypeInt::CC_GT; // greater 603 } else if (hi0 == lo1 && lo0 == hi1) { 604 return TypeInt::CC_EQ; // Equal results 605 } else if (lo0 >= hi1) { 606 return TypeInt::CC_GE; 607 } else if (hi0 <= lo1) { 608 // Check for special case in Hashtable::get. (See below.) 609 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) 610 return TypeInt::CC_LT; 611 return TypeInt::CC_LE; 612 } 613 } 614 // Check for special case in Hashtable::get - the hash index is 615 // mod'ed to the table size so the following range check is useless. 616 // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have 617 // to be positive. 618 // (This is a gross hack, since the sub method never 619 // looks at the structure of the node in any other case.) 620 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) 621 return TypeInt::CC_LT; 622 return TypeInt::CC; // else use worst case results 623 } 624 625 const Type* CmpUNode::Value(PhaseGVN* phase) const { 626 const Type* t = SubNode::Value_common(phase); 627 if (t != NULL) { 628 return t; 629 } 630 const Node* in1 = in(1); 631 const Node* in2 = in(2); 632 const Type* t1 = phase->type(in1); 633 const Type* t2 = phase->type(in2); 634 assert(t1->isa_int(), "CmpU has only Int type inputs"); 635 if (t2 == TypeInt::INT) { // Compare to bottom? 636 return bottom_type(); 637 } 638 uint in1_op = in1->Opcode(); 639 if (in1_op == Op_AddI || in1_op == Op_SubI) { 640 // The problem rise when result of AddI(SubI) may overflow 641 // signed integer value. Let say the input type is 642 // [256, maxint] then +128 will create 2 ranges due to 643 // overflow: [minint, minint+127] and [384, maxint]. 644 // But C2 type system keep only 1 type range and as result 645 // it use general [minint, maxint] for this case which we 646 // can't optimize. 647 // 648 // Make 2 separate type ranges based on types of AddI(SubI) inputs 649 // and compare results of their compare. If results are the same 650 // CmpU node can be optimized. 651 const Node* in11 = in1->in(1); 652 const Node* in12 = in1->in(2); 653 const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11); 654 const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12); 655 // Skip cases when input types are top or bottom. 656 if ((t11 != Type::TOP) && (t11 != TypeInt::INT) && 657 (t12 != Type::TOP) && (t12 != TypeInt::INT)) { 658 const TypeInt *r0 = t11->is_int(); 659 const TypeInt *r1 = t12->is_int(); 660 jlong lo_r0 = r0->_lo; 661 jlong hi_r0 = r0->_hi; 662 jlong lo_r1 = r1->_lo; 663 jlong hi_r1 = r1->_hi; 664 if (in1_op == Op_SubI) { 665 jlong tmp = hi_r1; 666 hi_r1 = -lo_r1; 667 lo_r1 = -tmp; 668 // Note, for substructing [minint,x] type range 669 // long arithmetic provides correct overflow answer. 670 // The confusion come from the fact that in 32-bit 671 // -minint == minint but in 64-bit -minint == maxint+1. 672 } 673 jlong lo_long = lo_r0 + lo_r1; 674 jlong hi_long = hi_r0 + hi_r1; 675 int lo_tr1 = min_jint; 676 int hi_tr1 = (int)hi_long; 677 int lo_tr2 = (int)lo_long; 678 int hi_tr2 = max_jint; 679 bool underflow = lo_long != (jlong)lo_tr2; 680 bool overflow = hi_long != (jlong)hi_tr1; 681 // Use sub(t1, t2) when there is no overflow (one type range) 682 // or when both overflow and underflow (too complex). 683 if ((underflow != overflow) && (hi_tr1 < lo_tr2)) { 684 // Overflow only on one boundary, compare 2 separate type ranges. 685 int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here 686 const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w); 687 const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w); 688 const Type* cmp1 = sub(tr1, t2); 689 const Type* cmp2 = sub(tr2, t2); 690 if (cmp1 == cmp2) { 691 return cmp1; // Hit! 692 } 693 } 694 } 695 } 696 697 return sub(t1, t2); // Local flavor of type subtraction 698 } 699 700 bool CmpUNode::is_index_range_check() const { 701 // Check for the "(X ModI Y) CmpU Y" shape 702 return (in(1)->Opcode() == Op_ModI && 703 in(1)->in(2)->eqv_uncast(in(2))); 704 } 705 706 //------------------------------Idealize--------------------------------------- 707 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) { 708 if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) { 709 switch (in(1)->Opcode()) { 710 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL 711 return new CmpLNode(in(1)->in(1),in(1)->in(2)); 712 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF 713 return new CmpFNode(in(1)->in(1),in(1)->in(2)); 714 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD 715 return new CmpDNode(in(1)->in(1),in(1)->in(2)); 716 //case Op_SubI: 717 // If (x - y) cannot overflow, then ((x - y) <?> 0) 718 // can be turned into (x <?> y). 719 // This is handled (with more general cases) by Ideal_sub_algebra. 720 } 721 } 722 return NULL; // No change 723 } 724 725 726 //============================================================================= 727 // Simplify a CmpL (compare 2 longs ) node, based on local information. 728 // If both inputs are constants, compare them. 729 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { 730 const TypeLong *r0 = t1->is_long(); // Handy access 731 const TypeLong *r1 = t2->is_long(); 732 733 if( r0->_hi < r1->_lo ) // Range is always low? 734 return TypeInt::CC_LT; 735 else if( r0->_lo > r1->_hi ) // Range is always high? 736 return TypeInt::CC_GT; 737 738 else if( r0->is_con() && r1->is_con() ) { // comparing constants? 739 assert(r0->get_con() == r1->get_con(), "must be equal"); 740 return TypeInt::CC_EQ; // Equal results. 741 } else if( r0->_hi == r1->_lo ) // Range is never high? 742 return TypeInt::CC_LE; 743 else if( r0->_lo == r1->_hi ) // Range is never low? 744 return TypeInt::CC_GE; 745 return TypeInt::CC; // else use worst case results 746 } 747 748 //============================================================================= 749 //------------------------------sub-------------------------------------------- 750 // Simplify an CmpP (compare 2 pointers) node, based on local information. 751 // If both inputs are constants, compare them. 752 const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { 753 const TypePtr *r0 = t1->is_ptr(); // Handy access 754 const TypePtr *r1 = t2->is_ptr(); 755 756 // Undefined inputs makes for an undefined result 757 if( TypePtr::above_centerline(r0->_ptr) || 758 TypePtr::above_centerline(r1->_ptr) ) 759 return Type::TOP; 760 761 if (r0 == r1 && r0->singleton()) { 762 // Equal pointer constants (klasses, nulls, etc.) 763 return TypeInt::CC_EQ; 764 } 765 766 // See if it is 2 unrelated classes. 767 const TypeOopPtr* p0 = r0->isa_oopptr(); 768 const TypeOopPtr* p1 = r1->isa_oopptr(); 769 if (p0 && p1) { 770 Node* in1 = in(1)->uncast(); 771 Node* in2 = in(2)->uncast(); 772 AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL); 773 AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL); 774 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) { 775 return TypeInt::CC_GT; // different pointers 776 } 777 ciKlass* klass0 = p0->klass(); 778 bool xklass0 = p0->klass_is_exact(); 779 ciKlass* klass1 = p1->klass(); 780 bool xklass1 = p1->klass_is_exact(); 781 int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0); 782 if (klass0 && klass1 && 783 kps != 1 && // both or neither are klass pointers 784 klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces 785 klass1->is_loaded() && !klass1->is_interface() && 786 (!klass0->is_obj_array_klass() || 787 !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) && 788 (!klass1->is_obj_array_klass() || 789 !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) { 790 bool unrelated_classes = false; 791 // See if neither subclasses the other, or if the class on top 792 // is precise. In either of these cases, the compare is known 793 // to fail if at least one of the pointers is provably not null. 794 if (klass0->equals(klass1)) { // if types are unequal but klasses are equal 795 // Do nothing; we know nothing for imprecise types 796 } else if (klass0->is_subtype_of(klass1)) { 797 // If klass1's type is PRECISE, then classes are unrelated. 798 unrelated_classes = xklass1; 799 } else if (klass1->is_subtype_of(klass0)) { 800 // If klass0's type is PRECISE, then classes are unrelated. 801 unrelated_classes = xklass0; 802 } else { // Neither subtypes the other 803 unrelated_classes = true; 804 } 805 if (unrelated_classes) { 806 // The oops classes are known to be unrelated. If the joined PTRs of 807 // two oops is not Null and not Bottom, then we are sure that one 808 // of the two oops is non-null, and the comparison will always fail. 809 TypePtr::PTR jp = r0->join_ptr(r1->_ptr); 810 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { 811 return TypeInt::CC_GT; 812 } 813 } 814 } 815 } 816 817 // Known constants can be compared exactly 818 // Null can be distinguished from any NotNull pointers 819 // Unknown inputs makes an unknown result 820 if( r0->singleton() ) { 821 intptr_t bits0 = r0->get_con(); 822 if( r1->singleton() ) 823 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; 824 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; 825 } else if( r1->singleton() ) { 826 intptr_t bits1 = r1->get_con(); 827 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; 828 } else 829 return TypeInt::CC; 830 } 831 832 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) { 833 // Return the klass node for 834 // LoadP(AddP(foo:Klass, #java_mirror)) 835 // or NULL if not matching. 836 if (n->Opcode() != Op_LoadP) return NULL; 837 838 const TypeInstPtr* tp = phase->type(n)->isa_instptr(); 839 if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL; 840 841 Node* adr = n->in(MemNode::Address); 842 intptr_t off = 0; 843 Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off); 844 if (k == NULL) return NULL; 845 const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr(); 846 if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL; 847 848 // We've found the klass node of a Java mirror load. 849 return k; 850 } 851 852 static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) { 853 // for ConP(Foo.class) return ConP(Foo.klass) 854 // otherwise return NULL 855 if (!n->is_Con()) return NULL; 856 857 const TypeInstPtr* tp = phase->type(n)->isa_instptr(); 858 if (!tp) return NULL; 859 860 ciType* mirror_type = tp->java_mirror_type(); 861 // TypeInstPtr::java_mirror_type() returns non-NULL for compile- 862 // time Class constants only. 863 if (!mirror_type) return NULL; 864 865 // x.getClass() == int.class can never be true (for all primitive types) 866 // Return a ConP(NULL) node for this case. 867 if (mirror_type->is_classless()) { 868 return phase->makecon(TypePtr::NULL_PTR); 869 } 870 871 // return the ConP(Foo.klass) 872 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*"); 873 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass())); 874 } 875 876 //------------------------------Ideal------------------------------------------ 877 // Normalize comparisons between Java mirror loads to compare the klass instead. 878 // 879 // Also check for the case of comparing an unknown klass loaded from the primary 880 // super-type array vs a known klass with no subtypes. This amounts to 881 // checking to see an unknown klass subtypes a known klass with no subtypes; 882 // this only happens on an exact match. We can shorten this test by 1 load. 883 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) { 884 // Normalize comparisons between Java mirrors into comparisons of the low- 885 // level klass, where a dependent load could be shortened. 886 // 887 // The new pattern has a nice effect of matching the same pattern used in the 888 // fast path of instanceof/checkcast/Class.isInstance(), which allows 889 // redundant exact type check be optimized away by GVN. 890 // For example, in 891 // if (x.getClass() == Foo.class) { 892 // Foo foo = (Foo) x; 893 // // ... use a ... 894 // } 895 // a CmpPNode could be shared between if_acmpne and checkcast 896 { 897 Node* k1 = isa_java_mirror_load(phase, in(1)); 898 Node* k2 = isa_java_mirror_load(phase, in(2)); 899 Node* conk2 = isa_const_java_mirror(phase, in(2)); 900 901 if (k1 && (k2 || conk2)) { 902 Node* lhs = k1; 903 Node* rhs = (k2 != NULL) ? k2 : conk2; 904 this->set_req(1, lhs); 905 this->set_req(2, rhs); 906 return this; 907 } 908 } 909 910 // Constant pointer on right? 911 const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr(); 912 if (t2 == NULL || !t2->klass_is_exact()) 913 return NULL; 914 // Get the constant klass we are comparing to. 915 ciKlass* superklass = t2->klass(); 916 917 // Now check for LoadKlass on left. 918 Node* ldk1 = in(1); 919 if (ldk1->is_DecodeNKlass()) { 920 ldk1 = ldk1->in(1); 921 if (ldk1->Opcode() != Op_LoadNKlass ) 922 return NULL; 923 } else if (ldk1->Opcode() != Op_LoadKlass ) 924 return NULL; 925 // Take apart the address of the LoadKlass: 926 Node* adr1 = ldk1->in(MemNode::Address); 927 intptr_t con2 = 0; 928 Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2); 929 if (ldk2 == NULL) 930 return NULL; 931 if (con2 == oopDesc::klass_offset_in_bytes()) { 932 // We are inspecting an object's concrete class. 933 // Short-circuit the check if the query is abstract. 934 if (superklass->is_interface() || 935 superklass->is_abstract()) { 936 // Make it come out always false: 937 this->set_req(2, phase->makecon(TypePtr::NULL_PTR)); 938 return this; 939 } 940 } 941 942 // Check for a LoadKlass from primary supertype array. 943 // Any nested loadklass from loadklass+con must be from the p.s. array. 944 if (ldk2->is_DecodeNKlass()) { 945 // Keep ldk2 as DecodeN since it could be used in CmpP below. 946 if (ldk2->in(1)->Opcode() != Op_LoadNKlass ) 947 return NULL; 948 } else if (ldk2->Opcode() != Op_LoadKlass) 949 return NULL; 950 951 // Verify that we understand the situation 952 if (con2 != (intptr_t) superklass->super_check_offset()) 953 return NULL; // Might be element-klass loading from array klass 954 955 // If 'superklass' has no subklasses and is not an interface, then we are 956 // assured that the only input which will pass the type check is 957 // 'superklass' itself. 958 // 959 // We could be more liberal here, and allow the optimization on interfaces 960 // which have a single implementor. This would require us to increase the 961 // expressiveness of the add_dependency() mechanism. 962 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. 963 964 // Object arrays must have their base element have no subtypes 965 while (superklass->is_obj_array_klass()) { 966 ciType* elem = superklass->as_obj_array_klass()->element_type(); 967 superklass = elem->as_klass(); 968 } 969 if (superklass->is_instance_klass()) { 970 ciInstanceKlass* ik = superklass->as_instance_klass(); 971 if (ik->has_subklass() || ik->is_interface()) return NULL; 972 // Add a dependency if there is a chance that a subclass will be added later. 973 if (!ik->is_final()) { 974 phase->C->dependencies()->assert_leaf_type(ik); 975 } 976 } 977 978 // Bypass the dependent load, and compare directly 979 this->set_req(1,ldk2); 980 981 return this; 982 } 983 984 //============================================================================= 985 //------------------------------sub-------------------------------------------- 986 // Simplify an CmpN (compare 2 pointers) node, based on local information. 987 // If both inputs are constants, compare them. 988 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { 989 const TypePtr *r0 = t1->make_ptr(); // Handy access 990 const TypePtr *r1 = t2->make_ptr(); 991 992 // Undefined inputs makes for an undefined result 993 if ((r0 == NULL) || (r1 == NULL) || 994 TypePtr::above_centerline(r0->_ptr) || 995 TypePtr::above_centerline(r1->_ptr)) { 996 return Type::TOP; 997 } 998 if (r0 == r1 && r0->singleton()) { 999 // Equal pointer constants (klasses, nulls, etc.) 1000 return TypeInt::CC_EQ; 1001 } 1002 1003 // See if it is 2 unrelated classes. 1004 const TypeOopPtr* p0 = r0->isa_oopptr(); 1005 const TypeOopPtr* p1 = r1->isa_oopptr(); 1006 if (p0 && p1) { 1007 ciKlass* klass0 = p0->klass(); 1008 bool xklass0 = p0->klass_is_exact(); 1009 ciKlass* klass1 = p1->klass(); 1010 bool xklass1 = p1->klass_is_exact(); 1011 int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0); 1012 if (klass0 && klass1 && 1013 kps != 1 && // both or neither are klass pointers 1014 !klass0->is_interface() && // do not trust interfaces 1015 !klass1->is_interface()) { 1016 bool unrelated_classes = false; 1017 // See if neither subclasses the other, or if the class on top 1018 // is precise. In either of these cases, the compare is known 1019 // to fail if at least one of the pointers is provably not null. 1020 if (klass0->equals(klass1)) { // if types are unequal but klasses are equal 1021 // Do nothing; we know nothing for imprecise types 1022 } else if (klass0->is_subtype_of(klass1)) { 1023 // If klass1's type is PRECISE, then classes are unrelated. 1024 unrelated_classes = xklass1; 1025 } else if (klass1->is_subtype_of(klass0)) { 1026 // If klass0's type is PRECISE, then classes are unrelated. 1027 unrelated_classes = xklass0; 1028 } else { // Neither subtypes the other 1029 unrelated_classes = true; 1030 } 1031 if (unrelated_classes) { 1032 // The oops classes are known to be unrelated. If the joined PTRs of 1033 // two oops is not Null and not Bottom, then we are sure that one 1034 // of the two oops is non-null, and the comparison will always fail. 1035 TypePtr::PTR jp = r0->join_ptr(r1->_ptr); 1036 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { 1037 return TypeInt::CC_GT; 1038 } 1039 } 1040 } 1041 } 1042 1043 // Known constants can be compared exactly 1044 // Null can be distinguished from any NotNull pointers 1045 // Unknown inputs makes an unknown result 1046 if( r0->singleton() ) { 1047 intptr_t bits0 = r0->get_con(); 1048 if( r1->singleton() ) 1049 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; 1050 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1051 } else if( r1->singleton() ) { 1052 intptr_t bits1 = r1->get_con(); 1053 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1054 } else 1055 return TypeInt::CC; 1056 } 1057 1058 //------------------------------Ideal------------------------------------------ 1059 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) { 1060 return NULL; 1061 } 1062 1063 //============================================================================= 1064 //------------------------------Value------------------------------------------ 1065 // Simplify an CmpF (compare 2 floats ) node, based on local information. 1066 // If both inputs are constants, compare them. 1067 const Type* CmpFNode::Value(PhaseGVN* phase) const { 1068 const Node* in1 = in(1); 1069 const Node* in2 = in(2); 1070 // Either input is TOP ==> the result is TOP 1071 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1072 if( t1 == Type::TOP ) return Type::TOP; 1073 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1074 if( t2 == Type::TOP ) return Type::TOP; 1075 1076 // Not constants? Don't know squat - even if they are the same 1077 // value! If they are NaN's they compare to LT instead of EQ. 1078 const TypeF *tf1 = t1->isa_float_constant(); 1079 const TypeF *tf2 = t2->isa_float_constant(); 1080 if( !tf1 || !tf2 ) return TypeInt::CC; 1081 1082 // This implements the Java bytecode fcmpl, so unordered returns -1. 1083 if( tf1->is_nan() || tf2->is_nan() ) 1084 return TypeInt::CC_LT; 1085 1086 if( tf1->_f < tf2->_f ) return TypeInt::CC_LT; 1087 if( tf1->_f > tf2->_f ) return TypeInt::CC_GT; 1088 assert( tf1->_f == tf2->_f, "do not understand FP behavior" ); 1089 return TypeInt::CC_EQ; 1090 } 1091 1092 1093 //============================================================================= 1094 //------------------------------Value------------------------------------------ 1095 // Simplify an CmpD (compare 2 doubles ) node, based on local information. 1096 // If both inputs are constants, compare them. 1097 const Type* CmpDNode::Value(PhaseGVN* phase) const { 1098 const Node* in1 = in(1); 1099 const Node* in2 = in(2); 1100 // Either input is TOP ==> the result is TOP 1101 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1102 if( t1 == Type::TOP ) return Type::TOP; 1103 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1104 if( t2 == Type::TOP ) return Type::TOP; 1105 1106 // Not constants? Don't know squat - even if they are the same 1107 // value! If they are NaN's they compare to LT instead of EQ. 1108 const TypeD *td1 = t1->isa_double_constant(); 1109 const TypeD *td2 = t2->isa_double_constant(); 1110 if( !td1 || !td2 ) return TypeInt::CC; 1111 1112 // This implements the Java bytecode dcmpl, so unordered returns -1. 1113 if( td1->is_nan() || td2->is_nan() ) 1114 return TypeInt::CC_LT; 1115 1116 if( td1->_d < td2->_d ) return TypeInt::CC_LT; 1117 if( td1->_d > td2->_d ) return TypeInt::CC_GT; 1118 assert( td1->_d == td2->_d, "do not understand FP behavior" ); 1119 return TypeInt::CC_EQ; 1120 } 1121 1122 //------------------------------Ideal------------------------------------------ 1123 Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){ 1124 // Check if we can change this to a CmpF and remove a ConvD2F operation. 1125 // Change (CMPD (F2D (float)) (ConD value)) 1126 // To (CMPF (float) (ConF value)) 1127 // Valid when 'value' does not lose precision as a float. 1128 // Benefits: eliminates conversion, does not require 24-bit mode 1129 1130 // NaNs prevent commuting operands. This transform works regardless of the 1131 // order of ConD and ConvF2D inputs by preserving the original order. 1132 int idx_f2d = 1; // ConvF2D on left side? 1133 if( in(idx_f2d)->Opcode() != Op_ConvF2D ) 1134 idx_f2d = 2; // No, swap to check for reversed args 1135 int idx_con = 3-idx_f2d; // Check for the constant on other input 1136 1137 if( ConvertCmpD2CmpF && 1138 in(idx_f2d)->Opcode() == Op_ConvF2D && 1139 in(idx_con)->Opcode() == Op_ConD ) { 1140 const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant(); 1141 double t2_value_as_double = t2->_d; 1142 float t2_value_as_float = (float)t2_value_as_double; 1143 if( t2_value_as_double == (double)t2_value_as_float ) { 1144 // Test value can be represented as a float 1145 // Eliminate the conversion to double and create new comparison 1146 Node *new_in1 = in(idx_f2d)->in(1); 1147 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) ); 1148 if( idx_f2d != 1 ) { // Must flip args to match original order 1149 Node *tmp = new_in1; 1150 new_in1 = new_in2; 1151 new_in2 = tmp; 1152 } 1153 CmpFNode *new_cmp = (Opcode() == Op_CmpD3) 1154 ? new CmpF3Node( new_in1, new_in2 ) 1155 : new CmpFNode ( new_in1, new_in2 ) ; 1156 return new_cmp; // Changed to CmpFNode 1157 } 1158 // Testing value required the precision of a double 1159 } 1160 return NULL; // No change 1161 } 1162 1163 1164 //============================================================================= 1165 //------------------------------cc2logical------------------------------------- 1166 // Convert a condition code type to a logical type 1167 const Type *BoolTest::cc2logical( const Type *CC ) const { 1168 if( CC == Type::TOP ) return Type::TOP; 1169 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse 1170 const TypeInt *ti = CC->is_int(); 1171 if( ti->is_con() ) { // Only 1 kind of condition codes set? 1172 // Match low order 2 bits 1173 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0; 1174 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result 1175 return TypeInt::make(tmp); // Boolean result 1176 } 1177 1178 if( CC == TypeInt::CC_GE ) { 1179 if( _test == ge ) return TypeInt::ONE; 1180 if( _test == lt ) return TypeInt::ZERO; 1181 } 1182 if( CC == TypeInt::CC_LE ) { 1183 if( _test == le ) return TypeInt::ONE; 1184 if( _test == gt ) return TypeInt::ZERO; 1185 } 1186 1187 return TypeInt::BOOL; 1188 } 1189 1190 //------------------------------dump_spec------------------------------------- 1191 // Print special per-node info 1192 void BoolTest::dump_on(outputStream *st) const { 1193 const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"}; 1194 st->print("%s", msg[_test]); 1195 } 1196 1197 //============================================================================= 1198 uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); } 1199 uint BoolNode::size_of() const { return sizeof(BoolNode); } 1200 1201 //------------------------------operator==------------------------------------- 1202 uint BoolNode::cmp( const Node &n ) const { 1203 const BoolNode *b = (const BoolNode *)&n; // Cast up 1204 return (_test._test == b->_test._test); 1205 } 1206 1207 //-------------------------------make_predicate-------------------------------- 1208 Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) { 1209 if (test_value->is_Con()) return test_value; 1210 if (test_value->is_Bool()) return test_value; 1211 if (test_value->is_CMove() && 1212 test_value->in(CMoveNode::Condition)->is_Bool()) { 1213 BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool(); 1214 const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse)); 1215 const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue)); 1216 if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) { 1217 return bol; 1218 } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) { 1219 return phase->transform( bol->negate(phase) ); 1220 } 1221 // Else fall through. The CMove gets in the way of the test. 1222 // It should be the case that make_predicate(bol->as_int_value()) == bol. 1223 } 1224 Node* cmp = new CmpINode(test_value, phase->intcon(0)); 1225 cmp = phase->transform(cmp); 1226 Node* bol = new BoolNode(cmp, BoolTest::ne); 1227 return phase->transform(bol); 1228 } 1229 1230 //--------------------------------as_int_value--------------------------------- 1231 Node* BoolNode::as_int_value(PhaseGVN* phase) { 1232 // Inverse to make_predicate. The CMove probably boils down to a Conv2B. 1233 Node* cmov = CMoveNode::make(NULL, this, 1234 phase->intcon(0), phase->intcon(1), 1235 TypeInt::BOOL); 1236 return phase->transform(cmov); 1237 } 1238 1239 //----------------------------------negate------------------------------------- 1240 BoolNode* BoolNode::negate(PhaseGVN* phase) { 1241 return new BoolNode(in(1), _test.negate()); 1242 } 1243 1244 // Change "bool eq/ne (cmp (add/sub A B) C)" into false/true if add/sub 1245 // overflows and we can prove that C is not in the two resulting ranges. 1246 // This optimization is similar to the one performed by CmpUNode::Value(). 1247 Node* BoolNode::fold_cmpI(PhaseGVN* phase, SubNode* cmp, Node* cmp1, int cmp_op, 1248 int cmp1_op, const TypeInt* cmp2_type) { 1249 // Only optimize eq/ne integer comparison of add/sub 1250 if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1251 (cmp_op == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) { 1252 // Skip cases were inputs of add/sub are not integers or of bottom type 1253 const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int(); 1254 const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int(); 1255 if ((r0 != NULL) && (r0 != TypeInt::INT) && 1256 (r1 != NULL) && (r1 != TypeInt::INT) && 1257 (cmp2_type != TypeInt::INT)) { 1258 // Compute exact (long) type range of add/sub result 1259 jlong lo_long = r0->_lo; 1260 jlong hi_long = r0->_hi; 1261 if (cmp1_op == Op_AddI) { 1262 lo_long += r1->_lo; 1263 hi_long += r1->_hi; 1264 } else { 1265 lo_long -= r1->_hi; 1266 hi_long -= r1->_lo; 1267 } 1268 // Check for over-/underflow by casting to integer 1269 int lo_int = (int)lo_long; 1270 int hi_int = (int)hi_long; 1271 bool underflow = lo_long != (jlong)lo_int; 1272 bool overflow = hi_long != (jlong)hi_int; 1273 if ((underflow != overflow) && (hi_int < lo_int)) { 1274 // Overflow on one boundary, compute resulting type ranges: 1275 // tr1 [MIN_INT, hi_int] and tr2 [lo_int, MAX_INT] 1276 int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here 1277 const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w); 1278 const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w); 1279 // Compare second input of cmp to both type ranges 1280 const Type* sub_tr1 = cmp->sub(tr1, cmp2_type); 1281 const Type* sub_tr2 = cmp->sub(tr2, cmp2_type); 1282 if (sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) { 1283 // The result of the add/sub will never equal cmp2. Replace BoolNode 1284 // by false (0) if it tests for equality and by true (1) otherwise. 1285 return ConINode::make((_test._test == BoolTest::eq) ? 0 : 1); 1286 } 1287 } 1288 } 1289 } 1290 return NULL; 1291 } 1292 1293 //------------------------------Ideal------------------------------------------ 1294 Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1295 // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)". 1296 // This moves the constant to the right. Helps value-numbering. 1297 Node *cmp = in(1); 1298 if( !cmp->is_Sub() ) return NULL; 1299 int cop = cmp->Opcode(); 1300 if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL; 1301 Node *cmp1 = cmp->in(1); 1302 Node *cmp2 = cmp->in(2); 1303 if( !cmp1 ) return NULL; 1304 1305 if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) { 1306 return NULL; 1307 } 1308 1309 // Constant on left? 1310 Node *con = cmp1; 1311 uint op2 = cmp2->Opcode(); 1312 // Move constants to the right of compare's to canonicalize. 1313 // Do not muck with Opaque1 nodes, as this indicates a loop 1314 // guard that cannot change shape. 1315 if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 && 1316 // Because of NaN's, CmpD and CmpF are not commutative 1317 cop != Op_CmpD && cop != Op_CmpF && 1318 // Protect against swapping inputs to a compare when it is used by a 1319 // counted loop exit, which requires maintaining the loop-limit as in(2) 1320 !is_counted_loop_exit_test() ) { 1321 // Ok, commute the constant to the right of the cmp node. 1322 // Clone the Node, getting a new Node of the same class 1323 cmp = cmp->clone(); 1324 // Swap inputs to the clone 1325 cmp->swap_edges(1, 2); 1326 cmp = phase->transform( cmp ); 1327 return new BoolNode( cmp, _test.commute() ); 1328 } 1329 1330 // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)". 1331 // The XOR-1 is an idiom used to flip the sense of a bool. We flip the 1332 // test instead. 1333 int cmp1_op = cmp1->Opcode(); 1334 const TypeInt* cmp2_type = phase->type(cmp2)->isa_int(); 1335 if (cmp2_type == NULL) return NULL; 1336 Node* j_xor = cmp1; 1337 if( cmp2_type == TypeInt::ZERO && 1338 cmp1_op == Op_XorI && 1339 j_xor->in(1) != j_xor && // An xor of itself is dead 1340 phase->type( j_xor->in(1) ) == TypeInt::BOOL && 1341 phase->type( j_xor->in(2) ) == TypeInt::ONE && 1342 (_test._test == BoolTest::eq || 1343 _test._test == BoolTest::ne) ) { 1344 Node *ncmp = phase->transform(new CmpINode(j_xor->in(1),cmp2)); 1345 return new BoolNode( ncmp, _test.negate() ); 1346 } 1347 1348 // Change ((x & m) u<= m) or ((m & x) u<= m) to always true 1349 // Same with ((x & m) u< m+1) and ((m & x) u< m+1) 1350 if (cop == Op_CmpU && 1351 cmp1->Opcode() == Op_AndI) { 1352 Node* bound = NULL; 1353 if (_test._test == BoolTest::le) { 1354 bound = cmp2; 1355 } else if (_test._test == BoolTest::lt && 1356 cmp2->Opcode() == Op_AddI && 1357 cmp2->in(2)->find_int_con(0) == 1) { 1358 bound = cmp2->in(1); 1359 } 1360 if (cmp1->in(2) == bound || cmp1->in(1) == bound) { 1361 return ConINode::make(1); 1362 } 1363 } 1364 1365 // Change ((x & (m - 1)) u< m) into (m > 0) 1366 // This is the off-by-one variant of the above 1367 if (cop == Op_CmpU && 1368 _test._test == BoolTest::lt && 1369 cmp1->Opcode() == Op_AndI) { 1370 Node* l = cmp1->in(1); 1371 Node* r = cmp1->in(2); 1372 for (int repeat = 0; repeat < 2; repeat++) { 1373 bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 && 1374 r->in(1) == cmp2; 1375 if (match) { 1376 // arraylength known to be non-negative, so a (arraylength != 0) is sufficient, 1377 // but to be compatible with the array range check pattern, use (arraylength u> 0) 1378 Node* ncmp = cmp2->Opcode() == Op_LoadRange 1379 ? phase->transform(new CmpUNode(cmp2, phase->intcon(0))) 1380 : phase->transform(new CmpINode(cmp2, phase->intcon(0))); 1381 return new BoolNode(ncmp, BoolTest::gt); 1382 } else { 1383 // commute and try again 1384 l = cmp1->in(2); 1385 r = cmp1->in(1); 1386 } 1387 } 1388 } 1389 1390 // Change (arraylength <= 0) or (arraylength == 0) 1391 // into (arraylength u<= 0) 1392 // Also change (arraylength != 0) into (arraylength u> 0) 1393 // The latter version matches the code pattern generated for 1394 // array range checks, which will more likely be optimized later. 1395 if (cop == Op_CmpI && 1396 cmp1->Opcode() == Op_LoadRange && 1397 cmp2->find_int_con(-1) == 0) { 1398 if (_test._test == BoolTest::le || _test._test == BoolTest::eq) { 1399 Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2)); 1400 return new BoolNode(ncmp, BoolTest::le); 1401 } else if (_test._test == BoolTest::ne) { 1402 Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2)); 1403 return new BoolNode(ncmp, BoolTest::gt); 1404 } 1405 } 1406 1407 // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)". 1408 // This is a standard idiom for branching on a boolean value. 1409 Node *c2b = cmp1; 1410 if( cmp2_type == TypeInt::ZERO && 1411 cmp1_op == Op_Conv2B && 1412 (_test._test == BoolTest::eq || 1413 _test._test == BoolTest::ne) ) { 1414 Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int() 1415 ? (Node*)new CmpINode(c2b->in(1),cmp2) 1416 : (Node*)new CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR)) 1417 ); 1418 return new BoolNode( ncmp, _test._test ); 1419 } 1420 1421 // Comparing a SubI against a zero is equal to comparing the SubI 1422 // arguments directly. This only works for eq and ne comparisons 1423 // due to possible integer overflow. 1424 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1425 (cop == Op_CmpI) && 1426 (cmp1->Opcode() == Op_SubI) && 1427 ( cmp2_type == TypeInt::ZERO ) ) { 1428 Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2))); 1429 return new BoolNode( ncmp, _test._test ); 1430 } 1431 1432 // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the 1433 // most general case because negating 0x80000000 does nothing. Needed for 1434 // the CmpF3/SubI/CmpI idiom. 1435 if( cop == Op_CmpI && 1436 cmp1->Opcode() == Op_SubI && 1437 cmp2_type == TypeInt::ZERO && 1438 phase->type( cmp1->in(1) ) == TypeInt::ZERO && 1439 phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) { 1440 Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2)); 1441 return new BoolNode( ncmp, _test.commute() ); 1442 } 1443 1444 // Try to optimize signed integer comparison 1445 return fold_cmpI(phase, cmp->as_Sub(), cmp1, cop, cmp1_op, cmp2_type); 1446 1447 // The transformation below is not valid for either signed or unsigned 1448 // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE. 1449 // This transformation can be resurrected when we are able to 1450 // make inferences about the range of values being subtracted from 1451 // (or added to) relative to the wraparound point. 1452 // 1453 // // Remove +/-1's if possible. 1454 // // "X <= Y-1" becomes "X < Y" 1455 // // "X+1 <= Y" becomes "X < Y" 1456 // // "X < Y+1" becomes "X <= Y" 1457 // // "X-1 < Y" becomes "X <= Y" 1458 // // Do not this to compares off of the counted-loop-end. These guys are 1459 // // checking the trip counter and they want to use the post-incremented 1460 // // counter. If they use the PRE-incremented counter, then the counter has 1461 // // to be incremented in a private block on a loop backedge. 1462 // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd ) 1463 // return NULL; 1464 // #ifndef PRODUCT 1465 // // Do not do this in a wash GVN pass during verification. 1466 // // Gets triggered by too many simple optimizations to be bothered with 1467 // // re-trying it again and again. 1468 // if( !phase->allow_progress() ) return NULL; 1469 // #endif 1470 // // Not valid for unsigned compare because of corner cases in involving zero. 1471 // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an 1472 // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but 1473 // // "0 <=u Y" is always true). 1474 // if( cmp->Opcode() == Op_CmpU ) return NULL; 1475 // int cmp2_op = cmp2->Opcode(); 1476 // if( _test._test == BoolTest::le ) { 1477 // if( cmp1_op == Op_AddI && 1478 // phase->type( cmp1->in(2) ) == TypeInt::ONE ) 1479 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt ); 1480 // else if( cmp2_op == Op_AddI && 1481 // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 ) 1482 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt ); 1483 // } else if( _test._test == BoolTest::lt ) { 1484 // if( cmp1_op == Op_AddI && 1485 // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 ) 1486 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le ); 1487 // else if( cmp2_op == Op_AddI && 1488 // phase->type( cmp2->in(2) ) == TypeInt::ONE ) 1489 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le ); 1490 // } 1491 } 1492 1493 //------------------------------Value------------------------------------------ 1494 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node, 1495 // based on local information. If the input is constant, do it. 1496 const Type* BoolNode::Value(PhaseGVN* phase) const { 1497 return _test.cc2logical( phase->type( in(1) ) ); 1498 } 1499 1500 #ifndef PRODUCT 1501 //------------------------------dump_spec-------------------------------------- 1502 // Dump special per-node info 1503 void BoolNode::dump_spec(outputStream *st) const { 1504 st->print("["); 1505 _test.dump_on(st); 1506 st->print("]"); 1507 } 1508 1509 //-------------------------------related--------------------------------------- 1510 // A BoolNode's related nodes are all of its data inputs, and all of its 1511 // outputs until control nodes are hit, which are included. In compact 1512 // representation, inputs till level 3 and immediate outputs are included. 1513 void BoolNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const { 1514 if (compact) { 1515 this->collect_nodes(in_rel, 3, false, true); 1516 this->collect_nodes(out_rel, -1, false, false); 1517 } else { 1518 this->collect_nodes_in_all_data(in_rel, false); 1519 this->collect_nodes_out_all_ctrl_boundary(out_rel); 1520 } 1521 } 1522 #endif 1523 1524 //----------------------is_counted_loop_exit_test------------------------------ 1525 // Returns true if node is used by a counted loop node. 1526 bool BoolNode::is_counted_loop_exit_test() { 1527 for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { 1528 Node* use = fast_out(i); 1529 if (use->is_CountedLoopEnd()) { 1530 return true; 1531 } 1532 } 1533 return false; 1534 } 1535 1536 //============================================================================= 1537 //------------------------------Value------------------------------------------ 1538 // Compute sqrt 1539 const Type* SqrtDNode::Value(PhaseGVN* phase) const { 1540 const Type *t1 = phase->type( in(1) ); 1541 if( t1 == Type::TOP ) return Type::TOP; 1542 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1543 double d = t1->getd(); 1544 if( d < 0.0 ) return Type::DOUBLE; 1545 return TypeD::make( sqrt( d ) ); 1546 } 1547 1548 //============================================================================= 1549 //------------------------------Value------------------------------------------ 1550 // Compute tan 1551 const Type* TanDNode::Value(PhaseGVN* phase) const { 1552 const Type *t1 = phase->type( in(1) ); 1553 if( t1 == Type::TOP ) return Type::TOP; 1554 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1555 double d = t1->getd(); 1556 return TypeD::make( StubRoutines::intrinsic_tan( d ) ); 1557 } 1558 1559 //============================================================================= 1560 //------------------------------Value------------------------------------------ 1561 // Compute log10 1562 const Type* Log10DNode::Value(PhaseGVN* phase) const { 1563 const Type *t1 = phase->type( in(1) ); 1564 if( t1 == Type::TOP ) return Type::TOP; 1565 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1566 double d = t1->getd(); 1567 return TypeD::make( StubRoutines::intrinsic_log10( d ) ); 1568 }