Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/opto/connode.cpp
83404 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//=============================================================================546547//------------------------------Ideal_DU_postCCP-------------------------------548// If not converting int->oop, throw away cast after constant propagation549Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {550const Type *t = ccp->type(in(1));551if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {552return NULL; // do not transform raw pointers or narrow oops553}554return ConstraintCastNode::Ideal_DU_postCCP(ccp);555}556557558559//=============================================================================560//------------------------------Identity---------------------------------------561// If input is already higher or equal to cast type, then this is an identity.562Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {563// Toned down to rescue meeting at a Phi 3 different oops all implementing564// the same interface. CompileTheWorld starting at 502, kd12rc1.zip.565return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;566}567568//------------------------------Value------------------------------------------569// Take 'join' of input and cast-up type, unless working with an Interface570const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {571if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;572573const Type *inn = phase->type(in(1));574if( inn == Type::TOP ) return Type::TOP; // No information yet575576const TypePtr *in_type = inn->isa_ptr();577const TypePtr *my_type = _type->isa_ptr();578const Type *result = _type;579if( in_type != NULL && my_type != NULL ) {580TypePtr::PTR in_ptr = in_type->ptr();581if( in_ptr == TypePtr::Null ) {582result = in_type;583} else if( in_ptr == TypePtr::Constant ) {584// Casting a constant oop to an interface?585// (i.e., a String to a Comparable?)586// Then return the interface.587const TypeOopPtr *jptr = my_type->isa_oopptr();588assert( jptr, "" );589result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type))590? my_type->cast_to_ptr_type( TypePtr::NotNull )591: in_type;592} else {593result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );594}595}596return result;597598// JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.599// FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!600601//602// Remove this code after overnight run indicates no performance603// loss from not performing JOIN at CheckCastPPNode604//605// const TypeInstPtr *in_oop = in->isa_instptr();606// const TypeInstPtr *my_oop = _type->isa_instptr();607// // If either input is an 'interface', return destination type608// assert (in_oop == NULL || in_oop->klass() != NULL, "");609// assert (my_oop == NULL || my_oop->klass() != NULL, "");610// if( (in_oop && in_oop->klass()->is_interface())611// ||(my_oop && my_oop->klass()->is_interface()) ) {612// TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;613// // Preserve cast away nullness for interfaces614// if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {615// return my_oop->cast_to_ptr_type(TypePtr::NotNull);616// }617// return _type;618// }619//620// // Neither the input nor the destination type is an interface,621//622// // history: JOIN used to cause weird corner case bugs623// // return (in == TypeOopPtr::NULL_PTR) ? in : _type;624// // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.625// // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr626// const Type *join = in->join(_type);627// // Check if join preserved NotNull'ness for pointers628// if( join->isa_ptr() && _type->isa_ptr() ) {629// TypePtr::PTR join_ptr = join->is_ptr()->_ptr;630// TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;631// // If there isn't any NotNull'ness to preserve632// // OR if join preserved NotNull'ness then return it633// if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null ||634// join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {635// return join;636// }637// // ELSE return same old type as before638// return _type;639// }640// // Not joining two pointers641// return join;642}643644//------------------------------Ideal------------------------------------------645// Return a node which is more "ideal" than the current node. Strip out646// control copies647Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){648return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;649}650651652Node* DecodeNNode::Identity(PhaseTransform* phase) {653const Type *t = phase->type( in(1) );654if( t == Type::TOP ) return in(1);655656if (in(1)->is_EncodeP()) {657// (DecodeN (EncodeP p)) -> p658return in(1)->in(1);659}660return this;661}662663const Type *DecodeNNode::Value( PhaseTransform *phase ) const {664const Type *t = phase->type( in(1) );665if (t == Type::TOP) return Type::TOP;666if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;667668assert(t->isa_narrowoop(), "only narrowoop here");669return t->make_ptr();670}671672Node* EncodePNode::Identity(PhaseTransform* phase) {673const Type *t = phase->type( in(1) );674if( t == Type::TOP ) return in(1);675676if (in(1)->is_DecodeN()) {677// (EncodeP (DecodeN p)) -> p678return in(1)->in(1);679}680return this;681}682683const Type *EncodePNode::Value( PhaseTransform *phase ) const {684const Type *t = phase->type( in(1) );685if (t == Type::TOP) return Type::TOP;686if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;687688assert(t->isa_oop_ptr(), "only oopptr here");689return t->make_narrowoop();690}691692693Node *EncodeNarrowPtrNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {694return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1));695}696697Node* DecodeNKlassNode::Identity(PhaseTransform* phase) {698const Type *t = phase->type( in(1) );699if( t == Type::TOP ) return in(1);700701if (in(1)->is_EncodePKlass()) {702// (DecodeNKlass (EncodePKlass p)) -> p703return in(1)->in(1);704}705return this;706}707708const Type *DecodeNKlassNode::Value( PhaseTransform *phase ) const {709const Type *t = phase->type( in(1) );710if (t == Type::TOP) return Type::TOP;711assert(t != TypeNarrowKlass::NULL_PTR, "null klass?");712713assert(t->isa_narrowklass(), "only narrow klass ptr here");714return t->make_ptr();715}716717Node* EncodePKlassNode::Identity(PhaseTransform* phase) {718const Type *t = phase->type( in(1) );719if( t == Type::TOP ) return in(1);720721if (in(1)->is_DecodeNKlass()) {722// (EncodePKlass (DecodeNKlass p)) -> p723return in(1)->in(1);724}725return this;726}727728const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const {729const Type *t = phase->type( in(1) );730if (t == Type::TOP) return Type::TOP;731assert (t != TypePtr::NULL_PTR, "null klass?");732733assert(UseCompressedClassPointers && t->isa_klassptr(), "only klass ptr here");734return t->make_narrowklass();735}736737738//=============================================================================739//------------------------------Identity---------------------------------------740Node *Conv2BNode::Identity( PhaseTransform *phase ) {741const Type *t = phase->type( in(1) );742if( t == Type::TOP ) return in(1);743if( t == TypeInt::ZERO ) return in(1);744if( t == TypeInt::ONE ) return in(1);745if( t == TypeInt::BOOL ) return in(1);746return this;747}748749//------------------------------Value------------------------------------------750const Type *Conv2BNode::Value( PhaseTransform *phase ) const {751const Type *t = phase->type( in(1) );752if( t == Type::TOP ) return Type::TOP;753if( t == TypeInt::ZERO ) return TypeInt::ZERO;754if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;755const TypePtr *tp = t->isa_ptr();756if( tp != NULL ) {757if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;758if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;759if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;760return TypeInt::BOOL;761}762if (t->base() != Type::Int) return TypeInt::BOOL;763const TypeInt *ti = t->is_int();764if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;765return TypeInt::BOOL;766}767768769// The conversions operations are all Alpha sorted. Please keep it that way!770//=============================================================================771//------------------------------Value------------------------------------------772const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {773const Type *t = phase->type( in(1) );774if( t == Type::TOP ) return Type::TOP;775if( t == Type::DOUBLE ) return Type::FLOAT;776const TypeD *td = t->is_double_constant();777return TypeF::make( (float)td->getd() );778}779780//------------------------------Identity---------------------------------------781// Float's can be converted to doubles with no loss of bits. Hence782// converting a float to a double and back to a float is a NOP.783Node *ConvD2FNode::Identity(PhaseTransform *phase) {784return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;785}786787//=============================================================================788//------------------------------Value------------------------------------------789const Type *ConvD2INode::Value( PhaseTransform *phase ) const {790const Type *t = phase->type( in(1) );791if( t == Type::TOP ) return Type::TOP;792if( t == Type::DOUBLE ) return TypeInt::INT;793const TypeD *td = t->is_double_constant();794return TypeInt::make( SharedRuntime::d2i( td->getd() ) );795}796797//------------------------------Ideal------------------------------------------798// If converting to an int type, skip any rounding nodes799Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {800if( in(1)->Opcode() == Op_RoundDouble )801set_req(1,in(1)->in(1));802return NULL;803}804805//------------------------------Identity---------------------------------------806// Int's can be converted to doubles with no loss of bits. Hence807// converting an integer to a double and back to an integer is a NOP.808Node *ConvD2INode::Identity(PhaseTransform *phase) {809return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;810}811812//=============================================================================813//------------------------------Value------------------------------------------814const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {815const Type *t = phase->type( in(1) );816if( t == Type::TOP ) return Type::TOP;817if( t == Type::DOUBLE ) return TypeLong::LONG;818const TypeD *td = t->is_double_constant();819return TypeLong::make( SharedRuntime::d2l( td->getd() ) );820}821822//------------------------------Identity---------------------------------------823Node *ConvD2LNode::Identity(PhaseTransform *phase) {824// Remove ConvD2L->ConvL2D->ConvD2L sequences.825if( in(1) ->Opcode() == Op_ConvL2D &&826in(1)->in(1)->Opcode() == Op_ConvD2L )827return in(1)->in(1);828return this;829}830831//------------------------------Ideal------------------------------------------832// If converting to an int type, skip any rounding nodes833Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {834if( in(1)->Opcode() == Op_RoundDouble )835set_req(1,in(1)->in(1));836return NULL;837}838839//=============================================================================840//------------------------------Value------------------------------------------841const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {842const Type *t = phase->type( in(1) );843if( t == Type::TOP ) return Type::TOP;844if( t == Type::FLOAT ) return Type::DOUBLE;845const TypeF *tf = t->is_float_constant();846return TypeD::make( (double)tf->getf() );847}848849//=============================================================================850//------------------------------Value------------------------------------------851const Type *ConvF2INode::Value( PhaseTransform *phase ) const {852const Type *t = phase->type( in(1) );853if( t == Type::TOP ) return Type::TOP;854if( t == Type::FLOAT ) return TypeInt::INT;855const TypeF *tf = t->is_float_constant();856return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );857}858859//------------------------------Identity---------------------------------------860Node *ConvF2INode::Identity(PhaseTransform *phase) {861// Remove ConvF2I->ConvI2F->ConvF2I sequences.862if( in(1) ->Opcode() == Op_ConvI2F &&863in(1)->in(1)->Opcode() == Op_ConvF2I )864return in(1)->in(1);865return this;866}867868//------------------------------Ideal------------------------------------------869// If converting to an int type, skip any rounding nodes870Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {871if( in(1)->Opcode() == Op_RoundFloat )872set_req(1,in(1)->in(1));873return NULL;874}875876//=============================================================================877//------------------------------Value------------------------------------------878const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {879const Type *t = phase->type( in(1) );880if( t == Type::TOP ) return Type::TOP;881if( t == Type::FLOAT ) return TypeLong::LONG;882const TypeF *tf = t->is_float_constant();883return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );884}885886//------------------------------Identity---------------------------------------887Node *ConvF2LNode::Identity(PhaseTransform *phase) {888// Remove ConvF2L->ConvL2F->ConvF2L sequences.889if( in(1) ->Opcode() == Op_ConvL2F &&890in(1)->in(1)->Opcode() == Op_ConvF2L )891return in(1)->in(1);892return this;893}894895//------------------------------Ideal------------------------------------------896// If converting to an int type, skip any rounding nodes897Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {898if( in(1)->Opcode() == Op_RoundFloat )899set_req(1,in(1)->in(1));900return NULL;901}902903//=============================================================================904//------------------------------Value------------------------------------------905const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {906const Type *t = phase->type( in(1) );907if( t == Type::TOP ) return Type::TOP;908const TypeInt *ti = t->is_int();909if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );910return bottom_type();911}912913//=============================================================================914//------------------------------Value------------------------------------------915const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {916const Type *t = phase->type( in(1) );917if( t == Type::TOP ) return Type::TOP;918const TypeInt *ti = t->is_int();919if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );920return bottom_type();921}922923//------------------------------Identity---------------------------------------924Node *ConvI2FNode::Identity(PhaseTransform *phase) {925// Remove ConvI2F->ConvF2I->ConvI2F sequences.926if( in(1) ->Opcode() == Op_ConvF2I &&927in(1)->in(1)->Opcode() == Op_ConvI2F )928return in(1)->in(1);929return this;930}931932//=============================================================================933//------------------------------Value------------------------------------------934const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {935const Type *t = phase->type( in(1) );936if( t == Type::TOP ) return Type::TOP;937const TypeInt *ti = t->is_int();938const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);939// Join my declared type against my incoming type.940tl = tl->filter(_type);941return tl;942}943944#ifdef _LP64945static inline bool long_ranges_overlap(jlong lo1, jlong hi1,946jlong lo2, jlong hi2) {947// Two ranges overlap iff one range's low point falls in the other range.948return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);949}950#endif951952//------------------------------Ideal------------------------------------------953Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {954const TypeLong* this_type = this->type()->is_long();955Node* this_changed = NULL;956957// If _major_progress, then more loop optimizations follow. Do NOT958// remove this node's type assertion until no more loop ops can happen.959// The progress bit is set in the major loop optimizations THEN comes the960// call to IterGVN and any chance of hitting this code. Cf. Opaque1Node.961if (can_reshape && !phase->C->major_progress()) {962const TypeInt* in_type = phase->type(in(1))->isa_int();963if (in_type != NULL && this_type != NULL &&964(in_type->_lo != this_type->_lo ||965in_type->_hi != this_type->_hi)) {966// Although this WORSENS the type, it increases GVN opportunities,967// because I2L nodes with the same input will common up, regardless968// of slightly differing type assertions. Such slight differences969// arise routinely as a result of loop unrolling, so this is a970// post-unrolling graph cleanup. Choose a type which depends only971// on my input. (Exception: Keep a range assertion of >=0 or <0.)972jlong lo1 = this_type->_lo;973jlong hi1 = this_type->_hi;974int w1 = this_type->_widen;975if (lo1 != (jint)lo1 ||976hi1 != (jint)hi1 ||977lo1 > hi1) {978// Overflow leads to wraparound, wraparound leads to range saturation.979lo1 = min_jint; hi1 = max_jint;980} else if (lo1 >= 0) {981// Keep a range assertion of >=0.982lo1 = 0; hi1 = max_jint;983} else if (hi1 < 0) {984// Keep a range assertion of <0.985lo1 = min_jint; hi1 = -1;986} else {987lo1 = min_jint; hi1 = max_jint;988}989const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),990MIN2((jlong)in_type->_hi, hi1),991MAX2((int)in_type->_widen, w1));992if (wtype != type()) {993set_type(wtype);994// Note: this_type still has old type value, for the logic below.995this_changed = this;996}997}998}9991000#ifdef _LP641001// Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y))1002// but only if x and y have subranges that cannot cause 32-bit overflow,1003// under the assumption that x+y is in my own subrange this->type().10041005// This assumption is based on a constraint (i.e., type assertion)1006// established in Parse::array_addressing or perhaps elsewhere.1007// This constraint has been adjoined to the "natural" type of1008// the incoming argument in(0). We know (because of runtime1009// checks) - that the result value I2L(x+y) is in the joined range.1010// Hence we can restrict the incoming terms (x, y) to values such1011// that their sum also lands in that range.10121013// This optimization is useful only on 64-bit systems, where we hope1014// the addition will end up subsumed in an addressing mode.1015// It is necessary to do this when optimizing an unrolled array1016// copy loop such as x[i++] = y[i++].10171018// On 32-bit systems, it's better to perform as much 32-bit math as1019// possible before the I2L conversion, because 32-bit math is cheaper.1020// There's no common reason to "leak" a constant offset through the I2L.1021// Addressing arithmetic will not absorb it as part of a 64-bit AddL.10221023Node* z = in(1);1024int op = z->Opcode();1025if (op == Op_AddI || op == Op_SubI) {1026Node* x = z->in(1);1027Node* y = z->in(2);1028assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");1029if (phase->type(x) == Type::TOP) return this_changed;1030if (phase->type(y) == Type::TOP) return this_changed;1031const TypeInt* tx = phase->type(x)->is_int();1032const TypeInt* ty = phase->type(y)->is_int();1033const TypeLong* tz = this_type;1034jlong xlo = tx->_lo;1035jlong xhi = tx->_hi;1036jlong ylo = ty->_lo;1037jlong yhi = ty->_hi;1038jlong zlo = tz->_lo;1039jlong zhi = tz->_hi;1040jlong vbit = CONST64(1) << BitsPerInt;1041int widen = MAX2(tx->_widen, ty->_widen);1042if (op == Op_SubI) {1043jlong ylo0 = ylo;1044ylo = -yhi;1045yhi = -ylo0;1046}1047// See if x+y can cause positive overflow into z+2**321048if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {1049return this_changed;1050}1051// See if x+y can cause negative overflow into z-2**321052if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {1053return this_changed;1054}1055// Now it's always safe to assume x+y does not overflow.1056// This is true even if some pairs x,y might cause overflow, as long1057// as that overflow value cannot fall into [zlo,zhi].10581059// Confident that the arithmetic is "as if infinite precision",1060// we can now use z's range to put constraints on those of x and y.1061// The "natural" range of x [xlo,xhi] can perhaps be narrowed to a1062// more "restricted" range by intersecting [xlo,xhi] with the1063// range obtained by subtracting y's range from the asserted range1064// of the I2L conversion. Here's the interval arithmetic algebra:1065// x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]1066// => x in [zlo-yhi, zhi-ylo]1067// => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]1068// => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]1069jlong rxlo = MAX2(xlo, zlo - yhi);1070jlong rxhi = MIN2(xhi, zhi - ylo);1071// And similarly, x changing place with y:1072jlong rylo = MAX2(ylo, zlo - xhi);1073jlong ryhi = MIN2(yhi, zhi - xlo);1074if (rxlo > rxhi || rylo > ryhi) {1075return this_changed; // x or y is dying; don't mess w/ it1076}1077if (op == Op_SubI) {1078jlong rylo0 = rylo;1079rylo = -ryhi;1080ryhi = -rylo0;1081}1082assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");1083assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");1084Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), NULL);1085Node *hook = new (phase->C) Node(1);1086hook->init_req(0, cx); // Add a use to cx to prevent him from dying1087Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), NULL);1088hook->del_req(0); // Just yank bogus edge1089hook->destruct();1090switch (op) {1091case Op_AddI: return new (phase->C) AddLNode(cx, cy);1092case Op_SubI: return new (phase->C) SubLNode(cx, cy);1093default: ShouldNotReachHere();1094}1095}1096#endif //_LP6410971098return this_changed;1099}11001101//=============================================================================1102//------------------------------Value------------------------------------------1103const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {1104const Type *t = phase->type( in(1) );1105if( t == Type::TOP ) return Type::TOP;1106const TypeLong *tl = t->is_long();1107if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );1108return bottom_type();1109}11101111//=============================================================================1112//------------------------------Value------------------------------------------1113const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {1114const Type *t = phase->type( in(1) );1115if( t == Type::TOP ) return Type::TOP;1116const TypeLong *tl = t->is_long();1117if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );1118return bottom_type();1119}11201121//=============================================================================1122//----------------------------Identity-----------------------------------------1123Node *ConvL2INode::Identity( PhaseTransform *phase ) {1124// Convert L2I(I2L(x)) => x1125if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);1126return this;1127}11281129//------------------------------Value------------------------------------------1130const Type *ConvL2INode::Value( PhaseTransform *phase ) const {1131const Type *t = phase->type( in(1) );1132if( t == Type::TOP ) return Type::TOP;1133const TypeLong *tl = t->is_long();1134if (tl->is_con())1135// Easy case.1136return TypeInt::make((jint)tl->get_con());1137return bottom_type();1138}11391140//------------------------------Ideal------------------------------------------1141// Return a node which is more "ideal" than the current node.1142// Blow off prior masking to int1143Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {1144Node *andl = in(1);1145uint andl_op = andl->Opcode();1146if( andl_op == Op_AndL ) {1147// Blow off prior masking to int1148if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {1149set_req(1,andl->in(1));1150return this;1151}1152}11531154// Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))1155// This replaces an 'AddL' with an 'AddI'.1156if( andl_op == Op_AddL ) {1157// Don't do this for nodes which have more than one user since1158// we'll end up computing the long add anyway.1159if (andl->outcnt() > 1) return NULL;11601161Node* x = andl->in(1);1162Node* y = andl->in(2);1163assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );1164if (phase->type(x) == Type::TOP) return NULL;1165if (phase->type(y) == Type::TOP) return NULL;1166Node *add1 = phase->transform(new (phase->C) ConvL2INode(x));1167Node *add2 = phase->transform(new (phase->C) ConvL2INode(y));1168return new (phase->C) AddINode(add1,add2);1169}11701171// Disable optimization: LoadL->ConvL2I ==> LoadI.1172// It causes problems (sizes of Load and Store nodes do not match)1173// in objects initialization code and Escape Analysis.1174return NULL;1175}11761177//=============================================================================1178//------------------------------Value------------------------------------------1179const Type *CastX2PNode::Value( PhaseTransform *phase ) const {1180const Type* t = phase->type(in(1));1181if (t == Type::TOP) return Type::TOP;1182if (t->base() == Type_X && t->singleton()) {1183uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();1184if (bits == 0) return TypePtr::NULL_PTR;1185return TypeRawPtr::make((address) bits);1186}1187return CastX2PNode::bottom_type();1188}11891190//------------------------------Idealize---------------------------------------1191static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {1192if (t == Type::TOP) return false;1193const TypeX* tl = t->is_intptr_t();1194jint lo = min_jint;1195jint hi = max_jint;1196if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow1197return (tl->_lo >= lo) && (tl->_hi <= hi);1198}11991200static inline Node* addP_of_X2P(PhaseGVN *phase,1201Node* base,1202Node* dispX,1203bool negate = false) {1204if (negate) {1205dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX));1206}1207return new (phase->C) AddPNode(phase->C->top(),1208phase->transform(new (phase->C) CastX2PNode(base)),1209phase->transform(dispX));1210}12111212Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {1213// convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int1214int op = in(1)->Opcode();1215Node* x;1216Node* y;1217switch (op) {1218case Op_SubX:1219x = in(1)->in(1);1220// Avoid ideal transformations ping-pong between this and AddP for raw pointers.1221if (phase->find_intptr_t_con(x, -1) == 0)1222break;1223y = in(1)->in(2);1224if (fits_in_int(phase->type(y), true)) {1225return addP_of_X2P(phase, x, y, true);1226}1227break;1228case Op_AddX:1229x = in(1)->in(1);1230y = in(1)->in(2);1231if (fits_in_int(phase->type(y))) {1232return addP_of_X2P(phase, x, y);1233}1234if (fits_in_int(phase->type(x))) {1235return addP_of_X2P(phase, y, x);1236}1237break;1238}1239return NULL;1240}12411242//------------------------------Identity---------------------------------------1243Node *CastX2PNode::Identity( PhaseTransform *phase ) {1244if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);1245return this;1246}12471248//=============================================================================1249//------------------------------Value------------------------------------------1250const Type *CastP2XNode::Value( PhaseTransform *phase ) const {1251const Type* t = phase->type(in(1));1252if (t == Type::TOP) return Type::TOP;1253if (t->base() == Type::RawPtr && t->singleton()) {1254uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();1255return TypeX::make(bits);1256}1257return CastP2XNode::bottom_type();1258}12591260Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {1261return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;1262}12631264//------------------------------Identity---------------------------------------1265Node *CastP2XNode::Identity( PhaseTransform *phase ) {1266if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);1267return this;1268}126912701271//=============================================================================1272//------------------------------Identity---------------------------------------1273// Remove redundant roundings1274Node *RoundFloatNode::Identity( PhaseTransform *phase ) {1275assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");1276// Do not round constants1277if (phase->type(in(1))->base() == Type::FloatCon) return in(1);1278int op = in(1)->Opcode();1279// Redundant rounding1280if( op == Op_RoundFloat ) return in(1);1281// Already rounded1282if( op == Op_Parm ) return in(1);1283if( op == Op_LoadF ) return in(1);1284return this;1285}12861287//------------------------------Value------------------------------------------1288const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {1289return phase->type( in(1) );1290}12911292//=============================================================================1293//------------------------------Identity---------------------------------------1294// Remove redundant roundings. Incoming arguments are already rounded.1295Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {1296assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");1297// Do not round constants1298if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);1299int op = in(1)->Opcode();1300// Redundant rounding1301if( op == Op_RoundDouble ) return in(1);1302// Already rounded1303if( op == Op_Parm ) return in(1);1304if( op == Op_LoadD ) return in(1);1305if( op == Op_ConvF2D ) return in(1);1306if( op == Op_ConvI2D ) return in(1);1307return this;1308}13091310//------------------------------Value------------------------------------------1311const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {1312return phase->type( in(1) );1313}131413151316//=============================================================================1317// Do not allow value-numbering1318uint Opaque1Node::hash() const { return NO_HASH; }1319uint Opaque1Node::cmp( const Node &n ) const {1320return (&n == this); // Always fail except on self1321}13221323//------------------------------Identity---------------------------------------1324// If _major_progress, then more loop optimizations follow. Do NOT remove1325// the opaque Node until no more loop ops can happen. Note the timing of1326// _major_progress; it's set in the major loop optimizations THEN comes the1327// call to IterGVN and any chance of hitting this code. Hence there's no1328// phase-ordering problem with stripping Opaque1 in IGVN followed by some1329// more loop optimizations that require it.1330Node *Opaque1Node::Identity( PhaseTransform *phase ) {1331return phase->C->major_progress() ? this : in(1);1332}13331334//=============================================================================1335// A node to prevent unwanted optimizations. Allows constant folding. Stops1336// value-numbering, most Ideal calls or Identity functions. This Node is1337// specifically designed to prevent the pre-increment value of a loop trip1338// counter from being live out of the bottom of the loop (hence causing the1339// pre- and post-increment values both being live and thus requiring an extra1340// temp register and an extra move). If we "accidentally" optimize through1341// this kind of a Node, we'll get slightly pessimal, but correct, code. Thus1342// it's OK to be slightly sloppy on optimizations here.13431344// Do not allow value-numbering1345uint Opaque2Node::hash() const { return NO_HASH; }1346uint Opaque2Node::cmp( const Node &n ) const {1347return (&n == this); // Always fail except on self1348}13491350//=============================================================================13511352uint ProfileBooleanNode::hash() const { return NO_HASH; }1353uint ProfileBooleanNode::cmp( const Node &n ) const {1354return (&n == this);1355}13561357Node *ProfileBooleanNode::Ideal(PhaseGVN *phase, bool can_reshape) {1358if (can_reshape && _delay_removal) {1359_delay_removal = false;1360return this;1361} else {1362return NULL;1363}1364}13651366Node *ProfileBooleanNode::Identity( PhaseTransform *phase ) {1367if (_delay_removal) {1368return this;1369} else {1370assert(_consumed, "profile should be consumed before elimination");1371return in(1);1372}1373}13741375//------------------------------Value------------------------------------------1376const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {1377const Type *t = phase->type( in(1) );1378if( t == Type::TOP ) return Type::TOP;1379const TypeLong *tl = t->is_long();1380if( !tl->is_con() ) return bottom_type();1381JavaValue v;1382v.set_jlong(tl->get_con());1383return TypeD::make( v.get_jdouble() );1384}13851386//------------------------------Value------------------------------------------1387const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {1388const Type *t = phase->type( in(1) );1389if( t == Type::TOP ) return Type::TOP;1390const TypeInt *ti = t->is_int();1391if( !ti->is_con() ) return bottom_type();1392JavaValue v;1393v.set_jint(ti->get_con());1394return TypeF::make( v.get_jfloat() );1395}13961397//------------------------------Value------------------------------------------1398const Type *MoveF2INode::Value( PhaseTransform *phase ) const {1399const Type *t = phase->type( in(1) );1400if( t == Type::TOP ) return Type::TOP;1401if( t == Type::FLOAT ) return TypeInt::INT;1402const TypeF *tf = t->is_float_constant();1403JavaValue v;1404v.set_jfloat(tf->getf());1405return TypeInt::make( v.get_jint() );1406}14071408//------------------------------Value------------------------------------------1409const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {1410const Type *t = phase->type( in(1) );1411if( t == Type::TOP ) return Type::TOP;1412if( t == Type::DOUBLE ) return TypeLong::LONG;1413const TypeD *td = t->is_double_constant();1414JavaValue v;1415v.set_jdouble(td->getd());1416return TypeLong::make( v.get_jlong() );1417}14181419//------------------------------Value------------------------------------------1420const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const {1421const Type* t = phase->type(in(1));1422if (t == Type::TOP) return Type::TOP;1423const TypeInt* ti = t->isa_int();1424if (ti && ti->is_con()) {1425jint i = ti->get_con();1426// HD, Figure 5-61427if (i == 0)1428return TypeInt::make(BitsPerInt);1429int n = 1;1430unsigned int x = i;1431if (x >> 16 == 0) { n += 16; x <<= 16; }1432if (x >> 24 == 0) { n += 8; x <<= 8; }1433if (x >> 28 == 0) { n += 4; x <<= 4; }1434if (x >> 30 == 0) { n += 2; x <<= 2; }1435n -= x >> 31;1436return TypeInt::make(n);1437}1438return TypeInt::INT;1439}14401441//------------------------------Value------------------------------------------1442const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const {1443const Type* t = phase->type(in(1));1444if (t == Type::TOP) return Type::TOP;1445const TypeLong* tl = t->isa_long();1446if (tl && tl->is_con()) {1447jlong l = tl->get_con();1448// HD, Figure 5-61449if (l == 0)1450return TypeInt::make(BitsPerLong);1451int n = 1;1452unsigned int x = (((julong) l) >> 32);1453if (x == 0) { n += 32; x = (int) l; }1454if (x >> 16 == 0) { n += 16; x <<= 16; }1455if (x >> 24 == 0) { n += 8; x <<= 8; }1456if (x >> 28 == 0) { n += 4; x <<= 4; }1457if (x >> 30 == 0) { n += 2; x <<= 2; }1458n -= x >> 31;1459return TypeInt::make(n);1460}1461return TypeInt::INT;1462}14631464//------------------------------Value------------------------------------------1465const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const {1466const Type* t = phase->type(in(1));1467if (t == Type::TOP) return Type::TOP;1468const TypeInt* ti = t->isa_int();1469if (ti && ti->is_con()) {1470jint i = ti->get_con();1471// HD, Figure 5-141472int y;1473if (i == 0)1474return TypeInt::make(BitsPerInt);1475int n = 31;1476y = i << 16; if (y != 0) { n = n - 16; i = y; }1477y = i << 8; if (y != 0) { n = n - 8; i = y; }1478y = i << 4; if (y != 0) { n = n - 4; i = y; }1479y = i << 2; if (y != 0) { n = n - 2; i = y; }1480y = i << 1; if (y != 0) { n = n - 1; }1481return TypeInt::make(n);1482}1483return TypeInt::INT;1484}14851486//------------------------------Value------------------------------------------1487const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const {1488const Type* t = phase->type(in(1));1489if (t == Type::TOP) return Type::TOP;1490const TypeLong* tl = t->isa_long();1491if (tl && tl->is_con()) {1492jlong l = tl->get_con();1493// HD, Figure 5-141494int x, y;1495if (l == 0)1496return TypeInt::make(BitsPerLong);1497int n = 63;1498y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);1499y = x << 16; if (y != 0) { n = n - 16; x = y; }1500y = x << 8; if (y != 0) { n = n - 8; x = y; }1501y = x << 4; if (y != 0) { n = n - 4; x = y; }1502y = x << 2; if (y != 0) { n = n - 2; x = y; }1503y = x << 1; if (y != 0) { n = n - 1; }1504return TypeInt::make(n);1505}1506return TypeInt::INT;1507}150815091510