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   if (res == Type::TOP) {
215     return Type::TOP;
216   }
217   assert(res->isa_int(), "res must be int");
218 
219   // Similar to ConvI2LNode::Value() for the same reasons
220   // see if we can remove type assertion after loop opts
221   // But here we have to pay extra attention:
222   // Do not narrow the type of range check dependent CastIINodes to
223   // avoid corruption of the graph if a CastII is replaced by TOP but
224   // the corresponding range check is not removed.
225   if (!_range_check_dependency && phase->C->post_loop_opts_phase()) {
226     const TypeInt* this_type = res->is_int();
227     const TypeInt* in_type = phase->type(in(1))->isa_int();
228     if (in_type != NULL &&
229         (in_type->_lo != this_type->_lo ||
230          in_type->_hi != this_type->_hi)) {
231       jint lo1 = this_type->_lo;
232       jint hi1 = this_type->_hi;
233       int w1 = this_type->_widen;
234       if (lo1 >= 0) {
235         // Keep a range assertion of >=0.
236         lo1 = 0;        hi1 = max_jint;
237       } else if (hi1 < 0) {
238         // Keep a range assertion of <0.
239         lo1 = min_jint; hi1 = -1;
240       } else {
241         lo1 = min_jint; hi1 = max_jint;
242       }
243       res = TypeInt::make(MAX2(in_type->_lo, lo1),
244                           MIN2(in_type->_hi, hi1),
245                           MAX2((int)in_type->_widen, w1));
246     }
247   }
248 
249   // Try to improve the type of the CastII if we recognize a CmpI/If
250   // pattern.
251   if (_dependency != RegularDependency) {
252     if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
253       assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
254       Node* proj = in(0);
255       if (proj->in(0)->in(1)->is_Bool()) {
256         Node* b = proj->in(0)->in(1);
257         if (b->in(1)->Opcode() == Op_CmpI) {
258           Node* cmp = b->in(1);
259           if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
260             const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
261             const Type* t = TypeInt::INT;
262             BoolTest test = b->as_Bool()->_test;
263             if (proj->is_IfFalse()) {
264               test = test.negate();
265             }
266             BoolTest::mask m = test._test;
267             jlong lo_long = min_jint;
268             jlong hi_long = max_jint;
269             if (m == BoolTest::le || m == BoolTest::lt) {
270               hi_long = in2_t->_hi;
271               if (m == BoolTest::lt) {
272                 hi_long -= 1;
273               }
274             } else if (m == BoolTest::ge || m == BoolTest::gt) {
275               lo_long = in2_t->_lo;
276               if (m == BoolTest::gt) {
277                 lo_long += 1;
278               }
279             } else if (m == BoolTest::eq) {
280               lo_long = in2_t->_lo;
281               hi_long = in2_t->_hi;
282             } else if (m == BoolTest::ne) {
283               // can't do any better
284             } else {
285               stringStream ss;
286               test.dump_on(&ss);
287               fatal("unexpected comparison %s", ss.as_string());
288             }
289             int lo_int = (int)lo_long;
290             int hi_int = (int)hi_long;
291 
292             if (lo_long != (jlong)lo_int) {
293               lo_int = min_jint;
294             }
295             if (hi_long != (jlong)hi_int) {
296               hi_int = max_jint;
297             }
298 
299             t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
300 
301             res = res->filter_speculative(t);
302             return res;
303           }
304         }
305       }
306     }
307   }
308   return res;
309 }
310 
311 static Node* find_or_make_CastII(PhaseIterGVN* igvn, Node* parent, Node* control, const TypeInt* type, ConstraintCastNode::DependencyType dependency) {
312   Node* n = new CastIINode(parent, type, dependency);
313   n->set_req(0, control);
314   Node* existing = igvn->hash_find_insert(n);
315   if (existing != NULL) {
316     n->destruct(igvn);
317     return existing;
318   }
319   return igvn->register_new_node_with_optimizer(n);
320 }
321 
322 Node *CastIINode::Ideal(PhaseGVN *phase, bool can_reshape) {
323   Node* progress = ConstraintCastNode::Ideal(phase, can_reshape);
324   if (progress != NULL) {
325     return progress;
326   }
327   if (can_reshape && !_range_check_dependency && !phase->C->post_loop_opts_phase()) {
328     // makes sure we run ::Value to potentially remove type assertion after loop opts
329     phase->C->record_for_post_loop_opts_igvn(this);
330   }
331   PhaseIterGVN* igvn = phase->is_IterGVN();
332   const TypeInt* this_type = this->type()->is_int();
333   Node* z = in(1);
334   const TypeInteger* rx = NULL;
335   const TypeInteger* ry = NULL;
336   // Similar to ConvI2LNode::Ideal() for the same reasons
337   if (!_range_check_dependency && Compile::push_thru_add(phase, z, this_type, rx, ry, T_INT)) {
338     if (igvn == NULL) {
339       // Postpone this optimization to iterative GVN, where we can handle deep
340       // AddI chains without an exponential number of recursive Ideal() calls.
341       phase->record_for_igvn(this);
342       return NULL;
343     }
344     int op = z->Opcode();
345     Node* x = z->in(1);
346     Node* y = z->in(2);
347 
348     Node* cx = find_or_make_CastII(igvn, x, in(0), rx->is_int(), _dependency);
349     Node* cy = find_or_make_CastII(igvn, y, in(0), ry->is_int(), _dependency);
350     switch (op) {
351       case Op_AddI:  return new AddINode(cx, cy);
352       case Op_SubI:  return new SubINode(cx, cy);
353       default:       ShouldNotReachHere();
354     }
355   }
356   return NULL;
357 }
358 
359 Node* CastIINode::Identity(PhaseGVN* phase) {
360   Node* progress = ConstraintCastNode::Identity(phase);
361   if (progress != this) {
362     return progress;
363   }
364   if (_range_check_dependency) {
365     if (phase->C->post_loop_opts_phase()) {
366       return this->in(1);
367     } else {
368       phase->C->record_for_post_loop_opts_igvn(this);
369     }
370   }
371   return this;
372 }
373 
374 bool CastIINode::cmp(const Node &n) const {
375   return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency;
376 }
377 
378 uint CastIINode::size_of() const {
379   return sizeof(*this);
380 }
381 
382 #ifndef PRODUCT
383 void CastIINode::dump_spec(outputStream* st) const {
384   ConstraintCastNode::dump_spec(st);
385   if (_range_check_dependency) {
386     st->print(" range check dependency");
387   }
388 }
389 #endif
390 
391 //=============================================================================
392 //------------------------------Identity---------------------------------------
393 // If input is already higher or equal to cast type, then this is an identity.
394 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
395   if (in(1)->is_InlineTypeBase() && _type->isa_oopptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_oopptr()->klass())) {
396     return in(1);
397   }
398   Node* dom = dominating_cast(phase, phase);
399   if (dom != NULL) {
400     return dom;
401   }
402   if (_dependency != RegularDependency) {
403     return this;
404   }
405   const Type* t = phase->type(in(1));
406   if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) {
407     if (t->higher_equal_speculative(phase->type(this))) {
408       return in(1);
409     }
410   } else if (t == phase->type(this)) {
411     // Toned down to rescue meeting at a Phi 3 different oops all implementing
412     // the same interface.
413     return in(1);
414   }
415   return this;
416 }
417 
418 //------------------------------Value------------------------------------------
419 // Take 'join' of input and cast-up type, unless working with an Interface
420 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
421   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
422 
423   const Type *inn = phase->type(in(1));
424   if( inn == Type::TOP ) return Type::TOP;  // No information yet
425 
426   const TypePtr *in_type   = inn->isa_ptr();
427   const TypePtr *my_type   = _type->isa_ptr();
428   const Type *result = _type;
429   if (in_type != NULL && my_type != NULL) {
430     if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
431       // Propagate array properties (not flat/null-free)
432       // Don't do this when StressReflectiveCode is enabled because it might lead to
433       // a dying data path while the corresponding flat/null-free check is not folded.
434       my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
435       if (my_type == NULL) {
436         return Type::TOP; // Inconsistent properties
437       }
438     }
439     TypePtr::PTR in_ptr = in_type->ptr();
440     if (in_ptr == TypePtr::Null) {
441       result = in_type;
442     } else if (in_ptr == TypePtr::Constant) {
443       if (my_type->isa_rawptr()) {
444         result = my_type;
445       } else {
446         const TypeOopPtr *jptr = my_type->isa_oopptr();
447         assert(jptr, "");
448         result = !in_type->higher_equal(_type)
449           ? my_type->cast_to_ptr_type(TypePtr::NotNull)
450           : in_type;
451       }
452     } else {
453       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
454     }
455   }
456 
457   // This is the code from TypePtr::xmeet() that prevents us from
458   // having 2 ways to represent the same type. We have to replicate it
459   // here because we don't go through meet/join.
460   if (result->remove_speculative() == result->speculative()) {
461     result = result->remove_speculative();
462   }
463 
464   // Same as above: because we don't go through meet/join, remove the
465   // speculative type if we know we won't use it.
466   return result->cleanup_speculative();
467 
468   // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
469   // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
470 
471   //
472   // Remove this code after overnight run indicates no performance
473   // loss from not performing JOIN at CheckCastPPNode
474   //
475   // const TypeInstPtr *in_oop = in->isa_instptr();
476   // const TypeInstPtr *my_oop = _type->isa_instptr();
477   // // If either input is an 'interface', return destination type
478   // assert (in_oop == NULL || in_oop->klass() != NULL, "");
479   // assert (my_oop == NULL || my_oop->klass() != NULL, "");
480   // if( (in_oop && in_oop->klass()->is_interface())
481   //   ||(my_oop && my_oop->klass()->is_interface()) ) {
482   //   TypePtr::PTR  in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
483   //   // Preserve cast away nullness for interfaces
484   //   if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
485   //     return my_oop->cast_to_ptr_type(TypePtr::NotNull);
486   //   }
487   //   return _type;
488   // }
489   //
490   // // Neither the input nor the destination type is an interface,
491   //
492   // // history: JOIN used to cause weird corner case bugs
493   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
494   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
495   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
496   // const Type *join = in->join(_type);
497   // // Check if join preserved NotNull'ness for pointers
498   // if( join->isa_ptr() && _type->isa_ptr() ) {
499   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
500   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
501   //   // If there isn't any NotNull'ness to preserve
502   //   // OR if join preserved NotNull'ness then return it
503   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
504   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
505   //     return join;
506   //   }
507   //   // ELSE return same old type as before
508   //   return _type;
509   // }
510   // // Not joining two pointers
511   // return join;
512 }
513 
514 //=============================================================================
515 //------------------------------Value------------------------------------------
516 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
517   const Type* t = phase->type(in(1));
518   if (t == Type::TOP) return Type::TOP;
519   if (t->base() == Type_X && t->singleton()) {
520     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
521     if (bits == 0)   return TypePtr::NULL_PTR;
522     return TypeRawPtr::make((address) bits);
523   }
524   return CastX2PNode::bottom_type();
525 }
526 
527 //------------------------------Idealize---------------------------------------
528 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
529   if (t == Type::TOP)  return false;
530   const TypeX* tl = t->is_intptr_t();
531   jint lo = min_jint;
532   jint hi = max_jint;
533   if (but_not_min_int)  ++lo;  // caller wants to negate the value w/o overflow
534   return (tl->_lo >= lo) && (tl->_hi <= hi);
535 }
536 
537 static inline Node* addP_of_X2P(PhaseGVN *phase,
538                                 Node* base,
539                                 Node* dispX,
540                                 bool negate = false) {
541   if (negate) {
542     dispX = phase->transform(new SubXNode(phase->MakeConX(0), dispX));
543   }
544   return new AddPNode(phase->C->top(),
545                       phase->transform(new CastX2PNode(base)),
546                       dispX);
547 }
548 
549 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
550   // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
551   int op = in(1)->Opcode();
552   Node* x;
553   Node* y;
554   switch (op) {
555     case Op_SubX:
556     x = in(1)->in(1);
557     // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
558     if (phase->find_intptr_t_con(x, -1) == 0)
559     break;
560     y = in(1)->in(2);
561     if (fits_in_int(phase->type(y), true)) {
562       return addP_of_X2P(phase, x, y, true);
563     }
564     break;
565     case Op_AddX:
566     x = in(1)->in(1);
567     y = in(1)->in(2);
568     if (fits_in_int(phase->type(y))) {
569       return addP_of_X2P(phase, x, y);
570     }
571     if (fits_in_int(phase->type(x))) {
572       return addP_of_X2P(phase, y, x);
573     }
574     break;
575   }
576   return NULL;
577 }
578 
579 //------------------------------Identity---------------------------------------
580 Node* CastX2PNode::Identity(PhaseGVN* phase) {
581   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
582   return this;
583 }
584 
585 //=============================================================================
586 //------------------------------Value------------------------------------------
587 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
588   const Type* t = phase->type(in(1));
589   if (t == Type::TOP) return Type::TOP;
590   if (t->base() == Type::RawPtr && t->singleton()) {
591     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
592     return TypeX::make(bits);
593   }
594 
595   if (t->is_zero_type() || !t->maybe_null()) {
596     for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
597       Node* u = fast_out(i);
598       if (u->Opcode() == Op_OrL) {
599         for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
600           Node* cmp = u->fast_out(j);
601           if (cmp->Opcode() == Op_CmpL) {
602             // Give CmpL a chance to get optimized
603             phase->record_for_igvn(cmp);
604           }
605         }
606       }
607     }
608   }
609 
610   return CastP2XNode::bottom_type();
611 }
612 
613 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
614   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
615 }
616 
617 //------------------------------Identity---------------------------------------
618 Node* CastP2XNode::Identity(PhaseGVN* phase) {
619   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
620   return this;
621 }
622 
623 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
624   Node* cast= NULL;
625   if (type->isa_int()) {
626     cast = make_cast(Op_CastII, c, in, type, dependency);
627   } else if (type->isa_long()) {
628     cast = make_cast(Op_CastLL, c, in, type, dependency);
629   } else if (type->isa_float()) {
630     cast = make_cast(Op_CastFF, c, in, type, dependency);
631   } else if (type->isa_double()) {
632     cast = make_cast(Op_CastDD, c, in, type, dependency);
633   } else if (type->isa_vect()) {
634     cast = make_cast(Op_CastVV, c, in, type, dependency);
635   } else if (type->isa_ptr()) {
636     cast = make_cast(Op_CastPP, c, in, type, dependency);
637   }
638   return cast;
639 }