annotate src/share/vm/opto/connode.cpp @ 747:93c14e5562c4

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