1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/subnode.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,1468 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "compiler/compileLog.hpp" 1.30 +#include "memory/allocation.inline.hpp" 1.31 +#include "opto/addnode.hpp" 1.32 +#include "opto/callnode.hpp" 1.33 +#include "opto/cfgnode.hpp" 1.34 +#include "opto/connode.hpp" 1.35 +#include "opto/loopnode.hpp" 1.36 +#include "opto/matcher.hpp" 1.37 +#include "opto/mulnode.hpp" 1.38 +#include "opto/opcodes.hpp" 1.39 +#include "opto/phaseX.hpp" 1.40 +#include "opto/subnode.hpp" 1.41 +#include "runtime/sharedRuntime.hpp" 1.42 + 1.43 +// Portions of code courtesy of Clifford Click 1.44 + 1.45 +// Optimization - Graph Style 1.46 + 1.47 +#include "math.h" 1.48 + 1.49 +//============================================================================= 1.50 +//------------------------------Identity--------------------------------------- 1.51 +// If right input is a constant 0, return the left input. 1.52 +Node *SubNode::Identity( PhaseTransform *phase ) { 1.53 + assert(in(1) != this, "Must already have called Value"); 1.54 + assert(in(2) != this, "Must already have called Value"); 1.55 + 1.56 + // Remove double negation 1.57 + const Type *zero = add_id(); 1.58 + if( phase->type( in(1) )->higher_equal( zero ) && 1.59 + in(2)->Opcode() == Opcode() && 1.60 + phase->type( in(2)->in(1) )->higher_equal( zero ) ) { 1.61 + return in(2)->in(2); 1.62 + } 1.63 + 1.64 + // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y 1.65 + if( in(1)->Opcode() == Op_AddI ) { 1.66 + if( phase->eqv(in(1)->in(2),in(2)) ) 1.67 + return in(1)->in(1); 1.68 + if (phase->eqv(in(1)->in(1),in(2))) 1.69 + return in(1)->in(2); 1.70 + 1.71 + // Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying 1.72 + // trip counter and X is likely to be loop-invariant (that's how O2 Nodes 1.73 + // are originally used, although the optimizer sometimes jiggers things). 1.74 + // This folding through an O2 removes a loop-exit use of a loop-varying 1.75 + // value and generally lowers register pressure in and around the loop. 1.76 + if( in(1)->in(2)->Opcode() == Op_Opaque2 && 1.77 + phase->eqv(in(1)->in(2)->in(1),in(2)) ) 1.78 + return in(1)->in(1); 1.79 + } 1.80 + 1.81 + return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this; 1.82 +} 1.83 + 1.84 +//------------------------------Value------------------------------------------ 1.85 +// A subtract node differences it's two inputs. 1.86 +const Type* SubNode::Value_common(PhaseTransform *phase) const { 1.87 + const Node* in1 = in(1); 1.88 + const Node* in2 = in(2); 1.89 + // Either input is TOP ==> the result is TOP 1.90 + const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1.91 + if( t1 == Type::TOP ) return Type::TOP; 1.92 + const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1.93 + if( t2 == Type::TOP ) return Type::TOP; 1.94 + 1.95 + // Not correct for SubFnode and AddFNode (must check for infinity) 1.96 + // Equal? Subtract is zero 1.97 + if (in1->eqv_uncast(in2)) return add_id(); 1.98 + 1.99 + // Either input is BOTTOM ==> the result is the local BOTTOM 1.100 + if( t1 == Type::BOTTOM || t2 == Type::BOTTOM ) 1.101 + return bottom_type(); 1.102 + 1.103 + return NULL; 1.104 +} 1.105 + 1.106 +const Type* SubNode::Value(PhaseTransform *phase) const { 1.107 + const Type* t = Value_common(phase); 1.108 + if (t != NULL) { 1.109 + return t; 1.110 + } 1.111 + const Type* t1 = phase->type(in(1)); 1.112 + const Type* t2 = phase->type(in(2)); 1.113 + return sub(t1,t2); // Local flavor of type subtraction 1.114 + 1.115 +} 1.116 + 1.117 +//============================================================================= 1.118 + 1.119 +//------------------------------Helper function-------------------------------- 1.120 +static bool ok_to_convert(Node* inc, Node* iv) { 1.121 + // Do not collapse (x+c0)-y if "+" is a loop increment, because the 1.122 + // "-" is loop invariant and collapsing extends the live-range of "x" 1.123 + // to overlap with the "+", forcing another register to be used in 1.124 + // the loop. 1.125 + // This test will be clearer with '&&' (apply DeMorgan's rule) 1.126 + // but I like the early cutouts that happen here. 1.127 + const PhiNode *phi; 1.128 + if( ( !inc->in(1)->is_Phi() || 1.129 + !(phi=inc->in(1)->as_Phi()) || 1.130 + phi->is_copy() || 1.131 + !phi->region()->is_CountedLoop() || 1.132 + inc != phi->region()->as_CountedLoop()->incr() ) 1.133 + && 1.134 + // Do not collapse (x+c0)-iv if "iv" is a loop induction variable, 1.135 + // because "x" maybe invariant. 1.136 + ( !iv->is_loop_iv() ) 1.137 + ) { 1.138 + return true; 1.139 + } else { 1.140 + return false; 1.141 + } 1.142 +} 1.143 +//------------------------------Ideal------------------------------------------ 1.144 +Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){ 1.145 + Node *in1 = in(1); 1.146 + Node *in2 = in(2); 1.147 + uint op1 = in1->Opcode(); 1.148 + uint op2 = in2->Opcode(); 1.149 + 1.150 +#ifdef ASSERT 1.151 + // Check for dead loop 1.152 + if( phase->eqv( in1, this ) || phase->eqv( in2, this ) || 1.153 + ( op1 == Op_AddI || op1 == Op_SubI ) && 1.154 + ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) || 1.155 + phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) ) 1.156 + assert(false, "dead loop in SubINode::Ideal"); 1.157 +#endif 1.158 + 1.159 + const Type *t2 = phase->type( in2 ); 1.160 + if( t2 == Type::TOP ) return NULL; 1.161 + // Convert "x-c0" into "x+ -c0". 1.162 + if( t2->base() == Type::Int ){ // Might be bottom or top... 1.163 + const TypeInt *i = t2->is_int(); 1.164 + if( i->is_con() ) 1.165 + return new (phase->C) AddINode(in1, phase->intcon(-i->get_con())); 1.166 + } 1.167 + 1.168 + // Convert "(x+c0) - y" into (x-y) + c0" 1.169 + // Do not collapse (x+c0)-y if "+" is a loop increment or 1.170 + // if "y" is a loop induction variable. 1.171 + if( op1 == Op_AddI && ok_to_convert(in1, in2) ) { 1.172 + const Type *tadd = phase->type( in1->in(2) ); 1.173 + if( tadd->singleton() && tadd != Type::TOP ) { 1.174 + Node *sub2 = phase->transform( new (phase->C) SubINode( in1->in(1), in2 )); 1.175 + return new (phase->C) AddINode( sub2, in1->in(2) ); 1.176 + } 1.177 + } 1.178 + 1.179 + 1.180 + // Convert "x - (y+c0)" into "(x-y) - c0" 1.181 + // Need the same check as in above optimization but reversed. 1.182 + if (op2 == Op_AddI && ok_to_convert(in2, in1)) { 1.183 + Node* in21 = in2->in(1); 1.184 + Node* in22 = in2->in(2); 1.185 + const TypeInt* tcon = phase->type(in22)->isa_int(); 1.186 + if (tcon != NULL && tcon->is_con()) { 1.187 + Node* sub2 = phase->transform( new (phase->C) SubINode(in1, in21) ); 1.188 + Node* neg_c0 = phase->intcon(- tcon->get_con()); 1.189 + return new (phase->C) AddINode(sub2, neg_c0); 1.190 + } 1.191 + } 1.192 + 1.193 + const Type *t1 = phase->type( in1 ); 1.194 + if( t1 == Type::TOP ) return NULL; 1.195 + 1.196 +#ifdef ASSERT 1.197 + // Check for dead loop 1.198 + if( ( op2 == Op_AddI || op2 == Op_SubI ) && 1.199 + ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) || 1.200 + phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) ) 1.201 + assert(false, "dead loop in SubINode::Ideal"); 1.202 +#endif 1.203 + 1.204 + // Convert "x - (x+y)" into "-y" 1.205 + if( op2 == Op_AddI && 1.206 + phase->eqv( in1, in2->in(1) ) ) 1.207 + return new (phase->C) SubINode( phase->intcon(0),in2->in(2)); 1.208 + // Convert "(x-y) - x" into "-y" 1.209 + if( op1 == Op_SubI && 1.210 + phase->eqv( in1->in(1), in2 ) ) 1.211 + return new (phase->C) SubINode( phase->intcon(0),in1->in(2)); 1.212 + // Convert "x - (y+x)" into "-y" 1.213 + if( op2 == Op_AddI && 1.214 + phase->eqv( in1, in2->in(2) ) ) 1.215 + return new (phase->C) SubINode( phase->intcon(0),in2->in(1)); 1.216 + 1.217 + // Convert "0 - (x-y)" into "y-x" 1.218 + if( t1 == TypeInt::ZERO && op2 == Op_SubI ) 1.219 + return new (phase->C) SubINode( in2->in(2), in2->in(1) ); 1.220 + 1.221 + // Convert "0 - (x+con)" into "-con-x" 1.222 + jint con; 1.223 + if( t1 == TypeInt::ZERO && op2 == Op_AddI && 1.224 + (con = in2->in(2)->find_int_con(0)) != 0 ) 1.225 + return new (phase->C) SubINode( phase->intcon(-con), in2->in(1) ); 1.226 + 1.227 + // Convert "(X+A) - (X+B)" into "A - B" 1.228 + if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) ) 1.229 + return new (phase->C) SubINode( in1->in(2), in2->in(2) ); 1.230 + 1.231 + // Convert "(A+X) - (B+X)" into "A - B" 1.232 + if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) ) 1.233 + return new (phase->C) SubINode( in1->in(1), in2->in(1) ); 1.234 + 1.235 + // Convert "(A+X) - (X+B)" into "A - B" 1.236 + if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) ) 1.237 + return new (phase->C) SubINode( in1->in(1), in2->in(2) ); 1.238 + 1.239 + // Convert "(X+A) - (B+X)" into "A - B" 1.240 + if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) 1.241 + return new (phase->C) SubINode( in1->in(2), in2->in(1) ); 1.242 + 1.243 + // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally 1.244 + // nicer to optimize than subtract. 1.245 + if( op2 == Op_SubI && in2->outcnt() == 1) { 1.246 + Node *add1 = phase->transform( new (phase->C) AddINode( in1, in2->in(2) ) ); 1.247 + return new (phase->C) SubINode( add1, in2->in(1) ); 1.248 + } 1.249 + 1.250 + return NULL; 1.251 +} 1.252 + 1.253 +//------------------------------sub-------------------------------------------- 1.254 +// A subtract node differences it's two inputs. 1.255 +const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { 1.256 + const TypeInt *r0 = t1->is_int(); // Handy access 1.257 + const TypeInt *r1 = t2->is_int(); 1.258 + int32 lo = r0->_lo - r1->_hi; 1.259 + int32 hi = r0->_hi - r1->_lo; 1.260 + 1.261 + // We next check for 32-bit overflow. 1.262 + // If that happens, we just assume all integers are possible. 1.263 + if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 1.264 + ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 1.265 + (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 1.266 + ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 1.267 + return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 1.268 + else // Overflow; assume all integers 1.269 + return TypeInt::INT; 1.270 +} 1.271 + 1.272 +//============================================================================= 1.273 +//------------------------------Ideal------------------------------------------ 1.274 +Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1.275 + Node *in1 = in(1); 1.276 + Node *in2 = in(2); 1.277 + uint op1 = in1->Opcode(); 1.278 + uint op2 = in2->Opcode(); 1.279 + 1.280 +#ifdef ASSERT 1.281 + // Check for dead loop 1.282 + if( phase->eqv( in1, this ) || phase->eqv( in2, this ) || 1.283 + ( op1 == Op_AddL || op1 == Op_SubL ) && 1.284 + ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) || 1.285 + phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) ) 1.286 + assert(false, "dead loop in SubLNode::Ideal"); 1.287 +#endif 1.288 + 1.289 + if( phase->type( in2 ) == Type::TOP ) return NULL; 1.290 + const TypeLong *i = phase->type( in2 )->isa_long(); 1.291 + // Convert "x-c0" into "x+ -c0". 1.292 + if( i && // Might be bottom or top... 1.293 + i->is_con() ) 1.294 + return new (phase->C) AddLNode(in1, phase->longcon(-i->get_con())); 1.295 + 1.296 + // Convert "(x+c0) - y" into (x-y) + c0" 1.297 + // Do not collapse (x+c0)-y if "+" is a loop increment or 1.298 + // if "y" is a loop induction variable. 1.299 + if( op1 == Op_AddL && ok_to_convert(in1, in2) ) { 1.300 + Node *in11 = in1->in(1); 1.301 + const Type *tadd = phase->type( in1->in(2) ); 1.302 + if( tadd->singleton() && tadd != Type::TOP ) { 1.303 + Node *sub2 = phase->transform( new (phase->C) SubLNode( in11, in2 )); 1.304 + return new (phase->C) AddLNode( sub2, in1->in(2) ); 1.305 + } 1.306 + } 1.307 + 1.308 + // Convert "x - (y+c0)" into "(x-y) - c0" 1.309 + // Need the same check as in above optimization but reversed. 1.310 + if (op2 == Op_AddL && ok_to_convert(in2, in1)) { 1.311 + Node* in21 = in2->in(1); 1.312 + Node* in22 = in2->in(2); 1.313 + const TypeLong* tcon = phase->type(in22)->isa_long(); 1.314 + if (tcon != NULL && tcon->is_con()) { 1.315 + Node* sub2 = phase->transform( new (phase->C) SubLNode(in1, in21) ); 1.316 + Node* neg_c0 = phase->longcon(- tcon->get_con()); 1.317 + return new (phase->C) AddLNode(sub2, neg_c0); 1.318 + } 1.319 + } 1.320 + 1.321 + const Type *t1 = phase->type( in1 ); 1.322 + if( t1 == Type::TOP ) return NULL; 1.323 + 1.324 +#ifdef ASSERT 1.325 + // Check for dead loop 1.326 + if( ( op2 == Op_AddL || op2 == Op_SubL ) && 1.327 + ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) || 1.328 + phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) ) 1.329 + assert(false, "dead loop in SubLNode::Ideal"); 1.330 +#endif 1.331 + 1.332 + // Convert "x - (x+y)" into "-y" 1.333 + if( op2 == Op_AddL && 1.334 + phase->eqv( in1, in2->in(1) ) ) 1.335 + return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2)); 1.336 + // Convert "x - (y+x)" into "-y" 1.337 + if( op2 == Op_AddL && 1.338 + phase->eqv( in1, in2->in(2) ) ) 1.339 + return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1)); 1.340 + 1.341 + // Convert "0 - (x-y)" into "y-x" 1.342 + if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL ) 1.343 + return new (phase->C) SubLNode( in2->in(2), in2->in(1) ); 1.344 + 1.345 + // Convert "(X+A) - (X+B)" into "A - B" 1.346 + if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) ) 1.347 + return new (phase->C) SubLNode( in1->in(2), in2->in(2) ); 1.348 + 1.349 + // Convert "(A+X) - (B+X)" into "A - B" 1.350 + if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) ) 1.351 + return new (phase->C) SubLNode( in1->in(1), in2->in(1) ); 1.352 + 1.353 + // Convert "A-(B-C)" into (A+C)-B" 1.354 + if( op2 == Op_SubL && in2->outcnt() == 1) { 1.355 + Node *add1 = phase->transform( new (phase->C) AddLNode( in1, in2->in(2) ) ); 1.356 + return new (phase->C) SubLNode( add1, in2->in(1) ); 1.357 + } 1.358 + 1.359 + return NULL; 1.360 +} 1.361 + 1.362 +//------------------------------sub-------------------------------------------- 1.363 +// A subtract node differences it's two inputs. 1.364 +const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const { 1.365 + const TypeLong *r0 = t1->is_long(); // Handy access 1.366 + const TypeLong *r1 = t2->is_long(); 1.367 + jlong lo = r0->_lo - r1->_hi; 1.368 + jlong hi = r0->_hi - r1->_lo; 1.369 + 1.370 + // We next check for 32-bit overflow. 1.371 + // If that happens, we just assume all integers are possible. 1.372 + if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 1.373 + ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 1.374 + (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 1.375 + ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 1.376 + return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 1.377 + else // Overflow; assume all integers 1.378 + return TypeLong::LONG; 1.379 +} 1.380 + 1.381 +//============================================================================= 1.382 +//------------------------------Value------------------------------------------ 1.383 +// A subtract node differences its two inputs. 1.384 +const Type *SubFPNode::Value( PhaseTransform *phase ) const { 1.385 + const Node* in1 = in(1); 1.386 + const Node* in2 = in(2); 1.387 + // Either input is TOP ==> the result is TOP 1.388 + const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1.389 + if( t1 == Type::TOP ) return Type::TOP; 1.390 + const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1.391 + if( t2 == Type::TOP ) return Type::TOP; 1.392 + 1.393 + // if both operands are infinity of same sign, the result is NaN; do 1.394 + // not replace with zero 1.395 + if( (t1->is_finite() && t2->is_finite()) ) { 1.396 + if( phase->eqv(in1, in2) ) return add_id(); 1.397 + } 1.398 + 1.399 + // Either input is BOTTOM ==> the result is the local BOTTOM 1.400 + const Type *bot = bottom_type(); 1.401 + if( (t1 == bot) || (t2 == bot) || 1.402 + (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) 1.403 + return bot; 1.404 + 1.405 + return sub(t1,t2); // Local flavor of type subtraction 1.406 +} 1.407 + 1.408 + 1.409 +//============================================================================= 1.410 +//------------------------------Ideal------------------------------------------ 1.411 +Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1.412 + const Type *t2 = phase->type( in(2) ); 1.413 + // Convert "x-c0" into "x+ -c0". 1.414 + if( t2->base() == Type::FloatCon ) { // Might be bottom or top... 1.415 + // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) ); 1.416 + } 1.417 + 1.418 + // Not associative because of boundary conditions (infinity) 1.419 + if( IdealizedNumerics && !phase->C->method()->is_strict() ) { 1.420 + // Convert "x - (x+y)" into "-y" 1.421 + if( in(2)->is_Add() && 1.422 + phase->eqv(in(1),in(2)->in(1) ) ) 1.423 + return new (phase->C) SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2)); 1.424 + } 1.425 + 1.426 + // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes 1.427 + // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0. 1.428 + //if( phase->type(in(1)) == TypeF::ZERO ) 1.429 + //return new (phase->C, 2) NegFNode(in(2)); 1.430 + 1.431 + return NULL; 1.432 +} 1.433 + 1.434 +//------------------------------sub-------------------------------------------- 1.435 +// A subtract node differences its two inputs. 1.436 +const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const { 1.437 + // no folding if one of operands is infinity or NaN, do not do constant folding 1.438 + if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) { 1.439 + return TypeF::make( t1->getf() - t2->getf() ); 1.440 + } 1.441 + else if( g_isnan(t1->getf()) ) { 1.442 + return t1; 1.443 + } 1.444 + else if( g_isnan(t2->getf()) ) { 1.445 + return t2; 1.446 + } 1.447 + else { 1.448 + return Type::FLOAT; 1.449 + } 1.450 +} 1.451 + 1.452 +//============================================================================= 1.453 +//------------------------------Ideal------------------------------------------ 1.454 +Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){ 1.455 + const Type *t2 = phase->type( in(2) ); 1.456 + // Convert "x-c0" into "x+ -c0". 1.457 + if( t2->base() == Type::DoubleCon ) { // Might be bottom or top... 1.458 + // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) ); 1.459 + } 1.460 + 1.461 + // Not associative because of boundary conditions (infinity) 1.462 + if( IdealizedNumerics && !phase->C->method()->is_strict() ) { 1.463 + // Convert "x - (x+y)" into "-y" 1.464 + if( in(2)->is_Add() && 1.465 + phase->eqv(in(1),in(2)->in(1) ) ) 1.466 + return new (phase->C) SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2)); 1.467 + } 1.468 + 1.469 + // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes 1.470 + // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0. 1.471 + //if( phase->type(in(1)) == TypeD::ZERO ) 1.472 + //return new (phase->C, 2) NegDNode(in(2)); 1.473 + 1.474 + return NULL; 1.475 +} 1.476 + 1.477 +//------------------------------sub-------------------------------------------- 1.478 +// A subtract node differences its two inputs. 1.479 +const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const { 1.480 + // no folding if one of operands is infinity or NaN, do not do constant folding 1.481 + if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) { 1.482 + return TypeD::make( t1->getd() - t2->getd() ); 1.483 + } 1.484 + else if( g_isnan(t1->getd()) ) { 1.485 + return t1; 1.486 + } 1.487 + else if( g_isnan(t2->getd()) ) { 1.488 + return t2; 1.489 + } 1.490 + else { 1.491 + return Type::DOUBLE; 1.492 + } 1.493 +} 1.494 + 1.495 +//============================================================================= 1.496 +//------------------------------Idealize--------------------------------------- 1.497 +// Unlike SubNodes, compare must still flatten return value to the 1.498 +// range -1, 0, 1. 1.499 +// And optimizations like those for (X + Y) - X fail if overflow happens. 1.500 +Node *CmpNode::Identity( PhaseTransform *phase ) { 1.501 + return this; 1.502 +} 1.503 + 1.504 +//============================================================================= 1.505 +//------------------------------cmp-------------------------------------------- 1.506 +// Simplify a CmpI (compare 2 integers) node, based on local information. 1.507 +// If both inputs are constants, compare them. 1.508 +const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const { 1.509 + const TypeInt *r0 = t1->is_int(); // Handy access 1.510 + const TypeInt *r1 = t2->is_int(); 1.511 + 1.512 + if( r0->_hi < r1->_lo ) // Range is always low? 1.513 + return TypeInt::CC_LT; 1.514 + else if( r0->_lo > r1->_hi ) // Range is always high? 1.515 + return TypeInt::CC_GT; 1.516 + 1.517 + else if( r0->is_con() && r1->is_con() ) { // comparing constants? 1.518 + assert(r0->get_con() == r1->get_con(), "must be equal"); 1.519 + return TypeInt::CC_EQ; // Equal results. 1.520 + } else if( r0->_hi == r1->_lo ) // Range is never high? 1.521 + return TypeInt::CC_LE; 1.522 + else if( r0->_lo == r1->_hi ) // Range is never low? 1.523 + return TypeInt::CC_GE; 1.524 + return TypeInt::CC; // else use worst case results 1.525 +} 1.526 + 1.527 +// Simplify a CmpU (compare 2 integers) node, based on local information. 1.528 +// If both inputs are constants, compare them. 1.529 +const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { 1.530 + assert(!t1->isa_ptr(), "obsolete usage of CmpU"); 1.531 + 1.532 + // comparing two unsigned ints 1.533 + const TypeInt *r0 = t1->is_int(); // Handy access 1.534 + const TypeInt *r1 = t2->is_int(); 1.535 + 1.536 + // Current installed version 1.537 + // Compare ranges for non-overlap 1.538 + juint lo0 = r0->_lo; 1.539 + juint hi0 = r0->_hi; 1.540 + juint lo1 = r1->_lo; 1.541 + juint hi1 = r1->_hi; 1.542 + 1.543 + // If either one has both negative and positive values, 1.544 + // it therefore contains both 0 and -1, and since [0..-1] is the 1.545 + // full unsigned range, the type must act as an unsigned bottom. 1.546 + bool bot0 = ((jint)(lo0 ^ hi0) < 0); 1.547 + bool bot1 = ((jint)(lo1 ^ hi1) < 0); 1.548 + 1.549 + if (bot0 || bot1) { 1.550 + // All unsigned values are LE -1 and GE 0. 1.551 + if (lo0 == 0 && hi0 == 0) { 1.552 + return TypeInt::CC_LE; // 0 <= bot 1.553 + } else if (lo1 == 0 && hi1 == 0) { 1.554 + return TypeInt::CC_GE; // bot >= 0 1.555 + } 1.556 + } else { 1.557 + // We can use ranges of the form [lo..hi] if signs are the same. 1.558 + assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); 1.559 + // results are reversed, '-' > '+' for unsigned compare 1.560 + if (hi0 < lo1) { 1.561 + return TypeInt::CC_LT; // smaller 1.562 + } else if (lo0 > hi1) { 1.563 + return TypeInt::CC_GT; // greater 1.564 + } else if (hi0 == lo1 && lo0 == hi1) { 1.565 + return TypeInt::CC_EQ; // Equal results 1.566 + } else if (lo0 >= hi1) { 1.567 + return TypeInt::CC_GE; 1.568 + } else if (hi0 <= lo1) { 1.569 + // Check for special case in Hashtable::get. (See below.) 1.570 + if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) 1.571 + return TypeInt::CC_LT; 1.572 + return TypeInt::CC_LE; 1.573 + } 1.574 + } 1.575 + // Check for special case in Hashtable::get - the hash index is 1.576 + // mod'ed to the table size so the following range check is useless. 1.577 + // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have 1.578 + // to be positive. 1.579 + // (This is a gross hack, since the sub method never 1.580 + // looks at the structure of the node in any other case.) 1.581 + if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) 1.582 + return TypeInt::CC_LT; 1.583 + return TypeInt::CC; // else use worst case results 1.584 +} 1.585 + 1.586 +const Type* CmpUNode::Value(PhaseTransform *phase) const { 1.587 + const Type* t = SubNode::Value_common(phase); 1.588 + if (t != NULL) { 1.589 + return t; 1.590 + } 1.591 + const Node* in1 = in(1); 1.592 + const Node* in2 = in(2); 1.593 + const Type* t1 = phase->type(in1); 1.594 + const Type* t2 = phase->type(in2); 1.595 + assert(t1->isa_int(), "CmpU has only Int type inputs"); 1.596 + if (t2 == TypeInt::INT) { // Compare to bottom? 1.597 + return bottom_type(); 1.598 + } 1.599 + uint in1_op = in1->Opcode(); 1.600 + if (in1_op == Op_AddI || in1_op == Op_SubI) { 1.601 + // The problem rise when result of AddI(SubI) may overflow 1.602 + // signed integer value. Let say the input type is 1.603 + // [256, maxint] then +128 will create 2 ranges due to 1.604 + // overflow: [minint, minint+127] and [384, maxint]. 1.605 + // But C2 type system keep only 1 type range and as result 1.606 + // it use general [minint, maxint] for this case which we 1.607 + // can't optimize. 1.608 + // 1.609 + // Make 2 separate type ranges based on types of AddI(SubI) inputs 1.610 + // and compare results of their compare. If results are the same 1.611 + // CmpU node can be optimized. 1.612 + const Node* in11 = in1->in(1); 1.613 + const Node* in12 = in1->in(2); 1.614 + const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11); 1.615 + const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12); 1.616 + // Skip cases when input types are top or bottom. 1.617 + if ((t11 != Type::TOP) && (t11 != TypeInt::INT) && 1.618 + (t12 != Type::TOP) && (t12 != TypeInt::INT)) { 1.619 + const TypeInt *r0 = t11->is_int(); 1.620 + const TypeInt *r1 = t12->is_int(); 1.621 + jlong lo_r0 = r0->_lo; 1.622 + jlong hi_r0 = r0->_hi; 1.623 + jlong lo_r1 = r1->_lo; 1.624 + jlong hi_r1 = r1->_hi; 1.625 + if (in1_op == Op_SubI) { 1.626 + jlong tmp = hi_r1; 1.627 + hi_r1 = -lo_r1; 1.628 + lo_r1 = -tmp; 1.629 + // Note, for substructing [minint,x] type range 1.630 + // long arithmetic provides correct overflow answer. 1.631 + // The confusion come from the fact that in 32-bit 1.632 + // -minint == minint but in 64-bit -minint == maxint+1. 1.633 + } 1.634 + jlong lo_long = lo_r0 + lo_r1; 1.635 + jlong hi_long = hi_r0 + hi_r1; 1.636 + int lo_tr1 = min_jint; 1.637 + int hi_tr1 = (int)hi_long; 1.638 + int lo_tr2 = (int)lo_long; 1.639 + int hi_tr2 = max_jint; 1.640 + bool underflow = lo_long != (jlong)lo_tr2; 1.641 + bool overflow = hi_long != (jlong)hi_tr1; 1.642 + // Use sub(t1, t2) when there is no overflow (one type range) 1.643 + // or when both overflow and underflow (too complex). 1.644 + if ((underflow != overflow) && (hi_tr1 < lo_tr2)) { 1.645 + // Overflow only on one boundary, compare 2 separate type ranges. 1.646 + int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here 1.647 + const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w); 1.648 + const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w); 1.649 + const Type* cmp1 = sub(tr1, t2); 1.650 + const Type* cmp2 = sub(tr2, t2); 1.651 + if (cmp1 == cmp2) { 1.652 + return cmp1; // Hit! 1.653 + } 1.654 + } 1.655 + } 1.656 + } 1.657 + 1.658 + return sub(t1, t2); // Local flavor of type subtraction 1.659 +} 1.660 + 1.661 +bool CmpUNode::is_index_range_check() const { 1.662 + // Check for the "(X ModI Y) CmpU Y" shape 1.663 + return (in(1)->Opcode() == Op_ModI && 1.664 + in(1)->in(2)->eqv_uncast(in(2))); 1.665 +} 1.666 + 1.667 +//------------------------------Idealize--------------------------------------- 1.668 +Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) { 1.669 + if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) { 1.670 + switch (in(1)->Opcode()) { 1.671 + case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL 1.672 + return new (phase->C) CmpLNode(in(1)->in(1),in(1)->in(2)); 1.673 + case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF 1.674 + return new (phase->C) CmpFNode(in(1)->in(1),in(1)->in(2)); 1.675 + case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD 1.676 + return new (phase->C) CmpDNode(in(1)->in(1),in(1)->in(2)); 1.677 + //case Op_SubI: 1.678 + // If (x - y) cannot overflow, then ((x - y) <?> 0) 1.679 + // can be turned into (x <?> y). 1.680 + // This is handled (with more general cases) by Ideal_sub_algebra. 1.681 + } 1.682 + } 1.683 + return NULL; // No change 1.684 +} 1.685 + 1.686 + 1.687 +//============================================================================= 1.688 +// Simplify a CmpL (compare 2 longs ) node, based on local information. 1.689 +// If both inputs are constants, compare them. 1.690 +const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { 1.691 + const TypeLong *r0 = t1->is_long(); // Handy access 1.692 + const TypeLong *r1 = t2->is_long(); 1.693 + 1.694 + if( r0->_hi < r1->_lo ) // Range is always low? 1.695 + return TypeInt::CC_LT; 1.696 + else if( r0->_lo > r1->_hi ) // Range is always high? 1.697 + return TypeInt::CC_GT; 1.698 + 1.699 + else if( r0->is_con() && r1->is_con() ) { // comparing constants? 1.700 + assert(r0->get_con() == r1->get_con(), "must be equal"); 1.701 + return TypeInt::CC_EQ; // Equal results. 1.702 + } else if( r0->_hi == r1->_lo ) // Range is never high? 1.703 + return TypeInt::CC_LE; 1.704 + else if( r0->_lo == r1->_hi ) // Range is never low? 1.705 + return TypeInt::CC_GE; 1.706 + return TypeInt::CC; // else use worst case results 1.707 +} 1.708 + 1.709 +//============================================================================= 1.710 +//------------------------------sub-------------------------------------------- 1.711 +// Simplify an CmpP (compare 2 pointers) node, based on local information. 1.712 +// If both inputs are constants, compare them. 1.713 +const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { 1.714 + const TypePtr *r0 = t1->is_ptr(); // Handy access 1.715 + const TypePtr *r1 = t2->is_ptr(); 1.716 + 1.717 + // Undefined inputs makes for an undefined result 1.718 + if( TypePtr::above_centerline(r0->_ptr) || 1.719 + TypePtr::above_centerline(r1->_ptr) ) 1.720 + return Type::TOP; 1.721 + 1.722 + if (r0 == r1 && r0->singleton()) { 1.723 + // Equal pointer constants (klasses, nulls, etc.) 1.724 + return TypeInt::CC_EQ; 1.725 + } 1.726 + 1.727 + // See if it is 2 unrelated classes. 1.728 + const TypeOopPtr* p0 = r0->isa_oopptr(); 1.729 + const TypeOopPtr* p1 = r1->isa_oopptr(); 1.730 + if (p0 && p1) { 1.731 + Node* in1 = in(1)->uncast(); 1.732 + Node* in2 = in(2)->uncast(); 1.733 + AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL); 1.734 + AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL); 1.735 + if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) { 1.736 + return TypeInt::CC_GT; // different pointers 1.737 + } 1.738 + ciKlass* klass0 = p0->klass(); 1.739 + bool xklass0 = p0->klass_is_exact(); 1.740 + ciKlass* klass1 = p1->klass(); 1.741 + bool xklass1 = p1->klass_is_exact(); 1.742 + int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0); 1.743 + if (klass0 && klass1 && 1.744 + kps != 1 && // both or neither are klass pointers 1.745 + klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces 1.746 + klass1->is_loaded() && !klass1->is_interface() && 1.747 + (!klass0->is_obj_array_klass() || 1.748 + !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) && 1.749 + (!klass1->is_obj_array_klass() || 1.750 + !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) { 1.751 + bool unrelated_classes = false; 1.752 + // See if neither subclasses the other, or if the class on top 1.753 + // is precise. In either of these cases, the compare is known 1.754 + // to fail if at least one of the pointers is provably not null. 1.755 + if (klass0->equals(klass1)) { // if types are unequal but klasses are equal 1.756 + // Do nothing; we know nothing for imprecise types 1.757 + } else if (klass0->is_subtype_of(klass1)) { 1.758 + // If klass1's type is PRECISE, then classes are unrelated. 1.759 + unrelated_classes = xklass1; 1.760 + } else if (klass1->is_subtype_of(klass0)) { 1.761 + // If klass0's type is PRECISE, then classes are unrelated. 1.762 + unrelated_classes = xklass0; 1.763 + } else { // Neither subtypes the other 1.764 + unrelated_classes = true; 1.765 + } 1.766 + if (unrelated_classes) { 1.767 + // The oops classes are known to be unrelated. If the joined PTRs of 1.768 + // two oops is not Null and not Bottom, then we are sure that one 1.769 + // of the two oops is non-null, and the comparison will always fail. 1.770 + TypePtr::PTR jp = r0->join_ptr(r1->_ptr); 1.771 + if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { 1.772 + return TypeInt::CC_GT; 1.773 + } 1.774 + } 1.775 + } 1.776 + } 1.777 + 1.778 + // Known constants can be compared exactly 1.779 + // Null can be distinguished from any NotNull pointers 1.780 + // Unknown inputs makes an unknown result 1.781 + if( r0->singleton() ) { 1.782 + intptr_t bits0 = r0->get_con(); 1.783 + if( r1->singleton() ) 1.784 + return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; 1.785 + return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1.786 + } else if( r1->singleton() ) { 1.787 + intptr_t bits1 = r1->get_con(); 1.788 + return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1.789 + } else 1.790 + return TypeInt::CC; 1.791 +} 1.792 + 1.793 +static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) { 1.794 + // Return the klass node for 1.795 + // LoadP(AddP(foo:Klass, #java_mirror)) 1.796 + // or NULL if not matching. 1.797 + if (n->Opcode() != Op_LoadP) return NULL; 1.798 + 1.799 + const TypeInstPtr* tp = phase->type(n)->isa_instptr(); 1.800 + if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL; 1.801 + 1.802 + Node* adr = n->in(MemNode::Address); 1.803 + intptr_t off = 0; 1.804 + Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off); 1.805 + if (k == NULL) return NULL; 1.806 + const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr(); 1.807 + if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL; 1.808 + 1.809 + // We've found the klass node of a Java mirror load. 1.810 + return k; 1.811 +} 1.812 + 1.813 +static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) { 1.814 + // for ConP(Foo.class) return ConP(Foo.klass) 1.815 + // otherwise return NULL 1.816 + if (!n->is_Con()) return NULL; 1.817 + 1.818 + const TypeInstPtr* tp = phase->type(n)->isa_instptr(); 1.819 + if (!tp) return NULL; 1.820 + 1.821 + ciType* mirror_type = tp->java_mirror_type(); 1.822 + // TypeInstPtr::java_mirror_type() returns non-NULL for compile- 1.823 + // time Class constants only. 1.824 + if (!mirror_type) return NULL; 1.825 + 1.826 + // x.getClass() == int.class can never be true (for all primitive types) 1.827 + // Return a ConP(NULL) node for this case. 1.828 + if (mirror_type->is_classless()) { 1.829 + return phase->makecon(TypePtr::NULL_PTR); 1.830 + } 1.831 + 1.832 + // return the ConP(Foo.klass) 1.833 + assert(mirror_type->is_klass(), "mirror_type should represent a Klass*"); 1.834 + return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass())); 1.835 +} 1.836 + 1.837 +//------------------------------Ideal------------------------------------------ 1.838 +// Normalize comparisons between Java mirror loads to compare the klass instead. 1.839 +// 1.840 +// Also check for the case of comparing an unknown klass loaded from the primary 1.841 +// super-type array vs a known klass with no subtypes. This amounts to 1.842 +// checking to see an unknown klass subtypes a known klass with no subtypes; 1.843 +// this only happens on an exact match. We can shorten this test by 1 load. 1.844 +Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) { 1.845 + // Normalize comparisons between Java mirrors into comparisons of the low- 1.846 + // level klass, where a dependent load could be shortened. 1.847 + // 1.848 + // The new pattern has a nice effect of matching the same pattern used in the 1.849 + // fast path of instanceof/checkcast/Class.isInstance(), which allows 1.850 + // redundant exact type check be optimized away by GVN. 1.851 + // For example, in 1.852 + // if (x.getClass() == Foo.class) { 1.853 + // Foo foo = (Foo) x; 1.854 + // // ... use a ... 1.855 + // } 1.856 + // a CmpPNode could be shared between if_acmpne and checkcast 1.857 + { 1.858 + Node* k1 = isa_java_mirror_load(phase, in(1)); 1.859 + Node* k2 = isa_java_mirror_load(phase, in(2)); 1.860 + Node* conk2 = isa_const_java_mirror(phase, in(2)); 1.861 + 1.862 + if (k1 && (k2 || conk2)) { 1.863 + Node* lhs = k1; 1.864 + Node* rhs = (k2 != NULL) ? k2 : conk2; 1.865 + this->set_req(1, lhs); 1.866 + this->set_req(2, rhs); 1.867 + return this; 1.868 + } 1.869 + } 1.870 + 1.871 + // Constant pointer on right? 1.872 + const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr(); 1.873 + if (t2 == NULL || !t2->klass_is_exact()) 1.874 + return NULL; 1.875 + // Get the constant klass we are comparing to. 1.876 + ciKlass* superklass = t2->klass(); 1.877 + 1.878 + // Now check for LoadKlass on left. 1.879 + Node* ldk1 = in(1); 1.880 + if (ldk1->is_DecodeNKlass()) { 1.881 + ldk1 = ldk1->in(1); 1.882 + if (ldk1->Opcode() != Op_LoadNKlass ) 1.883 + return NULL; 1.884 + } else if (ldk1->Opcode() != Op_LoadKlass ) 1.885 + return NULL; 1.886 + // Take apart the address of the LoadKlass: 1.887 + Node* adr1 = ldk1->in(MemNode::Address); 1.888 + intptr_t con2 = 0; 1.889 + Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2); 1.890 + if (ldk2 == NULL) 1.891 + return NULL; 1.892 + if (con2 == oopDesc::klass_offset_in_bytes()) { 1.893 + // We are inspecting an object's concrete class. 1.894 + // Short-circuit the check if the query is abstract. 1.895 + if (superklass->is_interface() || 1.896 + superklass->is_abstract()) { 1.897 + // Make it come out always false: 1.898 + this->set_req(2, phase->makecon(TypePtr::NULL_PTR)); 1.899 + return this; 1.900 + } 1.901 + } 1.902 + 1.903 + // Check for a LoadKlass from primary supertype array. 1.904 + // Any nested loadklass from loadklass+con must be from the p.s. array. 1.905 + if (ldk2->is_DecodeNKlass()) { 1.906 + // Keep ldk2 as DecodeN since it could be used in CmpP below. 1.907 + if (ldk2->in(1)->Opcode() != Op_LoadNKlass ) 1.908 + return NULL; 1.909 + } else if (ldk2->Opcode() != Op_LoadKlass) 1.910 + return NULL; 1.911 + 1.912 + // Verify that we understand the situation 1.913 + if (con2 != (intptr_t) superklass->super_check_offset()) 1.914 + return NULL; // Might be element-klass loading from array klass 1.915 + 1.916 + // If 'superklass' has no subklasses and is not an interface, then we are 1.917 + // assured that the only input which will pass the type check is 1.918 + // 'superklass' itself. 1.919 + // 1.920 + // We could be more liberal here, and allow the optimization on interfaces 1.921 + // which have a single implementor. This would require us to increase the 1.922 + // expressiveness of the add_dependency() mechanism. 1.923 + // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. 1.924 + 1.925 + // Object arrays must have their base element have no subtypes 1.926 + while (superklass->is_obj_array_klass()) { 1.927 + ciType* elem = superklass->as_obj_array_klass()->element_type(); 1.928 + superklass = elem->as_klass(); 1.929 + } 1.930 + if (superklass->is_instance_klass()) { 1.931 + ciInstanceKlass* ik = superklass->as_instance_klass(); 1.932 + if (ik->has_subklass() || ik->is_interface()) return NULL; 1.933 + // Add a dependency if there is a chance that a subclass will be added later. 1.934 + if (!ik->is_final()) { 1.935 + phase->C->dependencies()->assert_leaf_type(ik); 1.936 + } 1.937 + } 1.938 + 1.939 + // Bypass the dependent load, and compare directly 1.940 + this->set_req(1,ldk2); 1.941 + 1.942 + return this; 1.943 +} 1.944 + 1.945 +//============================================================================= 1.946 +//------------------------------sub-------------------------------------------- 1.947 +// Simplify an CmpN (compare 2 pointers) node, based on local information. 1.948 +// If both inputs are constants, compare them. 1.949 +const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { 1.950 + const TypePtr *r0 = t1->make_ptr(); // Handy access 1.951 + const TypePtr *r1 = t2->make_ptr(); 1.952 + 1.953 + // Undefined inputs makes for an undefined result 1.954 + if ((r0 == NULL) || (r1 == NULL) || 1.955 + TypePtr::above_centerline(r0->_ptr) || 1.956 + TypePtr::above_centerline(r1->_ptr)) { 1.957 + return Type::TOP; 1.958 + } 1.959 + if (r0 == r1 && r0->singleton()) { 1.960 + // Equal pointer constants (klasses, nulls, etc.) 1.961 + return TypeInt::CC_EQ; 1.962 + } 1.963 + 1.964 + // See if it is 2 unrelated classes. 1.965 + const TypeOopPtr* p0 = r0->isa_oopptr(); 1.966 + const TypeOopPtr* p1 = r1->isa_oopptr(); 1.967 + if (p0 && p1) { 1.968 + ciKlass* klass0 = p0->klass(); 1.969 + bool xklass0 = p0->klass_is_exact(); 1.970 + ciKlass* klass1 = p1->klass(); 1.971 + bool xklass1 = p1->klass_is_exact(); 1.972 + int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0); 1.973 + if (klass0 && klass1 && 1.974 + kps != 1 && // both or neither are klass pointers 1.975 + !klass0->is_interface() && // do not trust interfaces 1.976 + !klass1->is_interface()) { 1.977 + bool unrelated_classes = false; 1.978 + // See if neither subclasses the other, or if the class on top 1.979 + // is precise. In either of these cases, the compare is known 1.980 + // to fail if at least one of the pointers is provably not null. 1.981 + if (klass0->equals(klass1)) { // if types are unequal but klasses are equal 1.982 + // Do nothing; we know nothing for imprecise types 1.983 + } else if (klass0->is_subtype_of(klass1)) { 1.984 + // If klass1's type is PRECISE, then classes are unrelated. 1.985 + unrelated_classes = xklass1; 1.986 + } else if (klass1->is_subtype_of(klass0)) { 1.987 + // If klass0's type is PRECISE, then classes are unrelated. 1.988 + unrelated_classes = xklass0; 1.989 + } else { // Neither subtypes the other 1.990 + unrelated_classes = true; 1.991 + } 1.992 + if (unrelated_classes) { 1.993 + // The oops classes are known to be unrelated. If the joined PTRs of 1.994 + // two oops is not Null and not Bottom, then we are sure that one 1.995 + // of the two oops is non-null, and the comparison will always fail. 1.996 + TypePtr::PTR jp = r0->join_ptr(r1->_ptr); 1.997 + if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { 1.998 + return TypeInt::CC_GT; 1.999 + } 1.1000 + } 1.1001 + } 1.1002 + } 1.1003 + 1.1004 + // Known constants can be compared exactly 1.1005 + // Null can be distinguished from any NotNull pointers 1.1006 + // Unknown inputs makes an unknown result 1.1007 + if( r0->singleton() ) { 1.1008 + intptr_t bits0 = r0->get_con(); 1.1009 + if( r1->singleton() ) 1.1010 + return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; 1.1011 + return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1.1012 + } else if( r1->singleton() ) { 1.1013 + intptr_t bits1 = r1->get_con(); 1.1014 + return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; 1.1015 + } else 1.1016 + return TypeInt::CC; 1.1017 +} 1.1018 + 1.1019 +//------------------------------Ideal------------------------------------------ 1.1020 +Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) { 1.1021 + return NULL; 1.1022 +} 1.1023 + 1.1024 +//============================================================================= 1.1025 +//------------------------------Value------------------------------------------ 1.1026 +// Simplify an CmpF (compare 2 floats ) node, based on local information. 1.1027 +// If both inputs are constants, compare them. 1.1028 +const Type *CmpFNode::Value( PhaseTransform *phase ) const { 1.1029 + const Node* in1 = in(1); 1.1030 + const Node* in2 = in(2); 1.1031 + // Either input is TOP ==> the result is TOP 1.1032 + const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1.1033 + if( t1 == Type::TOP ) return Type::TOP; 1.1034 + const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1.1035 + if( t2 == Type::TOP ) return Type::TOP; 1.1036 + 1.1037 + // Not constants? Don't know squat - even if they are the same 1.1038 + // value! If they are NaN's they compare to LT instead of EQ. 1.1039 + const TypeF *tf1 = t1->isa_float_constant(); 1.1040 + const TypeF *tf2 = t2->isa_float_constant(); 1.1041 + if( !tf1 || !tf2 ) return TypeInt::CC; 1.1042 + 1.1043 + // This implements the Java bytecode fcmpl, so unordered returns -1. 1.1044 + if( tf1->is_nan() || tf2->is_nan() ) 1.1045 + return TypeInt::CC_LT; 1.1046 + 1.1047 + if( tf1->_f < tf2->_f ) return TypeInt::CC_LT; 1.1048 + if( tf1->_f > tf2->_f ) return TypeInt::CC_GT; 1.1049 + assert( tf1->_f == tf2->_f, "do not understand FP behavior" ); 1.1050 + return TypeInt::CC_EQ; 1.1051 +} 1.1052 + 1.1053 + 1.1054 +//============================================================================= 1.1055 +//------------------------------Value------------------------------------------ 1.1056 +// Simplify an CmpD (compare 2 doubles ) node, based on local information. 1.1057 +// If both inputs are constants, compare them. 1.1058 +const Type *CmpDNode::Value( PhaseTransform *phase ) const { 1.1059 + const Node* in1 = in(1); 1.1060 + const Node* in2 = in(2); 1.1061 + // Either input is TOP ==> the result is TOP 1.1062 + const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); 1.1063 + if( t1 == Type::TOP ) return Type::TOP; 1.1064 + const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); 1.1065 + if( t2 == Type::TOP ) return Type::TOP; 1.1066 + 1.1067 + // Not constants? Don't know squat - even if they are the same 1.1068 + // value! If they are NaN's they compare to LT instead of EQ. 1.1069 + const TypeD *td1 = t1->isa_double_constant(); 1.1070 + const TypeD *td2 = t2->isa_double_constant(); 1.1071 + if( !td1 || !td2 ) return TypeInt::CC; 1.1072 + 1.1073 + // This implements the Java bytecode dcmpl, so unordered returns -1. 1.1074 + if( td1->is_nan() || td2->is_nan() ) 1.1075 + return TypeInt::CC_LT; 1.1076 + 1.1077 + if( td1->_d < td2->_d ) return TypeInt::CC_LT; 1.1078 + if( td1->_d > td2->_d ) return TypeInt::CC_GT; 1.1079 + assert( td1->_d == td2->_d, "do not understand FP behavior" ); 1.1080 + return TypeInt::CC_EQ; 1.1081 +} 1.1082 + 1.1083 +//------------------------------Ideal------------------------------------------ 1.1084 +Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){ 1.1085 + // Check if we can change this to a CmpF and remove a ConvD2F operation. 1.1086 + // Change (CMPD (F2D (float)) (ConD value)) 1.1087 + // To (CMPF (float) (ConF value)) 1.1088 + // Valid when 'value' does not lose precision as a float. 1.1089 + // Benefits: eliminates conversion, does not require 24-bit mode 1.1090 + 1.1091 + // NaNs prevent commuting operands. This transform works regardless of the 1.1092 + // order of ConD and ConvF2D inputs by preserving the original order. 1.1093 + int idx_f2d = 1; // ConvF2D on left side? 1.1094 + if( in(idx_f2d)->Opcode() != Op_ConvF2D ) 1.1095 + idx_f2d = 2; // No, swap to check for reversed args 1.1096 + int idx_con = 3-idx_f2d; // Check for the constant on other input 1.1097 + 1.1098 + if( ConvertCmpD2CmpF && 1.1099 + in(idx_f2d)->Opcode() == Op_ConvF2D && 1.1100 + in(idx_con)->Opcode() == Op_ConD ) { 1.1101 + const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant(); 1.1102 + double t2_value_as_double = t2->_d; 1.1103 + float t2_value_as_float = (float)t2_value_as_double; 1.1104 + if( t2_value_as_double == (double)t2_value_as_float ) { 1.1105 + // Test value can be represented as a float 1.1106 + // Eliminate the conversion to double and create new comparison 1.1107 + Node *new_in1 = in(idx_f2d)->in(1); 1.1108 + Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) ); 1.1109 + if( idx_f2d != 1 ) { // Must flip args to match original order 1.1110 + Node *tmp = new_in1; 1.1111 + new_in1 = new_in2; 1.1112 + new_in2 = tmp; 1.1113 + } 1.1114 + CmpFNode *new_cmp = (Opcode() == Op_CmpD3) 1.1115 + ? new (phase->C) CmpF3Node( new_in1, new_in2 ) 1.1116 + : new (phase->C) CmpFNode ( new_in1, new_in2 ) ; 1.1117 + return new_cmp; // Changed to CmpFNode 1.1118 + } 1.1119 + // Testing value required the precision of a double 1.1120 + } 1.1121 + return NULL; // No change 1.1122 +} 1.1123 + 1.1124 + 1.1125 +//============================================================================= 1.1126 +//------------------------------cc2logical------------------------------------- 1.1127 +// Convert a condition code type to a logical type 1.1128 +const Type *BoolTest::cc2logical( const Type *CC ) const { 1.1129 + if( CC == Type::TOP ) return Type::TOP; 1.1130 + if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse 1.1131 + const TypeInt *ti = CC->is_int(); 1.1132 + if( ti->is_con() ) { // Only 1 kind of condition codes set? 1.1133 + // Match low order 2 bits 1.1134 + int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0; 1.1135 + if( _test & 4 ) tmp = 1-tmp; // Optionally complement result 1.1136 + return TypeInt::make(tmp); // Boolean result 1.1137 + } 1.1138 + 1.1139 + if( CC == TypeInt::CC_GE ) { 1.1140 + if( _test == ge ) return TypeInt::ONE; 1.1141 + if( _test == lt ) return TypeInt::ZERO; 1.1142 + } 1.1143 + if( CC == TypeInt::CC_LE ) { 1.1144 + if( _test == le ) return TypeInt::ONE; 1.1145 + if( _test == gt ) return TypeInt::ZERO; 1.1146 + } 1.1147 + 1.1148 + return TypeInt::BOOL; 1.1149 +} 1.1150 + 1.1151 +//------------------------------dump_spec------------------------------------- 1.1152 +// Print special per-node info 1.1153 +#ifndef PRODUCT 1.1154 +void BoolTest::dump_on(outputStream *st) const { 1.1155 + const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"}; 1.1156 + st->print("%s", msg[_test]); 1.1157 +} 1.1158 +#endif 1.1159 + 1.1160 +//============================================================================= 1.1161 +uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); } 1.1162 +uint BoolNode::size_of() const { return sizeof(BoolNode); } 1.1163 + 1.1164 +//------------------------------operator==------------------------------------- 1.1165 +uint BoolNode::cmp( const Node &n ) const { 1.1166 + const BoolNode *b = (const BoolNode *)&n; // Cast up 1.1167 + return (_test._test == b->_test._test); 1.1168 +} 1.1169 + 1.1170 +//-------------------------------make_predicate-------------------------------- 1.1171 +Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) { 1.1172 + if (test_value->is_Con()) return test_value; 1.1173 + if (test_value->is_Bool()) return test_value; 1.1174 + Compile* C = phase->C; 1.1175 + if (test_value->is_CMove() && 1.1176 + test_value->in(CMoveNode::Condition)->is_Bool()) { 1.1177 + BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool(); 1.1178 + const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse)); 1.1179 + const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue)); 1.1180 + if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) { 1.1181 + return bol; 1.1182 + } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) { 1.1183 + return phase->transform( bol->negate(phase) ); 1.1184 + } 1.1185 + // Else fall through. The CMove gets in the way of the test. 1.1186 + // It should be the case that make_predicate(bol->as_int_value()) == bol. 1.1187 + } 1.1188 + Node* cmp = new (C) CmpINode(test_value, phase->intcon(0)); 1.1189 + cmp = phase->transform(cmp); 1.1190 + Node* bol = new (C) BoolNode(cmp, BoolTest::ne); 1.1191 + return phase->transform(bol); 1.1192 +} 1.1193 + 1.1194 +//--------------------------------as_int_value--------------------------------- 1.1195 +Node* BoolNode::as_int_value(PhaseGVN* phase) { 1.1196 + // Inverse to make_predicate. The CMove probably boils down to a Conv2B. 1.1197 + Node* cmov = CMoveNode::make(phase->C, NULL, this, 1.1198 + phase->intcon(0), phase->intcon(1), 1.1199 + TypeInt::BOOL); 1.1200 + return phase->transform(cmov); 1.1201 +} 1.1202 + 1.1203 +//----------------------------------negate------------------------------------- 1.1204 +BoolNode* BoolNode::negate(PhaseGVN* phase) { 1.1205 + Compile* C = phase->C; 1.1206 + return new (C) BoolNode(in(1), _test.negate()); 1.1207 +} 1.1208 + 1.1209 + 1.1210 +//------------------------------Ideal------------------------------------------ 1.1211 +Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1.1212 + // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)". 1.1213 + // This moves the constant to the right. Helps value-numbering. 1.1214 + Node *cmp = in(1); 1.1215 + if( !cmp->is_Sub() ) return NULL; 1.1216 + int cop = cmp->Opcode(); 1.1217 + if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL; 1.1218 + Node *cmp1 = cmp->in(1); 1.1219 + Node *cmp2 = cmp->in(2); 1.1220 + if( !cmp1 ) return NULL; 1.1221 + 1.1222 + if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) { 1.1223 + return NULL; 1.1224 + } 1.1225 + 1.1226 + // Constant on left? 1.1227 + Node *con = cmp1; 1.1228 + uint op2 = cmp2->Opcode(); 1.1229 + // Move constants to the right of compare's to canonicalize. 1.1230 + // Do not muck with Opaque1 nodes, as this indicates a loop 1.1231 + // guard that cannot change shape. 1.1232 + if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 && 1.1233 + // Because of NaN's, CmpD and CmpF are not commutative 1.1234 + cop != Op_CmpD && cop != Op_CmpF && 1.1235 + // Protect against swapping inputs to a compare when it is used by a 1.1236 + // counted loop exit, which requires maintaining the loop-limit as in(2) 1.1237 + !is_counted_loop_exit_test() ) { 1.1238 + // Ok, commute the constant to the right of the cmp node. 1.1239 + // Clone the Node, getting a new Node of the same class 1.1240 + cmp = cmp->clone(); 1.1241 + // Swap inputs to the clone 1.1242 + cmp->swap_edges(1, 2); 1.1243 + cmp = phase->transform( cmp ); 1.1244 + return new (phase->C) BoolNode( cmp, _test.commute() ); 1.1245 + } 1.1246 + 1.1247 + // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)". 1.1248 + // The XOR-1 is an idiom used to flip the sense of a bool. We flip the 1.1249 + // test instead. 1.1250 + int cmp1_op = cmp1->Opcode(); 1.1251 + const TypeInt* cmp2_type = phase->type(cmp2)->isa_int(); 1.1252 + if (cmp2_type == NULL) return NULL; 1.1253 + Node* j_xor = cmp1; 1.1254 + if( cmp2_type == TypeInt::ZERO && 1.1255 + cmp1_op == Op_XorI && 1.1256 + j_xor->in(1) != j_xor && // An xor of itself is dead 1.1257 + phase->type( j_xor->in(1) ) == TypeInt::BOOL && 1.1258 + phase->type( j_xor->in(2) ) == TypeInt::ONE && 1.1259 + (_test._test == BoolTest::eq || 1.1260 + _test._test == BoolTest::ne) ) { 1.1261 + Node *ncmp = phase->transform(new (phase->C) CmpINode(j_xor->in(1),cmp2)); 1.1262 + return new (phase->C) BoolNode( ncmp, _test.negate() ); 1.1263 + } 1.1264 + 1.1265 + // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)". 1.1266 + // This is a standard idiom for branching on a boolean value. 1.1267 + Node *c2b = cmp1; 1.1268 + if( cmp2_type == TypeInt::ZERO && 1.1269 + cmp1_op == Op_Conv2B && 1.1270 + (_test._test == BoolTest::eq || 1.1271 + _test._test == BoolTest::ne) ) { 1.1272 + Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int() 1.1273 + ? (Node*)new (phase->C) CmpINode(c2b->in(1),cmp2) 1.1274 + : (Node*)new (phase->C) CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR)) 1.1275 + ); 1.1276 + return new (phase->C) BoolNode( ncmp, _test._test ); 1.1277 + } 1.1278 + 1.1279 + // Comparing a SubI against a zero is equal to comparing the SubI 1.1280 + // arguments directly. This only works for eq and ne comparisons 1.1281 + // due to possible integer overflow. 1.1282 + if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && 1.1283 + (cop == Op_CmpI) && 1.1284 + (cmp1->Opcode() == Op_SubI) && 1.1285 + ( cmp2_type == TypeInt::ZERO ) ) { 1.1286 + Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(1),cmp1->in(2))); 1.1287 + return new (phase->C) BoolNode( ncmp, _test._test ); 1.1288 + } 1.1289 + 1.1290 + // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the 1.1291 + // most general case because negating 0x80000000 does nothing. Needed for 1.1292 + // the CmpF3/SubI/CmpI idiom. 1.1293 + if( cop == Op_CmpI && 1.1294 + cmp1->Opcode() == Op_SubI && 1.1295 + cmp2_type == TypeInt::ZERO && 1.1296 + phase->type( cmp1->in(1) ) == TypeInt::ZERO && 1.1297 + phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) { 1.1298 + Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(2),cmp2)); 1.1299 + return new (phase->C) BoolNode( ncmp, _test.commute() ); 1.1300 + } 1.1301 + 1.1302 + // The transformation below is not valid for either signed or unsigned 1.1303 + // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE. 1.1304 + // This transformation can be resurrected when we are able to 1.1305 + // make inferences about the range of values being subtracted from 1.1306 + // (or added to) relative to the wraparound point. 1.1307 + // 1.1308 + // // Remove +/-1's if possible. 1.1309 + // // "X <= Y-1" becomes "X < Y" 1.1310 + // // "X+1 <= Y" becomes "X < Y" 1.1311 + // // "X < Y+1" becomes "X <= Y" 1.1312 + // // "X-1 < Y" becomes "X <= Y" 1.1313 + // // Do not this to compares off of the counted-loop-end. These guys are 1.1314 + // // checking the trip counter and they want to use the post-incremented 1.1315 + // // counter. If they use the PRE-incremented counter, then the counter has 1.1316 + // // to be incremented in a private block on a loop backedge. 1.1317 + // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd ) 1.1318 + // return NULL; 1.1319 + // #ifndef PRODUCT 1.1320 + // // Do not do this in a wash GVN pass during verification. 1.1321 + // // Gets triggered by too many simple optimizations to be bothered with 1.1322 + // // re-trying it again and again. 1.1323 + // if( !phase->allow_progress() ) return NULL; 1.1324 + // #endif 1.1325 + // // Not valid for unsigned compare because of corner cases in involving zero. 1.1326 + // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an 1.1327 + // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but 1.1328 + // // "0 <=u Y" is always true). 1.1329 + // if( cmp->Opcode() == Op_CmpU ) return NULL; 1.1330 + // int cmp2_op = cmp2->Opcode(); 1.1331 + // if( _test._test == BoolTest::le ) { 1.1332 + // if( cmp1_op == Op_AddI && 1.1333 + // phase->type( cmp1->in(2) ) == TypeInt::ONE ) 1.1334 + // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt ); 1.1335 + // else if( cmp2_op == Op_AddI && 1.1336 + // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 ) 1.1337 + // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt ); 1.1338 + // } else if( _test._test == BoolTest::lt ) { 1.1339 + // if( cmp1_op == Op_AddI && 1.1340 + // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 ) 1.1341 + // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le ); 1.1342 + // else if( cmp2_op == Op_AddI && 1.1343 + // phase->type( cmp2->in(2) ) == TypeInt::ONE ) 1.1344 + // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le ); 1.1345 + // } 1.1346 + 1.1347 + return NULL; 1.1348 +} 1.1349 + 1.1350 +//------------------------------Value------------------------------------------ 1.1351 +// Simplify a Bool (convert condition codes to boolean (1 or 0)) node, 1.1352 +// based on local information. If the input is constant, do it. 1.1353 +const Type *BoolNode::Value( PhaseTransform *phase ) const { 1.1354 + return _test.cc2logical( phase->type( in(1) ) ); 1.1355 +} 1.1356 + 1.1357 +//------------------------------dump_spec-------------------------------------- 1.1358 +// Dump special per-node info 1.1359 +#ifndef PRODUCT 1.1360 +void BoolNode::dump_spec(outputStream *st) const { 1.1361 + st->print("["); 1.1362 + _test.dump_on(st); 1.1363 + st->print("]"); 1.1364 +} 1.1365 +#endif 1.1366 + 1.1367 +//------------------------------is_counted_loop_exit_test-------------------------------------- 1.1368 +// Returns true if node is used by a counted loop node. 1.1369 +bool BoolNode::is_counted_loop_exit_test() { 1.1370 + for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { 1.1371 + Node* use = fast_out(i); 1.1372 + if (use->is_CountedLoopEnd()) { 1.1373 + return true; 1.1374 + } 1.1375 + } 1.1376 + return false; 1.1377 +} 1.1378 + 1.1379 +//============================================================================= 1.1380 +//------------------------------Value------------------------------------------ 1.1381 +// Compute sqrt 1.1382 +const Type *SqrtDNode::Value( PhaseTransform *phase ) const { 1.1383 + const Type *t1 = phase->type( in(1) ); 1.1384 + if( t1 == Type::TOP ) return Type::TOP; 1.1385 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1386 + double d = t1->getd(); 1.1387 + if( d < 0.0 ) return Type::DOUBLE; 1.1388 + return TypeD::make( sqrt( d ) ); 1.1389 +} 1.1390 + 1.1391 +//============================================================================= 1.1392 +//------------------------------Value------------------------------------------ 1.1393 +// Compute cos 1.1394 +const Type *CosDNode::Value( PhaseTransform *phase ) const { 1.1395 + const Type *t1 = phase->type( in(1) ); 1.1396 + if( t1 == Type::TOP ) return Type::TOP; 1.1397 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1398 + double d = t1->getd(); 1.1399 + return TypeD::make( StubRoutines::intrinsic_cos( d ) ); 1.1400 +} 1.1401 + 1.1402 +//============================================================================= 1.1403 +//------------------------------Value------------------------------------------ 1.1404 +// Compute sin 1.1405 +const Type *SinDNode::Value( PhaseTransform *phase ) const { 1.1406 + const Type *t1 = phase->type( in(1) ); 1.1407 + if( t1 == Type::TOP ) return Type::TOP; 1.1408 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1409 + double d = t1->getd(); 1.1410 + return TypeD::make( StubRoutines::intrinsic_sin( d ) ); 1.1411 +} 1.1412 + 1.1413 +//============================================================================= 1.1414 +//------------------------------Value------------------------------------------ 1.1415 +// Compute tan 1.1416 +const Type *TanDNode::Value( PhaseTransform *phase ) const { 1.1417 + const Type *t1 = phase->type( in(1) ); 1.1418 + if( t1 == Type::TOP ) return Type::TOP; 1.1419 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1420 + double d = t1->getd(); 1.1421 + return TypeD::make( StubRoutines::intrinsic_tan( d ) ); 1.1422 +} 1.1423 + 1.1424 +//============================================================================= 1.1425 +//------------------------------Value------------------------------------------ 1.1426 +// Compute log 1.1427 +const Type *LogDNode::Value( PhaseTransform *phase ) const { 1.1428 + const Type *t1 = phase->type( in(1) ); 1.1429 + if( t1 == Type::TOP ) return Type::TOP; 1.1430 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1431 + double d = t1->getd(); 1.1432 + return TypeD::make( StubRoutines::intrinsic_log( d ) ); 1.1433 +} 1.1434 + 1.1435 +//============================================================================= 1.1436 +//------------------------------Value------------------------------------------ 1.1437 +// Compute log10 1.1438 +const Type *Log10DNode::Value( PhaseTransform *phase ) const { 1.1439 + const Type *t1 = phase->type( in(1) ); 1.1440 + if( t1 == Type::TOP ) return Type::TOP; 1.1441 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1442 + double d = t1->getd(); 1.1443 + return TypeD::make( StubRoutines::intrinsic_log10( d ) ); 1.1444 +} 1.1445 + 1.1446 +//============================================================================= 1.1447 +//------------------------------Value------------------------------------------ 1.1448 +// Compute exp 1.1449 +const Type *ExpDNode::Value( PhaseTransform *phase ) const { 1.1450 + const Type *t1 = phase->type( in(1) ); 1.1451 + if( t1 == Type::TOP ) return Type::TOP; 1.1452 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1453 + double d = t1->getd(); 1.1454 + return TypeD::make( StubRoutines::intrinsic_exp( d ) ); 1.1455 +} 1.1456 + 1.1457 + 1.1458 +//============================================================================= 1.1459 +//------------------------------Value------------------------------------------ 1.1460 +// Compute pow 1.1461 +const Type *PowDNode::Value( PhaseTransform *phase ) const { 1.1462 + const Type *t1 = phase->type( in(1) ); 1.1463 + if( t1 == Type::TOP ) return Type::TOP; 1.1464 + if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1465 + const Type *t2 = phase->type( in(2) ); 1.1466 + if( t2 == Type::TOP ) return Type::TOP; 1.1467 + if( t2->base() != Type::DoubleCon ) return Type::DOUBLE; 1.1468 + double d1 = t1->getd(); 1.1469 + double d2 = t2->getd(); 1.1470 + return TypeD::make( StubRoutines::intrinsic_pow( d1, d2 ) ); 1.1471 +}