src/share/vm/opto/connode.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6313
de95063c0e34
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
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
aoqi@0 444
aoqi@0 445 //=============================================================================
aoqi@0 446
aoqi@0 447 //------------------------------Ideal_DU_postCCP-------------------------------
aoqi@0 448 // If not converting int->oop, throw away cast after constant propagation
aoqi@0 449 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
aoqi@0 450 const Type *t = ccp->type(in(1));
aoqi@0 451 if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {
aoqi@0 452 return NULL; // do not transform raw pointers or narrow oops
aoqi@0 453 }
aoqi@0 454 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
aoqi@0 455 }
aoqi@0 456
aoqi@0 457
aoqi@0 458
aoqi@0 459 //=============================================================================
aoqi@0 460 //------------------------------Identity---------------------------------------
aoqi@0 461 // If input is already higher or equal to cast type, then this is an identity.
aoqi@0 462 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
aoqi@0 463 // Toned down to rescue meeting at a Phi 3 different oops all implementing
aoqi@0 464 // the same interface. CompileTheWorld starting at 502, kd12rc1.zip.
aoqi@0 465 return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
aoqi@0 466 }
aoqi@0 467
aoqi@0 468 //------------------------------Value------------------------------------------
aoqi@0 469 // Take 'join' of input and cast-up type, unless working with an Interface
aoqi@0 470 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
aoqi@0 471 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
aoqi@0 472
aoqi@0 473 const Type *inn = phase->type(in(1));
aoqi@0 474 if( inn == Type::TOP ) return Type::TOP; // No information yet
aoqi@0 475
aoqi@0 476 const TypePtr *in_type = inn->isa_ptr();
aoqi@0 477 const TypePtr *my_type = _type->isa_ptr();
aoqi@0 478 const Type *result = _type;
aoqi@0 479 if( in_type != NULL && my_type != NULL ) {
aoqi@0 480 TypePtr::PTR in_ptr = in_type->ptr();
aoqi@0 481 if( in_ptr == TypePtr::Null ) {
aoqi@0 482 result = in_type;
aoqi@0 483 } else if( in_ptr == TypePtr::Constant ) {
aoqi@0 484 // Casting a constant oop to an interface?
aoqi@0 485 // (i.e., a String to a Comparable?)
aoqi@0 486 // Then return the interface.
aoqi@0 487 const TypeOopPtr *jptr = my_type->isa_oopptr();
aoqi@0 488 assert( jptr, "" );
aoqi@0 489 result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
aoqi@0 490 ? my_type->cast_to_ptr_type( TypePtr::NotNull )
aoqi@0 491 : in_type;
aoqi@0 492 } else {
aoqi@0 493 result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
aoqi@0 494 }
aoqi@0 495 }
aoqi@0 496 return result;
aoqi@0 497
aoqi@0 498 // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
aoqi@0 499 // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
aoqi@0 500
aoqi@0 501 //
aoqi@0 502 // Remove this code after overnight run indicates no performance
aoqi@0 503 // loss from not performing JOIN at CheckCastPPNode
aoqi@0 504 //
aoqi@0 505 // const TypeInstPtr *in_oop = in->isa_instptr();
aoqi@0 506 // const TypeInstPtr *my_oop = _type->isa_instptr();
aoqi@0 507 // // If either input is an 'interface', return destination type
aoqi@0 508 // assert (in_oop == NULL || in_oop->klass() != NULL, "");
aoqi@0 509 // assert (my_oop == NULL || my_oop->klass() != NULL, "");
aoqi@0 510 // if( (in_oop && in_oop->klass()->is_interface())
aoqi@0 511 // ||(my_oop && my_oop->klass()->is_interface()) ) {
aoqi@0 512 // TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
aoqi@0 513 // // Preserve cast away nullness for interfaces
aoqi@0 514 // if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
aoqi@0 515 // return my_oop->cast_to_ptr_type(TypePtr::NotNull);
aoqi@0 516 // }
aoqi@0 517 // return _type;
aoqi@0 518 // }
aoqi@0 519 //
aoqi@0 520 // // Neither the input nor the destination type is an interface,
aoqi@0 521 //
aoqi@0 522 // // history: JOIN used to cause weird corner case bugs
aoqi@0 523 // // return (in == TypeOopPtr::NULL_PTR) ? in : _type;
aoqi@0 524 // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
aoqi@0 525 // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
aoqi@0 526 // const Type *join = in->join(_type);
aoqi@0 527 // // Check if join preserved NotNull'ness for pointers
aoqi@0 528 // if( join->isa_ptr() && _type->isa_ptr() ) {
aoqi@0 529 // TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
aoqi@0 530 // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
aoqi@0 531 // // If there isn't any NotNull'ness to preserve
aoqi@0 532 // // OR if join preserved NotNull'ness then return it
aoqi@0 533 // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null ||
aoqi@0 534 // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
aoqi@0 535 // return join;
aoqi@0 536 // }
aoqi@0 537 // // ELSE return same old type as before
aoqi@0 538 // return _type;
aoqi@0 539 // }
aoqi@0 540 // // Not joining two pointers
aoqi@0 541 // return join;
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 //------------------------------Ideal------------------------------------------
aoqi@0 545 // Return a node which is more "ideal" than the current node. Strip out
aoqi@0 546 // control copies
aoqi@0 547 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 548 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
aoqi@0 549 }
aoqi@0 550
aoqi@0 551
aoqi@0 552 Node* DecodeNNode::Identity(PhaseTransform* phase) {
aoqi@0 553 const Type *t = phase->type( in(1) );
aoqi@0 554 if( t == Type::TOP ) return in(1);
aoqi@0 555
aoqi@0 556 if (in(1)->is_EncodeP()) {
aoqi@0 557 // (DecodeN (EncodeP p)) -> p
aoqi@0 558 return in(1)->in(1);
aoqi@0 559 }
aoqi@0 560 return this;
aoqi@0 561 }
aoqi@0 562
aoqi@0 563 const Type *DecodeNNode::Value( PhaseTransform *phase ) const {
aoqi@0 564 const Type *t = phase->type( in(1) );
aoqi@0 565 if (t == Type::TOP) return Type::TOP;
aoqi@0 566 if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;
aoqi@0 567
aoqi@0 568 assert(t->isa_narrowoop(), "only narrowoop here");
aoqi@0 569 return t->make_ptr();
aoqi@0 570 }
aoqi@0 571
aoqi@0 572 Node* EncodePNode::Identity(PhaseTransform* phase) {
aoqi@0 573 const Type *t = phase->type( in(1) );
aoqi@0 574 if( t == Type::TOP ) return in(1);
aoqi@0 575
aoqi@0 576 if (in(1)->is_DecodeN()) {
aoqi@0 577 // (EncodeP (DecodeN p)) -> p
aoqi@0 578 return in(1)->in(1);
aoqi@0 579 }
aoqi@0 580 return this;
aoqi@0 581 }
aoqi@0 582
aoqi@0 583 const Type *EncodePNode::Value( PhaseTransform *phase ) const {
aoqi@0 584 const Type *t = phase->type( in(1) );
aoqi@0 585 if (t == Type::TOP) return Type::TOP;
aoqi@0 586 if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;
aoqi@0 587
aoqi@0 588 assert(t->isa_oop_ptr(), "only oopptr here");
aoqi@0 589 return t->make_narrowoop();
aoqi@0 590 }
aoqi@0 591
aoqi@0 592
aoqi@0 593 Node *EncodeNarrowPtrNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
aoqi@0 594 return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1));
aoqi@0 595 }
aoqi@0 596
aoqi@0 597 Node* DecodeNKlassNode::Identity(PhaseTransform* phase) {
aoqi@0 598 const Type *t = phase->type( in(1) );
aoqi@0 599 if( t == Type::TOP ) return in(1);
aoqi@0 600
aoqi@0 601 if (in(1)->is_EncodePKlass()) {
aoqi@0 602 // (DecodeNKlass (EncodePKlass p)) -> p
aoqi@0 603 return in(1)->in(1);
aoqi@0 604 }
aoqi@0 605 return this;
aoqi@0 606 }
aoqi@0 607
aoqi@0 608 const Type *DecodeNKlassNode::Value( PhaseTransform *phase ) const {
aoqi@0 609 const Type *t = phase->type( in(1) );
aoqi@0 610 if (t == Type::TOP) return Type::TOP;
aoqi@0 611 assert(t != TypeNarrowKlass::NULL_PTR, "null klass?");
aoqi@0 612
aoqi@0 613 assert(t->isa_narrowklass(), "only narrow klass ptr here");
aoqi@0 614 return t->make_ptr();
aoqi@0 615 }
aoqi@0 616
aoqi@0 617 Node* EncodePKlassNode::Identity(PhaseTransform* phase) {
aoqi@0 618 const Type *t = phase->type( in(1) );
aoqi@0 619 if( t == Type::TOP ) return in(1);
aoqi@0 620
aoqi@0 621 if (in(1)->is_DecodeNKlass()) {
aoqi@0 622 // (EncodePKlass (DecodeNKlass p)) -> p
aoqi@0 623 return in(1)->in(1);
aoqi@0 624 }
aoqi@0 625 return this;
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const {
aoqi@0 629 const Type *t = phase->type( in(1) );
aoqi@0 630 if (t == Type::TOP) return Type::TOP;
aoqi@0 631 assert (t != TypePtr::NULL_PTR, "null klass?");
aoqi@0 632
aoqi@0 633 assert(UseCompressedClassPointers && t->isa_klassptr(), "only klass ptr here");
aoqi@0 634 return t->make_narrowklass();
aoqi@0 635 }
aoqi@0 636
aoqi@0 637
aoqi@0 638 //=============================================================================
aoqi@0 639 //------------------------------Identity---------------------------------------
aoqi@0 640 Node *Conv2BNode::Identity( PhaseTransform *phase ) {
aoqi@0 641 const Type *t = phase->type( in(1) );
aoqi@0 642 if( t == Type::TOP ) return in(1);
aoqi@0 643 if( t == TypeInt::ZERO ) return in(1);
aoqi@0 644 if( t == TypeInt::ONE ) return in(1);
aoqi@0 645 if( t == TypeInt::BOOL ) return in(1);
aoqi@0 646 return this;
aoqi@0 647 }
aoqi@0 648
aoqi@0 649 //------------------------------Value------------------------------------------
aoqi@0 650 const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
aoqi@0 651 const Type *t = phase->type( in(1) );
aoqi@0 652 if( t == Type::TOP ) return Type::TOP;
aoqi@0 653 if( t == TypeInt::ZERO ) return TypeInt::ZERO;
aoqi@0 654 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
aoqi@0 655 const TypePtr *tp = t->isa_ptr();
aoqi@0 656 if( tp != NULL ) {
aoqi@0 657 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
aoqi@0 658 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
aoqi@0 659 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;
aoqi@0 660 return TypeInt::BOOL;
aoqi@0 661 }
aoqi@0 662 if (t->base() != Type::Int) return TypeInt::BOOL;
aoqi@0 663 const TypeInt *ti = t->is_int();
aoqi@0 664 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
aoqi@0 665 return TypeInt::BOOL;
aoqi@0 666 }
aoqi@0 667
aoqi@0 668
aoqi@0 669 // The conversions operations are all Alpha sorted. Please keep it that way!
aoqi@0 670 //=============================================================================
aoqi@0 671 //------------------------------Value------------------------------------------
aoqi@0 672 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 673 const Type *t = phase->type( in(1) );
aoqi@0 674 if( t == Type::TOP ) return Type::TOP;
aoqi@0 675 if( t == Type::DOUBLE ) return Type::FLOAT;
aoqi@0 676 const TypeD *td = t->is_double_constant();
aoqi@0 677 return TypeF::make( (float)td->getd() );
aoqi@0 678 }
aoqi@0 679
aoqi@0 680 //------------------------------Identity---------------------------------------
aoqi@0 681 // Float's can be converted to doubles with no loss of bits. Hence
aoqi@0 682 // converting a float to a double and back to a float is a NOP.
aoqi@0 683 Node *ConvD2FNode::Identity(PhaseTransform *phase) {
aoqi@0 684 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
aoqi@0 685 }
aoqi@0 686
aoqi@0 687 //=============================================================================
aoqi@0 688 //------------------------------Value------------------------------------------
aoqi@0 689 const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
aoqi@0 690 const Type *t = phase->type( in(1) );
aoqi@0 691 if( t == Type::TOP ) return Type::TOP;
aoqi@0 692 if( t == Type::DOUBLE ) return TypeInt::INT;
aoqi@0 693 const TypeD *td = t->is_double_constant();
aoqi@0 694 return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
aoqi@0 695 }
aoqi@0 696
aoqi@0 697 //------------------------------Ideal------------------------------------------
aoqi@0 698 // If converting to an int type, skip any rounding nodes
aoqi@0 699 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 700 if( in(1)->Opcode() == Op_RoundDouble )
aoqi@0 701 set_req(1,in(1)->in(1));
aoqi@0 702 return NULL;
aoqi@0 703 }
aoqi@0 704
aoqi@0 705 //------------------------------Identity---------------------------------------
aoqi@0 706 // Int's can be converted to doubles with no loss of bits. Hence
aoqi@0 707 // converting an integer to a double and back to an integer is a NOP.
aoqi@0 708 Node *ConvD2INode::Identity(PhaseTransform *phase) {
aoqi@0 709 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
aoqi@0 710 }
aoqi@0 711
aoqi@0 712 //=============================================================================
aoqi@0 713 //------------------------------Value------------------------------------------
aoqi@0 714 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 715 const Type *t = phase->type( in(1) );
aoqi@0 716 if( t == Type::TOP ) return Type::TOP;
aoqi@0 717 if( t == Type::DOUBLE ) return TypeLong::LONG;
aoqi@0 718 const TypeD *td = t->is_double_constant();
aoqi@0 719 return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
aoqi@0 720 }
aoqi@0 721
aoqi@0 722 //------------------------------Identity---------------------------------------
aoqi@0 723 Node *ConvD2LNode::Identity(PhaseTransform *phase) {
aoqi@0 724 // Remove ConvD2L->ConvL2D->ConvD2L sequences.
aoqi@0 725 if( in(1) ->Opcode() == Op_ConvL2D &&
aoqi@0 726 in(1)->in(1)->Opcode() == Op_ConvD2L )
aoqi@0 727 return in(1)->in(1);
aoqi@0 728 return this;
aoqi@0 729 }
aoqi@0 730
aoqi@0 731 //------------------------------Ideal------------------------------------------
aoqi@0 732 // If converting to an int type, skip any rounding nodes
aoqi@0 733 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 734 if( in(1)->Opcode() == Op_RoundDouble )
aoqi@0 735 set_req(1,in(1)->in(1));
aoqi@0 736 return NULL;
aoqi@0 737 }
aoqi@0 738
aoqi@0 739 //=============================================================================
aoqi@0 740 //------------------------------Value------------------------------------------
aoqi@0 741 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 742 const Type *t = phase->type( in(1) );
aoqi@0 743 if( t == Type::TOP ) return Type::TOP;
aoqi@0 744 if( t == Type::FLOAT ) return Type::DOUBLE;
aoqi@0 745 const TypeF *tf = t->is_float_constant();
aoqi@0 746 return TypeD::make( (double)tf->getf() );
aoqi@0 747 }
aoqi@0 748
aoqi@0 749 //=============================================================================
aoqi@0 750 //------------------------------Value------------------------------------------
aoqi@0 751 const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
aoqi@0 752 const Type *t = phase->type( in(1) );
aoqi@0 753 if( t == Type::TOP ) return Type::TOP;
aoqi@0 754 if( t == Type::FLOAT ) return TypeInt::INT;
aoqi@0 755 const TypeF *tf = t->is_float_constant();
aoqi@0 756 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
aoqi@0 757 }
aoqi@0 758
aoqi@0 759 //------------------------------Identity---------------------------------------
aoqi@0 760 Node *ConvF2INode::Identity(PhaseTransform *phase) {
aoqi@0 761 // Remove ConvF2I->ConvI2F->ConvF2I sequences.
aoqi@0 762 if( in(1) ->Opcode() == Op_ConvI2F &&
aoqi@0 763 in(1)->in(1)->Opcode() == Op_ConvF2I )
aoqi@0 764 return in(1)->in(1);
aoqi@0 765 return this;
aoqi@0 766 }
aoqi@0 767
aoqi@0 768 //------------------------------Ideal------------------------------------------
aoqi@0 769 // If converting to an int type, skip any rounding nodes
aoqi@0 770 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 771 if( in(1)->Opcode() == Op_RoundFloat )
aoqi@0 772 set_req(1,in(1)->in(1));
aoqi@0 773 return NULL;
aoqi@0 774 }
aoqi@0 775
aoqi@0 776 //=============================================================================
aoqi@0 777 //------------------------------Value------------------------------------------
aoqi@0 778 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 779 const Type *t = phase->type( in(1) );
aoqi@0 780 if( t == Type::TOP ) return Type::TOP;
aoqi@0 781 if( t == Type::FLOAT ) return TypeLong::LONG;
aoqi@0 782 const TypeF *tf = t->is_float_constant();
aoqi@0 783 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
aoqi@0 784 }
aoqi@0 785
aoqi@0 786 //------------------------------Identity---------------------------------------
aoqi@0 787 Node *ConvF2LNode::Identity(PhaseTransform *phase) {
aoqi@0 788 // Remove ConvF2L->ConvL2F->ConvF2L sequences.
aoqi@0 789 if( in(1) ->Opcode() == Op_ConvL2F &&
aoqi@0 790 in(1)->in(1)->Opcode() == Op_ConvF2L )
aoqi@0 791 return in(1)->in(1);
aoqi@0 792 return this;
aoqi@0 793 }
aoqi@0 794
aoqi@0 795 //------------------------------Ideal------------------------------------------
aoqi@0 796 // If converting to an int type, skip any rounding nodes
aoqi@0 797 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 798 if( in(1)->Opcode() == Op_RoundFloat )
aoqi@0 799 set_req(1,in(1)->in(1));
aoqi@0 800 return NULL;
aoqi@0 801 }
aoqi@0 802
aoqi@0 803 //=============================================================================
aoqi@0 804 //------------------------------Value------------------------------------------
aoqi@0 805 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 806 const Type *t = phase->type( in(1) );
aoqi@0 807 if( t == Type::TOP ) return Type::TOP;
aoqi@0 808 const TypeInt *ti = t->is_int();
aoqi@0 809 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
aoqi@0 810 return bottom_type();
aoqi@0 811 }
aoqi@0 812
aoqi@0 813 //=============================================================================
aoqi@0 814 //------------------------------Value------------------------------------------
aoqi@0 815 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 816 const Type *t = phase->type( in(1) );
aoqi@0 817 if( t == Type::TOP ) return Type::TOP;
aoqi@0 818 const TypeInt *ti = t->is_int();
aoqi@0 819 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
aoqi@0 820 return bottom_type();
aoqi@0 821 }
aoqi@0 822
aoqi@0 823 //------------------------------Identity---------------------------------------
aoqi@0 824 Node *ConvI2FNode::Identity(PhaseTransform *phase) {
aoqi@0 825 // Remove ConvI2F->ConvF2I->ConvI2F sequences.
aoqi@0 826 if( in(1) ->Opcode() == Op_ConvF2I &&
aoqi@0 827 in(1)->in(1)->Opcode() == Op_ConvI2F )
aoqi@0 828 return in(1)->in(1);
aoqi@0 829 return this;
aoqi@0 830 }
aoqi@0 831
aoqi@0 832 //=============================================================================
aoqi@0 833 //------------------------------Value------------------------------------------
aoqi@0 834 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 835 const Type *t = phase->type( in(1) );
aoqi@0 836 if( t == Type::TOP ) return Type::TOP;
aoqi@0 837 const TypeInt *ti = t->is_int();
aoqi@0 838 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
aoqi@0 839 // Join my declared type against my incoming type.
aoqi@0 840 tl = tl->filter(_type);
aoqi@0 841 return tl;
aoqi@0 842 }
aoqi@0 843
aoqi@0 844 #ifdef _LP64
aoqi@0 845 static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
aoqi@0 846 jlong lo2, jlong hi2) {
aoqi@0 847 // Two ranges overlap iff one range's low point falls in the other range.
aoqi@0 848 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
aoqi@0 849 }
aoqi@0 850 #endif
aoqi@0 851
aoqi@0 852 //------------------------------Ideal------------------------------------------
aoqi@0 853 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 854 const TypeLong* this_type = this->type()->is_long();
aoqi@0 855 Node* this_changed = NULL;
aoqi@0 856
aoqi@0 857 // If _major_progress, then more loop optimizations follow. Do NOT
aoqi@0 858 // remove this node's type assertion until no more loop ops can happen.
aoqi@0 859 // The progress bit is set in the major loop optimizations THEN comes the
aoqi@0 860 // call to IterGVN and any chance of hitting this code. Cf. Opaque1Node.
aoqi@0 861 if (can_reshape && !phase->C->major_progress()) {
aoqi@0 862 const TypeInt* in_type = phase->type(in(1))->isa_int();
aoqi@0 863 if (in_type != NULL && this_type != NULL &&
aoqi@0 864 (in_type->_lo != this_type->_lo ||
aoqi@0 865 in_type->_hi != this_type->_hi)) {
aoqi@0 866 // Although this WORSENS the type, it increases GVN opportunities,
aoqi@0 867 // because I2L nodes with the same input will common up, regardless
aoqi@0 868 // of slightly differing type assertions. Such slight differences
aoqi@0 869 // arise routinely as a result of loop unrolling, so this is a
aoqi@0 870 // post-unrolling graph cleanup. Choose a type which depends only
aoqi@0 871 // on my input. (Exception: Keep a range assertion of >=0 or <0.)
aoqi@0 872 jlong lo1 = this_type->_lo;
aoqi@0 873 jlong hi1 = this_type->_hi;
aoqi@0 874 int w1 = this_type->_widen;
aoqi@0 875 if (lo1 != (jint)lo1 ||
aoqi@0 876 hi1 != (jint)hi1 ||
aoqi@0 877 lo1 > hi1) {
aoqi@0 878 // Overflow leads to wraparound, wraparound leads to range saturation.
aoqi@0 879 lo1 = min_jint; hi1 = max_jint;
aoqi@0 880 } else if (lo1 >= 0) {
aoqi@0 881 // Keep a range assertion of >=0.
aoqi@0 882 lo1 = 0; hi1 = max_jint;
aoqi@0 883 } else if (hi1 < 0) {
aoqi@0 884 // Keep a range assertion of <0.
aoqi@0 885 lo1 = min_jint; hi1 = -1;
aoqi@0 886 } else {
aoqi@0 887 lo1 = min_jint; hi1 = max_jint;
aoqi@0 888 }
aoqi@0 889 const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
aoqi@0 890 MIN2((jlong)in_type->_hi, hi1),
aoqi@0 891 MAX2((int)in_type->_widen, w1));
aoqi@0 892 if (wtype != type()) {
aoqi@0 893 set_type(wtype);
aoqi@0 894 // Note: this_type still has old type value, for the logic below.
aoqi@0 895 this_changed = this;
aoqi@0 896 }
aoqi@0 897 }
aoqi@0 898 }
aoqi@0 899
aoqi@0 900 #ifdef _LP64
aoqi@0 901 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
aoqi@0 902 // but only if x and y have subranges that cannot cause 32-bit overflow,
aoqi@0 903 // under the assumption that x+y is in my own subrange this->type().
aoqi@0 904
aoqi@0 905 // This assumption is based on a constraint (i.e., type assertion)
aoqi@0 906 // established in Parse::array_addressing or perhaps elsewhere.
aoqi@0 907 // This constraint has been adjoined to the "natural" type of
aoqi@0 908 // the incoming argument in(0). We know (because of runtime
aoqi@0 909 // checks) - that the result value I2L(x+y) is in the joined range.
aoqi@0 910 // Hence we can restrict the incoming terms (x, y) to values such
aoqi@0 911 // that their sum also lands in that range.
aoqi@0 912
aoqi@0 913 // This optimization is useful only on 64-bit systems, where we hope
aoqi@0 914 // the addition will end up subsumed in an addressing mode.
aoqi@0 915 // It is necessary to do this when optimizing an unrolled array
aoqi@0 916 // copy loop such as x[i++] = y[i++].
aoqi@0 917
aoqi@0 918 // On 32-bit systems, it's better to perform as much 32-bit math as
aoqi@0 919 // possible before the I2L conversion, because 32-bit math is cheaper.
aoqi@0 920 // There's no common reason to "leak" a constant offset through the I2L.
aoqi@0 921 // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
aoqi@0 922
aoqi@0 923 Node* z = in(1);
aoqi@0 924 int op = z->Opcode();
aoqi@0 925 if (op == Op_AddI || op == Op_SubI) {
aoqi@0 926 Node* x = z->in(1);
aoqi@0 927 Node* y = z->in(2);
aoqi@0 928 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
aoqi@0 929 if (phase->type(x) == Type::TOP) return this_changed;
aoqi@0 930 if (phase->type(y) == Type::TOP) return this_changed;
aoqi@0 931 const TypeInt* tx = phase->type(x)->is_int();
aoqi@0 932 const TypeInt* ty = phase->type(y)->is_int();
aoqi@0 933 const TypeLong* tz = this_type;
aoqi@0 934 jlong xlo = tx->_lo;
aoqi@0 935 jlong xhi = tx->_hi;
aoqi@0 936 jlong ylo = ty->_lo;
aoqi@0 937 jlong yhi = ty->_hi;
aoqi@0 938 jlong zlo = tz->_lo;
aoqi@0 939 jlong zhi = tz->_hi;
aoqi@0 940 jlong vbit = CONST64(1) << BitsPerInt;
aoqi@0 941 int widen = MAX2(tx->_widen, ty->_widen);
aoqi@0 942 if (op == Op_SubI) {
aoqi@0 943 jlong ylo0 = ylo;
aoqi@0 944 ylo = -yhi;
aoqi@0 945 yhi = -ylo0;
aoqi@0 946 }
aoqi@0 947 // See if x+y can cause positive overflow into z+2**32
aoqi@0 948 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
aoqi@0 949 return this_changed;
aoqi@0 950 }
aoqi@0 951 // See if x+y can cause negative overflow into z-2**32
aoqi@0 952 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
aoqi@0 953 return this_changed;
aoqi@0 954 }
aoqi@0 955 // Now it's always safe to assume x+y does not overflow.
aoqi@0 956 // This is true even if some pairs x,y might cause overflow, as long
aoqi@0 957 // as that overflow value cannot fall into [zlo,zhi].
aoqi@0 958
aoqi@0 959 // Confident that the arithmetic is "as if infinite precision",
aoqi@0 960 // we can now use z's range to put constraints on those of x and y.
aoqi@0 961 // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
aoqi@0 962 // more "restricted" range by intersecting [xlo,xhi] with the
aoqi@0 963 // range obtained by subtracting y's range from the asserted range
aoqi@0 964 // of the I2L conversion. Here's the interval arithmetic algebra:
aoqi@0 965 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
aoqi@0 966 // => x in [zlo-yhi, zhi-ylo]
aoqi@0 967 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
aoqi@0 968 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
aoqi@0 969 jlong rxlo = MAX2(xlo, zlo - yhi);
aoqi@0 970 jlong rxhi = MIN2(xhi, zhi - ylo);
aoqi@0 971 // And similarly, x changing place with y:
aoqi@0 972 jlong rylo = MAX2(ylo, zlo - xhi);
aoqi@0 973 jlong ryhi = MIN2(yhi, zhi - xlo);
aoqi@0 974 if (rxlo > rxhi || rylo > ryhi) {
aoqi@0 975 return this_changed; // x or y is dying; don't mess w/ it
aoqi@0 976 }
aoqi@0 977 if (op == Op_SubI) {
aoqi@0 978 jlong rylo0 = rylo;
aoqi@0 979 rylo = -ryhi;
aoqi@0 980 ryhi = -rylo0;
aoqi@0 981 }
aoqi@0 982
aoqi@0 983 Node* cx = phase->transform( new (phase->C) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
aoqi@0 984 Node* cy = phase->transform( new (phase->C) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
aoqi@0 985 switch (op) {
aoqi@0 986 case Op_AddI: return new (phase->C) AddLNode(cx, cy);
aoqi@0 987 case Op_SubI: return new (phase->C) SubLNode(cx, cy);
aoqi@0 988 default: ShouldNotReachHere();
aoqi@0 989 }
aoqi@0 990 }
aoqi@0 991 #endif //_LP64
aoqi@0 992
aoqi@0 993 return this_changed;
aoqi@0 994 }
aoqi@0 995
aoqi@0 996 //=============================================================================
aoqi@0 997 //------------------------------Value------------------------------------------
aoqi@0 998 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 999 const Type *t = phase->type( in(1) );
aoqi@0 1000 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1001 const TypeLong *tl = t->is_long();
aoqi@0 1002 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
aoqi@0 1003 return bottom_type();
aoqi@0 1004 }
aoqi@0 1005
aoqi@0 1006 //=============================================================================
aoqi@0 1007 //------------------------------Value------------------------------------------
aoqi@0 1008 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 1009 const Type *t = phase->type( in(1) );
aoqi@0 1010 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1011 const TypeLong *tl = t->is_long();
aoqi@0 1012 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
aoqi@0 1013 return bottom_type();
aoqi@0 1014 }
aoqi@0 1015
aoqi@0 1016 //=============================================================================
aoqi@0 1017 //----------------------------Identity-----------------------------------------
aoqi@0 1018 Node *ConvL2INode::Identity( PhaseTransform *phase ) {
aoqi@0 1019 // Convert L2I(I2L(x)) => x
aoqi@0 1020 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);
aoqi@0 1021 return this;
aoqi@0 1022 }
aoqi@0 1023
aoqi@0 1024 //------------------------------Value------------------------------------------
aoqi@0 1025 const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
aoqi@0 1026 const Type *t = phase->type( in(1) );
aoqi@0 1027 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1028 const TypeLong *tl = t->is_long();
aoqi@0 1029 if (tl->is_con())
aoqi@0 1030 // Easy case.
aoqi@0 1031 return TypeInt::make((jint)tl->get_con());
aoqi@0 1032 return bottom_type();
aoqi@0 1033 }
aoqi@0 1034
aoqi@0 1035 //------------------------------Ideal------------------------------------------
aoqi@0 1036 // Return a node which is more "ideal" than the current node.
aoqi@0 1037 // Blow off prior masking to int
aoqi@0 1038 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1039 Node *andl = in(1);
aoqi@0 1040 uint andl_op = andl->Opcode();
aoqi@0 1041 if( andl_op == Op_AndL ) {
aoqi@0 1042 // Blow off prior masking to int
aoqi@0 1043 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
aoqi@0 1044 set_req(1,andl->in(1));
aoqi@0 1045 return this;
aoqi@0 1046 }
aoqi@0 1047 }
aoqi@0 1048
aoqi@0 1049 // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
aoqi@0 1050 // This replaces an 'AddL' with an 'AddI'.
aoqi@0 1051 if( andl_op == Op_AddL ) {
aoqi@0 1052 // Don't do this for nodes which have more than one user since
aoqi@0 1053 // we'll end up computing the long add anyway.
aoqi@0 1054 if (andl->outcnt() > 1) return NULL;
aoqi@0 1055
aoqi@0 1056 Node* x = andl->in(1);
aoqi@0 1057 Node* y = andl->in(2);
aoqi@0 1058 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
aoqi@0 1059 if (phase->type(x) == Type::TOP) return NULL;
aoqi@0 1060 if (phase->type(y) == Type::TOP) return NULL;
aoqi@0 1061 Node *add1 = phase->transform(new (phase->C) ConvL2INode(x));
aoqi@0 1062 Node *add2 = phase->transform(new (phase->C) ConvL2INode(y));
aoqi@0 1063 return new (phase->C) AddINode(add1,add2);
aoqi@0 1064 }
aoqi@0 1065
aoqi@0 1066 // Disable optimization: LoadL->ConvL2I ==> LoadI.
aoqi@0 1067 // It causes problems (sizes of Load and Store nodes do not match)
aoqi@0 1068 // in objects initialization code and Escape Analysis.
aoqi@0 1069 return NULL;
aoqi@0 1070 }
aoqi@0 1071
aoqi@0 1072 //=============================================================================
aoqi@0 1073 //------------------------------Value------------------------------------------
aoqi@0 1074 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
aoqi@0 1075 const Type* t = phase->type(in(1));
aoqi@0 1076 if (t == Type::TOP) return Type::TOP;
aoqi@0 1077 if (t->base() == Type_X && t->singleton()) {
aoqi@0 1078 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
aoqi@0 1079 if (bits == 0) return TypePtr::NULL_PTR;
aoqi@0 1080 return TypeRawPtr::make((address) bits);
aoqi@0 1081 }
aoqi@0 1082 return CastX2PNode::bottom_type();
aoqi@0 1083 }
aoqi@0 1084
aoqi@0 1085 //------------------------------Idealize---------------------------------------
aoqi@0 1086 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
aoqi@0 1087 if (t == Type::TOP) return false;
aoqi@0 1088 const TypeX* tl = t->is_intptr_t();
aoqi@0 1089 jint lo = min_jint;
aoqi@0 1090 jint hi = max_jint;
aoqi@0 1091 if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow
aoqi@0 1092 return (tl->_lo >= lo) && (tl->_hi <= hi);
aoqi@0 1093 }
aoqi@0 1094
aoqi@0 1095 static inline Node* addP_of_X2P(PhaseGVN *phase,
aoqi@0 1096 Node* base,
aoqi@0 1097 Node* dispX,
aoqi@0 1098 bool negate = false) {
aoqi@0 1099 if (negate) {
aoqi@0 1100 dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX));
aoqi@0 1101 }
aoqi@0 1102 return new (phase->C) AddPNode(phase->C->top(),
aoqi@0 1103 phase->transform(new (phase->C) CastX2PNode(base)),
aoqi@0 1104 phase->transform(dispX));
aoqi@0 1105 }
aoqi@0 1106
aoqi@0 1107 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1108 // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
aoqi@0 1109 int op = in(1)->Opcode();
aoqi@0 1110 Node* x;
aoqi@0 1111 Node* y;
aoqi@0 1112 switch (op) {
aoqi@0 1113 case Op_SubX:
aoqi@0 1114 x = in(1)->in(1);
aoqi@0 1115 // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
aoqi@0 1116 if (phase->find_intptr_t_con(x, -1) == 0)
aoqi@0 1117 break;
aoqi@0 1118 y = in(1)->in(2);
aoqi@0 1119 if (fits_in_int(phase->type(y), true)) {
aoqi@0 1120 return addP_of_X2P(phase, x, y, true);
aoqi@0 1121 }
aoqi@0 1122 break;
aoqi@0 1123 case Op_AddX:
aoqi@0 1124 x = in(1)->in(1);
aoqi@0 1125 y = in(1)->in(2);
aoqi@0 1126 if (fits_in_int(phase->type(y))) {
aoqi@0 1127 return addP_of_X2P(phase, x, y);
aoqi@0 1128 }
aoqi@0 1129 if (fits_in_int(phase->type(x))) {
aoqi@0 1130 return addP_of_X2P(phase, y, x);
aoqi@0 1131 }
aoqi@0 1132 break;
aoqi@0 1133 }
aoqi@0 1134 return NULL;
aoqi@0 1135 }
aoqi@0 1136
aoqi@0 1137 //------------------------------Identity---------------------------------------
aoqi@0 1138 Node *CastX2PNode::Identity( PhaseTransform *phase ) {
aoqi@0 1139 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
aoqi@0 1140 return this;
aoqi@0 1141 }
aoqi@0 1142
aoqi@0 1143 //=============================================================================
aoqi@0 1144 //------------------------------Value------------------------------------------
aoqi@0 1145 const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
aoqi@0 1146 const Type* t = phase->type(in(1));
aoqi@0 1147 if (t == Type::TOP) return Type::TOP;
aoqi@0 1148 if (t->base() == Type::RawPtr && t->singleton()) {
aoqi@0 1149 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
aoqi@0 1150 return TypeX::make(bits);
aoqi@0 1151 }
aoqi@0 1152 return CastP2XNode::bottom_type();
aoqi@0 1153 }
aoqi@0 1154
aoqi@0 1155 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1156 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
aoqi@0 1157 }
aoqi@0 1158
aoqi@0 1159 //------------------------------Identity---------------------------------------
aoqi@0 1160 Node *CastP2XNode::Identity( PhaseTransform *phase ) {
aoqi@0 1161 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
aoqi@0 1162 return this;
aoqi@0 1163 }
aoqi@0 1164
aoqi@0 1165
aoqi@0 1166 //=============================================================================
aoqi@0 1167 //------------------------------Identity---------------------------------------
aoqi@0 1168 // Remove redundant roundings
aoqi@0 1169 Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
aoqi@0 1170 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
aoqi@0 1171 // Do not round constants
aoqi@0 1172 if (phase->type(in(1))->base() == Type::FloatCon) return in(1);
aoqi@0 1173 int op = in(1)->Opcode();
aoqi@0 1174 // Redundant rounding
aoqi@0 1175 if( op == Op_RoundFloat ) return in(1);
aoqi@0 1176 // Already rounded
aoqi@0 1177 if( op == Op_Parm ) return in(1);
aoqi@0 1178 if( op == Op_LoadF ) return in(1);
aoqi@0 1179 return this;
aoqi@0 1180 }
aoqi@0 1181
aoqi@0 1182 //------------------------------Value------------------------------------------
aoqi@0 1183 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
aoqi@0 1184 return phase->type( in(1) );
aoqi@0 1185 }
aoqi@0 1186
aoqi@0 1187 //=============================================================================
aoqi@0 1188 //------------------------------Identity---------------------------------------
aoqi@0 1189 // Remove redundant roundings. Incoming arguments are already rounded.
aoqi@0 1190 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
aoqi@0 1191 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
aoqi@0 1192 // Do not round constants
aoqi@0 1193 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);
aoqi@0 1194 int op = in(1)->Opcode();
aoqi@0 1195 // Redundant rounding
aoqi@0 1196 if( op == Op_RoundDouble ) return in(1);
aoqi@0 1197 // Already rounded
aoqi@0 1198 if( op == Op_Parm ) return in(1);
aoqi@0 1199 if( op == Op_LoadD ) return in(1);
aoqi@0 1200 if( op == Op_ConvF2D ) return in(1);
aoqi@0 1201 if( op == Op_ConvI2D ) return in(1);
aoqi@0 1202 return this;
aoqi@0 1203 }
aoqi@0 1204
aoqi@0 1205 //------------------------------Value------------------------------------------
aoqi@0 1206 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
aoqi@0 1207 return phase->type( in(1) );
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210
aoqi@0 1211 //=============================================================================
aoqi@0 1212 // Do not allow value-numbering
aoqi@0 1213 uint Opaque1Node::hash() const { return NO_HASH; }
aoqi@0 1214 uint Opaque1Node::cmp( const Node &n ) const {
aoqi@0 1215 return (&n == this); // Always fail except on self
aoqi@0 1216 }
aoqi@0 1217
aoqi@0 1218 //------------------------------Identity---------------------------------------
aoqi@0 1219 // If _major_progress, then more loop optimizations follow. Do NOT remove
aoqi@0 1220 // the opaque Node until no more loop ops can happen. Note the timing of
aoqi@0 1221 // _major_progress; it's set in the major loop optimizations THEN comes the
aoqi@0 1222 // call to IterGVN and any chance of hitting this code. Hence there's no
aoqi@0 1223 // phase-ordering problem with stripping Opaque1 in IGVN followed by some
aoqi@0 1224 // more loop optimizations that require it.
aoqi@0 1225 Node *Opaque1Node::Identity( PhaseTransform *phase ) {
aoqi@0 1226 return phase->C->major_progress() ? this : in(1);
aoqi@0 1227 }
aoqi@0 1228
aoqi@0 1229 //=============================================================================
aoqi@0 1230 // A node to prevent unwanted optimizations. Allows constant folding. Stops
aoqi@0 1231 // value-numbering, most Ideal calls or Identity functions. This Node is
aoqi@0 1232 // specifically designed to prevent the pre-increment value of a loop trip
aoqi@0 1233 // counter from being live out of the bottom of the loop (hence causing the
aoqi@0 1234 // pre- and post-increment values both being live and thus requiring an extra
aoqi@0 1235 // temp register and an extra move). If we "accidentally" optimize through
aoqi@0 1236 // this kind of a Node, we'll get slightly pessimal, but correct, code. Thus
aoqi@0 1237 // it's OK to be slightly sloppy on optimizations here.
aoqi@0 1238
aoqi@0 1239 // Do not allow value-numbering
aoqi@0 1240 uint Opaque2Node::hash() const { return NO_HASH; }
aoqi@0 1241 uint Opaque2Node::cmp( const Node &n ) const {
aoqi@0 1242 return (&n == this); // Always fail except on self
aoqi@0 1243 }
aoqi@0 1244
aoqi@0 1245
aoqi@0 1246 //------------------------------Value------------------------------------------
aoqi@0 1247 const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
aoqi@0 1248 const Type *t = phase->type( in(1) );
aoqi@0 1249 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1250 const TypeLong *tl = t->is_long();
aoqi@0 1251 if( !tl->is_con() ) return bottom_type();
aoqi@0 1252 JavaValue v;
aoqi@0 1253 v.set_jlong(tl->get_con());
aoqi@0 1254 return TypeD::make( v.get_jdouble() );
aoqi@0 1255 }
aoqi@0 1256
aoqi@0 1257 //------------------------------Value------------------------------------------
aoqi@0 1258 const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
aoqi@0 1259 const Type *t = phase->type( in(1) );
aoqi@0 1260 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1261 const TypeInt *ti = t->is_int();
aoqi@0 1262 if( !ti->is_con() ) return bottom_type();
aoqi@0 1263 JavaValue v;
aoqi@0 1264 v.set_jint(ti->get_con());
aoqi@0 1265 return TypeF::make( v.get_jfloat() );
aoqi@0 1266 }
aoqi@0 1267
aoqi@0 1268 //------------------------------Value------------------------------------------
aoqi@0 1269 const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
aoqi@0 1270 const Type *t = phase->type( in(1) );
aoqi@0 1271 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1272 if( t == Type::FLOAT ) return TypeInt::INT;
aoqi@0 1273 const TypeF *tf = t->is_float_constant();
aoqi@0 1274 JavaValue v;
aoqi@0 1275 v.set_jfloat(tf->getf());
aoqi@0 1276 return TypeInt::make( v.get_jint() );
aoqi@0 1277 }
aoqi@0 1278
aoqi@0 1279 //------------------------------Value------------------------------------------
aoqi@0 1280 const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
aoqi@0 1281 const Type *t = phase->type( in(1) );
aoqi@0 1282 if( t == Type::TOP ) return Type::TOP;
aoqi@0 1283 if( t == Type::DOUBLE ) return TypeLong::LONG;
aoqi@0 1284 const TypeD *td = t->is_double_constant();
aoqi@0 1285 JavaValue v;
aoqi@0 1286 v.set_jdouble(td->getd());
aoqi@0 1287 return TypeLong::make( v.get_jlong() );
aoqi@0 1288 }
aoqi@0 1289
aoqi@0 1290 //------------------------------Value------------------------------------------
aoqi@0 1291 const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const {
aoqi@0 1292 const Type* t = phase->type(in(1));
aoqi@0 1293 if (t == Type::TOP) return Type::TOP;
aoqi@0 1294 const TypeInt* ti = t->isa_int();
aoqi@0 1295 if (ti && ti->is_con()) {
aoqi@0 1296 jint i = ti->get_con();
aoqi@0 1297 // HD, Figure 5-6
aoqi@0 1298 if (i == 0)
aoqi@0 1299 return TypeInt::make(BitsPerInt);
aoqi@0 1300 int n = 1;
aoqi@0 1301 unsigned int x = i;
aoqi@0 1302 if (x >> 16 == 0) { n += 16; x <<= 16; }
aoqi@0 1303 if (x >> 24 == 0) { n += 8; x <<= 8; }
aoqi@0 1304 if (x >> 28 == 0) { n += 4; x <<= 4; }
aoqi@0 1305 if (x >> 30 == 0) { n += 2; x <<= 2; }
aoqi@0 1306 n -= x >> 31;
aoqi@0 1307 return TypeInt::make(n);
aoqi@0 1308 }
aoqi@0 1309 return TypeInt::INT;
aoqi@0 1310 }
aoqi@0 1311
aoqi@0 1312 //------------------------------Value------------------------------------------
aoqi@0 1313 const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const {
aoqi@0 1314 const Type* t = phase->type(in(1));
aoqi@0 1315 if (t == Type::TOP) return Type::TOP;
aoqi@0 1316 const TypeLong* tl = t->isa_long();
aoqi@0 1317 if (tl && tl->is_con()) {
aoqi@0 1318 jlong l = tl->get_con();
aoqi@0 1319 // HD, Figure 5-6
aoqi@0 1320 if (l == 0)
aoqi@0 1321 return TypeInt::make(BitsPerLong);
aoqi@0 1322 int n = 1;
aoqi@0 1323 unsigned int x = (((julong) l) >> 32);
aoqi@0 1324 if (x == 0) { n += 32; x = (int) l; }
aoqi@0 1325 if (x >> 16 == 0) { n += 16; x <<= 16; }
aoqi@0 1326 if (x >> 24 == 0) { n += 8; x <<= 8; }
aoqi@0 1327 if (x >> 28 == 0) { n += 4; x <<= 4; }
aoqi@0 1328 if (x >> 30 == 0) { n += 2; x <<= 2; }
aoqi@0 1329 n -= x >> 31;
aoqi@0 1330 return TypeInt::make(n);
aoqi@0 1331 }
aoqi@0 1332 return TypeInt::INT;
aoqi@0 1333 }
aoqi@0 1334
aoqi@0 1335 //------------------------------Value------------------------------------------
aoqi@0 1336 const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const {
aoqi@0 1337 const Type* t = phase->type(in(1));
aoqi@0 1338 if (t == Type::TOP) return Type::TOP;
aoqi@0 1339 const TypeInt* ti = t->isa_int();
aoqi@0 1340 if (ti && ti->is_con()) {
aoqi@0 1341 jint i = ti->get_con();
aoqi@0 1342 // HD, Figure 5-14
aoqi@0 1343 int y;
aoqi@0 1344 if (i == 0)
aoqi@0 1345 return TypeInt::make(BitsPerInt);
aoqi@0 1346 int n = 31;
aoqi@0 1347 y = i << 16; if (y != 0) { n = n - 16; i = y; }
aoqi@0 1348 y = i << 8; if (y != 0) { n = n - 8; i = y; }
aoqi@0 1349 y = i << 4; if (y != 0) { n = n - 4; i = y; }
aoqi@0 1350 y = i << 2; if (y != 0) { n = n - 2; i = y; }
aoqi@0 1351 y = i << 1; if (y != 0) { n = n - 1; }
aoqi@0 1352 return TypeInt::make(n);
aoqi@0 1353 }
aoqi@0 1354 return TypeInt::INT;
aoqi@0 1355 }
aoqi@0 1356
aoqi@0 1357 //------------------------------Value------------------------------------------
aoqi@0 1358 const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const {
aoqi@0 1359 const Type* t = phase->type(in(1));
aoqi@0 1360 if (t == Type::TOP) return Type::TOP;
aoqi@0 1361 const TypeLong* tl = t->isa_long();
aoqi@0 1362 if (tl && tl->is_con()) {
aoqi@0 1363 jlong l = tl->get_con();
aoqi@0 1364 // HD, Figure 5-14
aoqi@0 1365 int x, y;
aoqi@0 1366 if (l == 0)
aoqi@0 1367 return TypeInt::make(BitsPerLong);
aoqi@0 1368 int n = 63;
aoqi@0 1369 y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);
aoqi@0 1370 y = x << 16; if (y != 0) { n = n - 16; x = y; }
aoqi@0 1371 y = x << 8; if (y != 0) { n = n - 8; x = y; }
aoqi@0 1372 y = x << 4; if (y != 0) { n = n - 4; x = y; }
aoqi@0 1373 y = x << 2; if (y != 0) { n = n - 2; x = y; }
aoqi@0 1374 y = x << 1; if (y != 0) { n = n - 1; }
aoqi@0 1375 return TypeInt::make(n);
aoqi@0 1376 }
aoqi@0 1377 return TypeInt::INT;
aoqi@0 1378 }

mercurial