src/share/vm/opto/connode.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7422
d9e22e15d3f6
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "memory/allocation.inline.hpp"
aoqi@0 27 #include "opto/addnode.hpp"
aoqi@0 28 #include "opto/compile.hpp"
aoqi@0 29 #include "opto/connode.hpp"
aoqi@0 30 #include "opto/machnode.hpp"
aoqi@0 31 #include "opto/matcher.hpp"
aoqi@0 32 #include "opto/memnode.hpp"
aoqi@0 33 #include "opto/phaseX.hpp"
aoqi@0 34 #include "opto/subnode.hpp"
aoqi@0 35 #include "runtime/sharedRuntime.hpp"
aoqi@0 36
aoqi@0 37 // Optimization - Graph Style
aoqi@0 38
aoqi@0 39 //=============================================================================
aoqi@0 40 //------------------------------hash-------------------------------------------
aoqi@0 41 uint ConNode::hash() const {
aoqi@0 42 return (uintptr_t)in(TypeFunc::Control) + _type->hash();
aoqi@0 43 }
aoqi@0 44
aoqi@0 45 //------------------------------make-------------------------------------------
aoqi@0 46 ConNode *ConNode::make( Compile* C, const Type *t ) {
aoqi@0 47 switch( t->basic_type() ) {
aoqi@0 48 case T_INT: return new (C) ConINode( t->is_int() );
aoqi@0 49 case T_LONG: return new (C) ConLNode( t->is_long() );
aoqi@0 50 case T_FLOAT: return new (C) ConFNode( t->is_float_constant() );
aoqi@0 51 case T_DOUBLE: return new (C) ConDNode( t->is_double_constant() );
aoqi@0 52 case T_VOID: return new (C) ConNode ( Type::TOP );
aoqi@0 53 case T_OBJECT: return new (C) ConPNode( t->is_ptr() );
aoqi@0 54 case T_ARRAY: return new (C) ConPNode( t->is_aryptr() );
aoqi@0 55 case T_ADDRESS: return new (C) ConPNode( t->is_ptr() );
aoqi@0 56 case T_NARROWOOP: return new (C) ConNNode( t->is_narrowoop() );
aoqi@0 57 case T_NARROWKLASS: return new (C) ConNKlassNode( t->is_narrowklass() );
aoqi@0 58 case T_METADATA: return new (C) ConPNode( t->is_ptr() );
aoqi@0 59 // Expected cases: TypePtr::NULL_PTR, any is_rawptr()
aoqi@0 60 // Also seen: AnyPtr(TopPTR *+top); from command line:
aoqi@0 61 // r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660
aoqi@0 62 // %%%% Stop using TypePtr::NULL_PTR to represent nulls: use either TypeRawPtr::NULL_PTR
aoqi@0 63 // or else TypeOopPtr::NULL_PTR. Then set Type::_basic_type[AnyPtr] = T_ILLEGAL
aoqi@0 64 }
aoqi@0 65 ShouldNotReachHere();
aoqi@0 66 return NULL;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 //=============================================================================
aoqi@0 70 /*
aoqi@0 71 The major change is for CMoveP and StrComp. They have related but slightly
aoqi@0 72 different problems. They both take in TWO oops which are both null-checked
aoqi@0 73 independently before the using Node. After CCP removes the CastPP's they need
aoqi@0 74 to pick up the guarding test edge - in this case TWO control edges. I tried
aoqi@0 75 various solutions, all have problems:
aoqi@0 76
aoqi@0 77 (1) Do nothing. This leads to a bug where we hoist a Load from a CMoveP or a
aoqi@0 78 StrComp above a guarding null check. I've seen both cases in normal -Xcomp
aoqi@0 79 testing.
aoqi@0 80
aoqi@0 81 (2) Plug the control edge from 1 of the 2 oops in. Apparent problem here is
aoqi@0 82 to figure out which test post-dominates. The real problem is that it doesn't
aoqi@0 83 matter which one you pick. After you pick up, the dominating-test elider in
aoqi@0 84 IGVN can remove the test and allow you to hoist up to the dominating test on
aoqi@0 85 the chosen oop bypassing the test on the not-chosen oop. Seen in testing.
aoqi@0 86 Oops.
aoqi@0 87
aoqi@0 88 (3) Leave the CastPP's in. This makes the graph more accurate in some sense;
aoqi@0 89 we get to keep around the knowledge that an oop is not-null after some test.
aoqi@0 90 Alas, the CastPP's interfere with GVN (some values are the regular oop, some
aoqi@0 91 are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
aoqi@0 92 This cost us 10% on SpecJVM, even when I removed some of the more trivial
aoqi@0 93 cases in the optimizer. Removing more useless Phi's started allowing Loads to
aoqi@0 94 illegally float above null checks. I gave up on this approach.
aoqi@0 95
aoqi@0 96 (4) Add BOTH control edges to both tests. Alas, too much code knows that
aoqi@0 97 control edges are in slot-zero ONLY. Many quick asserts fail; no way to do
aoqi@0 98 this one. Note that I really want to allow the CMoveP to float and add both
aoqi@0 99 control edges to the dependent Load op - meaning I can select early but I
aoqi@0 100 cannot Load until I pass both tests.
aoqi@0 101
aoqi@0 102 (5) Do not hoist CMoveP and StrComp. To this end I added the v-call
aoqi@0 103 depends_only_on_test(). No obvious performance loss on Spec, but we are
aoqi@0 104 clearly conservative on CMoveP (also so on StrComp but that's unlikely to
aoqi@0 105 matter ever).
aoqi@0 106
aoqi@0 107 */
aoqi@0 108
aoqi@0 109
aoqi@0 110 //------------------------------Ideal------------------------------------------
aoqi@0 111 // Return a node which is more "ideal" than the current node.
aoqi@0 112 // Move constants to the right.
aoqi@0 113 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 114 if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
aoqi@0 115 // Don't bother trying to transform a dead node
aoqi@0 116 if( in(0) && in(0)->is_top() ) return NULL;
aoqi@0 117 assert( !phase->eqv(in(Condition), this) &&
aoqi@0 118 !phase->eqv(in(IfFalse), this) &&
aoqi@0 119 !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
aoqi@0 120 if( phase->type(in(Condition)) == Type::TOP )
aoqi@0 121 return NULL; // return NULL when Condition is dead
aoqi@0 122
aoqi@0 123 if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
aoqi@0 124 if( in(Condition)->is_Bool() ) {
aoqi@0 125 BoolNode* b = in(Condition)->as_Bool();
aoqi@0 126 BoolNode* b2 = b->negate(phase);
aoqi@0 127 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
aoqi@0 128 }
aoqi@0 129 }
aoqi@0 130 return NULL;
aoqi@0 131 }
aoqi@0 132
aoqi@0 133 //------------------------------is_cmove_id------------------------------------
aoqi@0 134 // Helper function to check for CMOVE identity. Shared with PhiNode::Identity
aoqi@0 135 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
aoqi@0 136 // Check for Cmp'ing and CMove'ing same values
aoqi@0 137 if( (phase->eqv(cmp->in(1),f) &&
aoqi@0 138 phase->eqv(cmp->in(2),t)) ||
aoqi@0 139 // Swapped Cmp is OK
aoqi@0 140 (phase->eqv(cmp->in(2),f) &&
aoqi@0 141 phase->eqv(cmp->in(1),t)) ) {
aoqi@0 142 // Give up this identity check for floating points because it may choose incorrect
aoqi@0 143 // value around 0.0 and -0.0
aoqi@0 144 if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
aoqi@0 145 return NULL;
aoqi@0 146 // Check for "(t==f)?t:f;" and replace with "f"
aoqi@0 147 if( b->_test._test == BoolTest::eq )
aoqi@0 148 return f;
aoqi@0 149 // Allow the inverted case as well
aoqi@0 150 // Check for "(t!=f)?t:f;" and replace with "t"
aoqi@0 151 if( b->_test._test == BoolTest::ne )
aoqi@0 152 return t;
aoqi@0 153 }
aoqi@0 154 return NULL;
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 //------------------------------Identity---------------------------------------
aoqi@0 158 // Conditional-move is an identity if both inputs are the same, or the test
aoqi@0 159 // true or false.
aoqi@0 160 Node *CMoveNode::Identity( PhaseTransform *phase ) {
aoqi@0 161 if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
aoqi@0 162 return in(IfFalse); // Then it doesn't matter
aoqi@0 163 if( phase->type(in(Condition)) == TypeInt::ZERO )
aoqi@0 164 return in(IfFalse); // Always pick left(false) input
aoqi@0 165 if( phase->type(in(Condition)) == TypeInt::ONE )
aoqi@0 166 return in(IfTrue); // Always pick right(true) input
aoqi@0 167
aoqi@0 168 // Check for CMove'ing a constant after comparing against the constant.
aoqi@0 169 // Happens all the time now, since if we compare equality vs a constant in
aoqi@0 170 // the parser, we "know" the variable is constant on one path and we force
aoqi@0 171 // it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
aoqi@0 172 // conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more
aoqi@0 173 // general in that we don't need constants.
aoqi@0 174 if( in(Condition)->is_Bool() ) {
aoqi@0 175 BoolNode *b = in(Condition)->as_Bool();
aoqi@0 176 Node *cmp = b->in(1);
aoqi@0 177 if( cmp->is_Cmp() ) {
aoqi@0 178 Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
aoqi@0 179 if( id ) return id;
aoqi@0 180 }
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 return this;
aoqi@0 184 }
aoqi@0 185
aoqi@0 186 //------------------------------Value------------------------------------------
aoqi@0 187 // Result is the meet of inputs
aoqi@0 188 const Type *CMoveNode::Value( PhaseTransform *phase ) const {
aoqi@0 189 if( phase->type(in(Condition)) == Type::TOP )
aoqi@0 190 return Type::TOP;
aoqi@0 191 return phase->type(in(IfFalse))->meet_speculative(phase->type(in(IfTrue)));
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 //------------------------------make-------------------------------------------
aoqi@0 195 // Make a correctly-flavored CMove. Since _type is directly determined
aoqi@0 196 // from the inputs we do not need to specify it here.
aoqi@0 197 CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {
aoqi@0 198 switch( t->basic_type() ) {
aoqi@0 199 case T_INT: return new (C) CMoveINode( bol, left, right, t->is_int() );
aoqi@0 200 case T_FLOAT: return new (C) CMoveFNode( bol, left, right, t );
aoqi@0 201 case T_DOUBLE: return new (C) CMoveDNode( bol, left, right, t );
aoqi@0 202 case T_LONG: return new (C) CMoveLNode( bol, left, right, t->is_long() );
aoqi@0 203 case T_OBJECT: return new (C) CMovePNode( c, bol, left, right, t->is_oopptr() );
aoqi@0 204 case T_ADDRESS: return new (C) CMovePNode( c, bol, left, right, t->is_ptr() );
aoqi@0 205 case T_NARROWOOP: return new (C) CMoveNNode( c, bol, left, right, t );
aoqi@0 206 default:
aoqi@0 207 ShouldNotReachHere();
aoqi@0 208 return NULL;
aoqi@0 209 }
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 //=============================================================================
aoqi@0 213 //------------------------------Ideal------------------------------------------
aoqi@0 214 // Return a node which is more "ideal" than the current node.
aoqi@0 215 // Check for conversions to boolean
aoqi@0 216 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 217 // Try generic ideal's first
aoqi@0 218 Node *x = CMoveNode::Ideal(phase, can_reshape);
aoqi@0 219 if( x ) return x;
aoqi@0 220
aoqi@0 221 // If zero is on the left (false-case, no-move-case) it must mean another
aoqi@0 222 // constant is on the right (otherwise the shared CMove::Ideal code would
aoqi@0 223 // have moved the constant to the right). This situation is bad for Intel
aoqi@0 224 // and a don't-care for Sparc. It's bad for Intel because the zero has to
aoqi@0 225 // be manifested in a register with a XOR which kills flags, which are live
aoqi@0 226 // on input to the CMoveI, leading to a situation which causes excessive
aoqi@0 227 // spilling on Intel. For Sparc, if the zero in on the left the Sparc will
aoqi@0 228 // zero a register via G0 and conditionally-move the other constant. If the
aoqi@0 229 // zero is on the right, the Sparc will load the first constant with a
aoqi@0 230 // 13-bit set-lo and conditionally move G0. See bug 4677505.
aoqi@0 231 if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
aoqi@0 232 if( in(Condition)->is_Bool() ) {
aoqi@0 233 BoolNode* b = in(Condition)->as_Bool();
aoqi@0 234 BoolNode* b2 = b->negate(phase);
aoqi@0 235 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
aoqi@0 236 }
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 // Now check for booleans
aoqi@0 240 int flip = 0;
aoqi@0 241
aoqi@0 242 // Check for picking from zero/one
aoqi@0 243 if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
aoqi@0 244 flip = 1 - flip;
aoqi@0 245 } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
aoqi@0 246 } else return NULL;
aoqi@0 247
aoqi@0 248 // Check for eq/ne test
aoqi@0 249 if( !in(1)->is_Bool() ) return NULL;
aoqi@0 250 BoolNode *bol = in(1)->as_Bool();
aoqi@0 251 if( bol->_test._test == BoolTest::eq ) {
aoqi@0 252 } else if( bol->_test._test == BoolTest::ne ) {
aoqi@0 253 flip = 1-flip;
aoqi@0 254 } else return NULL;
aoqi@0 255
aoqi@0 256 // Check for vs 0 or 1
aoqi@0 257 if( !bol->in(1)->is_Cmp() ) return NULL;
aoqi@0 258 const CmpNode *cmp = bol->in(1)->as_Cmp();
aoqi@0 259 if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
aoqi@0 260 } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
aoqi@0 261 // Allow cmp-vs-1 if the other input is bounded by 0-1
aoqi@0 262 if( phase->type(cmp->in(1)) != TypeInt::BOOL )
aoqi@0 263 return NULL;
aoqi@0 264 flip = 1 - flip;
aoqi@0 265 } else return NULL;
aoqi@0 266
aoqi@0 267 // Convert to a bool (flipped)
aoqi@0 268 // Build int->bool conversion
aoqi@0 269 #ifndef PRODUCT
aoqi@0 270 if( PrintOpto ) tty->print_cr("CMOV to I2B");
aoqi@0 271 #endif
aoqi@0 272 Node *n = new (phase->C) Conv2BNode( cmp->in(1) );
aoqi@0 273 if( flip )
aoqi@0 274 n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
aoqi@0 275
aoqi@0 276 return n;
aoqi@0 277 }
aoqi@0 278
aoqi@0 279 //=============================================================================
aoqi@0 280 //------------------------------Ideal------------------------------------------
aoqi@0 281 // Return a node which is more "ideal" than the current node.
aoqi@0 282 // Check for absolute value
aoqi@0 283 Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 284 // Try generic ideal's first
aoqi@0 285 Node *x = CMoveNode::Ideal(phase, can_reshape);
aoqi@0 286 if( x ) return x;
aoqi@0 287
aoqi@0 288 int cmp_zero_idx = 0; // Index of compare input where to look for zero
aoqi@0 289 int phi_x_idx = 0; // Index of phi input where to find naked x
aoqi@0 290
aoqi@0 291 // Find the Bool
aoqi@0 292 if( !in(1)->is_Bool() ) return NULL;
aoqi@0 293 BoolNode *bol = in(1)->as_Bool();
aoqi@0 294 // Check bool sense
aoqi@0 295 switch( bol->_test._test ) {
aoqi@0 296 case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;
aoqi@0 297 case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
aoqi@0 298 case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;
aoqi@0 299 case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
aoqi@0 300 default: return NULL; break;
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 // Find zero input of CmpF; the other input is being abs'd
aoqi@0 304 Node *cmpf = bol->in(1);
aoqi@0 305 if( cmpf->Opcode() != Op_CmpF ) return NULL;
aoqi@0 306 Node *X = NULL;
aoqi@0 307 bool flip = false;
aoqi@0 308 if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
aoqi@0 309 X = cmpf->in(3 - cmp_zero_idx);
aoqi@0 310 } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
aoqi@0 311 // The test is inverted, we should invert the result...
aoqi@0 312 X = cmpf->in(cmp_zero_idx);
aoqi@0 313 flip = true;
aoqi@0 314 } else {
aoqi@0 315 return NULL;
aoqi@0 316 }
aoqi@0 317
aoqi@0 318 // If X is found on the appropriate phi input, find the subtract on the other
aoqi@0 319 if( X != in(phi_x_idx) ) return NULL;
aoqi@0 320 int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
aoqi@0 321 Node *sub = in(phi_sub_idx);
aoqi@0 322
aoqi@0 323 // Allow only SubF(0,X) and fail out for all others; NegF is not OK
aoqi@0 324 if( sub->Opcode() != Op_SubF ||
aoqi@0 325 sub->in(2) != X ||
aoqi@0 326 phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
aoqi@0 327
aoqi@0 328 Node *abs = new (phase->C) AbsFNode( X );
aoqi@0 329 if( flip )
aoqi@0 330 abs = new (phase->C) SubFNode(sub->in(1), phase->transform(abs));
aoqi@0 331
aoqi@0 332 return abs;
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 //=============================================================================
aoqi@0 336 //------------------------------Ideal------------------------------------------
aoqi@0 337 // Return a node which is more "ideal" than the current node.
aoqi@0 338 // Check for absolute value
aoqi@0 339 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 340 // Try generic ideal's first
aoqi@0 341 Node *x = CMoveNode::Ideal(phase, can_reshape);
aoqi@0 342 if( x ) return x;
aoqi@0 343
aoqi@0 344 int cmp_zero_idx = 0; // Index of compare input where to look for zero
aoqi@0 345 int phi_x_idx = 0; // Index of phi input where to find naked x
aoqi@0 346
aoqi@0 347 // Find the Bool
aoqi@0 348 if( !in(1)->is_Bool() ) return NULL;
aoqi@0 349 BoolNode *bol = in(1)->as_Bool();
aoqi@0 350 // Check bool sense
aoqi@0 351 switch( bol->_test._test ) {
aoqi@0 352 case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;
aoqi@0 353 case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
aoqi@0 354 case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;
aoqi@0 355 case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
aoqi@0 356 default: return NULL; break;
aoqi@0 357 }
aoqi@0 358
aoqi@0 359 // Find zero input of CmpD; the other input is being abs'd
aoqi@0 360 Node *cmpd = bol->in(1);
aoqi@0 361 if( cmpd->Opcode() != Op_CmpD ) return NULL;
aoqi@0 362 Node *X = NULL;
aoqi@0 363 bool flip = false;
aoqi@0 364 if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
aoqi@0 365 X = cmpd->in(3 - cmp_zero_idx);
aoqi@0 366 } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
aoqi@0 367 // The test is inverted, we should invert the result...
aoqi@0 368 X = cmpd->in(cmp_zero_idx);
aoqi@0 369 flip = true;
aoqi@0 370 } else {
aoqi@0 371 return NULL;
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 // If X is found on the appropriate phi input, find the subtract on the other
aoqi@0 375 if( X != in(phi_x_idx) ) return NULL;
aoqi@0 376 int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
aoqi@0 377 Node *sub = in(phi_sub_idx);
aoqi@0 378
aoqi@0 379 // Allow only SubD(0,X) and fail out for all others; NegD is not OK
aoqi@0 380 if( sub->Opcode() != Op_SubD ||
aoqi@0 381 sub->in(2) != X ||
aoqi@0 382 phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
aoqi@0 383
aoqi@0 384 Node *abs = new (phase->C) AbsDNode( X );
aoqi@0 385 if( flip )
aoqi@0 386 abs = new (phase->C) SubDNode(sub->in(1), phase->transform(abs));
aoqi@0 387
aoqi@0 388 return abs;
aoqi@0 389 }
aoqi@0 390
aoqi@0 391
aoqi@0 392 //=============================================================================
aoqi@0 393 // If input is already higher or equal to cast type, then this is an identity.
aoqi@0 394 Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {
aoqi@0 395 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
aoqi@0 396 }
aoqi@0 397
aoqi@0 398 //------------------------------Value------------------------------------------
aoqi@0 399 // Take 'join' of input and cast-up type
aoqi@0 400 const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
aoqi@0 401 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
aoqi@0 402 const Type* ft = phase->type(in(1))->filter_speculative(_type);
aoqi@0 403
aoqi@0 404 #ifdef ASSERT
aoqi@0 405 // Previous versions of this function had some special case logic,
aoqi@0 406 // which is no longer necessary. Make sure of the required effects.
aoqi@0 407 switch (Opcode()) {
aoqi@0 408 case Op_CastII:
aoqi@0 409 {
aoqi@0 410 const Type* t1 = phase->type(in(1));
aoqi@0 411 if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1");
aoqi@0 412 const Type* rt = t1->join_speculative(_type);
aoqi@0 413 if (rt->empty()) assert(ft == Type::TOP, "special case #2");
aoqi@0 414 break;
aoqi@0 415 }
aoqi@0 416 case Op_CastPP:
aoqi@0 417 if (phase->type(in(1)) == TypePtr::NULL_PTR &&
aoqi@0 418 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
aoqi@0 419 assert(ft == Type::TOP, "special case #3");
aoqi@0 420 break;
aoqi@0 421 }
aoqi@0 422 #endif //ASSERT
aoqi@0 423
aoqi@0 424 return ft;
aoqi@0 425 }
aoqi@0 426
aoqi@0 427 //------------------------------Ideal------------------------------------------
aoqi@0 428 // Return a node which is more "ideal" than the current node. Strip out
aoqi@0 429 // control copies
aoqi@0 430 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 431 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
aoqi@0 432 }
aoqi@0 433
aoqi@0 434 //------------------------------Ideal_DU_postCCP-------------------------------
aoqi@0 435 // Throw away cast after constant propagation
aoqi@0 436 Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
aoqi@0 437 const Type *t = ccp->type(in(1));
aoqi@0 438 ccp->hash_delete(this);
aoqi@0 439 set_type(t); // Turn into ID function
aoqi@0 440 ccp->hash_insert(this);
aoqi@0 441 return this;
aoqi@0 442 }
aoqi@0 443
roland@7394 444 uint CastIINode::size_of() const {
roland@7394 445 return sizeof(*this);
roland@7394 446 }
roland@7394 447
roland@7394 448 uint CastIINode::cmp(const Node &n) const {
roland@7394 449 return TypeNode::cmp(n) && ((CastIINode&)n)._carry_dependency == _carry_dependency;
roland@7394 450 }
roland@7394 451
roland@7394 452 Node *CastIINode::Identity(PhaseTransform *phase) {
roland@7394 453 if (_carry_dependency) {
roland@7394 454 return this;
roland@7394 455 }
roland@7394 456 return ConstraintCastNode::Identity(phase);
roland@7394 457 }
roland@7394 458
roland@7394 459 const Type *CastIINode::Value(PhaseTransform *phase) const {
roland@7394 460 const Type *res = ConstraintCastNode::Value(phase);
roland@7394 461
roland@7394 462 // Try to improve the type of the CastII if we recognize a CmpI/If
roland@7394 463 // pattern.
roland@7394 464 if (_carry_dependency) {
roland@7422 465 if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
roland@7422 466 assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
roland@7394 467 Node* proj = in(0);
roland@7394 468 if (proj->in(0)->in(1)->is_Bool()) {
roland@7394 469 Node* b = proj->in(0)->in(1);
roland@7394 470 if (b->in(1)->Opcode() == Op_CmpI) {
roland@7394 471 Node* cmp = b->in(1);
roland@7394 472 if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
roland@7394 473 const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
roland@7394 474 const Type* t = TypeInt::INT;
roland@7394 475 BoolTest test = b->as_Bool()->_test;
roland@7394 476 if (proj->is_IfFalse()) {
roland@7394 477 test = test.negate();
roland@7394 478 }
roland@7394 479 BoolTest::mask m = test._test;
roland@7394 480 jlong lo_long = min_jint;
roland@7394 481 jlong hi_long = max_jint;
roland@7394 482 if (m == BoolTest::le || m == BoolTest::lt) {
roland@7394 483 hi_long = in2_t->_hi;
roland@7394 484 if (m == BoolTest::lt) {
roland@7394 485 hi_long -= 1;
roland@7394 486 }
roland@7394 487 } else if (m == BoolTest::ge || m == BoolTest::gt) {
roland@7394 488 lo_long = in2_t->_lo;
roland@7394 489 if (m == BoolTest::gt) {
roland@7394 490 lo_long += 1;
roland@7394 491 }
roland@7394 492 } else if (m == BoolTest::eq) {
roland@7394 493 lo_long = in2_t->_lo;
roland@7394 494 hi_long = in2_t->_hi;
roland@7394 495 } else if (m == BoolTest::ne) {
roland@7394 496 // can't do any better
roland@7394 497 } else {
roland@7394 498 stringStream ss;
roland@7394 499 test.dump_on(&ss);
roland@7394 500 fatal(err_msg_res("unexpected comparison %s", ss.as_string()));
roland@7394 501 }
roland@7394 502 int lo_int = (int)lo_long;
roland@7394 503 int hi_int = (int)hi_long;
roland@7394 504
roland@7394 505 if (lo_long != (jlong)lo_int) {
roland@7394 506 lo_int = min_jint;
roland@7394 507 }
roland@7394 508 if (hi_long != (jlong)hi_int) {
roland@7394 509 hi_int = max_jint;
roland@7394 510 }
roland@7394 511
roland@7394 512 t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
roland@7394 513
roland@7394 514 res = res->filter_speculative(t);
roland@7394 515
roland@7394 516 return res;
roland@7394 517 }
roland@7394 518 }
roland@7394 519 }
roland@7394 520 }
roland@7394 521 }
roland@7394 522 return res;
roland@7394 523 }
roland@7394 524
roland@7394 525 Node *CastIINode::Ideal_DU_postCCP(PhaseCCP *ccp) {
roland@7394 526 if (_carry_dependency) {
roland@7394 527 return NULL;
roland@7394 528 }
roland@7394 529 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
roland@7394 530 }
roland@7394 531
roland@7394 532 #ifndef PRODUCT
roland@7394 533 void CastIINode::dump_spec(outputStream *st) const {
roland@7394 534 TypeNode::dump_spec(st);
roland@7394 535 if (_carry_dependency) {
roland@7394 536 st->print(" carry dependency");
roland@7394 537 }
roland@7394 538 }
roland@7394 539 #endif
aoqi@0 540
aoqi@0 541 //=============================================================================
aoqi@0 542
aoqi@0 543 //------------------------------Ideal_DU_postCCP-------------------------------
aoqi@0 544 // If not converting int->oop, throw away cast after constant propagation
aoqi@0 545 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
aoqi@0 546 const Type *t = ccp->type(in(1));
aoqi@0 547 if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {
aoqi@0 548 return NULL; // do not transform raw pointers or narrow oops
aoqi@0 549 }
aoqi@0 550 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
aoqi@0 551 }
aoqi@0 552
aoqi@0 553
aoqi@0 554
aoqi@0 555 //=============================================================================
aoqi@0 556 //------------------------------Identity---------------------------------------
aoqi@0 557 // If input is already higher or equal to cast type, then this is an identity.
aoqi@0 558 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
aoqi@0 559 // Toned down to rescue meeting at a Phi 3 different oops all implementing
aoqi@0 560 // the same interface. CompileTheWorld starting at 502, kd12rc1.zip.
aoqi@0 561 return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
aoqi@0 562 }
aoqi@0 563
aoqi@0 564 //------------------------------Value------------------------------------------
aoqi@0 565 // Take 'join' of input and cast-up type, unless working with an Interface
aoqi@0 566 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
aoqi@0 567 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
aoqi@0 568
aoqi@0 569 const Type *inn = phase->type(in(1));
aoqi@0 570 if( inn == Type::TOP ) return Type::TOP; // No information yet
aoqi@0 571
aoqi@0 572 const TypePtr *in_type = inn->isa_ptr();
aoqi@0 573 const TypePtr *my_type = _type->isa_ptr();
aoqi@0 574 const Type *result = _type;
aoqi@0 575 if( in_type != NULL && my_type != NULL ) {
aoqi@0 576 TypePtr::PTR in_ptr = in_type->ptr();
aoqi@0 577 if( in_ptr == TypePtr::Null ) {
aoqi@0 578 result = in_type;
aoqi@0 579 } else if( in_ptr == TypePtr::Constant ) {
aoqi@0 580 // Casting a constant oop to an interface?
aoqi@0 581 // (i.e., a String to a Comparable?)
aoqi@0 582 // Then return the interface.
aoqi@0 583 const TypeOopPtr *jptr = my_type->isa_oopptr();
aoqi@0 584 assert( jptr, "" );
aoqi@0 585 result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
aoqi@0 586 ? my_type->cast_to_ptr_type( TypePtr::NotNull )
aoqi@0 587 : in_type;
aoqi@0 588 } else {
aoqi@0 589 result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
aoqi@0 590 }
aoqi@0 591 }
aoqi@0 592 return result;
aoqi@0 593
aoqi@0 594 // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
aoqi@0 595 // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
aoqi@0 596
aoqi@0 597 //
aoqi@0 598 // Remove this code after overnight run indicates no performance
aoqi@0 599 // loss from not performing JOIN at CheckCastPPNode
aoqi@0 600 //
aoqi@0 601 // const TypeInstPtr *in_oop = in->isa_instptr();
aoqi@0 602 // const TypeInstPtr *my_oop = _type->isa_instptr();
aoqi@0 603 // // If either input is an 'interface', return destination type
aoqi@0 604 // assert (in_oop == NULL || in_oop->klass() != NULL, "");
aoqi@0 605 // assert (my_oop == NULL || my_oop->klass() != NULL, "");
aoqi@0 606 // if( (in_oop && in_oop->klass()->is_interface())
aoqi@0 607 // ||(my_oop && my_oop->klass()->is_interface()) ) {
aoqi@0 608 // TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
aoqi@0 609 // // Preserve cast away nullness for interfaces
aoqi@0 610 // if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
aoqi@0 611 // return my_oop->cast_to_ptr_type(TypePtr::NotNull);
aoqi@0 612 // }
aoqi@0 613 // return _type;
aoqi@0 614 // }
aoqi@0 615 //
aoqi@0 616 // // Neither the input nor the destination type is an interface,
aoqi@0 617 //
aoqi@0 618 // // history: JOIN used to cause weird corner case bugs
aoqi@0 619 // // return (in == TypeOopPtr::NULL_PTR) ? in : _type;
aoqi@0 620 // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
aoqi@0 621 // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
aoqi@0 622 // const Type *join = in->join(_type);
aoqi@0 623 // // Check if join preserved NotNull'ness for pointers
aoqi@0 624 // if( join->isa_ptr() && _type->isa_ptr() ) {
aoqi@0 625 // TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
aoqi@0 626 // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
aoqi@0 627 // // If there isn't any NotNull'ness to preserve
aoqi@0 628 // // OR if join preserved NotNull'ness then return it
aoqi@0 629 // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null ||
aoqi@0 630 // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
aoqi@0 631 // return join;
aoqi@0 632 // }
aoqi@0 633 // // ELSE return same old type as before
aoqi@0 634 // return _type;
aoqi@0 635 // }
aoqi@0 636 // // Not joining two pointers
aoqi@0 637 // return join;
aoqi@0 638 }
aoqi@0 639
aoqi@0 640 //------------------------------Ideal------------------------------------------
aoqi@0 641 // Return a node which is more "ideal" than the current node. Strip out
aoqi@0 642 // control copies
aoqi@0 643 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 644 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
aoqi@0 645 }
aoqi@0 646
aoqi@0 647
aoqi@0 648 Node* DecodeNNode::Identity(PhaseTransform* phase) {
aoqi@0 649 const Type *t = phase->type( in(1) );
aoqi@0 650 if( t == Type::TOP ) return in(1);
aoqi@0 651
aoqi@0 652 if (in(1)->is_EncodeP()) {
aoqi@0 653 // (DecodeN (EncodeP p)) -> p
aoqi@0 654 return in(1)->in(1);
aoqi@0 655 }
aoqi@0 656 return this;
aoqi@0 657 }
aoqi@0 658
aoqi@0 659 const Type *DecodeNNode::Value( PhaseTransform *phase ) const {
aoqi@0 660 const Type *t = phase->type( in(1) );
aoqi@0 661 if (t == Type::TOP) return Type::TOP;
aoqi@0 662 if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;
aoqi@0 663
aoqi@0 664 assert(t->isa_narrowoop(), "only narrowoop here");
aoqi@0 665 return t->make_ptr();
aoqi@0 666 }
aoqi@0 667
aoqi@0 668 Node* EncodePNode::Identity(PhaseTransform* phase) {
aoqi@0 669 const Type *t = phase->type( in(1) );
aoqi@0 670 if( t == Type::TOP ) return in(1);
aoqi@0 671
aoqi@0 672 if (in(1)->is_DecodeN()) {
aoqi@0 673 // (EncodeP (DecodeN p)) -> p
aoqi@0 674 return in(1)->in(1);
aoqi@0 675 }
aoqi@0 676 return this;
aoqi@0 677 }
aoqi@0 678
aoqi@0 679 const Type *EncodePNode::Value( PhaseTransform *phase ) const {
aoqi@0 680 const Type *t = phase->type( in(1) );
aoqi@0 681 if (t == Type::TOP) return Type::TOP;
aoqi@0 682 if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;
aoqi@0 683
aoqi@0 684 assert(t->isa_oop_ptr(), "only oopptr here");
aoqi@0 685 return t->make_narrowoop();
aoqi@0 686 }
aoqi@0 687
aoqi@0 688
aoqi@0 689 Node *EncodeNarrowPtrNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
aoqi@0 690 return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1));
aoqi@0 691 }
aoqi@0 692
aoqi@0 693 Node* DecodeNKlassNode::Identity(PhaseTransform* phase) {
aoqi@0 694 const Type *t = phase->type( in(1) );
aoqi@0 695 if( t == Type::TOP ) return in(1);
aoqi@0 696
aoqi@0 697 if (in(1)->is_EncodePKlass()) {
aoqi@0 698 // (DecodeNKlass (EncodePKlass p)) -> p
aoqi@0 699 return in(1)->in(1);
aoqi@0 700 }
aoqi@0 701 return this;
aoqi@0 702 }
aoqi@0 703
aoqi@0 704 const Type *DecodeNKlassNode::Value( PhaseTransform *phase ) const {
aoqi@0 705 const Type *t = phase->type( in(1) );
aoqi@0 706 if (t == Type::TOP) return Type::TOP;
aoqi@0 707 assert(t != TypeNarrowKlass::NULL_PTR, "null klass?");
aoqi@0 708
aoqi@0 709 assert(t->isa_narrowklass(), "only narrow klass ptr here");
aoqi@0 710 return t->make_ptr();
aoqi@0 711 }
aoqi@0 712
aoqi@0 713 Node* EncodePKlassNode::Identity(PhaseTransform* phase) {
aoqi@0 714 const Type *t = phase->type( in(1) );
aoqi@0 715 if( t == Type::TOP ) return in(1);
aoqi@0 716
aoqi@0 717 if (in(1)->is_DecodeNKlass()) {
aoqi@0 718 // (EncodePKlass (DecodeNKlass p)) -> p
aoqi@0 719 return in(1)->in(1);
aoqi@0 720 }
aoqi@0 721 return this;
aoqi@0 722 }
aoqi@0 723
aoqi@0 724 const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const {
aoqi@0 725 const Type *t = phase->type( in(1) );
aoqi@0 726 if (t == Type::TOP) return Type::TOP;
aoqi@0 727 assert (t != TypePtr::NULL_PTR, "null klass?");
aoqi@0 728
aoqi@0 729 assert(UseCompressedClassPointers && t->isa_klassptr(), "only klass ptr here");
aoqi@0 730 return t->make_narrowklass();
aoqi@0 731 }
aoqi@0 732
aoqi@0 733
aoqi@0 734 //=============================================================================
aoqi@0 735 //------------------------------Identity---------------------------------------
aoqi@0 736 Node *Conv2BNode::Identity( PhaseTransform *phase ) {
aoqi@0 737 const Type *t = phase->type( in(1) );
aoqi@0 738 if( t == Type::TOP ) return in(1);
aoqi@0 739 if( t == TypeInt::ZERO ) return in(1);
aoqi@0 740 if( t == TypeInt::ONE ) return in(1);
aoqi@0 741 if( t == TypeInt::BOOL ) return in(1);
aoqi@0 742 return this;
aoqi@0 743 }
aoqi@0 744
aoqi@0 745 //------------------------------Value------------------------------------------
aoqi@0 746 const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
aoqi@0 747 const Type *t = phase->type( in(1) );
aoqi@0 748 if( t == Type::TOP ) return Type::TOP;
aoqi@0 749 if( t == TypeInt::ZERO ) return TypeInt::ZERO;
aoqi@0 750 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
aoqi@0 751 const TypePtr *tp = t->isa_ptr();
aoqi@0 752 if( tp != NULL ) {
aoqi@0 753 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
aoqi@0 754 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
aoqi@0 755 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;
aoqi@0 756 return TypeInt::BOOL;
aoqi@0 757 }
aoqi@0 758 if (t->base() != Type::Int) return TypeInt::BOOL;
aoqi@0 759 const TypeInt *ti = t->is_int();
aoqi@0 760 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
aoqi@0 761 return TypeInt::BOOL;
aoqi@0 762 }
aoqi@0 763
aoqi@0 764
aoqi@0 765 // The conversions operations are all Alpha sorted. Please keep it that way!
aoqi@0 766 //=============================================================================
aoqi@0 767 //------------------------------Value------------------------------------------
aoqi@0 768 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 769 const Type *t = phase->type( in(1) );
aoqi@0 770 if( t == Type::TOP ) return Type::TOP;
aoqi@0 771 if( t == Type::DOUBLE ) return Type::FLOAT;
aoqi@0 772 const TypeD *td = t->is_double_constant();
aoqi@0 773 return TypeF::make( (float)td->getd() );
aoqi@0 774 }
aoqi@0 775
aoqi@0 776 //------------------------------Identity---------------------------------------
aoqi@0 777 // Float's can be converted to doubles with no loss of bits. Hence
aoqi@0 778 // converting a float to a double and back to a float is a NOP.
aoqi@0 779 Node *ConvD2FNode::Identity(PhaseTransform *phase) {
aoqi@0 780 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
aoqi@0 781 }
aoqi@0 782
aoqi@0 783 //=============================================================================
aoqi@0 784 //------------------------------Value------------------------------------------
aoqi@0 785 const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
aoqi@0 786 const Type *t = phase->type( in(1) );
aoqi@0 787 if( t == Type::TOP ) return Type::TOP;
aoqi@0 788 if( t == Type::DOUBLE ) return TypeInt::INT;
aoqi@0 789 const TypeD *td = t->is_double_constant();
aoqi@0 790 return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
aoqi@0 791 }
aoqi@0 792
aoqi@0 793 //------------------------------Ideal------------------------------------------
aoqi@0 794 // If converting to an int type, skip any rounding nodes
aoqi@0 795 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 796 if( in(1)->Opcode() == Op_RoundDouble )
aoqi@0 797 set_req(1,in(1)->in(1));
aoqi@0 798 return NULL;
aoqi@0 799 }
aoqi@0 800
aoqi@0 801 //------------------------------Identity---------------------------------------
aoqi@0 802 // Int's can be converted to doubles with no loss of bits. Hence
aoqi@0 803 // converting an integer to a double and back to an integer is a NOP.
aoqi@0 804 Node *ConvD2INode::Identity(PhaseTransform *phase) {
aoqi@0 805 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
aoqi@0 806 }
aoqi@0 807
aoqi@0 808 //=============================================================================
aoqi@0 809 //------------------------------Value------------------------------------------
aoqi@0 810 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 811 const Type *t = phase->type( in(1) );
aoqi@0 812 if( t == Type::TOP ) return Type::TOP;
aoqi@0 813 if( t == Type::DOUBLE ) return TypeLong::LONG;
aoqi@0 814 const TypeD *td = t->is_double_constant();
aoqi@0 815 return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
aoqi@0 816 }
aoqi@0 817
aoqi@0 818 //------------------------------Identity---------------------------------------
aoqi@0 819 Node *ConvD2LNode::Identity(PhaseTransform *phase) {
aoqi@0 820 // Remove ConvD2L->ConvL2D->ConvD2L sequences.
aoqi@0 821 if( in(1) ->Opcode() == Op_ConvL2D &&
aoqi@0 822 in(1)->in(1)->Opcode() == Op_ConvD2L )
aoqi@0 823 return in(1)->in(1);
aoqi@0 824 return this;
aoqi@0 825 }
aoqi@0 826
aoqi@0 827 //------------------------------Ideal------------------------------------------
aoqi@0 828 // If converting to an int type, skip any rounding nodes
aoqi@0 829 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 830 if( in(1)->Opcode() == Op_RoundDouble )
aoqi@0 831 set_req(1,in(1)->in(1));
aoqi@0 832 return NULL;
aoqi@0 833 }
aoqi@0 834
aoqi@0 835 //=============================================================================
aoqi@0 836 //------------------------------Value------------------------------------------
aoqi@0 837 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 838 const Type *t = phase->type( in(1) );
aoqi@0 839 if( t == Type::TOP ) return Type::TOP;
aoqi@0 840 if( t == Type::FLOAT ) return Type::DOUBLE;
aoqi@0 841 const TypeF *tf = t->is_float_constant();
aoqi@0 842 return TypeD::make( (double)tf->getf() );
aoqi@0 843 }
aoqi@0 844
aoqi@0 845 //=============================================================================
aoqi@0 846 //------------------------------Value------------------------------------------
aoqi@0 847 const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
aoqi@0 848 const Type *t = phase->type( in(1) );
aoqi@0 849 if( t == Type::TOP ) return Type::TOP;
aoqi@0 850 if( t == Type::FLOAT ) return TypeInt::INT;
aoqi@0 851 const TypeF *tf = t->is_float_constant();
aoqi@0 852 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
aoqi@0 853 }
aoqi@0 854
aoqi@0 855 //------------------------------Identity---------------------------------------
aoqi@0 856 Node *ConvF2INode::Identity(PhaseTransform *phase) {
aoqi@0 857 // Remove ConvF2I->ConvI2F->ConvF2I sequences.
aoqi@0 858 if( in(1) ->Opcode() == Op_ConvI2F &&
aoqi@0 859 in(1)->in(1)->Opcode() == Op_ConvF2I )
aoqi@0 860 return in(1)->in(1);
aoqi@0 861 return this;
aoqi@0 862 }
aoqi@0 863
aoqi@0 864 //------------------------------Ideal------------------------------------------
aoqi@0 865 // If converting to an int type, skip any rounding nodes
aoqi@0 866 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 867 if( in(1)->Opcode() == Op_RoundFloat )
aoqi@0 868 set_req(1,in(1)->in(1));
aoqi@0 869 return NULL;
aoqi@0 870 }
aoqi@0 871
aoqi@0 872 //=============================================================================
aoqi@0 873 //------------------------------Value------------------------------------------
aoqi@0 874 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 875 const Type *t = phase->type( in(1) );
aoqi@0 876 if( t == Type::TOP ) return Type::TOP;
aoqi@0 877 if( t == Type::FLOAT ) return TypeLong::LONG;
aoqi@0 878 const TypeF *tf = t->is_float_constant();
aoqi@0 879 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
aoqi@0 880 }
aoqi@0 881
aoqi@0 882 //------------------------------Identity---------------------------------------
aoqi@0 883 Node *ConvF2LNode::Identity(PhaseTransform *phase) {
aoqi@0 884 // Remove ConvF2L->ConvL2F->ConvF2L sequences.
aoqi@0 885 if( in(1) ->Opcode() == Op_ConvL2F &&
aoqi@0 886 in(1)->in(1)->Opcode() == Op_ConvF2L )
aoqi@0 887 return in(1)->in(1);
aoqi@0 888 return this;
aoqi@0 889 }
aoqi@0 890
aoqi@0 891 //------------------------------Ideal------------------------------------------
aoqi@0 892 // If converting to an int type, skip any rounding nodes
aoqi@0 893 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 894 if( in(1)->Opcode() == Op_RoundFloat )
aoqi@0 895 set_req(1,in(1)->in(1));
aoqi@0 896 return NULL;
aoqi@0 897 }
aoqi@0 898
aoqi@0 899 //=============================================================================
aoqi@0 900 //------------------------------Value------------------------------------------
aoqi@0 901 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 902 const Type *t = phase->type( in(1) );
aoqi@0 903 if( t == Type::TOP ) return Type::TOP;
aoqi@0 904 const TypeInt *ti = t->is_int();
aoqi@0 905 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
aoqi@0 906 return bottom_type();
aoqi@0 907 }
aoqi@0 908
aoqi@0 909 //=============================================================================
aoqi@0 910 //------------------------------Value------------------------------------------
aoqi@0 911 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 912 const Type *t = phase->type( in(1) );
aoqi@0 913 if( t == Type::TOP ) return Type::TOP;
aoqi@0 914 const TypeInt *ti = t->is_int();
aoqi@0 915 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
aoqi@0 916 return bottom_type();
aoqi@0 917 }
aoqi@0 918
aoqi@0 919 //------------------------------Identity---------------------------------------
aoqi@0 920 Node *ConvI2FNode::Identity(PhaseTransform *phase) {
aoqi@0 921 // Remove ConvI2F->ConvF2I->ConvI2F sequences.
aoqi@0 922 if( in(1) ->Opcode() == Op_ConvF2I &&
aoqi@0 923 in(1)->in(1)->Opcode() == Op_ConvI2F )
aoqi@0 924 return in(1)->in(1);
aoqi@0 925 return this;
aoqi@0 926 }
aoqi@0 927
aoqi@0 928 //=============================================================================
aoqi@0 929 //------------------------------Value------------------------------------------
aoqi@0 930 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 931 const Type *t = phase->type( in(1) );
aoqi@0 932 if( t == Type::TOP ) return Type::TOP;
aoqi@0 933 const TypeInt *ti = t->is_int();
aoqi@0 934 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
aoqi@0 935 // Join my declared type against my incoming type.
aoqi@0 936 tl = tl->filter(_type);
aoqi@0 937 return tl;
aoqi@0 938 }
aoqi@0 939
aoqi@0 940 #ifdef _LP64
aoqi@0 941 static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
aoqi@0 942 jlong lo2, jlong hi2) {
aoqi@0 943 // Two ranges overlap iff one range's low point falls in the other range.
aoqi@0 944 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
aoqi@0 945 }
aoqi@0 946 #endif
aoqi@0 947
aoqi@0 948 //------------------------------Ideal------------------------------------------
aoqi@0 949 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 950 const TypeLong* this_type = this->type()->is_long();
aoqi@0 951 Node* this_changed = NULL;
aoqi@0 952
aoqi@0 953 // If _major_progress, then more loop optimizations follow. Do NOT
aoqi@0 954 // remove this node's type assertion until no more loop ops can happen.
aoqi@0 955 // The progress bit is set in the major loop optimizations THEN comes the
aoqi@0 956 // call to IterGVN and any chance of hitting this code. Cf. Opaque1Node.
aoqi@0 957 if (can_reshape && !phase->C->major_progress()) {
aoqi@0 958 const TypeInt* in_type = phase->type(in(1))->isa_int();
aoqi@0 959 if (in_type != NULL && this_type != NULL &&
aoqi@0 960 (in_type->_lo != this_type->_lo ||
aoqi@0 961 in_type->_hi != this_type->_hi)) {
aoqi@0 962 // Although this WORSENS the type, it increases GVN opportunities,
aoqi@0 963 // because I2L nodes with the same input will common up, regardless
aoqi@0 964 // of slightly differing type assertions. Such slight differences
aoqi@0 965 // arise routinely as a result of loop unrolling, so this is a
aoqi@0 966 // post-unrolling graph cleanup. Choose a type which depends only
aoqi@0 967 // on my input. (Exception: Keep a range assertion of >=0 or <0.)
aoqi@0 968 jlong lo1 = this_type->_lo;
aoqi@0 969 jlong hi1 = this_type->_hi;
aoqi@0 970 int w1 = this_type->_widen;
aoqi@0 971 if (lo1 != (jint)lo1 ||
aoqi@0 972 hi1 != (jint)hi1 ||
aoqi@0 973 lo1 > hi1) {
aoqi@0 974 // Overflow leads to wraparound, wraparound leads to range saturation.
aoqi@0 975 lo1 = min_jint; hi1 = max_jint;
aoqi@0 976 } else if (lo1 >= 0) {
aoqi@0 977 // Keep a range assertion of >=0.
aoqi@0 978 lo1 = 0; hi1 = max_jint;
aoqi@0 979 } else if (hi1 < 0) {
aoqi@0 980 // Keep a range assertion of <0.
aoqi@0 981 lo1 = min_jint; hi1 = -1;
aoqi@0 982 } else {
aoqi@0 983 lo1 = min_jint; hi1 = max_jint;
aoqi@0 984 }
aoqi@0 985 const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
aoqi@0 986 MIN2((jlong)in_type->_hi, hi1),
aoqi@0 987 MAX2((int)in_type->_widen, w1));
aoqi@0 988 if (wtype != type()) {
aoqi@0 989 set_type(wtype);
aoqi@0 990 // Note: this_type still has old type value, for the logic below.
aoqi@0 991 this_changed = this;
aoqi@0 992 }
aoqi@0 993 }
aoqi@0 994 }
aoqi@0 995
aoqi@0 996 #ifdef _LP64
aoqi@0 997 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
aoqi@0 998 // but only if x and y have subranges that cannot cause 32-bit overflow,
aoqi@0 999 // under the assumption that x+y is in my own subrange this->type().
aoqi@0 1000
aoqi@0 1001 // This assumption is based on a constraint (i.e., type assertion)
aoqi@0 1002 // established in Parse::array_addressing or perhaps elsewhere.
aoqi@0 1003 // This constraint has been adjoined to the "natural" type of
aoqi@0 1004 // the incoming argument in(0). We know (because of runtime
aoqi@0 1005 // checks) - that the result value I2L(x+y) is in the joined range.
aoqi@0 1006 // Hence we can restrict the incoming terms (x, y) to values such
aoqi@0 1007 // that their sum also lands in that range.
aoqi@0 1008
aoqi@0 1009 // This optimization is useful only on 64-bit systems, where we hope
aoqi@0 1010 // the addition will end up subsumed in an addressing mode.
aoqi@0 1011 // It is necessary to do this when optimizing an unrolled array
aoqi@0 1012 // copy loop such as x[i++] = y[i++].
aoqi@0 1013
aoqi@0 1014 // On 32-bit systems, it's better to perform as much 32-bit math as
aoqi@0 1015 // possible before the I2L conversion, because 32-bit math is cheaper.
aoqi@0 1016 // There's no common reason to "leak" a constant offset through the I2L.
aoqi@0 1017 // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
aoqi@0 1018
aoqi@0 1019 Node* z = in(1);
aoqi@0 1020 int op = z->Opcode();
aoqi@0 1021 if (op == Op_AddI || op == Op_SubI) {
aoqi@0 1022 Node* x = z->in(1);
aoqi@0 1023 Node* y = z->in(2);
aoqi@0 1024 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
aoqi@0 1025 if (phase->type(x) == Type::TOP) return this_changed;
aoqi@0 1026 if (phase->type(y) == Type::TOP) return this_changed;
aoqi@0 1027 const TypeInt* tx = phase->type(x)->is_int();
aoqi@0 1028 const TypeInt* ty = phase->type(y)->is_int();
aoqi@0 1029 const TypeLong* tz = this_type;
aoqi@0 1030 jlong xlo = tx->_lo;
aoqi@0 1031 jlong xhi = tx->_hi;
aoqi@0 1032 jlong ylo = ty->_lo;
aoqi@0 1033 jlong yhi = ty->_hi;
aoqi@0 1034 jlong zlo = tz->_lo;
aoqi@0 1035 jlong zhi = tz->_hi;
aoqi@0 1036 jlong vbit = CONST64(1) << BitsPerInt;
aoqi@0 1037 int widen = MAX2(tx->_widen, ty->_widen);
aoqi@0 1038 if (op == Op_SubI) {
aoqi@0 1039 jlong ylo0 = ylo;
aoqi@0 1040 ylo = -yhi;
aoqi@0 1041 yhi = -ylo0;
aoqi@0 1042 }
aoqi@0 1043 // See if x+y can cause positive overflow into z+2**32
aoqi@0 1044 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
aoqi@0 1045 return this_changed;
aoqi@0 1046 }
aoqi@0 1047 // See if x+y can cause negative overflow into z-2**32
aoqi@0 1048 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
aoqi@0 1049 return this_changed;
aoqi@0 1050 }
aoqi@0 1051 // Now it's always safe to assume x+y does not overflow.
aoqi@0 1052 // This is true even if some pairs x,y might cause overflow, as long
aoqi@0 1053 // as that overflow value cannot fall into [zlo,zhi].
aoqi@0 1054
aoqi@0 1055 // Confident that the arithmetic is "as if infinite precision",
aoqi@0 1056 // we can now use z's range to put constraints on those of x and y.
aoqi@0 1057 // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
aoqi@0 1058 // more "restricted" range by intersecting [xlo,xhi] with the
aoqi@0 1059 // range obtained by subtracting y's range from the asserted range
aoqi@0 1060 // of the I2L conversion. Here's the interval arithmetic algebra:
aoqi@0 1061 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
aoqi@0 1062 // => x in [zlo-yhi, zhi-ylo]
aoqi@0 1063 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
aoqi@0 1064 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
aoqi@0 1065 jlong rxlo = MAX2(xlo, zlo - yhi);
aoqi@0 1066 jlong rxhi = MIN2(xhi, zhi - ylo);
aoqi@0 1067 // And similarly, x changing place with y:
aoqi@0 1068 jlong rylo = MAX2(ylo, zlo - xhi);
aoqi@0 1069 jlong ryhi = MIN2(yhi, zhi - xlo);
aoqi@0 1070 if (rxlo > rxhi || rylo > ryhi) {
aoqi@0 1071 return this_changed; // x or y is dying; don't mess w/ it
aoqi@0 1072 }
aoqi@0 1073 if (op == Op_SubI) {
aoqi@0 1074 jlong rylo0 = rylo;
aoqi@0 1075 rylo = -ryhi;
aoqi@0 1076 ryhi = -rylo0;
aoqi@0 1077 }
aoqi@0 1078
aoqi@0 1079 Node* cx = phase->transform( new (phase->C) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
aoqi@0 1080 Node* cy = phase->transform( new (phase->C) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
aoqi@0 1081 switch (op) {
aoqi@0 1082 case Op_AddI: return new (phase->C) AddLNode(cx, cy);
aoqi@0 1083 case Op_SubI: return new (phase->C) SubLNode(cx, cy);
aoqi@0 1084 default: ShouldNotReachHere();
aoqi@0 1085 }
aoqi@0 1086 }
aoqi@0 1087 #endif //_LP64
aoqi@0 1088
aoqi@0 1089 return this_changed;
aoqi@0 1090 }
aoqi@0 1091
aoqi@0 1092 //=============================================================================
aoqi@0 1093 //------------------------------Value------------------------------------------
aoqi@0 1094 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 1095 const Type *t = phase->type( in(1) );
aoqi@0 1096 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1097 const TypeLong *tl = t->is_long();
aoqi@0 1098 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
aoqi@0 1099 return bottom_type();
aoqi@0 1100 }
aoqi@0 1101
aoqi@0 1102 //=============================================================================
aoqi@0 1103 //------------------------------Value------------------------------------------
aoqi@0 1104 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 1105 const Type *t = phase->type( in(1) );
aoqi@0 1106 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1107 const TypeLong *tl = t->is_long();
aoqi@0 1108 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
aoqi@0 1109 return bottom_type();
aoqi@0 1110 }
aoqi@0 1111
aoqi@0 1112 //=============================================================================
aoqi@0 1113 //----------------------------Identity-----------------------------------------
aoqi@0 1114 Node *ConvL2INode::Identity( PhaseTransform *phase ) {
aoqi@0 1115 // Convert L2I(I2L(x)) => x
aoqi@0 1116 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);
aoqi@0 1117 return this;
aoqi@0 1118 }
aoqi@0 1119
aoqi@0 1120 //------------------------------Value------------------------------------------
aoqi@0 1121 const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
aoqi@0 1122 const Type *t = phase->type( in(1) );
aoqi@0 1123 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1124 const TypeLong *tl = t->is_long();
aoqi@0 1125 if (tl->is_con())
aoqi@0 1126 // Easy case.
aoqi@0 1127 return TypeInt::make((jint)tl->get_con());
aoqi@0 1128 return bottom_type();
aoqi@0 1129 }
aoqi@0 1130
aoqi@0 1131 //------------------------------Ideal------------------------------------------
aoqi@0 1132 // Return a node which is more "ideal" than the current node.
aoqi@0 1133 // Blow off prior masking to int
aoqi@0 1134 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1135 Node *andl = in(1);
aoqi@0 1136 uint andl_op = andl->Opcode();
aoqi@0 1137 if( andl_op == Op_AndL ) {
aoqi@0 1138 // Blow off prior masking to int
aoqi@0 1139 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
aoqi@0 1140 set_req(1,andl->in(1));
aoqi@0 1141 return this;
aoqi@0 1142 }
aoqi@0 1143 }
aoqi@0 1144
aoqi@0 1145 // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
aoqi@0 1146 // This replaces an 'AddL' with an 'AddI'.
aoqi@0 1147 if( andl_op == Op_AddL ) {
aoqi@0 1148 // Don't do this for nodes which have more than one user since
aoqi@0 1149 // we'll end up computing the long add anyway.
aoqi@0 1150 if (andl->outcnt() > 1) return NULL;
aoqi@0 1151
aoqi@0 1152 Node* x = andl->in(1);
aoqi@0 1153 Node* y = andl->in(2);
aoqi@0 1154 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
aoqi@0 1155 if (phase->type(x) == Type::TOP) return NULL;
aoqi@0 1156 if (phase->type(y) == Type::TOP) return NULL;
aoqi@0 1157 Node *add1 = phase->transform(new (phase->C) ConvL2INode(x));
aoqi@0 1158 Node *add2 = phase->transform(new (phase->C) ConvL2INode(y));
aoqi@0 1159 return new (phase->C) AddINode(add1,add2);
aoqi@0 1160 }
aoqi@0 1161
aoqi@0 1162 // Disable optimization: LoadL->ConvL2I ==> LoadI.
aoqi@0 1163 // It causes problems (sizes of Load and Store nodes do not match)
aoqi@0 1164 // in objects initialization code and Escape Analysis.
aoqi@0 1165 return NULL;
aoqi@0 1166 }
aoqi@0 1167
aoqi@0 1168 //=============================================================================
aoqi@0 1169 //------------------------------Value------------------------------------------
aoqi@0 1170 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
aoqi@0 1171 const Type* t = phase->type(in(1));
aoqi@0 1172 if (t == Type::TOP) return Type::TOP;
aoqi@0 1173 if (t->base() == Type_X && t->singleton()) {
aoqi@0 1174 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
aoqi@0 1175 if (bits == 0) return TypePtr::NULL_PTR;
aoqi@0 1176 return TypeRawPtr::make((address) bits);
aoqi@0 1177 }
aoqi@0 1178 return CastX2PNode::bottom_type();
aoqi@0 1179 }
aoqi@0 1180
aoqi@0 1181 //------------------------------Idealize---------------------------------------
aoqi@0 1182 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
aoqi@0 1183 if (t == Type::TOP) return false;
aoqi@0 1184 const TypeX* tl = t->is_intptr_t();
aoqi@0 1185 jint lo = min_jint;
aoqi@0 1186 jint hi = max_jint;
aoqi@0 1187 if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow
aoqi@0 1188 return (tl->_lo >= lo) && (tl->_hi <= hi);
aoqi@0 1189 }
aoqi@0 1190
aoqi@0 1191 static inline Node* addP_of_X2P(PhaseGVN *phase,
aoqi@0 1192 Node* base,
aoqi@0 1193 Node* dispX,
aoqi@0 1194 bool negate = false) {
aoqi@0 1195 if (negate) {
aoqi@0 1196 dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX));
aoqi@0 1197 }
aoqi@0 1198 return new (phase->C) AddPNode(phase->C->top(),
aoqi@0 1199 phase->transform(new (phase->C) CastX2PNode(base)),
aoqi@0 1200 phase->transform(dispX));
aoqi@0 1201 }
aoqi@0 1202
aoqi@0 1203 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1204 // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
aoqi@0 1205 int op = in(1)->Opcode();
aoqi@0 1206 Node* x;
aoqi@0 1207 Node* y;
aoqi@0 1208 switch (op) {
aoqi@0 1209 case Op_SubX:
aoqi@0 1210 x = in(1)->in(1);
aoqi@0 1211 // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
aoqi@0 1212 if (phase->find_intptr_t_con(x, -1) == 0)
aoqi@0 1213 break;
aoqi@0 1214 y = in(1)->in(2);
aoqi@0 1215 if (fits_in_int(phase->type(y), true)) {
aoqi@0 1216 return addP_of_X2P(phase, x, y, true);
aoqi@0 1217 }
aoqi@0 1218 break;
aoqi@0 1219 case Op_AddX:
aoqi@0 1220 x = in(1)->in(1);
aoqi@0 1221 y = in(1)->in(2);
aoqi@0 1222 if (fits_in_int(phase->type(y))) {
aoqi@0 1223 return addP_of_X2P(phase, x, y);
aoqi@0 1224 }
aoqi@0 1225 if (fits_in_int(phase->type(x))) {
aoqi@0 1226 return addP_of_X2P(phase, y, x);
aoqi@0 1227 }
aoqi@0 1228 break;
aoqi@0 1229 }
aoqi@0 1230 return NULL;
aoqi@0 1231 }
aoqi@0 1232
aoqi@0 1233 //------------------------------Identity---------------------------------------
aoqi@0 1234 Node *CastX2PNode::Identity( PhaseTransform *phase ) {
aoqi@0 1235 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
aoqi@0 1236 return this;
aoqi@0 1237 }
aoqi@0 1238
aoqi@0 1239 //=============================================================================
aoqi@0 1240 //------------------------------Value------------------------------------------
aoqi@0 1241 const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
aoqi@0 1242 const Type* t = phase->type(in(1));
aoqi@0 1243 if (t == Type::TOP) return Type::TOP;
aoqi@0 1244 if (t->base() == Type::RawPtr && t->singleton()) {
aoqi@0 1245 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
aoqi@0 1246 return TypeX::make(bits);
aoqi@0 1247 }
aoqi@0 1248 return CastP2XNode::bottom_type();
aoqi@0 1249 }
aoqi@0 1250
aoqi@0 1251 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1252 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
aoqi@0 1253 }
aoqi@0 1254
aoqi@0 1255 //------------------------------Identity---------------------------------------
aoqi@0 1256 Node *CastP2XNode::Identity( PhaseTransform *phase ) {
aoqi@0 1257 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
aoqi@0 1258 return this;
aoqi@0 1259 }
aoqi@0 1260
aoqi@0 1261
aoqi@0 1262 //=============================================================================
aoqi@0 1263 //------------------------------Identity---------------------------------------
aoqi@0 1264 // Remove redundant roundings
aoqi@0 1265 Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
aoqi@0 1266 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
aoqi@0 1267 // Do not round constants
aoqi@0 1268 if (phase->type(in(1))->base() == Type::FloatCon) return in(1);
aoqi@0 1269 int op = in(1)->Opcode();
aoqi@0 1270 // Redundant rounding
aoqi@0 1271 if( op == Op_RoundFloat ) return in(1);
aoqi@0 1272 // Already rounded
aoqi@0 1273 if( op == Op_Parm ) return in(1);
aoqi@0 1274 if( op == Op_LoadF ) return in(1);
aoqi@0 1275 return this;
aoqi@0 1276 }
aoqi@0 1277
aoqi@0 1278 //------------------------------Value------------------------------------------
aoqi@0 1279 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
aoqi@0 1280 return phase->type( in(1) );
aoqi@0 1281 }
aoqi@0 1282
aoqi@0 1283 //=============================================================================
aoqi@0 1284 //------------------------------Identity---------------------------------------
aoqi@0 1285 // Remove redundant roundings. Incoming arguments are already rounded.
aoqi@0 1286 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
aoqi@0 1287 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
aoqi@0 1288 // Do not round constants
aoqi@0 1289 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);
aoqi@0 1290 int op = in(1)->Opcode();
aoqi@0 1291 // Redundant rounding
aoqi@0 1292 if( op == Op_RoundDouble ) return in(1);
aoqi@0 1293 // Already rounded
aoqi@0 1294 if( op == Op_Parm ) return in(1);
aoqi@0 1295 if( op == Op_LoadD ) return in(1);
aoqi@0 1296 if( op == Op_ConvF2D ) return in(1);
aoqi@0 1297 if( op == Op_ConvI2D ) return in(1);
aoqi@0 1298 return this;
aoqi@0 1299 }
aoqi@0 1300
aoqi@0 1301 //------------------------------Value------------------------------------------
aoqi@0 1302 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
aoqi@0 1303 return phase->type( in(1) );
aoqi@0 1304 }
aoqi@0 1305
aoqi@0 1306
aoqi@0 1307 //=============================================================================
aoqi@0 1308 // Do not allow value-numbering
aoqi@0 1309 uint Opaque1Node::hash() const { return NO_HASH; }
aoqi@0 1310 uint Opaque1Node::cmp( const Node &n ) const {
aoqi@0 1311 return (&n == this); // Always fail except on self
aoqi@0 1312 }
aoqi@0 1313
aoqi@0 1314 //------------------------------Identity---------------------------------------
aoqi@0 1315 // If _major_progress, then more loop optimizations follow. Do NOT remove
aoqi@0 1316 // the opaque Node until no more loop ops can happen. Note the timing of
aoqi@0 1317 // _major_progress; it's set in the major loop optimizations THEN comes the
aoqi@0 1318 // call to IterGVN and any chance of hitting this code. Hence there's no
aoqi@0 1319 // phase-ordering problem with stripping Opaque1 in IGVN followed by some
aoqi@0 1320 // more loop optimizations that require it.
aoqi@0 1321 Node *Opaque1Node::Identity( PhaseTransform *phase ) {
aoqi@0 1322 return phase->C->major_progress() ? this : in(1);
aoqi@0 1323 }
aoqi@0 1324
aoqi@0 1325 //=============================================================================
aoqi@0 1326 // A node to prevent unwanted optimizations. Allows constant folding. Stops
aoqi@0 1327 // value-numbering, most Ideal calls or Identity functions. This Node is
aoqi@0 1328 // specifically designed to prevent the pre-increment value of a loop trip
aoqi@0 1329 // counter from being live out of the bottom of the loop (hence causing the
aoqi@0 1330 // pre- and post-increment values both being live and thus requiring an extra
aoqi@0 1331 // temp register and an extra move). If we "accidentally" optimize through
aoqi@0 1332 // this kind of a Node, we'll get slightly pessimal, but correct, code. Thus
aoqi@0 1333 // it's OK to be slightly sloppy on optimizations here.
aoqi@0 1334
aoqi@0 1335 // Do not allow value-numbering
aoqi@0 1336 uint Opaque2Node::hash() const { return NO_HASH; }
aoqi@0 1337 uint Opaque2Node::cmp( const Node &n ) const {
aoqi@0 1338 return (&n == this); // Always fail except on self
aoqi@0 1339 }
aoqi@0 1340
aoqi@0 1341
aoqi@0 1342 //------------------------------Value------------------------------------------
aoqi@0 1343 const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 1344 const Type *t = phase->type( in(1) );
aoqi@0 1345 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1346 const TypeLong *tl = t->is_long();
aoqi@0 1347 if( !tl->is_con() ) return bottom_type();
aoqi@0 1348 JavaValue v;
aoqi@0 1349 v.set_jlong(tl->get_con());
aoqi@0 1350 return TypeD::make( v.get_jdouble() );
aoqi@0 1351 }
aoqi@0 1352
aoqi@0 1353 //------------------------------Value------------------------------------------
aoqi@0 1354 const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 1355 const Type *t = phase->type( in(1) );
aoqi@0 1356 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1357 const TypeInt *ti = t->is_int();
aoqi@0 1358 if( !ti->is_con() ) return bottom_type();
aoqi@0 1359 JavaValue v;
aoqi@0 1360 v.set_jint(ti->get_con());
aoqi@0 1361 return TypeF::make( v.get_jfloat() );
aoqi@0 1362 }
aoqi@0 1363
aoqi@0 1364 //------------------------------Value------------------------------------------
aoqi@0 1365 const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
aoqi@0 1366 const Type *t = phase->type( in(1) );
aoqi@0 1367 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1368 if( t == Type::FLOAT ) return TypeInt::INT;
aoqi@0 1369 const TypeF *tf = t->is_float_constant();
aoqi@0 1370 JavaValue v;
aoqi@0 1371 v.set_jfloat(tf->getf());
aoqi@0 1372 return TypeInt::make( v.get_jint() );
aoqi@0 1373 }
aoqi@0 1374
aoqi@0 1375 //------------------------------Value------------------------------------------
aoqi@0 1376 const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 1377 const Type *t = phase->type( in(1) );
aoqi@0 1378 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1379 if( t == Type::DOUBLE ) return TypeLong::LONG;
aoqi@0 1380 const TypeD *td = t->is_double_constant();
aoqi@0 1381 JavaValue v;
aoqi@0 1382 v.set_jdouble(td->getd());
aoqi@0 1383 return TypeLong::make( v.get_jlong() );
aoqi@0 1384 }
aoqi@0 1385
aoqi@0 1386 //------------------------------Value------------------------------------------
aoqi@0 1387 const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const {
aoqi@0 1388 const Type* t = phase->type(in(1));
aoqi@0 1389 if (t == Type::TOP) return Type::TOP;
aoqi@0 1390 const TypeInt* ti = t->isa_int();
aoqi@0 1391 if (ti && ti->is_con()) {
aoqi@0 1392 jint i = ti->get_con();
aoqi@0 1393 // HD, Figure 5-6
aoqi@0 1394 if (i == 0)
aoqi@0 1395 return TypeInt::make(BitsPerInt);
aoqi@0 1396 int n = 1;
aoqi@0 1397 unsigned int x = i;
aoqi@0 1398 if (x >> 16 == 0) { n += 16; x <<= 16; }
aoqi@0 1399 if (x >> 24 == 0) { n += 8; x <<= 8; }
aoqi@0 1400 if (x >> 28 == 0) { n += 4; x <<= 4; }
aoqi@0 1401 if (x >> 30 == 0) { n += 2; x <<= 2; }
aoqi@0 1402 n -= x >> 31;
aoqi@0 1403 return TypeInt::make(n);
aoqi@0 1404 }
aoqi@0 1405 return TypeInt::INT;
aoqi@0 1406 }
aoqi@0 1407
aoqi@0 1408 //------------------------------Value------------------------------------------
aoqi@0 1409 const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const {
aoqi@0 1410 const Type* t = phase->type(in(1));
aoqi@0 1411 if (t == Type::TOP) return Type::TOP;
aoqi@0 1412 const TypeLong* tl = t->isa_long();
aoqi@0 1413 if (tl && tl->is_con()) {
aoqi@0 1414 jlong l = tl->get_con();
aoqi@0 1415 // HD, Figure 5-6
aoqi@0 1416 if (l == 0)
aoqi@0 1417 return TypeInt::make(BitsPerLong);
aoqi@0 1418 int n = 1;
aoqi@0 1419 unsigned int x = (((julong) l) >> 32);
aoqi@0 1420 if (x == 0) { n += 32; x = (int) l; }
aoqi@0 1421 if (x >> 16 == 0) { n += 16; x <<= 16; }
aoqi@0 1422 if (x >> 24 == 0) { n += 8; x <<= 8; }
aoqi@0 1423 if (x >> 28 == 0) { n += 4; x <<= 4; }
aoqi@0 1424 if (x >> 30 == 0) { n += 2; x <<= 2; }
aoqi@0 1425 n -= x >> 31;
aoqi@0 1426 return TypeInt::make(n);
aoqi@0 1427 }
aoqi@0 1428 return TypeInt::INT;
aoqi@0 1429 }
aoqi@0 1430
aoqi@0 1431 //------------------------------Value------------------------------------------
aoqi@0 1432 const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const {
aoqi@0 1433 const Type* t = phase->type(in(1));
aoqi@0 1434 if (t == Type::TOP) return Type::TOP;
aoqi@0 1435 const TypeInt* ti = t->isa_int();
aoqi@0 1436 if (ti && ti->is_con()) {
aoqi@0 1437 jint i = ti->get_con();
aoqi@0 1438 // HD, Figure 5-14
aoqi@0 1439 int y;
aoqi@0 1440 if (i == 0)
aoqi@0 1441 return TypeInt::make(BitsPerInt);
aoqi@0 1442 int n = 31;
aoqi@0 1443 y = i << 16; if (y != 0) { n = n - 16; i = y; }
aoqi@0 1444 y = i << 8; if (y != 0) { n = n - 8; i = y; }
aoqi@0 1445 y = i << 4; if (y != 0) { n = n - 4; i = y; }
aoqi@0 1446 y = i << 2; if (y != 0) { n = n - 2; i = y; }
aoqi@0 1447 y = i << 1; if (y != 0) { n = n - 1; }
aoqi@0 1448 return TypeInt::make(n);
aoqi@0 1449 }
aoqi@0 1450 return TypeInt::INT;
aoqi@0 1451 }
aoqi@0 1452
aoqi@0 1453 //------------------------------Value------------------------------------------
aoqi@0 1454 const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const {
aoqi@0 1455 const Type* t = phase->type(in(1));
aoqi@0 1456 if (t == Type::TOP) return Type::TOP;
aoqi@0 1457 const TypeLong* tl = t->isa_long();
aoqi@0 1458 if (tl && tl->is_con()) {
aoqi@0 1459 jlong l = tl->get_con();
aoqi@0 1460 // HD, Figure 5-14
aoqi@0 1461 int x, y;
aoqi@0 1462 if (l == 0)
aoqi@0 1463 return TypeInt::make(BitsPerLong);
aoqi@0 1464 int n = 63;
aoqi@0 1465 y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);
aoqi@0 1466 y = x << 16; if (y != 0) { n = n - 16; x = y; }
aoqi@0 1467 y = x << 8; if (y != 0) { n = n - 8; x = y; }
aoqi@0 1468 y = x << 4; if (y != 0) { n = n - 4; x = y; }
aoqi@0 1469 y = x << 2; if (y != 0) { n = n - 2; x = y; }
aoqi@0 1470 y = x << 1; if (y != 0) { n = n - 1; }
aoqi@0 1471 return TypeInt::make(n);
aoqi@0 1472 }
aoqi@0 1473 return TypeInt::INT;
aoqi@0 1474 }

mercurial