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