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 "opto/addnode.hpp" 27 #include "opto/convertnode.hpp" 28 #include "opto/matcher.hpp" 29 #include "opto/phaseX.hpp" 30 #include "opto/subnode.hpp" 31 #include "runtime/sharedRuntime.hpp" 32 33 //============================================================================= 34 //------------------------------Identity--------------------------------------- 35 Node *Conv2BNode::Identity( PhaseTransform *phase ) { 36 const Type *t = phase->type( in(1) ); 37 if( t == Type::TOP ) return in(1); 38 if( t == TypeInt::ZERO ) return in(1); 39 if( t == TypeInt::ONE ) return in(1); 40 if( t == TypeInt::BOOL ) return in(1); 41 return this; 42 } 43 44 //------------------------------Value------------------------------------------ 45 const Type *Conv2BNode::Value( PhaseTransform *phase ) const { 46 const Type *t = phase->type( in(1) ); 47 if( t == Type::TOP ) return Type::TOP; 48 if( t == TypeInt::ZERO ) return TypeInt::ZERO; 49 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO; 50 const TypePtr *tp = t->isa_ptr(); 51 if( tp != NULL ) { 52 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP; 53 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE; 54 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE; 55 return TypeInt::BOOL; 56 } 57 if (t->base() != Type::Int) return TypeInt::BOOL; 58 const TypeInt *ti = t->is_int(); 59 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE; 60 return TypeInt::BOOL; 61 } 62 63 64 // The conversions operations are all Alpha sorted. Please keep it that way! 65 //============================================================================= 66 //------------------------------Value------------------------------------------ 67 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const { 68 const Type *t = phase->type( in(1) ); 69 if( t == Type::TOP ) return Type::TOP; 70 if( t == Type::DOUBLE ) return Type::FLOAT; 71 const TypeD *td = t->is_double_constant(); 72 return TypeF::make( (float)td->getd() ); 73 } 74 75 //------------------------------Identity--------------------------------------- 76 // Float's can be converted to doubles with no loss of bits. Hence 77 // converting a float to a double and back to a float is a NOP. 78 Node *ConvD2FNode::Identity(PhaseTransform *phase) { 79 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this; 80 } 81 82 //============================================================================= 83 //------------------------------Value------------------------------------------ 84 const Type *ConvD2INode::Value( PhaseTransform *phase ) const { 85 const Type *t = phase->type( in(1) ); 86 if( t == Type::TOP ) return Type::TOP; 87 if( t == Type::DOUBLE ) return TypeInt::INT; 88 const TypeD *td = t->is_double_constant(); 89 return TypeInt::make( SharedRuntime::d2i( td->getd() ) ); 90 } 91 92 //------------------------------Ideal------------------------------------------ 93 // If converting to an int type, skip any rounding nodes 94 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) { 95 if( in(1)->Opcode() == Op_RoundDouble ) 96 set_req(1,in(1)->in(1)); 97 return NULL; 98 } 99 100 //------------------------------Identity--------------------------------------- 101 // Int's can be converted to doubles with no loss of bits. Hence 102 // converting an integer to a double and back to an integer is a NOP. 103 Node *ConvD2INode::Identity(PhaseTransform *phase) { 104 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this; 105 } 106 107 //============================================================================= 108 //------------------------------Value------------------------------------------ 109 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const { 110 const Type *t = phase->type( in(1) ); 111 if( t == Type::TOP ) return Type::TOP; 112 if( t == Type::DOUBLE ) return TypeLong::LONG; 113 const TypeD *td = t->is_double_constant(); 114 return TypeLong::make( SharedRuntime::d2l( td->getd() ) ); 115 } 116 117 //------------------------------Identity--------------------------------------- 118 Node *ConvD2LNode::Identity(PhaseTransform *phase) { 119 // Remove ConvD2L->ConvL2D->ConvD2L sequences. 120 if( in(1) ->Opcode() == Op_ConvL2D && 121 in(1)->in(1)->Opcode() == Op_ConvD2L ) 122 return in(1)->in(1); 123 return this; 124 } 125 126 //------------------------------Ideal------------------------------------------ 127 // If converting to an int type, skip any rounding nodes 128 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { 129 if( in(1)->Opcode() == Op_RoundDouble ) 130 set_req(1,in(1)->in(1)); 131 return NULL; 132 } 133 134 //============================================================================= 135 //------------------------------Value------------------------------------------ 136 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const { 137 const Type *t = phase->type( in(1) ); 138 if( t == Type::TOP ) return Type::TOP; 139 if( t == Type::FLOAT ) return Type::DOUBLE; 140 const TypeF *tf = t->is_float_constant(); 141 return TypeD::make( (double)tf->getf() ); 142 } 143 144 //============================================================================= 145 //------------------------------Value------------------------------------------ 146 const Type *ConvF2INode::Value( PhaseTransform *phase ) const { 147 const Type *t = phase->type( in(1) ); 148 if( t == Type::TOP ) return Type::TOP; 149 if( t == Type::FLOAT ) return TypeInt::INT; 150 const TypeF *tf = t->is_float_constant(); 151 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) ); 152 } 153 154 //------------------------------Identity--------------------------------------- 155 Node *ConvF2INode::Identity(PhaseTransform *phase) { 156 // Remove ConvF2I->ConvI2F->ConvF2I sequences. 157 if( in(1) ->Opcode() == Op_ConvI2F && 158 in(1)->in(1)->Opcode() == Op_ConvF2I ) 159 return in(1)->in(1); 160 return this; 161 } 162 163 //------------------------------Ideal------------------------------------------ 164 // If converting to an int type, skip any rounding nodes 165 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) { 166 if( in(1)->Opcode() == Op_RoundFloat ) 167 set_req(1,in(1)->in(1)); 168 return NULL; 169 } 170 171 //============================================================================= 172 //------------------------------Value------------------------------------------ 173 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const { 174 const Type *t = phase->type( in(1) ); 175 if( t == Type::TOP ) return Type::TOP; 176 if( t == Type::FLOAT ) return TypeLong::LONG; 177 const TypeF *tf = t->is_float_constant(); 178 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) ); 179 } 180 181 //------------------------------Identity--------------------------------------- 182 Node *ConvF2LNode::Identity(PhaseTransform *phase) { 183 // Remove ConvF2L->ConvL2F->ConvF2L sequences. 184 if( in(1) ->Opcode() == Op_ConvL2F && 185 in(1)->in(1)->Opcode() == Op_ConvF2L ) 186 return in(1)->in(1); 187 return this; 188 } 189 190 //------------------------------Ideal------------------------------------------ 191 // If converting to an int type, skip any rounding nodes 192 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { 193 if( in(1)->Opcode() == Op_RoundFloat ) 194 set_req(1,in(1)->in(1)); 195 return NULL; 196 } 197 198 //============================================================================= 199 //------------------------------Value------------------------------------------ 200 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const { 201 const Type *t = phase->type( in(1) ); 202 if( t == Type::TOP ) return Type::TOP; 203 const TypeInt *ti = t->is_int(); 204 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() ); 205 return bottom_type(); 206 } 207 208 //============================================================================= 209 //------------------------------Value------------------------------------------ 210 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const { 211 const Type *t = phase->type( in(1) ); 212 if( t == Type::TOP ) return Type::TOP; 213 const TypeInt *ti = t->is_int(); 214 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() ); 215 return bottom_type(); 216 } 217 218 //------------------------------Identity--------------------------------------- 219 Node *ConvI2FNode::Identity(PhaseTransform *phase) { 220 // Remove ConvI2F->ConvF2I->ConvI2F sequences. 221 if( in(1) ->Opcode() == Op_ConvF2I && 222 in(1)->in(1)->Opcode() == Op_ConvI2F ) 223 return in(1)->in(1); 224 return this; 225 } 226 227 //============================================================================= 228 //------------------------------Value------------------------------------------ 229 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const { 230 const Type *t = phase->type( in(1) ); 231 if( t == Type::TOP ) return Type::TOP; 232 const TypeInt *ti = t->is_int(); 233 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen); 234 // Join my declared type against my incoming type. 235 tl = tl->filter(_type); 236 return tl; 237 } 238 239 #ifdef _LP64 240 static inline bool long_ranges_overlap(jlong lo1, jlong hi1, 241 jlong lo2, jlong hi2) { 242 // Two ranges overlap iff one range's low point falls in the other range. 243 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1); 244 } 245 #endif 246 247 //------------------------------Ideal------------------------------------------ 248 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { 249 const TypeLong* this_type = this->type()->is_long(); 373 jlong rylo0 = rylo; 374 rylo = -ryhi; 375 ryhi = -rylo0; 376 } 377 378 Node* cx = phase->transform( new ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) ); 379 Node* cy = phase->transform( new ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) ); 380 switch (op) { 381 case Op_AddI: return new AddLNode(cx, cy); 382 case Op_SubI: return new SubLNode(cx, cy); 383 default: ShouldNotReachHere(); 384 } 385 } 386 #endif //_LP64 387 388 return this_changed; 389 } 390 391 //============================================================================= 392 //------------------------------Value------------------------------------------ 393 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const { 394 const Type *t = phase->type( in(1) ); 395 if( t == Type::TOP ) return Type::TOP; 396 const TypeLong *tl = t->is_long(); 397 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() ); 398 return bottom_type(); 399 } 400 401 //============================================================================= 402 //------------------------------Value------------------------------------------ 403 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const { 404 const Type *t = phase->type( in(1) ); 405 if( t == Type::TOP ) return Type::TOP; 406 const TypeLong *tl = t->is_long(); 407 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() ); 408 return bottom_type(); 409 } 410 411 //============================================================================= 412 //----------------------------Identity----------------------------------------- 413 Node *ConvL2INode::Identity( PhaseTransform *phase ) { 414 // Convert L2I(I2L(x)) => x 415 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1); 416 return this; 417 } 418 419 //------------------------------Value------------------------------------------ 420 const Type *ConvL2INode::Value( PhaseTransform *phase ) const { 421 const Type *t = phase->type( in(1) ); 422 if( t == Type::TOP ) return Type::TOP; 423 const TypeLong *tl = t->is_long(); 424 if (tl->is_con()) 425 // Easy case. 426 return TypeInt::make((jint)tl->get_con()); 427 return bottom_type(); 428 } 429 430 //------------------------------Ideal------------------------------------------ 431 // Return a node which is more "ideal" than the current node. 432 // Blow off prior masking to int 433 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) { 434 Node *andl = in(1); 435 uint andl_op = andl->Opcode(); 436 if( andl_op == Op_AndL ) { 437 // Blow off prior masking to int 438 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) { 439 set_req(1,andl->in(1)); 440 return this; 452 Node* y = andl->in(2); 453 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" ); 454 if (phase->type(x) == Type::TOP) return NULL; 455 if (phase->type(y) == Type::TOP) return NULL; 456 Node *add1 = phase->transform(new ConvL2INode(x)); 457 Node *add2 = phase->transform(new ConvL2INode(y)); 458 return new AddINode(add1,add2); 459 } 460 461 // Disable optimization: LoadL->ConvL2I ==> LoadI. 462 // It causes problems (sizes of Load and Store nodes do not match) 463 // in objects initialization code and Escape Analysis. 464 return NULL; 465 } 466 467 468 469 //============================================================================= 470 //------------------------------Identity--------------------------------------- 471 // Remove redundant roundings 472 Node *RoundFloatNode::Identity( PhaseTransform *phase ) { 473 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); 474 // Do not round constants 475 if (phase->type(in(1))->base() == Type::FloatCon) return in(1); 476 int op = in(1)->Opcode(); 477 // Redundant rounding 478 if( op == Op_RoundFloat ) return in(1); 479 // Already rounded 480 if( op == Op_Parm ) return in(1); 481 if( op == Op_LoadF ) return in(1); 482 return this; 483 } 484 485 //------------------------------Value------------------------------------------ 486 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const { 487 return phase->type( in(1) ); 488 } 489 490 //============================================================================= 491 //------------------------------Identity--------------------------------------- 492 // Remove redundant roundings. Incoming arguments are already rounded. 493 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) { 494 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); 495 // Do not round constants 496 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1); 497 int op = in(1)->Opcode(); 498 // Redundant rounding 499 if( op == Op_RoundDouble ) return in(1); 500 // Already rounded 501 if( op == Op_Parm ) return in(1); 502 if( op == Op_LoadD ) return in(1); 503 if( op == Op_ConvF2D ) return in(1); 504 if( op == Op_ConvI2D ) return in(1); 505 return this; 506 } 507 508 //------------------------------Value------------------------------------------ 509 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const { 510 return phase->type( in(1) ); 511 } 512 513 | 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 "opto/addnode.hpp" 27 #include "opto/convertnode.hpp" 28 #include "opto/matcher.hpp" 29 #include "opto/phaseX.hpp" 30 #include "opto/subnode.hpp" 31 #include "runtime/sharedRuntime.hpp" 32 33 //============================================================================= 34 //------------------------------Identity--------------------------------------- 35 Node* Conv2BNode::Identity(PhaseGVN* phase) { 36 const Type *t = phase->type( in(1) ); 37 if( t == Type::TOP ) return in(1); 38 if( t == TypeInt::ZERO ) return in(1); 39 if( t == TypeInt::ONE ) return in(1); 40 if( t == TypeInt::BOOL ) return in(1); 41 return this; 42 } 43 44 //------------------------------Value------------------------------------------ 45 const Type* Conv2BNode::Value(PhaseGVN* phase) const { 46 const Type *t = phase->type( in(1) ); 47 if( t == Type::TOP ) return Type::TOP; 48 if( t == TypeInt::ZERO ) return TypeInt::ZERO; 49 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO; 50 const TypePtr *tp = t->isa_ptr(); 51 if( tp != NULL ) { 52 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP; 53 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE; 54 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE; 55 return TypeInt::BOOL; 56 } 57 if (t->base() != Type::Int) return TypeInt::BOOL; 58 const TypeInt *ti = t->is_int(); 59 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE; 60 return TypeInt::BOOL; 61 } 62 63 64 // The conversions operations are all Alpha sorted. Please keep it that way! 65 //============================================================================= 66 //------------------------------Value------------------------------------------ 67 const Type* ConvD2FNode::Value(PhaseGVN* phase) const { 68 const Type *t = phase->type( in(1) ); 69 if( t == Type::TOP ) return Type::TOP; 70 if( t == Type::DOUBLE ) return Type::FLOAT; 71 const TypeD *td = t->is_double_constant(); 72 return TypeF::make( (float)td->getd() ); 73 } 74 75 //------------------------------Identity--------------------------------------- 76 // Float's can be converted to doubles with no loss of bits. Hence 77 // converting a float to a double and back to a float is a NOP. 78 Node* ConvD2FNode::Identity(PhaseGVN* phase) { 79 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this; 80 } 81 82 //============================================================================= 83 //------------------------------Value------------------------------------------ 84 const Type* ConvD2INode::Value(PhaseGVN* phase) const { 85 const Type *t = phase->type( in(1) ); 86 if( t == Type::TOP ) return Type::TOP; 87 if( t == Type::DOUBLE ) return TypeInt::INT; 88 const TypeD *td = t->is_double_constant(); 89 return TypeInt::make( SharedRuntime::d2i( td->getd() ) ); 90 } 91 92 //------------------------------Ideal------------------------------------------ 93 // If converting to an int type, skip any rounding nodes 94 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) { 95 if( in(1)->Opcode() == Op_RoundDouble ) 96 set_req(1,in(1)->in(1)); 97 return NULL; 98 } 99 100 //------------------------------Identity--------------------------------------- 101 // Int's can be converted to doubles with no loss of bits. Hence 102 // converting an integer to a double and back to an integer is a NOP. 103 Node* ConvD2INode::Identity(PhaseGVN* phase) { 104 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this; 105 } 106 107 //============================================================================= 108 //------------------------------Value------------------------------------------ 109 const Type* ConvD2LNode::Value(PhaseGVN* phase) const { 110 const Type *t = phase->type( in(1) ); 111 if( t == Type::TOP ) return Type::TOP; 112 if( t == Type::DOUBLE ) return TypeLong::LONG; 113 const TypeD *td = t->is_double_constant(); 114 return TypeLong::make( SharedRuntime::d2l( td->getd() ) ); 115 } 116 117 //------------------------------Identity--------------------------------------- 118 Node* ConvD2LNode::Identity(PhaseGVN* phase) { 119 // Remove ConvD2L->ConvL2D->ConvD2L sequences. 120 if( in(1) ->Opcode() == Op_ConvL2D && 121 in(1)->in(1)->Opcode() == Op_ConvD2L ) 122 return in(1)->in(1); 123 return this; 124 } 125 126 //------------------------------Ideal------------------------------------------ 127 // If converting to an int type, skip any rounding nodes 128 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { 129 if( in(1)->Opcode() == Op_RoundDouble ) 130 set_req(1,in(1)->in(1)); 131 return NULL; 132 } 133 134 //============================================================================= 135 //------------------------------Value------------------------------------------ 136 const Type* ConvF2DNode::Value(PhaseGVN* phase) const { 137 const Type *t = phase->type( in(1) ); 138 if( t == Type::TOP ) return Type::TOP; 139 if( t == Type::FLOAT ) return Type::DOUBLE; 140 const TypeF *tf = t->is_float_constant(); 141 return TypeD::make( (double)tf->getf() ); 142 } 143 144 //============================================================================= 145 //------------------------------Value------------------------------------------ 146 const Type* ConvF2INode::Value(PhaseGVN* phase) const { 147 const Type *t = phase->type( in(1) ); 148 if( t == Type::TOP ) return Type::TOP; 149 if( t == Type::FLOAT ) return TypeInt::INT; 150 const TypeF *tf = t->is_float_constant(); 151 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) ); 152 } 153 154 //------------------------------Identity--------------------------------------- 155 Node* ConvF2INode::Identity(PhaseGVN* phase) { 156 // Remove ConvF2I->ConvI2F->ConvF2I sequences. 157 if( in(1) ->Opcode() == Op_ConvI2F && 158 in(1)->in(1)->Opcode() == Op_ConvF2I ) 159 return in(1)->in(1); 160 return this; 161 } 162 163 //------------------------------Ideal------------------------------------------ 164 // If converting to an int type, skip any rounding nodes 165 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) { 166 if( in(1)->Opcode() == Op_RoundFloat ) 167 set_req(1,in(1)->in(1)); 168 return NULL; 169 } 170 171 //============================================================================= 172 //------------------------------Value------------------------------------------ 173 const Type* ConvF2LNode::Value(PhaseGVN* phase) const { 174 const Type *t = phase->type( in(1) ); 175 if( t == Type::TOP ) return Type::TOP; 176 if( t == Type::FLOAT ) return TypeLong::LONG; 177 const TypeF *tf = t->is_float_constant(); 178 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) ); 179 } 180 181 //------------------------------Identity--------------------------------------- 182 Node* ConvF2LNode::Identity(PhaseGVN* phase) { 183 // Remove ConvF2L->ConvL2F->ConvF2L sequences. 184 if( in(1) ->Opcode() == Op_ConvL2F && 185 in(1)->in(1)->Opcode() == Op_ConvF2L ) 186 return in(1)->in(1); 187 return this; 188 } 189 190 //------------------------------Ideal------------------------------------------ 191 // If converting to an int type, skip any rounding nodes 192 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { 193 if( in(1)->Opcode() == Op_RoundFloat ) 194 set_req(1,in(1)->in(1)); 195 return NULL; 196 } 197 198 //============================================================================= 199 //------------------------------Value------------------------------------------ 200 const Type* ConvI2DNode::Value(PhaseGVN* phase) const { 201 const Type *t = phase->type( in(1) ); 202 if( t == Type::TOP ) return Type::TOP; 203 const TypeInt *ti = t->is_int(); 204 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() ); 205 return bottom_type(); 206 } 207 208 //============================================================================= 209 //------------------------------Value------------------------------------------ 210 const Type* ConvI2FNode::Value(PhaseGVN* phase) const { 211 const Type *t = phase->type( in(1) ); 212 if( t == Type::TOP ) return Type::TOP; 213 const TypeInt *ti = t->is_int(); 214 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() ); 215 return bottom_type(); 216 } 217 218 //------------------------------Identity--------------------------------------- 219 Node* ConvI2FNode::Identity(PhaseGVN* phase) { 220 // Remove ConvI2F->ConvF2I->ConvI2F sequences. 221 if( in(1) ->Opcode() == Op_ConvF2I && 222 in(1)->in(1)->Opcode() == Op_ConvI2F ) 223 return in(1)->in(1); 224 return this; 225 } 226 227 //============================================================================= 228 //------------------------------Value------------------------------------------ 229 const Type* ConvI2LNode::Value(PhaseGVN* phase) const { 230 const Type *t = phase->type( in(1) ); 231 if( t == Type::TOP ) return Type::TOP; 232 const TypeInt *ti = t->is_int(); 233 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen); 234 // Join my declared type against my incoming type. 235 tl = tl->filter(_type); 236 return tl; 237 } 238 239 #ifdef _LP64 240 static inline bool long_ranges_overlap(jlong lo1, jlong hi1, 241 jlong lo2, jlong hi2) { 242 // Two ranges overlap iff one range's low point falls in the other range. 243 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1); 244 } 245 #endif 246 247 //------------------------------Ideal------------------------------------------ 248 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { 249 const TypeLong* this_type = this->type()->is_long(); 373 jlong rylo0 = rylo; 374 rylo = -ryhi; 375 ryhi = -rylo0; 376 } 377 378 Node* cx = phase->transform( new ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) ); 379 Node* cy = phase->transform( new ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) ); 380 switch (op) { 381 case Op_AddI: return new AddLNode(cx, cy); 382 case Op_SubI: return new SubLNode(cx, cy); 383 default: ShouldNotReachHere(); 384 } 385 } 386 #endif //_LP64 387 388 return this_changed; 389 } 390 391 //============================================================================= 392 //------------------------------Value------------------------------------------ 393 const Type* ConvL2DNode::Value(PhaseGVN* phase) const { 394 const Type *t = phase->type( in(1) ); 395 if( t == Type::TOP ) return Type::TOP; 396 const TypeLong *tl = t->is_long(); 397 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() ); 398 return bottom_type(); 399 } 400 401 //============================================================================= 402 //------------------------------Value------------------------------------------ 403 const Type* ConvL2FNode::Value(PhaseGVN* phase) const { 404 const Type *t = phase->type( in(1) ); 405 if( t == Type::TOP ) return Type::TOP; 406 const TypeLong *tl = t->is_long(); 407 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() ); 408 return bottom_type(); 409 } 410 411 //============================================================================= 412 //----------------------------Identity----------------------------------------- 413 Node* ConvL2INode::Identity(PhaseGVN* phase) { 414 // Convert L2I(I2L(x)) => x 415 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1); 416 return this; 417 } 418 419 //------------------------------Value------------------------------------------ 420 const Type* ConvL2INode::Value(PhaseGVN* phase) const { 421 const Type *t = phase->type( in(1) ); 422 if( t == Type::TOP ) return Type::TOP; 423 const TypeLong *tl = t->is_long(); 424 if (tl->is_con()) 425 // Easy case. 426 return TypeInt::make((jint)tl->get_con()); 427 return bottom_type(); 428 } 429 430 //------------------------------Ideal------------------------------------------ 431 // Return a node which is more "ideal" than the current node. 432 // Blow off prior masking to int 433 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) { 434 Node *andl = in(1); 435 uint andl_op = andl->Opcode(); 436 if( andl_op == Op_AndL ) { 437 // Blow off prior masking to int 438 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) { 439 set_req(1,andl->in(1)); 440 return this; 452 Node* y = andl->in(2); 453 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" ); 454 if (phase->type(x) == Type::TOP) return NULL; 455 if (phase->type(y) == Type::TOP) return NULL; 456 Node *add1 = phase->transform(new ConvL2INode(x)); 457 Node *add2 = phase->transform(new ConvL2INode(y)); 458 return new AddINode(add1,add2); 459 } 460 461 // Disable optimization: LoadL->ConvL2I ==> LoadI. 462 // It causes problems (sizes of Load and Store nodes do not match) 463 // in objects initialization code and Escape Analysis. 464 return NULL; 465 } 466 467 468 469 //============================================================================= 470 //------------------------------Identity--------------------------------------- 471 // Remove redundant roundings 472 Node* RoundFloatNode::Identity(PhaseGVN* phase) { 473 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); 474 // Do not round constants 475 if (phase->type(in(1))->base() == Type::FloatCon) return in(1); 476 int op = in(1)->Opcode(); 477 // Redundant rounding 478 if( op == Op_RoundFloat ) return in(1); 479 // Already rounded 480 if( op == Op_Parm ) return in(1); 481 if( op == Op_LoadF ) return in(1); 482 return this; 483 } 484 485 //------------------------------Value------------------------------------------ 486 const Type* RoundFloatNode::Value(PhaseGVN* phase) const { 487 return phase->type( in(1) ); 488 } 489 490 //============================================================================= 491 //------------------------------Identity--------------------------------------- 492 // Remove redundant roundings. Incoming arguments are already rounded. 493 Node* RoundDoubleNode::Identity(PhaseGVN* phase) { 494 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); 495 // Do not round constants 496 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1); 497 int op = in(1)->Opcode(); 498 // Redundant rounding 499 if( op == Op_RoundDouble ) return in(1); 500 // Already rounded 501 if( op == Op_Parm ) return in(1); 502 if( op == Op_LoadD ) return in(1); 503 if( op == Op_ConvF2D ) return in(1); 504 if( op == Op_ConvI2D ) return in(1); 505 return this; 506 } 507 508 //------------------------------Value------------------------------------------ 509 const Type* RoundDoubleNode::Value(PhaseGVN* phase) const { 510 return phase->type( in(1) ); 511 } 512 513 |