src/share/vm/opto/connode.cpp

Wed, 10 Aug 2016 14:59:21 +0200

author
simonis
date
Wed, 10 Aug 2016 14:59:21 +0200
changeset 8608
0d78aecb0948
parent 8435
64bd5b63923c
child 8604
04d83ba48607
child 8727
3d8d14307428
permissions
-rw-r--r--

8152172: PPC64: Support AES intrinsics
Summary: Add support for AES intrinsics on PPC64.
Reviewed-by: kvn, mdoerr, simonis, zmajo
Contributed-by: Hiroshi H Horii <horii@jp.ibm.com>

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

mercurial