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