Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/connode.cpp
32285 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "memory/allocation.inline.hpp"26#include "opto/addnode.hpp"27#include "opto/compile.hpp"28#include "opto/connode.hpp"29#include "opto/machnode.hpp"30#include "opto/matcher.hpp"31#include "opto/memnode.hpp"32#include "opto/phaseX.hpp"33#include "opto/subnode.hpp"34#include "runtime/sharedRuntime.hpp"3536// Optimization - Graph Style3738//=============================================================================39//------------------------------hash-------------------------------------------40uint ConNode::hash() const {41return (uintptr_t)in(TypeFunc::Control) + _type->hash();42}4344//------------------------------make-------------------------------------------45ConNode *ConNode::make( Compile* C, const Type *t ) {46switch( t->basic_type() ) {47case T_INT: return new (C) ConINode( t->is_int() );48case T_LONG: return new (C) ConLNode( t->is_long() );49case T_FLOAT: return new (C) ConFNode( t->is_float_constant() );50case T_DOUBLE: return new (C) ConDNode( t->is_double_constant() );51case T_VOID: return new (C) ConNode ( Type::TOP );52case T_OBJECT: return new (C) ConPNode( t->is_ptr() );53case T_ARRAY: return new (C) ConPNode( t->is_aryptr() );54case T_ADDRESS: return new (C) ConPNode( t->is_ptr() );55case T_NARROWOOP: return new (C) ConNNode( t->is_narrowoop() );56case T_NARROWKLASS: return new (C) ConNKlassNode( t->is_narrowklass() );57case T_METADATA: return new (C) ConPNode( t->is_ptr() );58// Expected cases: TypePtr::NULL_PTR, any is_rawptr()59// Also seen: AnyPtr(TopPTR *+top); from command line:60// r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=66061// %%%% Stop using TypePtr::NULL_PTR to represent nulls: use either TypeRawPtr::NULL_PTR62// or else TypeOopPtr::NULL_PTR. Then set Type::_basic_type[AnyPtr] = T_ILLEGAL63}64ShouldNotReachHere();65return NULL;66}6768//=============================================================================69/*70The major change is for CMoveP and StrComp. They have related but slightly71different problems. They both take in TWO oops which are both null-checked72independently before the using Node. After CCP removes the CastPP's they need73to pick up the guarding test edge - in this case TWO control edges. I tried74various solutions, all have problems:7576(1) Do nothing. This leads to a bug where we hoist a Load from a CMoveP or a77StrComp above a guarding null check. I've seen both cases in normal -Xcomp78testing.7980(2) Plug the control edge from 1 of the 2 oops in. Apparent problem here is81to figure out which test post-dominates. The real problem is that it doesn't82matter which one you pick. After you pick up, the dominating-test elider in83IGVN can remove the test and allow you to hoist up to the dominating test on84the chosen oop bypassing the test on the not-chosen oop. Seen in testing.85Oops.8687(3) Leave the CastPP's in. This makes the graph more accurate in some sense;88we get to keep around the knowledge that an oop is not-null after some test.89Alas, the CastPP's interfere with GVN (some values are the regular oop, some90are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).91This cost us 10% on SpecJVM, even when I removed some of the more trivial92cases in the optimizer. Removing more useless Phi's started allowing Loads to93illegally float above null checks. I gave up on this approach.9495(4) Add BOTH control edges to both tests. Alas, too much code knows that96control edges are in slot-zero ONLY. Many quick asserts fail; no way to do97this one. Note that I really want to allow the CMoveP to float and add both98control edges to the dependent Load op - meaning I can select early but I99cannot Load until I pass both tests.100101(5) Do not hoist CMoveP and StrComp. To this end I added the v-call102depends_only_on_test(). No obvious performance loss on Spec, but we are103clearly conservative on CMoveP (also so on StrComp but that's unlikely to104matter ever).105106*/107108109//------------------------------Ideal------------------------------------------110// Return a node which is more "ideal" than the current node.111// Move constants to the right.112Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {113if( in(0) && remove_dead_region(phase, can_reshape) ) return this;114// Don't bother trying to transform a dead node115if( in(0) && in(0)->is_top() ) return NULL;116assert( !phase->eqv(in(Condition), this) &&117!phase->eqv(in(IfFalse), this) &&118!phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );119if( phase->type(in(Condition)) == Type::TOP )120return NULL; // return NULL when Condition is dead121122if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {123if( in(Condition)->is_Bool() ) {124BoolNode* b = in(Condition)->as_Bool();125BoolNode* b2 = b->negate(phase);126return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );127}128}129return NULL;130}131132//------------------------------is_cmove_id------------------------------------133// Helper function to check for CMOVE identity. Shared with PhiNode::Identity134Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {135// Check for Cmp'ing and CMove'ing same values136if( (phase->eqv(cmp->in(1),f) &&137phase->eqv(cmp->in(2),t)) ||138// Swapped Cmp is OK139(phase->eqv(cmp->in(2),f) &&140phase->eqv(cmp->in(1),t)) ) {141// Give up this identity check for floating points because it may choose incorrect142// value around 0.0 and -0.0143if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )144return NULL;145// Check for "(t==f)?t:f;" and replace with "f"146if( b->_test._test == BoolTest::eq )147return f;148// Allow the inverted case as well149// Check for "(t!=f)?t:f;" and replace with "t"150if( b->_test._test == BoolTest::ne )151return t;152}153return NULL;154}155156//------------------------------Identity---------------------------------------157// Conditional-move is an identity if both inputs are the same, or the test158// true or false.159Node *CMoveNode::Identity( PhaseTransform *phase ) {160if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?161return in(IfFalse); // Then it doesn't matter162if( phase->type(in(Condition)) == TypeInt::ZERO )163return in(IfFalse); // Always pick left(false) input164if( phase->type(in(Condition)) == TypeInt::ONE )165return in(IfTrue); // Always pick right(true) input166167// Check for CMove'ing a constant after comparing against the constant.168// Happens all the time now, since if we compare equality vs a constant in169// the parser, we "know" the variable is constant on one path and we force170// it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a171// conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more172// general in that we don't need constants.173if( in(Condition)->is_Bool() ) {174BoolNode *b = in(Condition)->as_Bool();175Node *cmp = b->in(1);176if( cmp->is_Cmp() ) {177Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );178if( id ) return id;179}180}181182return this;183}184185//------------------------------Value------------------------------------------186// Result is the meet of inputs187const Type *CMoveNode::Value( PhaseTransform *phase ) const {188if( phase->type(in(Condition)) == Type::TOP )189return Type::TOP;190return phase->type(in(IfFalse))->meet_speculative(phase->type(in(IfTrue)));191}192193//------------------------------make-------------------------------------------194// Make a correctly-flavored CMove. Since _type is directly determined195// from the inputs we do not need to specify it here.196CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {197switch( t->basic_type() ) {198case T_INT: return new (C) CMoveINode( bol, left, right, t->is_int() );199case T_FLOAT: return new (C) CMoveFNode( bol, left, right, t );200case T_DOUBLE: return new (C) CMoveDNode( bol, left, right, t );201case T_LONG: return new (C) CMoveLNode( bol, left, right, t->is_long() );202case T_OBJECT: return new (C) CMovePNode( c, bol, left, right, t->is_oopptr() );203case T_ADDRESS: return new (C) CMovePNode( c, bol, left, right, t->is_ptr() );204case T_NARROWOOP: return new (C) CMoveNNode( c, bol, left, right, t );205default:206ShouldNotReachHere();207return NULL;208}209}210211//=============================================================================212//------------------------------Ideal------------------------------------------213// Return a node which is more "ideal" than the current node.214// Check for conversions to boolean215Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {216// Try generic ideal's first217Node *x = CMoveNode::Ideal(phase, can_reshape);218if( x ) return x;219220// If zero is on the left (false-case, no-move-case) it must mean another221// constant is on the right (otherwise the shared CMove::Ideal code would222// have moved the constant to the right). This situation is bad for Intel223// and a don't-care for Sparc. It's bad for Intel because the zero has to224// be manifested in a register with a XOR which kills flags, which are live225// on input to the CMoveI, leading to a situation which causes excessive226// spilling on Intel. For Sparc, if the zero in on the left the Sparc will227// zero a register via G0 and conditionally-move the other constant. If the228// zero is on the right, the Sparc will load the first constant with a229// 13-bit set-lo and conditionally move G0. See bug 4677505.230if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {231if( in(Condition)->is_Bool() ) {232BoolNode* b = in(Condition)->as_Bool();233BoolNode* b2 = b->negate(phase);234return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );235}236}237238// Now check for booleans239int flip = 0;240241// Check for picking from zero/one242if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {243flip = 1 - flip;244} else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {245} else return NULL;246247// Check for eq/ne test248if( !in(1)->is_Bool() ) return NULL;249BoolNode *bol = in(1)->as_Bool();250if( bol->_test._test == BoolTest::eq ) {251} else if( bol->_test._test == BoolTest::ne ) {252flip = 1-flip;253} else return NULL;254255// Check for vs 0 or 1256if( !bol->in(1)->is_Cmp() ) return NULL;257const CmpNode *cmp = bol->in(1)->as_Cmp();258if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {259} else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {260// Allow cmp-vs-1 if the other input is bounded by 0-1261if( phase->type(cmp->in(1)) != TypeInt::BOOL )262return NULL;263flip = 1 - flip;264} else return NULL;265266// Convert to a bool (flipped)267// Build int->bool conversion268#ifndef PRODUCT269if( PrintOpto ) tty->print_cr("CMOV to I2B");270#endif271Node *n = new (phase->C) Conv2BNode( cmp->in(1) );272if( flip )273n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );274275return n;276}277278//=============================================================================279//------------------------------Ideal------------------------------------------280// Return a node which is more "ideal" than the current node.281// Check for absolute value282Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {283// Try generic ideal's first284Node *x = CMoveNode::Ideal(phase, can_reshape);285if( x ) return x;286287int cmp_zero_idx = 0; // Index of compare input where to look for zero288int phi_x_idx = 0; // Index of phi input where to find naked x289290// Find the Bool291if( !in(1)->is_Bool() ) return NULL;292BoolNode *bol = in(1)->as_Bool();293// Check bool sense294switch( bol->_test._test ) {295case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;296case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;297case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;298case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;299default: return NULL; break;300}301302// Find zero input of CmpF; the other input is being abs'd303Node *cmpf = bol->in(1);304if( cmpf->Opcode() != Op_CmpF ) return NULL;305Node *X = NULL;306bool flip = false;307if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {308X = cmpf->in(3 - cmp_zero_idx);309} else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {310// The test is inverted, we should invert the result...311X = cmpf->in(cmp_zero_idx);312flip = true;313} else {314return NULL;315}316317// If X is found on the appropriate phi input, find the subtract on the other318if( X != in(phi_x_idx) ) return NULL;319int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;320Node *sub = in(phi_sub_idx);321322// Allow only SubF(0,X) and fail out for all others; NegF is not OK323if( sub->Opcode() != Op_SubF ||324sub->in(2) != X ||325phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;326327Node *abs = new (phase->C) AbsFNode( X );328if( flip )329abs = new (phase->C) SubFNode(sub->in(1), phase->transform(abs));330331return abs;332}333334//=============================================================================335//------------------------------Ideal------------------------------------------336// Return a node which is more "ideal" than the current node.337// Check for absolute value338Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {339// Try generic ideal's first340Node *x = CMoveNode::Ideal(phase, can_reshape);341if( x ) return x;342343int cmp_zero_idx = 0; // Index of compare input where to look for zero344int phi_x_idx = 0; // Index of phi input where to find naked x345346// Find the Bool347if( !in(1)->is_Bool() ) return NULL;348BoolNode *bol = in(1)->as_Bool();349// Check bool sense350switch( bol->_test._test ) {351case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;352case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;353case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;354case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;355default: return NULL; break;356}357358// Find zero input of CmpD; the other input is being abs'd359Node *cmpd = bol->in(1);360if( cmpd->Opcode() != Op_CmpD ) return NULL;361Node *X = NULL;362bool flip = false;363if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {364X = cmpd->in(3 - cmp_zero_idx);365} else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {366// The test is inverted, we should invert the result...367X = cmpd->in(cmp_zero_idx);368flip = true;369} else {370return NULL;371}372373// If X is found on the appropriate phi input, find the subtract on the other374if( X != in(phi_x_idx) ) return NULL;375int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;376Node *sub = in(phi_sub_idx);377378// Allow only SubD(0,X) and fail out for all others; NegD is not OK379if( sub->Opcode() != Op_SubD ||380sub->in(2) != X ||381phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;382383Node *abs = new (phase->C) AbsDNode( X );384if( flip )385abs = new (phase->C) SubDNode(sub->in(1), phase->transform(abs));386387return abs;388}389390391//=============================================================================392// If input is already higher or equal to cast type, then this is an identity.393Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {394return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;395}396397//------------------------------Value------------------------------------------398// Take 'join' of input and cast-up type399const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {400if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;401const Type* ft = phase->type(in(1))->filter_speculative(_type);402403#ifdef ASSERT404// Previous versions of this function had some special case logic,405// which is no longer necessary. Make sure of the required effects.406switch (Opcode()) {407case Op_CastII:408{409const Type* t1 = phase->type(in(1));410if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1");411const Type* rt = t1->join_speculative(_type);412if (rt->empty()) assert(ft == Type::TOP, "special case #2");413break;414}415case Op_CastPP:416if (phase->type(in(1)) == TypePtr::NULL_PTR &&417_type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)418assert(ft == Type::TOP, "special case #3");419break;420}421#endif //ASSERT422423return ft;424}425426//------------------------------Ideal------------------------------------------427// Return a node which is more "ideal" than the current node. Strip out428// control copies429Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){430return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;431}432433//------------------------------Ideal_DU_postCCP-------------------------------434// Throw away cast after constant propagation435Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {436const Type *t = ccp->type(in(1));437ccp->hash_delete(this);438set_type(t); // Turn into ID function439ccp->hash_insert(this);440return this;441}442443uint CastIINode::size_of() const {444return sizeof(*this);445}446447uint CastIINode::cmp(const Node &n) const {448return TypeNode::cmp(n) &&449((CastIINode&)n)._carry_dependency == _carry_dependency &&450((CastIINode&)n)._range_check_dependency == _range_check_dependency;451}452453Node *CastIINode::Identity(PhaseTransform *phase) {454if (_carry_dependency) {455return this;456}457return ConstraintCastNode::Identity(phase);458}459460const Type *CastIINode::Value(PhaseTransform *phase) const {461const Type *res = ConstraintCastNode::Value(phase);462463// Try to improve the type of the CastII if we recognize a CmpI/If464// pattern.465if (_carry_dependency) {466if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {467assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");468Node* proj = in(0);469if (proj->in(0)->in(1)->is_Bool()) {470Node* b = proj->in(0)->in(1);471if (b->in(1)->Opcode() == Op_CmpI) {472Node* cmp = b->in(1);473if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {474const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();475const Type* t = TypeInt::INT;476BoolTest test = b->as_Bool()->_test;477if (proj->is_IfFalse()) {478test = test.negate();479}480BoolTest::mask m = test._test;481jlong lo_long = min_jint;482jlong hi_long = max_jint;483if (m == BoolTest::le || m == BoolTest::lt) {484hi_long = in2_t->_hi;485if (m == BoolTest::lt) {486hi_long -= 1;487}488} else if (m == BoolTest::ge || m == BoolTest::gt) {489lo_long = in2_t->_lo;490if (m == BoolTest::gt) {491lo_long += 1;492}493} else if (m == BoolTest::eq) {494lo_long = in2_t->_lo;495hi_long = in2_t->_hi;496} else if (m == BoolTest::ne) {497// can't do any better498} else {499stringStream ss;500test.dump_on(&ss);501fatal(err_msg_res("unexpected comparison %s", ss.as_string()));502}503int lo_int = (int)lo_long;504int hi_int = (int)hi_long;505506if (lo_long != (jlong)lo_int) {507lo_int = min_jint;508}509if (hi_long != (jlong)hi_int) {510hi_int = max_jint;511}512513t = TypeInt::make(lo_int, hi_int, Type::WidenMax);514515res = res->filter_speculative(t);516517return res;518}519}520}521}522}523return res;524}525526Node *CastIINode::Ideal_DU_postCCP(PhaseCCP *ccp) {527if (_carry_dependency || _range_check_dependency) {528return NULL;529}530return ConstraintCastNode::Ideal_DU_postCCP(ccp);531}532533#ifndef PRODUCT534void CastIINode::dump_spec(outputStream *st) const {535TypeNode::dump_spec(st);536if (_carry_dependency) {537st->print(" carry dependency");538}539if (_range_check_dependency) {540st->print(" range check dependency");541}542}543#endif544545//=============================================================================546//------------------------------Identity---------------------------------------547// If input is already higher or equal to cast type, then this is an identity.548Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {549// Toned down to rescue meeting at a Phi 3 different oops all implementing550// the same interface. CompileTheWorld starting at 502, kd12rc1.zip.551return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;552}553554//------------------------------Value------------------------------------------555// Take 'join' of input and cast-up type, unless working with an Interface556const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {557if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;558559const Type *inn = phase->type(in(1));560if( inn == Type::TOP ) return Type::TOP; // No information yet561562const TypePtr *in_type = inn->isa_ptr();563const TypePtr *my_type = _type->isa_ptr();564const Type *result = _type;565if( in_type != NULL && my_type != NULL ) {566TypePtr::PTR in_ptr = in_type->ptr();567if( in_ptr == TypePtr::Null ) {568result = in_type;569} else if( in_ptr == TypePtr::Constant ) {570// Casting a constant oop to an interface?571// (i.e., a String to a Comparable?)572// Then return the interface.573const TypeOopPtr *jptr = my_type->isa_oopptr();574assert( jptr, "" );575result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type))576? my_type->cast_to_ptr_type( TypePtr::NotNull )577: in_type;578} else {579result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );580}581}582return result;583584// JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.585// FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!586587//588// Remove this code after overnight run indicates no performance589// loss from not performing JOIN at CheckCastPPNode590//591// const TypeInstPtr *in_oop = in->isa_instptr();592// const TypeInstPtr *my_oop = _type->isa_instptr();593// // If either input is an 'interface', return destination type594// assert (in_oop == NULL || in_oop->klass() != NULL, "");595// assert (my_oop == NULL || my_oop->klass() != NULL, "");596// if( (in_oop && in_oop->klass()->is_interface())597// ||(my_oop && my_oop->klass()->is_interface()) ) {598// TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;599// // Preserve cast away nullness for interfaces600// if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {601// return my_oop->cast_to_ptr_type(TypePtr::NotNull);602// }603// return _type;604// }605//606// // Neither the input nor the destination type is an interface,607//608// // history: JOIN used to cause weird corner case bugs609// // return (in == TypeOopPtr::NULL_PTR) ? in : _type;610// // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.611// // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr612// const Type *join = in->join(_type);613// // Check if join preserved NotNull'ness for pointers614// if( join->isa_ptr() && _type->isa_ptr() ) {615// TypePtr::PTR join_ptr = join->is_ptr()->_ptr;616// TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;617// // If there isn't any NotNull'ness to preserve618// // OR if join preserved NotNull'ness then return it619// if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null ||620// join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {621// return join;622// }623// // ELSE return same old type as before624// return _type;625// }626// // Not joining two pointers627// return join;628}629630//------------------------------Ideal------------------------------------------631// Return a node which is more "ideal" than the current node. Strip out632// control copies633Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){634return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;635}636637638Node* DecodeNNode::Identity(PhaseTransform* phase) {639const Type *t = phase->type( in(1) );640if( t == Type::TOP ) return in(1);641642if (in(1)->is_EncodeP()) {643// (DecodeN (EncodeP p)) -> p644return in(1)->in(1);645}646return this;647}648649const Type *DecodeNNode::Value( PhaseTransform *phase ) const {650const Type *t = phase->type( in(1) );651if (t == Type::TOP) return Type::TOP;652if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;653654assert(t->isa_narrowoop(), "only narrowoop here");655return t->make_ptr();656}657658Node* EncodePNode::Identity(PhaseTransform* phase) {659const Type *t = phase->type( in(1) );660if( t == Type::TOP ) return in(1);661662if (in(1)->is_DecodeN()) {663// (EncodeP (DecodeN p)) -> p664return in(1)->in(1);665}666return this;667}668669const Type *EncodePNode::Value( PhaseTransform *phase ) const {670const Type *t = phase->type( in(1) );671if (t == Type::TOP) return Type::TOP;672if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;673674assert(t->isa_oop_ptr(), "only oopptr here");675return t->make_narrowoop();676}677678679Node* DecodeNKlassNode::Identity(PhaseTransform* phase) {680const Type *t = phase->type( in(1) );681if( t == Type::TOP ) return in(1);682683if (in(1)->is_EncodePKlass()) {684// (DecodeNKlass (EncodePKlass p)) -> p685return in(1)->in(1);686}687return this;688}689690const Type *DecodeNKlassNode::Value( PhaseTransform *phase ) const {691const Type *t = phase->type( in(1) );692if (t == Type::TOP) return Type::TOP;693assert(t != TypeNarrowKlass::NULL_PTR, "null klass?");694695assert(t->isa_narrowklass(), "only narrow klass ptr here");696return t->make_ptr();697}698699Node* EncodePKlassNode::Identity(PhaseTransform* phase) {700const Type *t = phase->type( in(1) );701if( t == Type::TOP ) return in(1);702703if (in(1)->is_DecodeNKlass()) {704// (EncodePKlass (DecodeNKlass p)) -> p705return in(1)->in(1);706}707return this;708}709710const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const {711const Type *t = phase->type( in(1) );712if (t == Type::TOP) return Type::TOP;713assert (t != TypePtr::NULL_PTR, "null klass?");714715assert(UseCompressedClassPointers && t->isa_klassptr(), "only klass ptr here");716return t->make_narrowklass();717}718719720//=============================================================================721//------------------------------Identity---------------------------------------722Node *Conv2BNode::Identity( PhaseTransform *phase ) {723const Type *t = phase->type( in(1) );724if( t == Type::TOP ) return in(1);725if( t == TypeInt::ZERO ) return in(1);726if( t == TypeInt::ONE ) return in(1);727if( t == TypeInt::BOOL ) return in(1);728return this;729}730731//------------------------------Value------------------------------------------732const Type *Conv2BNode::Value( PhaseTransform *phase ) const {733const Type *t = phase->type( in(1) );734if( t == Type::TOP ) return Type::TOP;735if( t == TypeInt::ZERO ) return TypeInt::ZERO;736if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;737const TypePtr *tp = t->isa_ptr();738if( tp != NULL ) {739if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;740if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;741if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;742return TypeInt::BOOL;743}744if (t->base() != Type::Int) return TypeInt::BOOL;745const TypeInt *ti = t->is_int();746if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;747return TypeInt::BOOL;748}749750751// The conversions operations are all Alpha sorted. Please keep it that way!752//=============================================================================753//------------------------------Value------------------------------------------754const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {755const Type *t = phase->type( in(1) );756if( t == Type::TOP ) return Type::TOP;757if( t == Type::DOUBLE ) return Type::FLOAT;758const TypeD *td = t->is_double_constant();759return TypeF::make( (float)td->getd() );760}761762//------------------------------Identity---------------------------------------763// Float's can be converted to doubles with no loss of bits. Hence764// converting a float to a double and back to a float is a NOP.765Node *ConvD2FNode::Identity(PhaseTransform *phase) {766return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;767}768769//=============================================================================770//------------------------------Value------------------------------------------771const Type *ConvD2INode::Value( PhaseTransform *phase ) const {772const Type *t = phase->type( in(1) );773if( t == Type::TOP ) return Type::TOP;774if( t == Type::DOUBLE ) return TypeInt::INT;775const TypeD *td = t->is_double_constant();776return TypeInt::make( SharedRuntime::d2i( td->getd() ) );777}778779//------------------------------Ideal------------------------------------------780// If converting to an int type, skip any rounding nodes781Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {782if( in(1)->Opcode() == Op_RoundDouble )783set_req(1,in(1)->in(1));784return NULL;785}786787//------------------------------Identity---------------------------------------788// Int's can be converted to doubles with no loss of bits. Hence789// converting an integer to a double and back to an integer is a NOP.790Node *ConvD2INode::Identity(PhaseTransform *phase) {791return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;792}793794//=============================================================================795//------------------------------Value------------------------------------------796const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {797const Type *t = phase->type( in(1) );798if( t == Type::TOP ) return Type::TOP;799if( t == Type::DOUBLE ) return TypeLong::LONG;800const TypeD *td = t->is_double_constant();801return TypeLong::make( SharedRuntime::d2l( td->getd() ) );802}803804//------------------------------Identity---------------------------------------805Node *ConvD2LNode::Identity(PhaseTransform *phase) {806// Remove ConvD2L->ConvL2D->ConvD2L sequences.807if( in(1) ->Opcode() == Op_ConvL2D &&808in(1)->in(1)->Opcode() == Op_ConvD2L )809return in(1)->in(1);810return this;811}812813//------------------------------Ideal------------------------------------------814// If converting to an int type, skip any rounding nodes815Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {816if( in(1)->Opcode() == Op_RoundDouble )817set_req(1,in(1)->in(1));818return NULL;819}820821//=============================================================================822//------------------------------Value------------------------------------------823const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {824const Type *t = phase->type( in(1) );825if( t == Type::TOP ) return Type::TOP;826if( t == Type::FLOAT ) return Type::DOUBLE;827const TypeF *tf = t->is_float_constant();828return TypeD::make( (double)tf->getf() );829}830831//=============================================================================832//------------------------------Value------------------------------------------833const Type *ConvF2INode::Value( PhaseTransform *phase ) const {834const Type *t = phase->type( in(1) );835if( t == Type::TOP ) return Type::TOP;836if( t == Type::FLOAT ) return TypeInt::INT;837const TypeF *tf = t->is_float_constant();838return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );839}840841//------------------------------Identity---------------------------------------842Node *ConvF2INode::Identity(PhaseTransform *phase) {843// Remove ConvF2I->ConvI2F->ConvF2I sequences.844if( in(1) ->Opcode() == Op_ConvI2F &&845in(1)->in(1)->Opcode() == Op_ConvF2I )846return in(1)->in(1);847return this;848}849850//------------------------------Ideal------------------------------------------851// If converting to an int type, skip any rounding nodes852Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {853if( in(1)->Opcode() == Op_RoundFloat )854set_req(1,in(1)->in(1));855return NULL;856}857858//=============================================================================859//------------------------------Value------------------------------------------860const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {861const Type *t = phase->type( in(1) );862if( t == Type::TOP ) return Type::TOP;863if( t == Type::FLOAT ) return TypeLong::LONG;864const TypeF *tf = t->is_float_constant();865return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );866}867868//------------------------------Identity---------------------------------------869Node *ConvF2LNode::Identity(PhaseTransform *phase) {870// Remove ConvF2L->ConvL2F->ConvF2L sequences.871if( in(1) ->Opcode() == Op_ConvL2F &&872in(1)->in(1)->Opcode() == Op_ConvF2L )873return in(1)->in(1);874return this;875}876877//------------------------------Ideal------------------------------------------878// If converting to an int type, skip any rounding nodes879Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {880if( in(1)->Opcode() == Op_RoundFloat )881set_req(1,in(1)->in(1));882return NULL;883}884885//=============================================================================886//------------------------------Value------------------------------------------887const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {888const Type *t = phase->type( in(1) );889if( t == Type::TOP ) return Type::TOP;890const TypeInt *ti = t->is_int();891if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );892return bottom_type();893}894895//=============================================================================896//------------------------------Value------------------------------------------897const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {898const Type *t = phase->type( in(1) );899if( t == Type::TOP ) return Type::TOP;900const TypeInt *ti = t->is_int();901if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );902return bottom_type();903}904905//------------------------------Identity---------------------------------------906Node *ConvI2FNode::Identity(PhaseTransform *phase) {907// Remove ConvI2F->ConvF2I->ConvI2F sequences.908if( in(1) ->Opcode() == Op_ConvF2I &&909in(1)->in(1)->Opcode() == Op_ConvI2F )910return in(1)->in(1);911return this;912}913914//=============================================================================915//------------------------------Value------------------------------------------916const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {917const Type *t = phase->type( in(1) );918if( t == Type::TOP ) return Type::TOP;919const TypeInt *ti = t->is_int();920const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);921// Join my declared type against my incoming type.922tl = tl->filter(_type);923return tl;924}925926#ifdef _LP64927static inline bool long_ranges_overlap(jlong lo1, jlong hi1,928jlong lo2, jlong hi2) {929// Two ranges overlap iff one range's low point falls in the other range.930return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);931}932#endif933934//------------------------------Ideal------------------------------------------935Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {936const TypeLong* this_type = this->type()->is_long();937Node* this_changed = NULL;938939// If _major_progress, then more loop optimizations follow. Do NOT940// remove this node's type assertion until no more loop ops can happen.941// The progress bit is set in the major loop optimizations THEN comes the942// call to IterGVN and any chance of hitting this code. Cf. Opaque1Node.943if (can_reshape && !phase->C->major_progress()) {944const TypeInt* in_type = phase->type(in(1))->isa_int();945if (in_type != NULL && this_type != NULL &&946(in_type->_lo != this_type->_lo ||947in_type->_hi != this_type->_hi)) {948// Although this WORSENS the type, it increases GVN opportunities,949// because I2L nodes with the same input will common up, regardless950// of slightly differing type assertions. Such slight differences951// arise routinely as a result of loop unrolling, so this is a952// post-unrolling graph cleanup. Choose a type which depends only953// on my input. (Exception: Keep a range assertion of >=0 or <0.)954jlong lo1 = this_type->_lo;955jlong hi1 = this_type->_hi;956int w1 = this_type->_widen;957if (lo1 != (jint)lo1 ||958hi1 != (jint)hi1 ||959lo1 > hi1) {960// Overflow leads to wraparound, wraparound leads to range saturation.961lo1 = min_jint; hi1 = max_jint;962} else if (lo1 >= 0) {963// Keep a range assertion of >=0.964lo1 = 0; hi1 = max_jint;965} else if (hi1 < 0) {966// Keep a range assertion of <0.967lo1 = min_jint; hi1 = -1;968} else {969lo1 = min_jint; hi1 = max_jint;970}971const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),972MIN2((jlong)in_type->_hi, hi1),973MAX2((int)in_type->_widen, w1));974if (wtype != type()) {975set_type(wtype);976// Note: this_type still has old type value, for the logic below.977this_changed = this;978}979}980}981982#ifdef _LP64983// Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y))984// but only if x and y have subranges that cannot cause 32-bit overflow,985// under the assumption that x+y is in my own subrange this->type().986987// This assumption is based on a constraint (i.e., type assertion)988// established in Parse::array_addressing or perhaps elsewhere.989// This constraint has been adjoined to the "natural" type of990// the incoming argument in(0). We know (because of runtime991// checks) - that the result value I2L(x+y) is in the joined range.992// Hence we can restrict the incoming terms (x, y) to values such993// that their sum also lands in that range.994995// This optimization is useful only on 64-bit systems, where we hope996// the addition will end up subsumed in an addressing mode.997// It is necessary to do this when optimizing an unrolled array998// copy loop such as x[i++] = y[i++].9991000// On 32-bit systems, it's better to perform as much 32-bit math as1001// possible before the I2L conversion, because 32-bit math is cheaper.1002// There's no common reason to "leak" a constant offset through the I2L.1003// Addressing arithmetic will not absorb it as part of a 64-bit AddL.10041005Node* z = in(1);1006int op = z->Opcode();1007if (op == Op_AddI || op == Op_SubI) {1008Node* x = z->in(1);1009Node* y = z->in(2);1010assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");1011if (phase->type(x) == Type::TOP) return this_changed;1012if (phase->type(y) == Type::TOP) return this_changed;1013const TypeInt* tx = phase->type(x)->is_int();1014const TypeInt* ty = phase->type(y)->is_int();1015const TypeLong* tz = this_type;1016jlong xlo = tx->_lo;1017jlong xhi = tx->_hi;1018jlong ylo = ty->_lo;1019jlong yhi = ty->_hi;1020jlong zlo = tz->_lo;1021jlong zhi = tz->_hi;1022jlong vbit = CONST64(1) << BitsPerInt;1023int widen = MAX2(tx->_widen, ty->_widen);1024if (op == Op_SubI) {1025jlong ylo0 = ylo;1026ylo = -yhi;1027yhi = -ylo0;1028}1029// See if x+y can cause positive overflow into z+2**321030if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {1031return this_changed;1032}1033// See if x+y can cause negative overflow into z-2**321034if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {1035return this_changed;1036}1037// Now it's always safe to assume x+y does not overflow.1038// This is true even if some pairs x,y might cause overflow, as long1039// as that overflow value cannot fall into [zlo,zhi].10401041// Confident that the arithmetic is "as if infinite precision",1042// we can now use z's range to put constraints on those of x and y.1043// The "natural" range of x [xlo,xhi] can perhaps be narrowed to a1044// more "restricted" range by intersecting [xlo,xhi] with the1045// range obtained by subtracting y's range from the asserted range1046// of the I2L conversion. Here's the interval arithmetic algebra:1047// x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]1048// => x in [zlo-yhi, zhi-ylo]1049// => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]1050// => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]1051jlong rxlo = MAX2(xlo, zlo - yhi);1052jlong rxhi = MIN2(xhi, zhi - ylo);1053// And similarly, x changing place with y:1054jlong rylo = MAX2(ylo, zlo - xhi);1055jlong ryhi = MIN2(yhi, zhi - xlo);1056if (rxlo > rxhi || rylo > ryhi) {1057return this_changed; // x or y is dying; don't mess w/ it1058}1059if (op == Op_SubI) {1060jlong rylo0 = rylo;1061rylo = -ryhi;1062ryhi = -rylo0;1063}1064assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");1065assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");1066Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), NULL);1067Node *hook = new (phase->C) Node(1);1068hook->init_req(0, cx); // Add a use to cx to prevent him from dying1069Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), NULL);1070hook->del_req(0); // Just yank bogus edge1071hook->destruct();1072switch (op) {1073case Op_AddI: return new (phase->C) AddLNode(cx, cy);1074case Op_SubI: return new (phase->C) SubLNode(cx, cy);1075default: ShouldNotReachHere();1076}1077}1078#endif //_LP6410791080return this_changed;1081}10821083//=============================================================================1084//------------------------------Value------------------------------------------1085const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {1086const Type *t = phase->type( in(1) );1087if( t == Type::TOP ) return Type::TOP;1088const TypeLong *tl = t->is_long();1089if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );1090return bottom_type();1091}10921093//=============================================================================1094//------------------------------Value------------------------------------------1095const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {1096const Type *t = phase->type( in(1) );1097if( t == Type::TOP ) return Type::TOP;1098const TypeLong *tl = t->is_long();1099if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );1100return bottom_type();1101}11021103//=============================================================================1104//----------------------------Identity-----------------------------------------1105Node *ConvL2INode::Identity( PhaseTransform *phase ) {1106// Convert L2I(I2L(x)) => x1107if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);1108return this;1109}11101111//------------------------------Value------------------------------------------1112const Type *ConvL2INode::Value( PhaseTransform *phase ) const {1113const Type *t = phase->type( in(1) );1114if( t == Type::TOP ) return Type::TOP;1115const TypeLong *tl = t->is_long();1116if (tl->is_con())1117// Easy case.1118return TypeInt::make((jint)tl->get_con());1119return bottom_type();1120}11211122//------------------------------Ideal------------------------------------------1123// Return a node which is more "ideal" than the current node.1124// Blow off prior masking to int1125Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {1126Node *andl = in(1);1127uint andl_op = andl->Opcode();1128if( andl_op == Op_AndL ) {1129// Blow off prior masking to int1130if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {1131set_req(1,andl->in(1));1132return this;1133}1134}11351136// Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))1137// This replaces an 'AddL' with an 'AddI'.1138if( andl_op == Op_AddL ) {1139// Don't do this for nodes which have more than one user since1140// we'll end up computing the long add anyway.1141if (andl->outcnt() > 1) return NULL;11421143Node* x = andl->in(1);1144Node* y = andl->in(2);1145assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );1146if (phase->type(x) == Type::TOP) return NULL;1147if (phase->type(y) == Type::TOP) return NULL;1148Node *add1 = phase->transform(new (phase->C) ConvL2INode(x));1149Node *add2 = phase->transform(new (phase->C) ConvL2INode(y));1150return new (phase->C) AddINode(add1,add2);1151}11521153// Disable optimization: LoadL->ConvL2I ==> LoadI.1154// It causes problems (sizes of Load and Store nodes do not match)1155// in objects initialization code and Escape Analysis.1156return NULL;1157}11581159//=============================================================================1160//------------------------------Value------------------------------------------1161const Type *CastX2PNode::Value( PhaseTransform *phase ) const {1162const Type* t = phase->type(in(1));1163if (t == Type::TOP) return Type::TOP;1164if (t->base() == Type_X && t->singleton()) {1165uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();1166if (bits == 0) return TypePtr::NULL_PTR;1167return TypeRawPtr::make((address) bits);1168}1169return CastX2PNode::bottom_type();1170}11711172//------------------------------Idealize---------------------------------------1173static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {1174if (t == Type::TOP) return false;1175const TypeX* tl = t->is_intptr_t();1176jint lo = min_jint;1177jint hi = max_jint;1178if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow1179return (tl->_lo >= lo) && (tl->_hi <= hi);1180}11811182static inline Node* addP_of_X2P(PhaseGVN *phase,1183Node* base,1184Node* dispX,1185bool negate = false) {1186if (negate) {1187dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX));1188}1189return new (phase->C) AddPNode(phase->C->top(),1190phase->transform(new (phase->C) CastX2PNode(base)),1191phase->transform(dispX));1192}11931194Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {1195// convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int1196int op = in(1)->Opcode();1197Node* x;1198Node* y;1199switch (op) {1200case Op_SubX:1201x = in(1)->in(1);1202// Avoid ideal transformations ping-pong between this and AddP for raw pointers.1203if (phase->find_intptr_t_con(x, -1) == 0)1204break;1205y = in(1)->in(2);1206if (fits_in_int(phase->type(y), true)) {1207return addP_of_X2P(phase, x, y, true);1208}1209break;1210case Op_AddX:1211x = in(1)->in(1);1212y = in(1)->in(2);1213if (fits_in_int(phase->type(y))) {1214return addP_of_X2P(phase, x, y);1215}1216if (fits_in_int(phase->type(x))) {1217return addP_of_X2P(phase, y, x);1218}1219break;1220}1221return NULL;1222}12231224//------------------------------Identity---------------------------------------1225Node *CastX2PNode::Identity( PhaseTransform *phase ) {1226if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);1227return this;1228}12291230//=============================================================================1231//------------------------------Value------------------------------------------1232const Type *CastP2XNode::Value( PhaseTransform *phase ) const {1233const Type* t = phase->type(in(1));1234if (t == Type::TOP) return Type::TOP;1235if (t->base() == Type::RawPtr && t->singleton()) {1236uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();1237return TypeX::make(bits);1238}1239return CastP2XNode::bottom_type();1240}12411242Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {1243return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;1244}12451246//------------------------------Identity---------------------------------------1247Node *CastP2XNode::Identity( PhaseTransform *phase ) {1248if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);1249return this;1250}125112521253//=============================================================================1254//------------------------------Identity---------------------------------------1255// Remove redundant roundings1256Node *RoundFloatNode::Identity( PhaseTransform *phase ) {1257assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");1258// Do not round constants1259if (phase->type(in(1))->base() == Type::FloatCon) return in(1);1260int op = in(1)->Opcode();1261// Redundant rounding1262if( op == Op_RoundFloat ) return in(1);1263// Already rounded1264if( op == Op_Parm ) return in(1);1265if( op == Op_LoadF ) return in(1);1266return this;1267}12681269//------------------------------Value------------------------------------------1270const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {1271return phase->type( in(1) );1272}12731274//=============================================================================1275//------------------------------Identity---------------------------------------1276// Remove redundant roundings. Incoming arguments are already rounded.1277Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {1278assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");1279// Do not round constants1280if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);1281int op = in(1)->Opcode();1282// Redundant rounding1283if( op == Op_RoundDouble ) return in(1);1284// Already rounded1285if( op == Op_Parm ) return in(1);1286if( op == Op_LoadD ) return in(1);1287if( op == Op_ConvF2D ) return in(1);1288if( op == Op_ConvI2D ) return in(1);1289return this;1290}12911292//------------------------------Value------------------------------------------1293const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {1294return phase->type( in(1) );1295}129612971298//=============================================================================1299// Do not allow value-numbering1300uint Opaque1Node::hash() const { return NO_HASH; }1301uint Opaque1Node::cmp( const Node &n ) const {1302return (&n == this); // Always fail except on self1303}13041305//------------------------------Identity---------------------------------------1306// If _major_progress, then more loop optimizations follow. Do NOT remove1307// the opaque Node until no more loop ops can happen. Note the timing of1308// _major_progress; it's set in the major loop optimizations THEN comes the1309// call to IterGVN and any chance of hitting this code. Hence there's no1310// phase-ordering problem with stripping Opaque1 in IGVN followed by some1311// more loop optimizations that require it.1312Node *Opaque1Node::Identity( PhaseTransform *phase ) {1313return phase->C->major_progress() ? this : in(1);1314}13151316//=============================================================================1317// A node to prevent unwanted optimizations. Allows constant folding. Stops1318// value-numbering, most Ideal calls or Identity functions. This Node is1319// specifically designed to prevent the pre-increment value of a loop trip1320// counter from being live out of the bottom of the loop (hence causing the1321// pre- and post-increment values both being live and thus requiring an extra1322// temp register and an extra move). If we "accidentally" optimize through1323// this kind of a Node, we'll get slightly pessimal, but correct, code. Thus1324// it's OK to be slightly sloppy on optimizations here.13251326// Do not allow value-numbering1327uint Opaque2Node::hash() const { return NO_HASH; }1328uint Opaque2Node::cmp( const Node &n ) const {1329return (&n == this); // Always fail except on self1330}13311332//=============================================================================13331334uint ProfileBooleanNode::hash() const { return NO_HASH; }1335uint ProfileBooleanNode::cmp( const Node &n ) const {1336return (&n == this);1337}13381339Node *ProfileBooleanNode::Ideal(PhaseGVN *phase, bool can_reshape) {1340if (can_reshape && _delay_removal) {1341_delay_removal = false;1342return this;1343} else {1344return NULL;1345}1346}13471348Node *ProfileBooleanNode::Identity( PhaseTransform *phase ) {1349if (_delay_removal) {1350return this;1351} else {1352assert(_consumed, "profile should be consumed before elimination");1353return in(1);1354}1355}13561357//------------------------------Value------------------------------------------1358const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {1359const Type *t = phase->type( in(1) );1360if( t == Type::TOP ) return Type::TOP;1361const TypeLong *tl = t->is_long();1362if( !tl->is_con() ) return bottom_type();1363JavaValue v;1364v.set_jlong(tl->get_con());1365return TypeD::make( v.get_jdouble() );1366}13671368//------------------------------Value------------------------------------------1369const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {1370const Type *t = phase->type( in(1) );1371if( t == Type::TOP ) return Type::TOP;1372const TypeInt *ti = t->is_int();1373if( !ti->is_con() ) return bottom_type();1374JavaValue v;1375v.set_jint(ti->get_con());1376return TypeF::make( v.get_jfloat() );1377}13781379//------------------------------Value------------------------------------------1380const Type *MoveF2INode::Value( PhaseTransform *phase ) const {1381const Type *t = phase->type( in(1) );1382if( t == Type::TOP ) return Type::TOP;1383if( t == Type::FLOAT ) return TypeInt::INT;1384const TypeF *tf = t->is_float_constant();1385JavaValue v;1386v.set_jfloat(tf->getf());1387return TypeInt::make( v.get_jint() );1388}13891390//------------------------------Value------------------------------------------1391const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {1392const Type *t = phase->type( in(1) );1393if( t == Type::TOP ) return Type::TOP;1394if( t == Type::DOUBLE ) return TypeLong::LONG;1395const TypeD *td = t->is_double_constant();1396JavaValue v;1397v.set_jdouble(td->getd());1398return TypeLong::make( v.get_jlong() );1399}14001401//------------------------------Value------------------------------------------1402const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const {1403const Type* t = phase->type(in(1));1404if (t == Type::TOP) return Type::TOP;1405const TypeInt* ti = t->isa_int();1406if (ti && ti->is_con()) {1407jint i = ti->get_con();1408// HD, Figure 5-61409if (i == 0)1410return TypeInt::make(BitsPerInt);1411int n = 1;1412unsigned int x = i;1413if (x >> 16 == 0) { n += 16; x <<= 16; }1414if (x >> 24 == 0) { n += 8; x <<= 8; }1415if (x >> 28 == 0) { n += 4; x <<= 4; }1416if (x >> 30 == 0) { n += 2; x <<= 2; }1417n -= x >> 31;1418return TypeInt::make(n);1419}1420return TypeInt::INT;1421}14221423//------------------------------Value------------------------------------------1424const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const {1425const Type* t = phase->type(in(1));1426if (t == Type::TOP) return Type::TOP;1427const TypeLong* tl = t->isa_long();1428if (tl && tl->is_con()) {1429jlong l = tl->get_con();1430// HD, Figure 5-61431if (l == 0)1432return TypeInt::make(BitsPerLong);1433int n = 1;1434unsigned int x = (((julong) l) >> 32);1435if (x == 0) { n += 32; x = (int) l; }1436if (x >> 16 == 0) { n += 16; x <<= 16; }1437if (x >> 24 == 0) { n += 8; x <<= 8; }1438if (x >> 28 == 0) { n += 4; x <<= 4; }1439if (x >> 30 == 0) { n += 2; x <<= 2; }1440n -= x >> 31;1441return TypeInt::make(n);1442}1443return TypeInt::INT;1444}14451446//------------------------------Value------------------------------------------1447const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const {1448const Type* t = phase->type(in(1));1449if (t == Type::TOP) return Type::TOP;1450const TypeInt* ti = t->isa_int();1451if (ti && ti->is_con()) {1452jint i = ti->get_con();1453// HD, Figure 5-141454int y;1455if (i == 0)1456return TypeInt::make(BitsPerInt);1457int n = 31;1458y = i << 16; if (y != 0) { n = n - 16; i = y; }1459y = i << 8; if (y != 0) { n = n - 8; i = y; }1460y = i << 4; if (y != 0) { n = n - 4; i = y; }1461y = i << 2; if (y != 0) { n = n - 2; i = y; }1462y = i << 1; if (y != 0) { n = n - 1; }1463return TypeInt::make(n);1464}1465return TypeInt::INT;1466}14671468//------------------------------Value------------------------------------------1469const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const {1470const Type* t = phase->type(in(1));1471if (t == Type::TOP) return Type::TOP;1472const TypeLong* tl = t->isa_long();1473if (tl && tl->is_con()) {1474jlong l = tl->get_con();1475// HD, Figure 5-141476int x, y;1477if (l == 0)1478return TypeInt::make(BitsPerLong);1479int n = 63;1480y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);1481y = x << 16; if (y != 0) { n = n - 16; x = y; }1482y = x << 8; if (y != 0) { n = n - 8; x = y; }1483y = x << 4; if (y != 0) { n = n - 4; x = y; }1484y = x << 2; if (y != 0) { n = n - 2; x = y; }1485y = x << 1; if (y != 0) { n = n - 1; }1486return TypeInt::make(n);1487}1488return TypeInt::INT;1489}149014911492