duke@435: /* kvn@3604: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "opto/addnode.hpp" stefank@2314: #include "opto/compile.hpp" stefank@2314: #include "opto/connode.hpp" stefank@2314: #include "opto/machnode.hpp" stefank@2314: #include "opto/matcher.hpp" stefank@2314: #include "opto/memnode.hpp" stefank@2314: #include "opto/phaseX.hpp" stefank@2314: #include "opto/subnode.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: duke@435: // Optimization - Graph Style duke@435: duke@435: //============================================================================= duke@435: //------------------------------hash------------------------------------------- duke@435: uint ConNode::hash() const { duke@435: return (uintptr_t)in(TypeFunc::Control) + _type->hash(); duke@435: } duke@435: duke@435: //------------------------------make------------------------------------------- duke@435: ConNode *ConNode::make( Compile* C, const Type *t ) { duke@435: switch( t->basic_type() ) { kvn@4115: case T_INT: return new (C) ConINode( t->is_int() ); kvn@4115: case T_LONG: return new (C) ConLNode( t->is_long() ); kvn@4115: case T_FLOAT: return new (C) ConFNode( t->is_float_constant() ); kvn@4115: case T_DOUBLE: return new (C) ConDNode( t->is_double_constant() ); kvn@4115: case T_VOID: return new (C) ConNode ( Type::TOP ); kvn@4115: case T_OBJECT: return new (C) ConPNode( t->is_ptr() ); kvn@4115: case T_ARRAY: return new (C) ConPNode( t->is_aryptr() ); kvn@4115: case T_ADDRESS: return new (C) ConPNode( t->is_ptr() ); kvn@4115: case T_NARROWOOP: return new (C) ConNNode( t->is_narrowoop() ); kvn@4115: case T_METADATA: return new (C) ConPNode( t->is_ptr() ); duke@435: // Expected cases: TypePtr::NULL_PTR, any is_rawptr() duke@435: // Also seen: AnyPtr(TopPTR *+top); from command line: duke@435: // r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660 duke@435: // %%%% Stop using TypePtr::NULL_PTR to represent nulls: use either TypeRawPtr::NULL_PTR duke@435: // or else TypeOopPtr::NULL_PTR. Then set Type::_basic_type[AnyPtr] = T_ILLEGAL duke@435: } duke@435: ShouldNotReachHere(); duke@435: return NULL; duke@435: } duke@435: duke@435: //============================================================================= duke@435: /* duke@435: The major change is for CMoveP and StrComp. They have related but slightly duke@435: different problems. They both take in TWO oops which are both null-checked duke@435: independently before the using Node. After CCP removes the CastPP's they need duke@435: to pick up the guarding test edge - in this case TWO control edges. I tried duke@435: various solutions, all have problems: duke@435: duke@435: (1) Do nothing. This leads to a bug where we hoist a Load from a CMoveP or a duke@435: StrComp above a guarding null check. I've seen both cases in normal -Xcomp duke@435: testing. duke@435: duke@435: (2) Plug the control edge from 1 of the 2 oops in. Apparent problem here is duke@435: to figure out which test post-dominates. The real problem is that it doesn't duke@435: matter which one you pick. After you pick up, the dominating-test elider in duke@435: IGVN can remove the test and allow you to hoist up to the dominating test on twisti@1040: the chosen oop bypassing the test on the not-chosen oop. Seen in testing. duke@435: Oops. duke@435: duke@435: (3) Leave the CastPP's in. This makes the graph more accurate in some sense; duke@435: we get to keep around the knowledge that an oop is not-null after some test. duke@435: Alas, the CastPP's interfere with GVN (some values are the regular oop, some duke@435: are the CastPP of the oop, all merge at Phi's which cannot collapse, etc). duke@435: This cost us 10% on SpecJVM, even when I removed some of the more trivial duke@435: cases in the optimizer. Removing more useless Phi's started allowing Loads to duke@435: illegally float above null checks. I gave up on this approach. duke@435: duke@435: (4) Add BOTH control edges to both tests. Alas, too much code knows that duke@435: control edges are in slot-zero ONLY. Many quick asserts fail; no way to do duke@435: this one. Note that I really want to allow the CMoveP to float and add both duke@435: control edges to the dependent Load op - meaning I can select early but I duke@435: cannot Load until I pass both tests. duke@435: duke@435: (5) Do not hoist CMoveP and StrComp. To this end I added the v-call duke@435: depends_only_on_test(). No obvious performance loss on Spec, but we are duke@435: clearly conservative on CMoveP (also so on StrComp but that's unlikely to duke@435: matter ever). duke@435: duke@435: */ duke@435: duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. duke@435: // Move constants to the right. duke@435: Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if( in(0) && remove_dead_region(phase, can_reshape) ) return this; kvn@740: // Don't bother trying to transform a dead node kvn@740: if( in(0) && in(0)->is_top() ) return NULL; duke@435: assert( !phase->eqv(in(Condition), this) && duke@435: !phase->eqv(in(IfFalse), this) && duke@435: !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" ); duke@435: if( phase->type(in(Condition)) == Type::TOP ) duke@435: return NULL; // return NULL when Condition is dead duke@435: duke@435: if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) { duke@435: if( in(Condition)->is_Bool() ) { duke@435: BoolNode* b = in(Condition)->as_Bool(); duke@435: BoolNode* b2 = b->negate(phase); duke@435: return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type ); duke@435: } duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: //------------------------------is_cmove_id------------------------------------ duke@435: // Helper function to check for CMOVE identity. Shared with PhiNode::Identity duke@435: Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) { duke@435: // Check for Cmp'ing and CMove'ing same values duke@435: if( (phase->eqv(cmp->in(1),f) && duke@435: phase->eqv(cmp->in(2),t)) || duke@435: // Swapped Cmp is OK duke@435: (phase->eqv(cmp->in(2),f) && duke@435: phase->eqv(cmp->in(1),t)) ) { cfang@1190: // Give up this identity check for floating points because it may choose incorrect cfang@1190: // value around 0.0 and -0.0 cfang@1190: if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD ) cfang@1190: return NULL; duke@435: // Check for "(t==f)?t:f;" and replace with "f" duke@435: if( b->_test._test == BoolTest::eq ) duke@435: return f; duke@435: // Allow the inverted case as well duke@435: // Check for "(t!=f)?t:f;" and replace with "t" duke@435: if( b->_test._test == BoolTest::ne ) duke@435: return t; duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: // Conditional-move is an identity if both inputs are the same, or the test duke@435: // true or false. duke@435: Node *CMoveNode::Identity( PhaseTransform *phase ) { duke@435: if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs? duke@435: return in(IfFalse); // Then it doesn't matter duke@435: if( phase->type(in(Condition)) == TypeInt::ZERO ) duke@435: return in(IfFalse); // Always pick left(false) input duke@435: if( phase->type(in(Condition)) == TypeInt::ONE ) duke@435: return in(IfTrue); // Always pick right(true) input duke@435: duke@435: // Check for CMove'ing a constant after comparing against the constant. duke@435: // Happens all the time now, since if we compare equality vs a constant in duke@435: // the parser, we "know" the variable is constant on one path and we force duke@435: // it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a duke@435: // conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more duke@435: // general in that we don't need constants. duke@435: if( in(Condition)->is_Bool() ) { duke@435: BoolNode *b = in(Condition)->as_Bool(); duke@435: Node *cmp = b->in(1); duke@435: if( cmp->is_Cmp() ) { duke@435: Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b ); duke@435: if( id ) return id; duke@435: } duke@435: } duke@435: duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: // Result is the meet of inputs duke@435: const Type *CMoveNode::Value( PhaseTransform *phase ) const { duke@435: if( phase->type(in(Condition)) == Type::TOP ) duke@435: return Type::TOP; duke@435: return phase->type(in(IfFalse))->meet(phase->type(in(IfTrue))); duke@435: } duke@435: duke@435: //------------------------------make------------------------------------------- duke@435: // Make a correctly-flavored CMove. Since _type is directly determined duke@435: // from the inputs we do not need to specify it here. duke@435: CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) { duke@435: switch( t->basic_type() ) { kvn@4115: case T_INT: return new (C) CMoveINode( bol, left, right, t->is_int() ); kvn@4115: case T_FLOAT: return new (C) CMoveFNode( bol, left, right, t ); kvn@4115: case T_DOUBLE: return new (C) CMoveDNode( bol, left, right, t ); kvn@4115: case T_LONG: return new (C) CMoveLNode( bol, left, right, t->is_long() ); kvn@4115: case T_OBJECT: return new (C) CMovePNode( c, bol, left, right, t->is_oopptr() ); kvn@4115: case T_ADDRESS: return new (C) CMovePNode( c, bol, left, right, t->is_ptr() ); kvn@4115: case T_NARROWOOP: return new (C) CMoveNNode( c, bol, left, right, t ); duke@435: default: duke@435: ShouldNotReachHere(); duke@435: return NULL; duke@435: } duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. duke@435: // Check for conversions to boolean duke@435: Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: // Try generic ideal's first duke@435: Node *x = CMoveNode::Ideal(phase, can_reshape); duke@435: if( x ) return x; duke@435: duke@435: // If zero is on the left (false-case, no-move-case) it must mean another duke@435: // constant is on the right (otherwise the shared CMove::Ideal code would duke@435: // have moved the constant to the right). This situation is bad for Intel duke@435: // and a don't-care for Sparc. It's bad for Intel because the zero has to duke@435: // be manifested in a register with a XOR which kills flags, which are live duke@435: // on input to the CMoveI, leading to a situation which causes excessive duke@435: // spilling on Intel. For Sparc, if the zero in on the left the Sparc will duke@435: // zero a register via G0 and conditionally-move the other constant. If the duke@435: // zero is on the right, the Sparc will load the first constant with a duke@435: // 13-bit set-lo and conditionally move G0. See bug 4677505. duke@435: if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) { duke@435: if( in(Condition)->is_Bool() ) { duke@435: BoolNode* b = in(Condition)->as_Bool(); duke@435: BoolNode* b2 = b->negate(phase); duke@435: return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type ); duke@435: } duke@435: } duke@435: duke@435: // Now check for booleans duke@435: int flip = 0; duke@435: duke@435: // Check for picking from zero/one duke@435: if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) { duke@435: flip = 1 - flip; duke@435: } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) { duke@435: } else return NULL; duke@435: duke@435: // Check for eq/ne test duke@435: if( !in(1)->is_Bool() ) return NULL; duke@435: BoolNode *bol = in(1)->as_Bool(); duke@435: if( bol->_test._test == BoolTest::eq ) { duke@435: } else if( bol->_test._test == BoolTest::ne ) { duke@435: flip = 1-flip; duke@435: } else return NULL; duke@435: duke@435: // Check for vs 0 or 1 duke@435: if( !bol->in(1)->is_Cmp() ) return NULL; duke@435: const CmpNode *cmp = bol->in(1)->as_Cmp(); duke@435: if( phase->type(cmp->in(2)) == TypeInt::ZERO ) { duke@435: } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) { duke@435: // Allow cmp-vs-1 if the other input is bounded by 0-1 duke@435: if( phase->type(cmp->in(1)) != TypeInt::BOOL ) duke@435: return NULL; duke@435: flip = 1 - flip; duke@435: } else return NULL; duke@435: duke@435: // Convert to a bool (flipped) duke@435: // Build int->bool conversion duke@435: #ifndef PRODUCT duke@435: if( PrintOpto ) tty->print_cr("CMOV to I2B"); duke@435: #endif kvn@4115: Node *n = new (phase->C) Conv2BNode( cmp->in(1) ); duke@435: if( flip ) kvn@4115: n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) ); duke@435: duke@435: return n; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. duke@435: // Check for absolute value duke@435: Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: // Try generic ideal's first duke@435: Node *x = CMoveNode::Ideal(phase, can_reshape); duke@435: if( x ) return x; duke@435: duke@435: int cmp_zero_idx = 0; // Index of compare input where to look for zero duke@435: int phi_x_idx = 0; // Index of phi input where to find naked x duke@435: duke@435: // Find the Bool duke@435: if( !in(1)->is_Bool() ) return NULL; duke@435: BoolNode *bol = in(1)->as_Bool(); duke@435: // Check bool sense duke@435: switch( bol->_test._test ) { duke@435: case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break; duke@435: case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break; duke@435: case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break; duke@435: case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break; duke@435: default: return NULL; break; duke@435: } duke@435: duke@435: // Find zero input of CmpF; the other input is being abs'd duke@435: Node *cmpf = bol->in(1); duke@435: if( cmpf->Opcode() != Op_CmpF ) return NULL; duke@435: Node *X = NULL; duke@435: bool flip = false; duke@435: if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) { duke@435: X = cmpf->in(3 - cmp_zero_idx); duke@435: } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) { duke@435: // The test is inverted, we should invert the result... duke@435: X = cmpf->in(cmp_zero_idx); duke@435: flip = true; duke@435: } else { duke@435: return NULL; duke@435: } duke@435: duke@435: // If X is found on the appropriate phi input, find the subtract on the other duke@435: if( X != in(phi_x_idx) ) return NULL; duke@435: int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue; duke@435: Node *sub = in(phi_sub_idx); duke@435: duke@435: // Allow only SubF(0,X) and fail out for all others; NegF is not OK duke@435: if( sub->Opcode() != Op_SubF || duke@435: sub->in(2) != X || duke@435: phase->type(sub->in(1)) != TypeF::ZERO ) return NULL; duke@435: kvn@4115: Node *abs = new (phase->C) AbsFNode( X ); duke@435: if( flip ) kvn@4115: abs = new (phase->C) SubFNode(sub->in(1), phase->transform(abs)); duke@435: duke@435: return abs; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. duke@435: // Check for absolute value duke@435: Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: // Try generic ideal's first duke@435: Node *x = CMoveNode::Ideal(phase, can_reshape); duke@435: if( x ) return x; duke@435: duke@435: int cmp_zero_idx = 0; // Index of compare input where to look for zero duke@435: int phi_x_idx = 0; // Index of phi input where to find naked x duke@435: duke@435: // Find the Bool duke@435: if( !in(1)->is_Bool() ) return NULL; duke@435: BoolNode *bol = in(1)->as_Bool(); duke@435: // Check bool sense duke@435: switch( bol->_test._test ) { duke@435: case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break; duke@435: case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break; duke@435: case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break; duke@435: case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break; duke@435: default: return NULL; break; duke@435: } duke@435: duke@435: // Find zero input of CmpD; the other input is being abs'd duke@435: Node *cmpd = bol->in(1); duke@435: if( cmpd->Opcode() != Op_CmpD ) return NULL; duke@435: Node *X = NULL; duke@435: bool flip = false; duke@435: if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) { duke@435: X = cmpd->in(3 - cmp_zero_idx); duke@435: } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) { duke@435: // The test is inverted, we should invert the result... duke@435: X = cmpd->in(cmp_zero_idx); duke@435: flip = true; duke@435: } else { duke@435: return NULL; duke@435: } duke@435: duke@435: // If X is found on the appropriate phi input, find the subtract on the other duke@435: if( X != in(phi_x_idx) ) return NULL; duke@435: int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue; duke@435: Node *sub = in(phi_sub_idx); duke@435: duke@435: // Allow only SubD(0,X) and fail out for all others; NegD is not OK duke@435: if( sub->Opcode() != Op_SubD || duke@435: sub->in(2) != X || duke@435: phase->type(sub->in(1)) != TypeD::ZERO ) return NULL; duke@435: kvn@4115: Node *abs = new (phase->C) AbsDNode( X ); duke@435: if( flip ) kvn@4115: abs = new (phase->C) SubDNode(sub->in(1), phase->transform(abs)); duke@435: duke@435: return abs; duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: // If input is already higher or equal to cast type, then this is an identity. duke@435: Node *ConstraintCastNode::Identity( PhaseTransform *phase ) { duke@435: return phase->type(in(1))->higher_equal(_type) ? in(1) : this; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: // Take 'join' of input and cast-up type duke@435: const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const { duke@435: if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP; duke@435: const Type* ft = phase->type(in(1))->filter(_type); duke@435: duke@435: #ifdef ASSERT duke@435: // Previous versions of this function had some special case logic, duke@435: // which is no longer necessary. Make sure of the required effects. duke@435: switch (Opcode()) { duke@435: case Op_CastII: duke@435: { duke@435: const Type* t1 = phase->type(in(1)); duke@435: if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1"); duke@435: const Type* rt = t1->join(_type); duke@435: if (rt->empty()) assert(ft == Type::TOP, "special case #2"); duke@435: break; duke@435: } duke@435: case Op_CastPP: duke@435: if (phase->type(in(1)) == TypePtr::NULL_PTR && duke@435: _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) duke@435: assert(ft == Type::TOP, "special case #3"); duke@435: break; duke@435: } duke@435: #endif //ASSERT duke@435: duke@435: return ft; duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. Strip out duke@435: // control copies duke@435: Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){ duke@435: return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL; duke@435: } duke@435: duke@435: //------------------------------Ideal_DU_postCCP------------------------------- duke@435: // Throw away cast after constant propagation duke@435: Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) { duke@435: const Type *t = ccp->type(in(1)); duke@435: ccp->hash_delete(this); duke@435: set_type(t); // Turn into ID function duke@435: ccp->hash_insert(this); duke@435: return this; duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: duke@435: //------------------------------Ideal_DU_postCCP------------------------------- duke@435: // If not converting int->oop, throw away cast after constant propagation duke@435: Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) { duke@435: const Type *t = ccp->type(in(1)); kvn@1930: if (!t->isa_oop_ptr() || (in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks())) { kvn@803: return NULL; // do not transform raw pointers or narrow oops duke@435: } duke@435: return ConstraintCastNode::Ideal_DU_postCCP(ccp); duke@435: } duke@435: duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Identity--------------------------------------- duke@435: // If input is already higher or equal to cast type, then this is an identity. duke@435: Node *CheckCastPPNode::Identity( PhaseTransform *phase ) { duke@435: // Toned down to rescue meeting at a Phi 3 different oops all implementing duke@435: // the same interface. CompileTheWorld starting at 502, kd12rc1.zip. duke@435: return (phase->type(in(1)) == phase->type(this)) ? in(1) : this; duke@435: } duke@435: duke@435: // Determine whether "n" is a node which can cause an alias of one of its inputs. Node types duke@435: // which can create aliases are: CheckCastPP, Phi, and any store (if there is also a load from duke@435: // the location.) duke@435: // Note: this checks for aliases created in this compilation, not ones which may duke@435: // be potentially created at call sites. duke@435: static bool can_cause_alias(Node *n, PhaseTransform *phase) { duke@435: bool possible_alias = false; duke@435: duke@435: if (n->is_Store()) { duke@435: possible_alias = !n->as_Store()->value_never_loaded(phase); duke@435: } else { duke@435: int opc = n->Opcode(); duke@435: possible_alias = n->is_Phi() || duke@435: opc == Op_CheckCastPP || duke@435: opc == Op_StorePConditional || coleenp@548: opc == Op_CompareAndSwapP || roland@4106: opc == Op_CompareAndSwapN || roland@4106: opc == Op_GetAndSetP || roland@4106: opc == Op_GetAndSetN; duke@435: } duke@435: return possible_alias; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: // Take 'join' of input and cast-up type, unless working with an Interface duke@435: const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const { duke@435: if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP; duke@435: duke@435: const Type *inn = phase->type(in(1)); duke@435: if( inn == Type::TOP ) return Type::TOP; // No information yet duke@435: duke@435: const TypePtr *in_type = inn->isa_ptr(); duke@435: const TypePtr *my_type = _type->isa_ptr(); duke@435: const Type *result = _type; duke@435: if( in_type != NULL && my_type != NULL ) { duke@435: TypePtr::PTR in_ptr = in_type->ptr(); duke@435: if( in_ptr == TypePtr::Null ) { duke@435: result = in_type; duke@435: } else if( in_ptr == TypePtr::Constant ) { duke@435: // Casting a constant oop to an interface? duke@435: // (i.e., a String to a Comparable?) duke@435: // Then return the interface. duke@435: const TypeOopPtr *jptr = my_type->isa_oopptr(); duke@435: assert( jptr, "" ); duke@435: result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type)) duke@435: ? my_type->cast_to_ptr_type( TypePtr::NotNull ) duke@435: : in_type; duke@435: } else { duke@435: result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) ); duke@435: } duke@435: } duke@435: return result; duke@435: duke@435: // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES. duke@435: // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR! duke@435: duke@435: // duke@435: // Remove this code after overnight run indicates no performance duke@435: // loss from not performing JOIN at CheckCastPPNode duke@435: // duke@435: // const TypeInstPtr *in_oop = in->isa_instptr(); duke@435: // const TypeInstPtr *my_oop = _type->isa_instptr(); duke@435: // // If either input is an 'interface', return destination type duke@435: // assert (in_oop == NULL || in_oop->klass() != NULL, ""); duke@435: // assert (my_oop == NULL || my_oop->klass() != NULL, ""); coleenp@4037: // if( (in_oop && in_oop->klass()->is_interface()) coleenp@4037: // ||(my_oop && my_oop->klass()->is_interface()) ) { duke@435: // TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR; duke@435: // // Preserve cast away nullness for interfaces duke@435: // if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) { duke@435: // return my_oop->cast_to_ptr_type(TypePtr::NotNull); duke@435: // } duke@435: // return _type; duke@435: // } duke@435: // duke@435: // // Neither the input nor the destination type is an interface, duke@435: // duke@435: // // history: JOIN used to cause weird corner case bugs duke@435: // // return (in == TypeOopPtr::NULL_PTR) ? in : _type; duke@435: // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops. duke@435: // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr duke@435: // const Type *join = in->join(_type); duke@435: // // Check if join preserved NotNull'ness for pointers duke@435: // if( join->isa_ptr() && _type->isa_ptr() ) { duke@435: // TypePtr::PTR join_ptr = join->is_ptr()->_ptr; duke@435: // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr; duke@435: // // If there isn't any NotNull'ness to preserve duke@435: // // OR if join preserved NotNull'ness then return it duke@435: // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null || duke@435: // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) { duke@435: // return join; duke@435: // } duke@435: // // ELSE return same old type as before duke@435: // return _type; duke@435: // } duke@435: // // Not joining two pointers duke@435: // return join; duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. Strip out duke@435: // control copies duke@435: Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){ duke@435: return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL; duke@435: } duke@435: coleenp@548: coleenp@548: Node* DecodeNNode::Identity(PhaseTransform* phase) { coleenp@548: const Type *t = phase->type( in(1) ); coleenp@548: if( t == Type::TOP ) return in(1); coleenp@548: kvn@603: if (in(1)->is_EncodeP()) { coleenp@548: // (DecodeN (EncodeP p)) -> p coleenp@548: return in(1)->in(1); coleenp@548: } coleenp@548: return this; coleenp@548: } coleenp@548: kvn@559: const Type *DecodeNNode::Value( PhaseTransform *phase ) const { kvn@651: const Type *t = phase->type( in(1) ); kvn@651: if (t == Type::TOP) return Type::TOP; kvn@651: if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR; kvn@651: kvn@651: assert(t->isa_narrowoop(), "only narrowoop here"); kvn@656: return t->make_ptr(); kvn@559: } kvn@559: coleenp@548: Node* EncodePNode::Identity(PhaseTransform* phase) { coleenp@548: const Type *t = phase->type( in(1) ); coleenp@548: if( t == Type::TOP ) return in(1); coleenp@548: kvn@603: if (in(1)->is_DecodeN()) { coleenp@548: // (EncodeP (DecodeN p)) -> p coleenp@548: return in(1)->in(1); coleenp@548: } coleenp@548: return this; coleenp@548: } coleenp@548: kvn@559: const Type *EncodePNode::Value( PhaseTransform *phase ) const { kvn@651: const Type *t = phase->type( in(1) ); kvn@651: if (t == Type::TOP) return Type::TOP; kvn@651: if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR; kvn@651: coleenp@4037: assert(t->isa_oop_ptr() || UseCompressedKlassPointers && t->isa_klassptr(), "only oopptr here"); kvn@656: return t->make_narrowoop(); kvn@559: } coleenp@548: coleenp@548: kvn@598: Node *EncodePNode::Ideal_DU_postCCP( PhaseCCP *ccp ) { kvn@598: return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1)); kvn@598: } coleenp@548: duke@435: //============================================================================= duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *Conv2BNode::Identity( PhaseTransform *phase ) { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return in(1); duke@435: if( t == TypeInt::ZERO ) return in(1); duke@435: if( t == TypeInt::ONE ) return in(1); duke@435: if( t == TypeInt::BOOL ) return in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *Conv2BNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == TypeInt::ZERO ) return TypeInt::ZERO; duke@435: if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO; duke@435: const TypePtr *tp = t->isa_ptr(); duke@435: if( tp != NULL ) { duke@435: if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP; duke@435: if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE; duke@435: if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE; duke@435: return TypeInt::BOOL; duke@435: } duke@435: if (t->base() != Type::Int) return TypeInt::BOOL; duke@435: const TypeInt *ti = t->is_int(); duke@435: if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE; duke@435: return TypeInt::BOOL; duke@435: } duke@435: duke@435: duke@435: // The conversions operations are all Alpha sorted. Please keep it that way! duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvD2FNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::DOUBLE ) return Type::FLOAT; duke@435: const TypeD *td = t->is_double_constant(); duke@435: return TypeF::make( (float)td->getd() ); duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: // Float's can be converted to doubles with no loss of bits. Hence duke@435: // converting a float to a double and back to a float is a NOP. duke@435: Node *ConvD2FNode::Identity(PhaseTransform *phase) { duke@435: return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvD2INode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::DOUBLE ) return TypeInt::INT; duke@435: const TypeD *td = t->is_double_constant(); duke@435: return TypeInt::make( SharedRuntime::d2i( td->getd() ) ); duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // If converting to an int type, skip any rounding nodes duke@435: Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if( in(1)->Opcode() == Op_RoundDouble ) duke@435: set_req(1,in(1)->in(1)); duke@435: return NULL; duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: // Int's can be converted to doubles with no loss of bits. Hence duke@435: // converting an integer to a double and back to an integer is a NOP. duke@435: Node *ConvD2INode::Identity(PhaseTransform *phase) { duke@435: return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvD2LNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::DOUBLE ) return TypeLong::LONG; duke@435: const TypeD *td = t->is_double_constant(); duke@435: return TypeLong::make( SharedRuntime::d2l( td->getd() ) ); duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *ConvD2LNode::Identity(PhaseTransform *phase) { duke@435: // Remove ConvD2L->ConvL2D->ConvD2L sequences. duke@435: if( in(1) ->Opcode() == Op_ConvL2D && duke@435: in(1)->in(1)->Opcode() == Op_ConvD2L ) duke@435: return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // If converting to an int type, skip any rounding nodes duke@435: Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if( in(1)->Opcode() == Op_RoundDouble ) duke@435: set_req(1,in(1)->in(1)); duke@435: return NULL; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvF2DNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::FLOAT ) return Type::DOUBLE; duke@435: const TypeF *tf = t->is_float_constant(); duke@435: return TypeD::make( (double)tf->getf() ); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvF2INode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::FLOAT ) return TypeInt::INT; duke@435: const TypeF *tf = t->is_float_constant(); duke@435: return TypeInt::make( SharedRuntime::f2i( tf->getf() ) ); duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *ConvF2INode::Identity(PhaseTransform *phase) { duke@435: // Remove ConvF2I->ConvI2F->ConvF2I sequences. duke@435: if( in(1) ->Opcode() == Op_ConvI2F && duke@435: in(1)->in(1)->Opcode() == Op_ConvF2I ) duke@435: return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // If converting to an int type, skip any rounding nodes duke@435: Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if( in(1)->Opcode() == Op_RoundFloat ) duke@435: set_req(1,in(1)->in(1)); duke@435: return NULL; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvF2LNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::FLOAT ) return TypeLong::LONG; duke@435: const TypeF *tf = t->is_float_constant(); duke@435: return TypeLong::make( SharedRuntime::f2l( tf->getf() ) ); duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *ConvF2LNode::Identity(PhaseTransform *phase) { duke@435: // Remove ConvF2L->ConvL2F->ConvF2L sequences. duke@435: if( in(1) ->Opcode() == Op_ConvL2F && duke@435: in(1)->in(1)->Opcode() == Op_ConvF2L ) duke@435: return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // If converting to an int type, skip any rounding nodes duke@435: Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if( in(1)->Opcode() == Op_RoundFloat ) duke@435: set_req(1,in(1)->in(1)); duke@435: return NULL; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvI2DNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeInt *ti = t->is_int(); duke@435: if( ti->is_con() ) return TypeD::make( (double)ti->get_con() ); duke@435: return bottom_type(); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvI2FNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeInt *ti = t->is_int(); duke@435: if( ti->is_con() ) return TypeF::make( (float)ti->get_con() ); duke@435: return bottom_type(); duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *ConvI2FNode::Identity(PhaseTransform *phase) { duke@435: // Remove ConvI2F->ConvF2I->ConvI2F sequences. duke@435: if( in(1) ->Opcode() == Op_ConvF2I && duke@435: in(1)->in(1)->Opcode() == Op_ConvI2F ) duke@435: return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvI2LNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeInt *ti = t->is_int(); duke@435: const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen); duke@435: // Join my declared type against my incoming type. duke@435: tl = tl->filter(_type); duke@435: return tl; duke@435: } duke@435: duke@435: #ifdef _LP64 duke@435: static inline bool long_ranges_overlap(jlong lo1, jlong hi1, duke@435: jlong lo2, jlong hi2) { duke@435: // Two ranges overlap iff one range's low point falls in the other range. duke@435: return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1); duke@435: } duke@435: #endif duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: const TypeLong* this_type = this->type()->is_long(); duke@435: Node* this_changed = NULL; duke@435: duke@435: // If _major_progress, then more loop optimizations follow. Do NOT duke@435: // remove this node's type assertion until no more loop ops can happen. duke@435: // The progress bit is set in the major loop optimizations THEN comes the duke@435: // call to IterGVN and any chance of hitting this code. Cf. Opaque1Node. duke@435: if (can_reshape && !phase->C->major_progress()) { duke@435: const TypeInt* in_type = phase->type(in(1))->isa_int(); duke@435: if (in_type != NULL && this_type != NULL && duke@435: (in_type->_lo != this_type->_lo || duke@435: in_type->_hi != this_type->_hi)) { duke@435: // Although this WORSENS the type, it increases GVN opportunities, duke@435: // because I2L nodes with the same input will common up, regardless duke@435: // of slightly differing type assertions. Such slight differences duke@435: // arise routinely as a result of loop unrolling, so this is a duke@435: // post-unrolling graph cleanup. Choose a type which depends only duke@435: // on my input. (Exception: Keep a range assertion of >=0 or <0.) duke@435: jlong lo1 = this_type->_lo; duke@435: jlong hi1 = this_type->_hi; duke@435: int w1 = this_type->_widen; duke@435: if (lo1 != (jint)lo1 || duke@435: hi1 != (jint)hi1 || duke@435: lo1 > hi1) { duke@435: // Overflow leads to wraparound, wraparound leads to range saturation. duke@435: lo1 = min_jint; hi1 = max_jint; duke@435: } else if (lo1 >= 0) { duke@435: // Keep a range assertion of >=0. duke@435: lo1 = 0; hi1 = max_jint; duke@435: } else if (hi1 < 0) { duke@435: // Keep a range assertion of <0. duke@435: lo1 = min_jint; hi1 = -1; duke@435: } else { duke@435: lo1 = min_jint; hi1 = max_jint; duke@435: } duke@435: const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1), duke@435: MIN2((jlong)in_type->_hi, hi1), duke@435: MAX2((int)in_type->_widen, w1)); duke@435: if (wtype != type()) { duke@435: set_type(wtype); duke@435: // Note: this_type still has old type value, for the logic below. duke@435: this_changed = this; duke@435: } duke@435: } duke@435: } duke@435: duke@435: #ifdef _LP64 duke@435: // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) , duke@435: // but only if x and y have subranges that cannot cause 32-bit overflow, duke@435: // under the assumption that x+y is in my own subrange this->type(). duke@435: duke@435: // This assumption is based on a constraint (i.e., type assertion) duke@435: // established in Parse::array_addressing or perhaps elsewhere. duke@435: // This constraint has been adjoined to the "natural" type of duke@435: // the incoming argument in(0). We know (because of runtime duke@435: // checks) - that the result value I2L(x+y) is in the joined range. duke@435: // Hence we can restrict the incoming terms (x, y) to values such duke@435: // that their sum also lands in that range. duke@435: duke@435: // This optimization is useful only on 64-bit systems, where we hope duke@435: // the addition will end up subsumed in an addressing mode. duke@435: // It is necessary to do this when optimizing an unrolled array duke@435: // copy loop such as x[i++] = y[i++]. duke@435: duke@435: // On 32-bit systems, it's better to perform as much 32-bit math as duke@435: // possible before the I2L conversion, because 32-bit math is cheaper. duke@435: // There's no common reason to "leak" a constant offset through the I2L. duke@435: // Addressing arithmetic will not absorb it as part of a 64-bit AddL. duke@435: duke@435: Node* z = in(1); duke@435: int op = z->Opcode(); duke@435: if (op == Op_AddI || op == Op_SubI) { duke@435: Node* x = z->in(1); duke@435: Node* y = z->in(2); duke@435: assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal"); duke@435: if (phase->type(x) == Type::TOP) return this_changed; duke@435: if (phase->type(y) == Type::TOP) return this_changed; duke@435: const TypeInt* tx = phase->type(x)->is_int(); duke@435: const TypeInt* ty = phase->type(y)->is_int(); duke@435: const TypeLong* tz = this_type; duke@435: jlong xlo = tx->_lo; duke@435: jlong xhi = tx->_hi; duke@435: jlong ylo = ty->_lo; duke@435: jlong yhi = ty->_hi; duke@435: jlong zlo = tz->_lo; duke@435: jlong zhi = tz->_hi; duke@435: jlong vbit = CONST64(1) << BitsPerInt; duke@435: int widen = MAX2(tx->_widen, ty->_widen); duke@435: if (op == Op_SubI) { duke@435: jlong ylo0 = ylo; duke@435: ylo = -yhi; duke@435: yhi = -ylo0; duke@435: } duke@435: // See if x+y can cause positive overflow into z+2**32 duke@435: if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) { duke@435: return this_changed; duke@435: } duke@435: // See if x+y can cause negative overflow into z-2**32 duke@435: if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) { duke@435: return this_changed; duke@435: } duke@435: // Now it's always safe to assume x+y does not overflow. duke@435: // This is true even if some pairs x,y might cause overflow, as long duke@435: // as that overflow value cannot fall into [zlo,zhi]. duke@435: duke@435: // Confident that the arithmetic is "as if infinite precision", duke@435: // we can now use z's range to put constraints on those of x and y. duke@435: // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a duke@435: // more "restricted" range by intersecting [xlo,xhi] with the duke@435: // range obtained by subtracting y's range from the asserted range duke@435: // of the I2L conversion. Here's the interval arithmetic algebra: duke@435: // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo] duke@435: // => x in [zlo-yhi, zhi-ylo] duke@435: // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi] duke@435: // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo] duke@435: jlong rxlo = MAX2(xlo, zlo - yhi); duke@435: jlong rxhi = MIN2(xhi, zhi - ylo); duke@435: // And similarly, x changing place with y: duke@435: jlong rylo = MAX2(ylo, zlo - xhi); duke@435: jlong ryhi = MIN2(yhi, zhi - xlo); duke@435: if (rxlo > rxhi || rylo > ryhi) { duke@435: return this_changed; // x or y is dying; don't mess w/ it duke@435: } duke@435: if (op == Op_SubI) { duke@435: jlong rylo0 = rylo; duke@435: rylo = -ryhi; duke@435: ryhi = -rylo0; duke@435: } duke@435: kvn@4115: Node* cx = phase->transform( new (phase->C) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) ); kvn@4115: Node* cy = phase->transform( new (phase->C) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) ); duke@435: switch (op) { kvn@4115: case Op_AddI: return new (phase->C) AddLNode(cx, cy); kvn@4115: case Op_SubI: return new (phase->C) SubLNode(cx, cy); duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: #endif //_LP64 duke@435: duke@435: return this_changed; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvL2DNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeLong *tl = t->is_long(); duke@435: if( tl->is_con() ) return TypeD::make( (double)tl->get_con() ); duke@435: return bottom_type(); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvL2FNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeLong *tl = t->is_long(); duke@435: if( tl->is_con() ) return TypeF::make( (float)tl->get_con() ); duke@435: return bottom_type(); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //----------------------------Identity----------------------------------------- duke@435: Node *ConvL2INode::Identity( PhaseTransform *phase ) { duke@435: // Convert L2I(I2L(x)) => x duke@435: if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ConvL2INode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeLong *tl = t->is_long(); duke@435: if (tl->is_con()) duke@435: // Easy case. duke@435: return TypeInt::make((jint)tl->get_con()); duke@435: return bottom_type(); duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // Return a node which is more "ideal" than the current node. duke@435: // Blow off prior masking to int duke@435: Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: Node *andl = in(1); duke@435: uint andl_op = andl->Opcode(); duke@435: if( andl_op == Op_AndL ) { duke@435: // Blow off prior masking to int duke@435: if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) { duke@435: set_req(1,andl->in(1)); duke@435: return this; duke@435: } duke@435: } duke@435: duke@435: // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y)) duke@435: // This replaces an 'AddL' with an 'AddI'. duke@435: if( andl_op == Op_AddL ) { duke@435: // Don't do this for nodes which have more than one user since duke@435: // we'll end up computing the long add anyway. duke@435: if (andl->outcnt() > 1) return NULL; duke@435: duke@435: Node* x = andl->in(1); duke@435: Node* y = andl->in(2); duke@435: assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" ); duke@435: if (phase->type(x) == Type::TOP) return NULL; duke@435: if (phase->type(y) == Type::TOP) return NULL; kvn@4115: Node *add1 = phase->transform(new (phase->C) ConvL2INode(x)); kvn@4115: Node *add2 = phase->transform(new (phase->C) ConvL2INode(y)); kvn@4115: return new (phase->C) AddINode(add1,add2); duke@435: } duke@435: kvn@471: // Disable optimization: LoadL->ConvL2I ==> LoadI. kvn@471: // It causes problems (sizes of Load and Store nodes do not match) kvn@471: // in objects initialization code and Escape Analysis. duke@435: return NULL; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *CastX2PNode::Value( PhaseTransform *phase ) const { duke@435: const Type* t = phase->type(in(1)); kvn@3604: if (t == Type::TOP) return Type::TOP; duke@435: if (t->base() == Type_X && t->singleton()) { duke@435: uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con(); duke@435: if (bits == 0) return TypePtr::NULL_PTR; duke@435: return TypeRawPtr::make((address) bits); duke@435: } duke@435: return CastX2PNode::bottom_type(); duke@435: } duke@435: duke@435: //------------------------------Idealize--------------------------------------- duke@435: static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) { duke@435: if (t == Type::TOP) return false; duke@435: const TypeX* tl = t->is_intptr_t(); duke@435: jint lo = min_jint; duke@435: jint hi = max_jint; duke@435: if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow duke@435: return (tl->_lo >= lo) && (tl->_hi <= hi); duke@435: } duke@435: duke@435: static inline Node* addP_of_X2P(PhaseGVN *phase, duke@435: Node* base, duke@435: Node* dispX, duke@435: bool negate = false) { duke@435: if (negate) { kvn@4115: dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX)); duke@435: } kvn@4115: return new (phase->C) AddPNode(phase->C->top(), kvn@4115: phase->transform(new (phase->C) CastX2PNode(base)), duke@435: phase->transform(dispX)); duke@435: } duke@435: duke@435: Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int duke@435: int op = in(1)->Opcode(); duke@435: Node* x; duke@435: Node* y; duke@435: switch (op) { duke@435: case Op_SubX: duke@435: x = in(1)->in(1); kvn@1430: // Avoid ideal transformations ping-pong between this and AddP for raw pointers. kvn@1430: if (phase->find_intptr_t_con(x, -1) == 0) kvn@1430: break; duke@435: y = in(1)->in(2); duke@435: if (fits_in_int(phase->type(y), true)) { duke@435: return addP_of_X2P(phase, x, y, true); duke@435: } duke@435: break; duke@435: case Op_AddX: duke@435: x = in(1)->in(1); duke@435: y = in(1)->in(2); duke@435: if (fits_in_int(phase->type(y))) { duke@435: return addP_of_X2P(phase, x, y); duke@435: } duke@435: if (fits_in_int(phase->type(x))) { duke@435: return addP_of_X2P(phase, y, x); duke@435: } duke@435: break; duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *CastX2PNode::Identity( PhaseTransform *phase ) { duke@435: if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *CastP2XNode::Value( PhaseTransform *phase ) const { duke@435: const Type* t = phase->type(in(1)); kvn@3604: if (t == Type::TOP) return Type::TOP; duke@435: if (t->base() == Type::RawPtr && t->singleton()) { duke@435: uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con(); duke@435: return TypeX::make(bits); duke@435: } duke@435: return CastP2XNode::bottom_type(); duke@435: } duke@435: duke@435: Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL; duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: Node *CastP2XNode::Identity( PhaseTransform *phase ) { duke@435: if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1); duke@435: return this; duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Identity--------------------------------------- duke@435: // Remove redundant roundings duke@435: Node *RoundFloatNode::Identity( PhaseTransform *phase ) { duke@435: assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); duke@435: // Do not round constants duke@435: if (phase->type(in(1))->base() == Type::FloatCon) return in(1); duke@435: int op = in(1)->Opcode(); duke@435: // Redundant rounding duke@435: if( op == Op_RoundFloat ) return in(1); duke@435: // Already rounded duke@435: if( op == Op_Parm ) return in(1); duke@435: if( op == Op_LoadF ) return in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *RoundFloatNode::Value( PhaseTransform *phase ) const { duke@435: return phase->type( in(1) ); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Identity--------------------------------------- duke@435: // Remove redundant roundings. Incoming arguments are already rounded. duke@435: Node *RoundDoubleNode::Identity( PhaseTransform *phase ) { duke@435: assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); duke@435: // Do not round constants duke@435: if (phase->type(in(1))->base() == Type::DoubleCon) return in(1); duke@435: int op = in(1)->Opcode(); duke@435: // Redundant rounding duke@435: if( op == Op_RoundDouble ) return in(1); duke@435: // Already rounded duke@435: if( op == Op_Parm ) return in(1); duke@435: if( op == Op_LoadD ) return in(1); duke@435: if( op == Op_ConvF2D ) return in(1); duke@435: if( op == Op_ConvI2D ) return in(1); duke@435: return this; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const { duke@435: return phase->type( in(1) ); duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: // Do not allow value-numbering duke@435: uint Opaque1Node::hash() const { return NO_HASH; } duke@435: uint Opaque1Node::cmp( const Node &n ) const { duke@435: return (&n == this); // Always fail except on self duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: // If _major_progress, then more loop optimizations follow. Do NOT remove duke@435: // the opaque Node until no more loop ops can happen. Note the timing of duke@435: // _major_progress; it's set in the major loop optimizations THEN comes the duke@435: // call to IterGVN and any chance of hitting this code. Hence there's no duke@435: // phase-ordering problem with stripping Opaque1 in IGVN followed by some duke@435: // more loop optimizations that require it. duke@435: Node *Opaque1Node::Identity( PhaseTransform *phase ) { duke@435: return phase->C->major_progress() ? this : in(1); duke@435: } duke@435: duke@435: //============================================================================= duke@435: // A node to prevent unwanted optimizations. Allows constant folding. Stops duke@435: // value-numbering, most Ideal calls or Identity functions. This Node is duke@435: // specifically designed to prevent the pre-increment value of a loop trip duke@435: // counter from being live out of the bottom of the loop (hence causing the duke@435: // pre- and post-increment values both being live and thus requiring an extra duke@435: // temp register and an extra move). If we "accidentally" optimize through duke@435: // this kind of a Node, we'll get slightly pessimal, but correct, code. Thus duke@435: // it's OK to be slightly sloppy on optimizations here. duke@435: duke@435: // Do not allow value-numbering duke@435: uint Opaque2Node::hash() const { return NO_HASH; } duke@435: uint Opaque2Node::cmp( const Node &n ) const { duke@435: return (&n == this); // Always fail except on self duke@435: } duke@435: duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *MoveL2DNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeLong *tl = t->is_long(); duke@435: if( !tl->is_con() ) return bottom_type(); duke@435: JavaValue v; duke@435: v.set_jlong(tl->get_con()); duke@435: return TypeD::make( v.get_jdouble() ); duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *MoveI2FNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: const TypeInt *ti = t->is_int(); duke@435: if( !ti->is_con() ) return bottom_type(); duke@435: JavaValue v; duke@435: v.set_jint(ti->get_con()); duke@435: return TypeF::make( v.get_jfloat() ); duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *MoveF2INode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::FLOAT ) return TypeInt::INT; duke@435: const TypeF *tf = t->is_float_constant(); duke@435: JavaValue v; duke@435: v.set_jfloat(tf->getf()); duke@435: return TypeInt::make( v.get_jint() ); duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *MoveD2LNode::Value( PhaseTransform *phase ) const { duke@435: const Type *t = phase->type( in(1) ); duke@435: if( t == Type::TOP ) return Type::TOP; duke@435: if( t == Type::DOUBLE ) return TypeLong::LONG; duke@435: const TypeD *td = t->is_double_constant(); duke@435: JavaValue v; duke@435: v.set_jdouble(td->getd()); duke@435: return TypeLong::make( v.get_jlong() ); duke@435: } twisti@1210: twisti@1210: //------------------------------Value------------------------------------------ twisti@1210: const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const { twisti@1210: const Type* t = phase->type(in(1)); twisti@1210: if (t == Type::TOP) return Type::TOP; twisti@1210: const TypeInt* ti = t->isa_int(); twisti@1210: if (ti && ti->is_con()) { twisti@1210: jint i = ti->get_con(); twisti@1210: // HD, Figure 5-6 twisti@1210: if (i == 0) twisti@1210: return TypeInt::make(BitsPerInt); twisti@1210: int n = 1; twisti@1210: unsigned int x = i; twisti@1210: if (x >> 16 == 0) { n += 16; x <<= 16; } twisti@1210: if (x >> 24 == 0) { n += 8; x <<= 8; } twisti@1210: if (x >> 28 == 0) { n += 4; x <<= 4; } twisti@1210: if (x >> 30 == 0) { n += 2; x <<= 2; } twisti@1210: n -= x >> 31; twisti@1210: return TypeInt::make(n); twisti@1210: } twisti@1210: return TypeInt::INT; twisti@1210: } twisti@1210: twisti@1210: //------------------------------Value------------------------------------------ twisti@1210: const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const { twisti@1210: const Type* t = phase->type(in(1)); twisti@1210: if (t == Type::TOP) return Type::TOP; twisti@1210: const TypeLong* tl = t->isa_long(); twisti@1210: if (tl && tl->is_con()) { twisti@1210: jlong l = tl->get_con(); twisti@1210: // HD, Figure 5-6 twisti@1210: if (l == 0) twisti@1210: return TypeInt::make(BitsPerLong); twisti@1210: int n = 1; twisti@1210: unsigned int x = (((julong) l) >> 32); twisti@1210: if (x == 0) { n += 32; x = (int) l; } twisti@1210: if (x >> 16 == 0) { n += 16; x <<= 16; } twisti@1210: if (x >> 24 == 0) { n += 8; x <<= 8; } twisti@1210: if (x >> 28 == 0) { n += 4; x <<= 4; } twisti@1210: if (x >> 30 == 0) { n += 2; x <<= 2; } twisti@1210: n -= x >> 31; twisti@1210: return TypeInt::make(n); twisti@1210: } twisti@1210: return TypeInt::INT; twisti@1210: } twisti@1210: twisti@1210: //------------------------------Value------------------------------------------ twisti@1210: const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const { twisti@1210: const Type* t = phase->type(in(1)); twisti@1210: if (t == Type::TOP) return Type::TOP; twisti@1210: const TypeInt* ti = t->isa_int(); twisti@1210: if (ti && ti->is_con()) { twisti@1210: jint i = ti->get_con(); twisti@1210: // HD, Figure 5-14 twisti@1210: int y; twisti@1210: if (i == 0) twisti@1210: return TypeInt::make(BitsPerInt); twisti@1210: int n = 31; twisti@1210: y = i << 16; if (y != 0) { n = n - 16; i = y; } twisti@1210: y = i << 8; if (y != 0) { n = n - 8; i = y; } twisti@1210: y = i << 4; if (y != 0) { n = n - 4; i = y; } twisti@1210: y = i << 2; if (y != 0) { n = n - 2; i = y; } twisti@1210: y = i << 1; if (y != 0) { n = n - 1; } twisti@1210: return TypeInt::make(n); twisti@1210: } twisti@1210: return TypeInt::INT; twisti@1210: } twisti@1210: twisti@1210: //------------------------------Value------------------------------------------ twisti@1210: const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const { twisti@1210: const Type* t = phase->type(in(1)); twisti@1210: if (t == Type::TOP) return Type::TOP; twisti@1210: const TypeLong* tl = t->isa_long(); twisti@1210: if (tl && tl->is_con()) { twisti@1210: jlong l = tl->get_con(); twisti@1210: // HD, Figure 5-14 twisti@1210: int x, y; twisti@1210: if (l == 0) twisti@1210: return TypeInt::make(BitsPerLong); twisti@1210: int n = 63; twisti@1210: y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32); twisti@1210: y = x << 16; if (y != 0) { n = n - 16; x = y; } twisti@1210: y = x << 8; if (y != 0) { n = n - 8; x = y; } twisti@1210: y = x << 4; if (y != 0) { n = n - 4; x = y; } twisti@1210: y = x << 2; if (y != 0) { n = n - 2; x = y; } twisti@1210: y = x << 1; if (y != 0) { n = n - 1; } twisti@1210: return TypeInt::make(n); twisti@1210: } twisti@1210: return TypeInt::INT; twisti@1210: }