1 /*
   2  * Copyright (c) 2014, 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 "opto/addnode.hpp"
  27 #include "opto/callnode.hpp"
  28 #include "opto/castnode.hpp"
  29 #include "opto/connode.hpp"
  30 #include "opto/matcher.hpp"
  31 #include "opto/phaseX.hpp"
  32 #include "opto/rootnode.hpp"
  33 #include "opto/subnode.hpp"
  34 #include "opto/type.hpp"
  35 #include "opto/valuetypenode.hpp"
  36 
  37 //=============================================================================
  38 // If input is already higher or equal to cast type, then this is an identity.
  39 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
  40   Node* dom = dominating_cast(phase);
  41   if (dom != NULL) {
  42     return dom;
  43   }
  44   if (_carry_dependency) {
  45     return this;
  46   }
  47   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
  48 }
  49 
  50 //------------------------------Value------------------------------------------
  51 // Take 'join' of input and cast-up type
  52 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
  53   if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;
  54   const Type* ft = phase->type(in(1))->filter_speculative(_type);
  55 
  56 #ifdef ASSERT
  57   // Previous versions of this function had some special case logic,
  58   // which is no longer necessary.  Make sure of the required effects.
  59   switch (Opcode()) {
  60     case Op_CastII:
  61     {
  62       const Type* t1 = phase->type(in(1));
  63       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
  64       const Type* rt = t1->join_speculative(_type);
  65       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
  66       break;
  67     }
  68     case Op_CastPP:
  69     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
  70         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
  71     assert(ft == Type::TOP, "special case #3");
  72     break;
  73   }
  74 #endif //ASSERT
  75 
  76   return ft;
  77 }
  78 
  79 //------------------------------Ideal------------------------------------------
  80 // Return a node which is more "ideal" than the current node.  Strip out
  81 // control copies
  82 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  83   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
  84 }
  85 
  86 uint ConstraintCastNode::cmp(const Node &n) const {
  87   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._carry_dependency == _carry_dependency;
  88 }
  89 
  90 uint ConstraintCastNode::size_of() const {
  91   return sizeof(*this);
  92 }
  93 
  94 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, bool carry_dependency) {
  95   switch(opcode) {
  96   case Op_CastII: {
  97     Node* cast = new CastIINode(n, t, carry_dependency);
  98     cast->set_req(0, c);
  99     return cast;
 100   }
 101   case Op_CastPP: {
 102     Node* cast = new CastPPNode(n, t, carry_dependency);
 103     cast->set_req(0, c);
 104     return cast;
 105   }
 106   case Op_CheckCastPP: return new CheckCastPPNode(c, n, t, carry_dependency);
 107   default:
 108     fatal("Bad opcode %d", opcode);
 109   }
 110   return NULL;
 111 }
 112 
 113 TypeNode* ConstraintCastNode::dominating_cast(PhaseTransform *phase) const {
 114   Node* val = in(1);
 115   Node* ctl = in(0);
 116   int opc = Opcode();
 117   if (ctl == NULL) {
 118     return NULL;
 119   }
 120   // Range check CastIIs may all end up under a single range check and
 121   // in that case only the narrower CastII would be kept by the code
 122   // below which would be incorrect.
 123   if (is_CastII() && as_CastII()->has_range_check()) {
 124     return NULL;
 125   }
 126   for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
 127     Node* u = val->fast_out(i);
 128     if (u != this &&
 129         u->outcnt() > 0 &&
 130         u->Opcode() == opc &&
 131         u->in(0) != NULL &&
 132         u->bottom_type()->higher_equal(type())) {
 133       if (phase->is_dominator(u->in(0), ctl)) {
 134         return u->as_Type();
 135       }
 136       if (is_CheckCastPP() && u->in(1)->is_Proj() && u->in(1)->in(0)->is_Allocate() &&
 137           u->in(0)->is_Proj() && u->in(0)->in(0)->is_Initialize() &&
 138           u->in(1)->in(0)->as_Allocate()->initialization() == u->in(0)->in(0)) {
 139         // CheckCastPP following an allocation always dominates all
 140         // use of the allocation result
 141         return u->as_Type();
 142       }
 143     }
 144   }
 145   return NULL;
 146 }
 147 
 148 #ifndef PRODUCT
 149 void ConstraintCastNode::dump_spec(outputStream *st) const {
 150   TypeNode::dump_spec(st);
 151   if (_carry_dependency) {
 152     st->print(" carry dependency");
 153   }
 154 }
 155 #endif
 156 
 157 const Type* CastIINode::Value(PhaseGVN* phase) const {
 158   const Type *res = ConstraintCastNode::Value(phase);
 159 
 160   // Try to improve the type of the CastII if we recognize a CmpI/If
 161   // pattern.
 162   if (_carry_dependency) {
 163     if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
 164       assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
 165       Node* proj = in(0);
 166       if (proj->in(0)->in(1)->is_Bool()) {
 167         Node* b = proj->in(0)->in(1);
 168         if (b->in(1)->Opcode() == Op_CmpI) {
 169           Node* cmp = b->in(1);
 170           if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
 171             const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
 172             const Type* t = TypeInt::INT;
 173             BoolTest test = b->as_Bool()->_test;
 174             if (proj->is_IfFalse()) {
 175               test = test.negate();
 176             }
 177             BoolTest::mask m = test._test;
 178             jlong lo_long = min_jint;
 179             jlong hi_long = max_jint;
 180             if (m == BoolTest::le || m == BoolTest::lt) {
 181               hi_long = in2_t->_hi;
 182               if (m == BoolTest::lt) {
 183                 hi_long -= 1;
 184               }
 185             } else if (m == BoolTest::ge || m == BoolTest::gt) {
 186               lo_long = in2_t->_lo;
 187               if (m == BoolTest::gt) {
 188                 lo_long += 1;
 189               }
 190             } else if (m == BoolTest::eq) {
 191               lo_long = in2_t->_lo;
 192               hi_long = in2_t->_hi;
 193             } else if (m == BoolTest::ne) {
 194               // can't do any better
 195             } else {
 196               stringStream ss;
 197               test.dump_on(&ss);
 198               fatal("unexpected comparison %s", ss.as_string());
 199             }
 200             int lo_int = (int)lo_long;
 201             int hi_int = (int)hi_long;
 202 
 203             if (lo_long != (jlong)lo_int) {
 204               lo_int = min_jint;
 205             }
 206             if (hi_long != (jlong)hi_int) {
 207               hi_int = max_jint;
 208             }
 209 
 210             t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
 211 
 212             res = res->filter_speculative(t);
 213 
 214             return res;
 215           }
 216         }
 217       }
 218     }
 219   }
 220   return res;
 221 }
 222 
 223 Node *CastIINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 224   Node* progress = ConstraintCastNode::Ideal(phase, can_reshape);
 225   if (progress != NULL) {
 226     return progress;
 227   }
 228 
 229   // Similar to ConvI2LNode::Ideal() for the same reasons
 230   // Do not narrow the type of range check dependent CastIINodes to
 231   // avoid corruption of the graph if a CastII is replaced by TOP but
 232   // the corresponding range check is not removed.
 233   if (can_reshape && !_range_check_dependency && !phase->C->major_progress()) {
 234     const TypeInt* this_type = this->type()->is_int();
 235     const TypeInt* in_type = phase->type(in(1))->isa_int();
 236     if (in_type != NULL && this_type != NULL &&
 237         (in_type->_lo != this_type->_lo ||
 238          in_type->_hi != this_type->_hi)) {
 239       int lo1 = this_type->_lo;
 240       int hi1 = this_type->_hi;
 241       int w1  = this_type->_widen;
 242 
 243       if (lo1 >= 0) {
 244         // Keep a range assertion of >=0.
 245         lo1 = 0;        hi1 = max_jint;
 246       } else if (hi1 < 0) {
 247         // Keep a range assertion of <0.
 248         lo1 = min_jint; hi1 = -1;
 249       } else {
 250         lo1 = min_jint; hi1 = max_jint;
 251       }
 252       const TypeInt* wtype = TypeInt::make(MAX2(in_type->_lo, lo1),
 253                                            MIN2(in_type->_hi, hi1),
 254                                            MAX2((int)in_type->_widen, w1));
 255       if (wtype != type()) {
 256         set_type(wtype);
 257         return this;
 258       }
 259     }
 260   }
 261   return NULL;
 262 }
 263 
 264 uint CastIINode::cmp(const Node &n) const {
 265   return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency;
 266 }
 267 
 268 uint CastIINode::size_of() const {
 269   return sizeof(*this);
 270 }
 271 
 272 #ifndef PRODUCT
 273 void CastIINode::dump_spec(outputStream* st) const {
 274   ConstraintCastNode::dump_spec(st);
 275   if (_range_check_dependency) {
 276     st->print(" range check dependency");
 277   }
 278 }
 279 #endif
 280 
 281 //=============================================================================
 282 //------------------------------Identity---------------------------------------
 283 // If input is already higher or equal to cast type, then this is an identity.
 284 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
 285   // This is a value type, its input is a phi. That phi is also a
 286   // value type of that same type and its inputs are value types of
 287   // the same type: push the cast through the phi.
 288   if (phase->is_IterGVN() &&
 289       in(0) == NULL &&
 290       type()->isa_valuetypeptr() &&
 291       in(1) != NULL &&
 292       in(1)->is_Phi()) {
 293     PhaseIterGVN* igvn = phase->is_IterGVN();
 294     Node* phi = in(1);
 295     const Type* vtptr = type();
 296     for (uint i = 1; i < phi->req(); i++) {
 297       if (phi->in(i) != NULL && !phase->type(phi->in(i))->higher_equal(vtptr)) {
 298         Node* cast = phase->transform(new CheckCastPPNode(NULL, phi->in(i), vtptr));
 299         igvn->replace_input_of(phi, i, cast);
 300       }
 301     }
 302     return phi;
 303   }
 304 
 305   Node* dom = dominating_cast(phase);
 306   if (dom != NULL) {
 307     return dom;
 308   }
 309   if (_carry_dependency) {
 310     return this;
 311   }
 312   // Toned down to rescue meeting at a Phi 3 different oops all implementing
 313   // the same interface.  CompileTheWorld starting at 502, kd12rc1.zip.
 314   return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
 315 }
 316 
 317 //------------------------------Value------------------------------------------
 318 // Take 'join' of input and cast-up type, unless working with an Interface
 319 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
 320   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
 321 
 322   const Type *inn = phase->type(in(1));
 323   if( inn == Type::TOP ) return Type::TOP;  // No information yet
 324 
 325   const TypePtr *in_type   = inn->isa_ptr();
 326   const TypePtr *my_type   = _type->isa_ptr();
 327   const Type *result = _type;
 328   if( in_type != NULL && my_type != NULL ) {
 329     TypePtr::PTR   in_ptr    = in_type->ptr();
 330     if (in_ptr == TypePtr::Null) {
 331       result = in_type;
 332     } else if (in_ptr == TypePtr::Constant) {
 333       const TypeOopPtr *jptr = my_type->isa_oopptr();
 334       assert(jptr, "");
 335       result = !in_type->higher_equal(_type)
 336       ? my_type->cast_to_ptr_type(TypePtr::NotNull)
 337       : in_type;
 338     } else {
 339       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
 340     }
 341   }
 342 
 343   // This is the code from TypePtr::xmeet() that prevents us from
 344   // having 2 ways to represent the same type. We have to replicate it
 345   // here because we don't go through meet/join.
 346   if (result->remove_speculative() == result->speculative()) {
 347     result = result->remove_speculative();
 348   }
 349 
 350   // Same as above: because we don't go through meet/join, remove the
 351   // speculative type if we know we won't use it.
 352   return result->cleanup_speculative();
 353 
 354   // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
 355   // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
 356 
 357   //
 358   // Remove this code after overnight run indicates no performance
 359   // loss from not performing JOIN at CheckCastPPNode
 360   //
 361   // const TypeInstPtr *in_oop = in->isa_instptr();
 362   // const TypeInstPtr *my_oop = _type->isa_instptr();
 363   // // If either input is an 'interface', return destination type
 364   // assert (in_oop == NULL || in_oop->klass() != NULL, "");
 365   // assert (my_oop == NULL || my_oop->klass() != NULL, "");
 366   // if( (in_oop && in_oop->klass()->is_interface())
 367   //   ||(my_oop && my_oop->klass()->is_interface()) ) {
 368   //   TypePtr::PTR  in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
 369   //   // Preserve cast away nullness for interfaces
 370   //   if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
 371   //     return my_oop->cast_to_ptr_type(TypePtr::NotNull);
 372   //   }
 373   //   return _type;
 374   // }
 375   //
 376   // // Neither the input nor the destination type is an interface,
 377   //
 378   // // history: JOIN used to cause weird corner case bugs
 379   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
 380   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
 381   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
 382   // const Type *join = in->join(_type);
 383   // // Check if join preserved NotNull'ness for pointers
 384   // if( join->isa_ptr() && _type->isa_ptr() ) {
 385   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
 386   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
 387   //   // If there isn't any NotNull'ness to preserve
 388   //   // OR if join preserved NotNull'ness then return it
 389   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
 390   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
 391   //     return join;
 392   //   }
 393   //   // ELSE return same old type as before
 394   //   return _type;
 395   // }
 396   // // Not joining two pointers
 397   // return join;
 398 }
 399 
 400 static void replace_in_uses(PhaseIterGVN *igvn, Node* n, Node* m, uint last) {
 401   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
 402     Node* u = n->fast_out(i);
 403     if (u->_idx < last) {
 404       assert(n != u && m != u, "cycle!");
 405       igvn->rehash_node_delayed(u);
 406       int nb = u->replace_edge(n, m);
 407       --i, imax -= nb;
 408     }
 409   }
 410 }
 411 
 412 Node* CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 413   // This is a value type. Its input is the return of a call: the call
 414   // returns a value type and we now know its exact type: build a
 415   // ValueTypePtrNode from the call.
 416   if (can_reshape &&
 417       in(0) == NULL &&
 418       phase->C->can_add_value_type_ptr() &&
 419       type()->isa_valuetypeptr() &&
 420       in(1) != NULL && in(1)->is_Proj() &&
 421       in(1)->in(0) != NULL && in(1)->in(0)->is_CallStaticJava() &&
 422       in(1)->as_Proj()->_con == TypeFunc::Parms) {
 423     ciValueKlass* vk = type()->is_valuetypeptr()->value_type()->value_klass();
 424     assert(vk != phase->C->env()->___Value_klass(), "why cast to __Value?");
 425     PhaseIterGVN *igvn = phase->is_IterGVN();
 426 
 427     if (ValueTypeReturnedAsFields && vk->can_be_returned_as_fields()) {
 428       CallNode* call = in(1)->in(0)->as_Call();
 429       // We now know the return type of the call
 430       const TypeTuple *range_sig = TypeTuple::make_range(vk, false);
 431       const TypeTuple *range_cc = TypeTuple::make_range(vk, true);
 432       assert(range_sig != call->_tf->range_sig() && range_cc != call->_tf->range_cc(), "type should change");
 433       call->_tf = TypeFunc::make(call->_tf->domain_sig(), call->_tf->domain_cc(),
 434                                  range_sig, range_cc);
 435       phase->set_type(call, call->Value(phase));
 436 
 437       CallProjections projs;
 438       call->extract_projections(&projs, true, true);
 439       Node* ctl = projs.fallthrough_catchproj;
 440       Node* mem = projs.fallthrough_memproj;
 441       Node* io = projs.fallthrough_ioproj;
 442       Node* ex_ctl = projs.catchall_catchproj;
 443       Node* ex_mem = projs.catchall_memproj;
 444       Node* ex_io = projs.catchall_ioproj;
 445 
 446       uint last = phase->C->unique();
 447 
 448       Node* r = new RegionNode(3);
 449       Node* mem_phi = new PhiNode(r, Type::MEMORY, TypePtr::BOTTOM);
 450       Node* io_phi = new PhiNode(r, Type::ABIO);
 451 
 452       r->init_req(2, ex_ctl);
 453       mem_phi->init_req(2, ex_mem);
 454       io_phi->init_req(2, ex_io);
 455 
 456       // We need an oop pointer in case allocation elimination
 457       // fails. Allocate a new instance here.
 458       Node* javaoop = ValueTypeBaseNode::allocate(type(), ctl, mem, io,
 459                                                   call->in(TypeFunc::FramePtr),
 460                                                   ex_ctl, ex_mem, ex_io,
 461                                                   call->jvms(), igvn);
 462 
 463 
 464 
 465       r->init_req(1, ex_ctl);
 466       mem_phi->init_req(1, ex_mem);
 467       io_phi->init_req(1, ex_io);
 468 
 469       r = igvn->transform(r);
 470       mem_phi = igvn->transform(mem_phi);
 471       io_phi = igvn->transform(io_phi);
 472 
 473       replace_in_uses(igvn, ex_ctl, r, last);
 474       replace_in_uses(igvn, ex_mem, mem_phi, last);
 475       replace_in_uses(igvn, ex_io, io_phi, last);
 476 
 477       // Create the ValueTypePtrNode. This will add extra projections
 478       // to the call.
 479       ValueTypePtrNode* vtptr = ValueTypePtrNode::make(igvn, this);
 480       igvn->set_delay_transform(true); // stores can be captured. If
 481                                        // they are the whole subgraph
 482                                        // shouldn't go away.
 483 
 484       // Newly allocated value type must be initialized
 485       vtptr->store(igvn, ctl, mem->as_MergeMem(), javaoop);
 486       igvn->set_delay_transform(false);
 487       vtptr->set_oop(javaoop);
 488 
 489       mem = igvn->transform(mem);
 490       replace_in_uses(igvn, projs.fallthrough_catchproj, ctl, last);
 491       replace_in_uses(igvn, projs.fallthrough_memproj, mem, last);
 492       replace_in_uses(igvn, projs.fallthrough_ioproj, io, last);
 493 
 494       igvn->replace_node(in(1), igvn->transform(vtptr));
 495 
 496       return this;
 497     } else {
 498       CallNode* call = in(1)->in(0)->as_Call();
 499       // We now know the return type of the call
 500       const TypeTuple *range = TypeTuple::make_range(vk, false);
 501       if (range != call->_tf->range_sig()) {
 502         // Build the ValueTypePtrNode by loading the fields. Use call
 503         // return as oop edge in the ValueTypePtrNode.
 504         call->_tf = TypeFunc::make(call->_tf->domain_sig(), call->_tf->domain_cc(),
 505                                    range, range);
 506         phase->set_type(call, call->Value(phase));
 507         phase->set_type(in(1), in(1)->Value(phase));
 508         uint last = phase->C->unique();
 509         CallNode* call = in(1)->in(0)->as_Call();
 510         CallProjections projs;
 511         call->extract_projections(&projs, true, true);
 512         Node* mem = projs.fallthrough_memproj;
 513         Node* vtptr = ValueTypePtrNode::make(*phase, mem, in(1));
 514 
 515         return vtptr;
 516       }
 517     }
 518   }
 519   return NULL;
 520 }
 521 
 522 //=============================================================================
 523 //------------------------------Value------------------------------------------
 524 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
 525   const Type* t = phase->type(in(1));
 526   if (t == Type::TOP) return Type::TOP;
 527   if (t->base() == Type_X && t->singleton()) {
 528     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
 529     if (bits == 0)   return TypePtr::NULL_PTR;
 530     return TypeRawPtr::make((address) bits);
 531   }
 532   return CastX2PNode::bottom_type();
 533 }
 534 
 535 //------------------------------Idealize---------------------------------------
 536 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
 537   if (t == Type::TOP)  return false;
 538   const TypeX* tl = t->is_intptr_t();
 539   jint lo = min_jint;
 540   jint hi = max_jint;
 541   if (but_not_min_int)  ++lo;  // caller wants to negate the value w/o overflow
 542   return (tl->_lo >= lo) && (tl->_hi <= hi);
 543 }
 544 
 545 static inline Node* addP_of_X2P(PhaseGVN *phase,
 546                                 Node* base,
 547                                 Node* dispX,
 548                                 bool negate = false) {
 549   if (negate) {
 550     dispX = new SubXNode(phase->MakeConX(0), phase->transform(dispX));
 551   }
 552   return new AddPNode(phase->C->top(),
 553                       phase->transform(new CastX2PNode(base)),
 554                       phase->transform(dispX));
 555 }
 556 
 557 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 558   // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
 559   int op = in(1)->Opcode();
 560   Node* x;
 561   Node* y;
 562   switch (op) {
 563     case Op_SubX:
 564     x = in(1)->in(1);
 565     // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
 566     if (phase->find_intptr_t_con(x, -1) == 0)
 567     break;
 568     y = in(1)->in(2);
 569     if (fits_in_int(phase->type(y), true)) {
 570       return addP_of_X2P(phase, x, y, true);
 571     }
 572     break;
 573     case Op_AddX:
 574     x = in(1)->in(1);
 575     y = in(1)->in(2);
 576     if (fits_in_int(phase->type(y))) {
 577       return addP_of_X2P(phase, x, y);
 578     }
 579     if (fits_in_int(phase->type(x))) {
 580       return addP_of_X2P(phase, y, x);
 581     }
 582     break;
 583   }
 584   return NULL;
 585 }
 586 
 587 //------------------------------Identity---------------------------------------
 588 Node* CastX2PNode::Identity(PhaseGVN* phase) {
 589   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
 590   return this;
 591 }
 592 
 593 //=============================================================================
 594 //------------------------------Value------------------------------------------
 595 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
 596   const Type* t = phase->type(in(1));
 597   if (t == Type::TOP) return Type::TOP;
 598   if (t->base() == Type::RawPtr && t->singleton()) {
 599     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
 600     return TypeX::make(bits);
 601   }
 602   return CastP2XNode::bottom_type();
 603 }
 604 
 605 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 606   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
 607 }
 608 
 609 //------------------------------Identity---------------------------------------
 610 Node* CastP2XNode::Identity(PhaseGVN* phase) {
 611   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
 612   return this;
 613 }