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/graphKit.hpp"
 31 #include "opto/inlinetypenode.hpp"
 32 #include "opto/matcher.hpp"
 33 #include "opto/phaseX.hpp"
 34 #include "opto/rootnode.hpp"
 35 #include "opto/subnode.hpp"
 36 #include "opto/type.hpp"
 37 
 38 //=============================================================================
 39 // If input is already higher or equal to cast type, then this is an identity.
 40 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 41   Node* dom = dominating_cast(phase, phase);
 42   if (dom != NULL) {
 43     return dom;
 44   }
 45   if (_dependency != RegularDependency) {
 46     return this;
 47   }
 48   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
 49 }
 50 
 51 //------------------------------Value------------------------------------------
 52 // Take 'join' of input and cast-up type
 53 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
 54   if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;
 55   const Type* ft = phase->type(in(1))->filter_speculative(_type);
 56 
 57 #ifdef ASSERT
 58   // Previous versions of this function had some special case logic,
 59   // which is no longer necessary.  Make sure of the required effects.
 60   switch (Opcode()) {
 61     case Op_CastII:
 62     {
 63       const Type* t1 = phase->type(in(1));
 64       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
 65       const Type* rt = t1->join_speculative(_type);
 66       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
 67       break;
 68     }
 69     case Op_CastPP:
 70     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
 71         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
 72     assert(ft == Type::TOP, "special case #3");
 73     break;
 74   }
 75 #endif //ASSERT
 76 
 77   return ft;
 78 }
 79 
 80 //------------------------------Ideal------------------------------------------
 81 // Return a node which is more "ideal" than the current node.  Strip out
 82 // control copies
 83 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 84   if (in(0) && remove_dead_region(phase, can_reshape)) {
 85     return this;
 86   }
 87 
 88   // Push cast through InlineTypePtrNode
 89   InlineTypePtrNode* vt = in(1)->isa_InlineTypePtr();
 90   if (vt != NULL && phase->type(vt)->filter_speculative(_type) != Type::TOP) {
 91     Node* cast = clone();
 92     cast->set_req(1, vt->get_oop());
 93     vt = vt->clone()->as_InlineTypePtr();
 94     vt->set_oop(phase->transform(cast));
 95     return vt;
 96   }
 97 
 98   return NULL;
 99 }
100 
101 bool ConstraintCastNode::cmp(const Node &n) const {
102   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
103 }
104 
105 uint ConstraintCastNode::size_of() const {
106   return sizeof(*this);
107 }
108 
109 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
110   switch(opcode) {
111   case Op_CastII: {
112     Node* cast = new CastIINode(n, t, dependency);
113     cast->set_req(0, c);
114     return cast;
115   }
116   case Op_CastLL: {
117     Node* cast = new CastLLNode(n, t, dependency);
118     cast->set_req(0, c);
119     return cast;
120   }
121   case Op_CastPP: {
122     Node* cast = new CastPPNode(n, t, dependency);
123     cast->set_req(0, c);
124     return cast;
125   }
126   case Op_CastFF: {
127     Node* cast = new CastFFNode(n, t, dependency);
128     cast->set_req(0, c);
129     return cast;
130   }
131   case Op_CastDD: {
132     Node* cast = new CastDDNode(n, t, dependency);
133     cast->set_req(0, c);
134     return cast;
135   }
136   case Op_CastVV: {
137     Node* cast = new CastVVNode(n, t, dependency);
138     cast->set_req(0, c);
139     return cast;
140   }
141   case Op_CheckCastPP: return new CheckCastPPNode(c, n, t, dependency);
142   default:
143     fatal("Bad opcode %d", opcode);
144   }
145   return NULL;
146 }
147 
148 Node* ConstraintCastNode::make(Node* c, Node *n, const Type *t, BasicType bt) {
149   switch(bt) {
150   case T_INT: {
151     return make_cast(Op_CastII, c, n, t, RegularDependency);
152   }
153   case T_LONG: {
154     return make_cast(Op_CastLL, c, n, t, RegularDependency);
155   }
156   default:
157     fatal("Bad basic type %s", type2name(bt));
158   }
159   return NULL;
160 }
161 
162 TypeNode* ConstraintCastNode::dominating_cast(PhaseGVN* gvn, PhaseTransform* pt) const {
163   if (_dependency == UnconditionalDependency) {
164     return NULL;
165   }
166   Node* val = in(1);
167   Node* ctl = in(0);
168   int opc = Opcode();
169   if (ctl == NULL) {
170     return NULL;
171   }
172   // Range check CastIIs may all end up under a single range check and
173   // in that case only the narrower CastII would be kept by the code
174   // below which would be incorrect.
175   if (is_CastII() && as_CastII()->has_range_check()) {
176     return NULL;
177   }
178   if (type()->isa_rawptr() && (gvn->type_or_null(val) == NULL || gvn->type(val)->isa_oopptr())) {
179     return NULL;
180   }
181   for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
182     Node* u = val->fast_out(i);
183     if (u != this &&
184         u->outcnt() > 0 &&
185         u->Opcode() == opc &&
186         u->in(0) != NULL &&
187         u->bottom_type()->higher_equal(type())) {
188       if (pt->is_dominator(u->in(0), ctl)) {
189         return u->as_Type();
190       }
191       if (is_CheckCastPP() && u->in(1)->is_Proj() && u->in(1)->in(0)->is_Allocate() &&
192           u->in(0)->is_Proj() && u->in(0)->in(0)->is_Initialize() &&
193           u->in(1)->in(0)->as_Allocate()->initialization() == u->in(0)->in(0)) {
194         // CheckCastPP following an allocation always dominates all
195         // use of the allocation result
196         return u->as_Type();
197       }
198     }
199   }
200   return NULL;
201 }
202 
203 #ifndef PRODUCT
204 void ConstraintCastNode::dump_spec(outputStream *st) const {
205   TypeNode::dump_spec(st);
206   if (_dependency != RegularDependency) {
207     st->print(" %s dependency", _dependency == StrongDependency ? "strong" : "unconditional");
208   }
209 }
210 #endif
211 
212 const Type* CastIINode::Value(PhaseGVN* phase) const {
213   const Type *res = ConstraintCastNode::Value(phase);
214 
215   // Try to improve the type of the CastII if we recognize a CmpI/If
216   // pattern.
217   if (_dependency != RegularDependency) {
218     if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
219       assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
220       Node* proj = in(0);
221       if (proj->in(0)->in(1)->is_Bool()) {
222         Node* b = proj->in(0)->in(1);
223         if (b->in(1)->Opcode() == Op_CmpI) {
224           Node* cmp = b->in(1);
225           if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
226             const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
227             const Type* t = TypeInt::INT;
228             BoolTest test = b->as_Bool()->_test;
229             if (proj->is_IfFalse()) {
230               test = test.negate();
231             }
232             BoolTest::mask m = test._test;
233             jlong lo_long = min_jint;
234             jlong hi_long = max_jint;
235             if (m == BoolTest::le || m == BoolTest::lt) {
236               hi_long = in2_t->_hi;
237               if (m == BoolTest::lt) {
238                 hi_long -= 1;
239               }
240             } else if (m == BoolTest::ge || m == BoolTest::gt) {
241               lo_long = in2_t->_lo;
242               if (m == BoolTest::gt) {
243                 lo_long += 1;
244               }
245             } else if (m == BoolTest::eq) {
246               lo_long = in2_t->_lo;
247               hi_long = in2_t->_hi;
248             } else if (m == BoolTest::ne) {
249               // can't do any better
250             } else {
251               stringStream ss;
252               test.dump_on(&ss);
253               fatal("unexpected comparison %s", ss.as_string());
254             }
255             int lo_int = (int)lo_long;
256             int hi_int = (int)hi_long;
257 
258             if (lo_long != (jlong)lo_int) {
259               lo_int = min_jint;
260             }
261             if (hi_long != (jlong)hi_int) {
262               hi_int = max_jint;
263             }
264 
265             t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
266 
267             res = res->filter_speculative(t);
268 
269             return res;
270           }
271         }
272       }
273     }
274   }
275   return res;
276 }
277 
278 static Node* find_or_make_CastII(PhaseIterGVN* igvn, Node* parent, Node* control, const TypeInt* type, ConstraintCastNode::DependencyType dependency) {
279   Node* n = new CastIINode(parent, type, dependency);
280   n->set_req(0, control);
281   Node* existing = igvn->hash_find_insert(n);
282   if (existing != NULL) {
283     n->destruct(igvn);
284     return existing;
285   }
286   return igvn->register_new_node_with_optimizer(n);
287 }
288 
289 Node *CastIINode::Ideal(PhaseGVN *phase, bool can_reshape) {
290   Node* progress = ConstraintCastNode::Ideal(phase, can_reshape);
291   if (progress != NULL) {
292     return progress;
293   }
294 
295   PhaseIterGVN *igvn = phase->is_IterGVN();
296   const TypeInt* this_type = this->type()->is_int();
297   Node* z = in(1);
298   const TypeInteger* rx = NULL;
299   const TypeInteger* ry = NULL;
300   // Similar to ConvI2LNode::Ideal() for the same reasons
301   if (!_range_check_dependency && Compile::push_thru_add(phase, z, this_type, rx, ry, T_INT)) {
302     if (igvn == NULL) {
303       // Postpone this optimization to iterative GVN, where we can handle deep
304       // AddI chains without an exponential number of recursive Ideal() calls.
305       phase->record_for_igvn(this);
306       return NULL;
307     }
308     int op = z->Opcode();
309     Node* x = z->in(1);
310     Node* y = z->in(2);
311 
312     Node* cx = find_or_make_CastII(igvn, x, in(0), rx->is_int(), _dependency);
313     Node* cy = find_or_make_CastII(igvn, y, in(0), ry->is_int(), _dependency);
314     switch (op) {
315       case Op_AddI:  return new AddINode(cx, cy);
316       case Op_SubI:  return new SubINode(cx, cy);
317       default:       ShouldNotReachHere();
318     }
319   }
320 
321   // Similar to ConvI2LNode::Ideal() for the same reasons
322   // Do not narrow the type of range check dependent CastIINodes to
323   // avoid corruption of the graph if a CastII is replaced by TOP but
324   // the corresponding range check is not removed.
325   if (can_reshape && !_range_check_dependency) {
326     if (phase->C->post_loop_opts_phase()) {
327       const TypeInt* this_type = this->type()->is_int();
328       const TypeInt* in_type = phase->type(in(1))->isa_int();
329       if (in_type != NULL && this_type != NULL &&
330           (in_type->_lo != this_type->_lo ||
331            in_type->_hi != this_type->_hi)) {
332         jint lo1 = this_type->_lo;
333         jint hi1 = this_type->_hi;
334         int w1  = this_type->_widen;
335 
336         if (lo1 >= 0) {
337           // Keep a range assertion of >=0.
338           lo1 = 0;        hi1 = max_jint;
339         } else if (hi1 < 0) {
340           // Keep a range assertion of <0.
341           lo1 = min_jint; hi1 = -1;
342         } else {
343           lo1 = min_jint; hi1 = max_jint;
344         }
345         const TypeInt* wtype = TypeInt::make(MAX2(in_type->_lo, lo1),
346                                              MIN2(in_type->_hi, hi1),
347                                              MAX2((int)in_type->_widen, w1));
348         if (wtype != type()) {
349           set_type(wtype);
350           return this;
351         }
352       }
353     } else {
354       phase->C->record_for_post_loop_opts_igvn(this);
355     }
356   }
357   return NULL;
358 }
359 
360 Node* CastIINode::Identity(PhaseGVN* phase) {
361   Node* progress = ConstraintCastNode::Identity(phase);
362   if (progress != this) {
363     return progress;
364   }
365   if (_range_check_dependency) {
366     if (phase->C->post_loop_opts_phase()) {
367       return this->in(1);
368     } else {
369       phase->C->record_for_post_loop_opts_igvn(this);
370     }
371   }
372   return this;
373 }
374 
375 bool CastIINode::cmp(const Node &n) const {
376   return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency;
377 }
378 
379 uint CastIINode::size_of() const {
380   return sizeof(*this);
381 }
382 
383 #ifndef PRODUCT
384 void CastIINode::dump_spec(outputStream* st) const {
385   ConstraintCastNode::dump_spec(st);
386   if (_range_check_dependency) {
387     st->print(" range check dependency");
388   }
389 }
390 #endif
391 
392 //=============================================================================
393 //------------------------------Identity---------------------------------------
394 // If input is already higher or equal to cast type, then this is an identity.
395 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
396   if (in(1)->is_InlineTypeBase() && _type->isa_oopptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_oopptr()->klass())) {
397     return in(1);
398   }
399   Node* dom = dominating_cast(phase, phase);
400   if (dom != NULL) {
401     return dom;
402   }
403   if (_dependency != RegularDependency) {
404     return this;
405   }
406   const Type* t = phase->type(in(1));
407   if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) {
408     if (t->higher_equal_speculative(phase->type(this))) {
409       return in(1);
410     }
411   } else if (t == phase->type(this)) {
412     // Toned down to rescue meeting at a Phi 3 different oops all implementing
413     // the same interface.
414     return in(1);
415   }
416   return this;
417 }
418 
419 //------------------------------Value------------------------------------------
420 // Take 'join' of input and cast-up type, unless working with an Interface
421 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
422   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
423 
424   const Type *inn = phase->type(in(1));
425   if( inn == Type::TOP ) return Type::TOP;  // No information yet
426 
427   const TypePtr *in_type   = inn->isa_ptr();
428   const TypePtr *my_type   = _type->isa_ptr();
429   const Type *result = _type;
430   if (in_type != NULL && my_type != NULL) {
431     if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
432       // Propagate array properties (not flat/null-free)
433       // Don't do this when StressReflectiveCode is enabled because it might lead to
434       // a dying data path while the corresponding flat/null-free check is not folded.
435       my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
436       if (my_type == NULL) {
437         return Type::TOP; // Inconsistent properties
438       }
439     }
440     TypePtr::PTR in_ptr = in_type->ptr();
441     if (in_ptr == TypePtr::Null) {
442       result = in_type;
443     } else if (in_ptr == TypePtr::Constant) {
444       if (my_type->isa_rawptr()) {
445         result = my_type;
446       } else {
447         const TypeOopPtr *jptr = my_type->isa_oopptr();
448         assert(jptr, "");
449         result = !in_type->higher_equal(_type)
450           ? my_type->cast_to_ptr_type(TypePtr::NotNull)
451           : in_type;
452       }
453     } else {
454       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
455     }
456   }
457 
458   // This is the code from TypePtr::xmeet() that prevents us from
459   // having 2 ways to represent the same type. We have to replicate it
460   // here because we don't go through meet/join.
461   if (result->remove_speculative() == result->speculative()) {
462     result = result->remove_speculative();
463   }
464 
465   // Same as above: because we don't go through meet/join, remove the
466   // speculative type if we know we won't use it.
467   return result->cleanup_speculative();
468 
469   // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
470   // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
471 
472   //
473   // Remove this code after overnight run indicates no performance
474   // loss from not performing JOIN at CheckCastPPNode
475   //
476   // const TypeInstPtr *in_oop = in->isa_instptr();
477   // const TypeInstPtr *my_oop = _type->isa_instptr();
478   // // If either input is an 'interface', return destination type
479   // assert (in_oop == NULL || in_oop->klass() != NULL, "");
480   // assert (my_oop == NULL || my_oop->klass() != NULL, "");
481   // if( (in_oop && in_oop->klass()->is_interface())
482   //   ||(my_oop && my_oop->klass()->is_interface()) ) {
483   //   TypePtr::PTR  in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
484   //   // Preserve cast away nullness for interfaces
485   //   if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
486   //     return my_oop->cast_to_ptr_type(TypePtr::NotNull);
487   //   }
488   //   return _type;
489   // }
490   //
491   // // Neither the input nor the destination type is an interface,
492   //
493   // // history: JOIN used to cause weird corner case bugs
494   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
495   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
496   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
497   // const Type *join = in->join(_type);
498   // // Check if join preserved NotNull'ness for pointers
499   // if( join->isa_ptr() && _type->isa_ptr() ) {
500   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
501   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
502   //   // If there isn't any NotNull'ness to preserve
503   //   // OR if join preserved NotNull'ness then return it
504   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
505   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
506   //     return join;
507   //   }
508   //   // ELSE return same old type as before
509   //   return _type;
510   // }
511   // // Not joining two pointers
512   // return join;
513 }
514 
515 //=============================================================================
516 //------------------------------Value------------------------------------------
517 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
518   const Type* t = phase->type(in(1));
519   if (t == Type::TOP) return Type::TOP;
520   if (t->base() == Type_X && t->singleton()) {
521     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
522     if (bits == 0)   return TypePtr::NULL_PTR;
523     return TypeRawPtr::make((address) bits);
524   }
525   return CastX2PNode::bottom_type();
526 }
527 
528 //------------------------------Idealize---------------------------------------
529 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
530   if (t == Type::TOP)  return false;
531   const TypeX* tl = t->is_intptr_t();
532   jint lo = min_jint;
533   jint hi = max_jint;
534   if (but_not_min_int)  ++lo;  // caller wants to negate the value w/o overflow
535   return (tl->_lo >= lo) && (tl->_hi <= hi);
536 }
537 
538 static inline Node* addP_of_X2P(PhaseGVN *phase,
539                                 Node* base,
540                                 Node* dispX,
541                                 bool negate = false) {
542   if (negate) {
543     dispX = phase->transform(new SubXNode(phase->MakeConX(0), dispX));
544   }
545   return new AddPNode(phase->C->top(),
546                       phase->transform(new CastX2PNode(base)),
547                       dispX);
548 }
549 
550 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
551   // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
552   int op = in(1)->Opcode();
553   Node* x;
554   Node* y;
555   switch (op) {
556     case Op_SubX:
557     x = in(1)->in(1);
558     // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
559     if (phase->find_intptr_t_con(x, -1) == 0)
560     break;
561     y = in(1)->in(2);
562     if (fits_in_int(phase->type(y), true)) {
563       return addP_of_X2P(phase, x, y, true);
564     }
565     break;
566     case Op_AddX:
567     x = in(1)->in(1);
568     y = in(1)->in(2);
569     if (fits_in_int(phase->type(y))) {
570       return addP_of_X2P(phase, x, y);
571     }
572     if (fits_in_int(phase->type(x))) {
573       return addP_of_X2P(phase, y, x);
574     }
575     break;
576   }
577   return NULL;
578 }
579 
580 //------------------------------Identity---------------------------------------
581 Node* CastX2PNode::Identity(PhaseGVN* phase) {
582   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
583   return this;
584 }
585 
586 //=============================================================================
587 //------------------------------Value------------------------------------------
588 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
589   const Type* t = phase->type(in(1));
590   if (t == Type::TOP) return Type::TOP;
591   if (t->base() == Type::RawPtr && t->singleton()) {
592     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
593     return TypeX::make(bits);
594   }
595 
596   if (t->is_zero_type() || !t->maybe_null()) {
597     for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
598       Node* u = fast_out(i);
599       if (u->Opcode() == Op_OrL) {
600         for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
601           Node* cmp = u->fast_out(j);
602           if (cmp->Opcode() == Op_CmpL) {
603             // Give CmpL a chance to get optimized
604             phase->record_for_igvn(cmp);
605           }
606         }
607       }
608     }
609   }
610 
611   return CastP2XNode::bottom_type();
612 }
613 
614 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
615   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
616 }
617 
618 //------------------------------Identity---------------------------------------
619 Node* CastP2XNode::Identity(PhaseGVN* phase) {
620   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
621   return this;
622 }
623 
624 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
625   Node* cast= NULL;
626   if (type->isa_int()) {
627     cast = make_cast(Op_CastII, c, in, type, dependency);
628   } else if (type->isa_long()) {
629     cast = make_cast(Op_CastLL, c, in, type, dependency);
630   } else if (type->isa_float()) {
631     cast = make_cast(Op_CastFF, c, in, type, dependency);
632   } else if (type->isa_double()) {
633     cast = make_cast(Op_CastDD, c, in, type, dependency);
634   } else if (type->isa_vect()) {
635     cast = make_cast(Op_CastVV, c, in, type, dependency);
636   } else if (type->isa_ptr()) {
637     cast = make_cast(Op_CastPP, c, in, type, dependency);
638   }
639   return cast;
640 }