0N/A/*
1472N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "compiler/compileLog.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/callnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/loopnode.hpp"
1879N/A#include "opto/matcher.hpp"
1879N/A#include "opto/mulnode.hpp"
1879N/A#include "opto/opcodes.hpp"
1879N/A#include "opto/phaseX.hpp"
1879N/A#include "opto/subnode.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A
0N/A// Portions of code courtesy of Clifford Click
0N/A
0N/A// Optimization - Graph Style
0N/A
0N/A#include "math.h"
0N/A
0N/A//=============================================================================
0N/A//------------------------------Identity---------------------------------------
0N/A// If right input is a constant 0, return the left input.
0N/ANode *SubNode::Identity( PhaseTransform *phase ) {
0N/A assert(in(1) != this, "Must already have called Value");
0N/A assert(in(2) != this, "Must already have called Value");
0N/A
0N/A // Remove double negation
0N/A const Type *zero = add_id();
0N/A if( phase->type( in(1) )->higher_equal( zero ) &&
0N/A in(2)->Opcode() == Opcode() &&
0N/A phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
0N/A return in(2)->in(2);
0N/A }
0N/A
212N/A // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y
0N/A if( in(1)->Opcode() == Op_AddI ) {
0N/A if( phase->eqv(in(1)->in(2),in(2)) )
0N/A return in(1)->in(1);
212N/A if (phase->eqv(in(1)->in(1),in(2)))
212N/A return in(1)->in(2);
212N/A
0N/A // Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying
0N/A // trip counter and X is likely to be loop-invariant (that's how O2 Nodes
0N/A // are originally used, although the optimizer sometimes jiggers things).
0N/A // This folding through an O2 removes a loop-exit use of a loop-varying
0N/A // value and generally lowers register pressure in and around the loop.
0N/A if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
0N/A phase->eqv(in(1)->in(2)->in(1),in(2)) )
0N/A return in(1)->in(1);
0N/A }
0N/A
0N/A return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
0N/A}
0N/A
0N/A//------------------------------Value------------------------------------------
0N/A// A subtract node differences it's two inputs.
0N/Aconst Type *SubNode::Value( PhaseTransform *phase ) const {
0N/A const Node* in1 = in(1);
0N/A const Node* in2 = in(2);
0N/A // Either input is TOP ==> the result is TOP
0N/A const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
0N/A if( t1 == Type::TOP ) return Type::TOP;
0N/A const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
0N/A if( t2 == Type::TOP ) return Type::TOP;
0N/A
0N/A // Not correct for SubFnode and AddFNode (must check for infinity)
0N/A // Equal? Subtract is zero
3058N/A if (in1->eqv_uncast(in2)) return add_id();
0N/A
0N/A // Either input is BOTTOM ==> the result is the local BOTTOM
0N/A if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
0N/A return bottom_type();
0N/A
0N/A return sub(t1,t2); // Local flavor of type subtraction
0N/A
0N/A}
0N/A
0N/A//=============================================================================
0N/A
0N/A//------------------------------Helper function--------------------------------
0N/Astatic bool ok_to_convert(Node* inc, Node* iv) {
0N/A // Do not collapse (x+c0)-y if "+" is a loop increment, because the
0N/A // "-" is loop invariant and collapsing extends the live-range of "x"
0N/A // to overlap with the "+", forcing another register to be used in
0N/A // the loop.
0N/A // This test will be clearer with '&&' (apply DeMorgan's rule)
0N/A // but I like the early cutouts that happen here.
0N/A const PhiNode *phi;
0N/A if( ( !inc->in(1)->is_Phi() ||
0N/A !(phi=inc->in(1)->as_Phi()) ||
0N/A phi->is_copy() ||
0N/A !phi->region()->is_CountedLoop() ||
0N/A inc != phi->region()->as_CountedLoop()->incr() )
0N/A &&
0N/A // Do not collapse (x+c0)-iv if "iv" is a loop induction variable,
0N/A // because "x" maybe invariant.
0N/A ( !iv->is_loop_iv() )
0N/A ) {
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A}
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
0N/A Node *in1 = in(1);
0N/A Node *in2 = in(2);
0N/A uint op1 = in1->Opcode();
0N/A uint op2 = in2->Opcode();
0N/A
0N/A#ifdef ASSERT
0N/A // Check for dead loop
0N/A if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
0N/A ( op1 == Op_AddI || op1 == Op_SubI ) &&
0N/A ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
0N/A phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) )
0N/A assert(false, "dead loop in SubINode::Ideal");
0N/A#endif
0N/A
0N/A const Type *t2 = phase->type( in2 );
0N/A if( t2 == Type::TOP ) return NULL;
0N/A // Convert "x-c0" into "x+ -c0".
0N/A if( t2->base() == Type::Int ){ // Might be bottom or top...
0N/A const TypeInt *i = t2->is_int();
0N/A if( i->is_con() )
4022N/A return new (phase->C) AddINode(in1, phase->intcon(-i->get_con()));
0N/A }
0N/A
0N/A // Convert "(x+c0) - y" into (x-y) + c0"
0N/A // Do not collapse (x+c0)-y if "+" is a loop increment or
0N/A // if "y" is a loop induction variable.
0N/A if( op1 == Op_AddI && ok_to_convert(in1, in2) ) {
0N/A const Type *tadd = phase->type( in1->in(2) );
0N/A if( tadd->singleton() && tadd != Type::TOP ) {
4022N/A Node *sub2 = phase->transform( new (phase->C) SubINode( in1->in(1), in2 ));
4022N/A return new (phase->C) AddINode( sub2, in1->in(2) );
0N/A }
0N/A }
0N/A
0N/A
0N/A // Convert "x - (y+c0)" into "(x-y) - c0"
0N/A // Need the same check as in above optimization but reversed.
0N/A if (op2 == Op_AddI && ok_to_convert(in2, in1)) {
0N/A Node* in21 = in2->in(1);
0N/A Node* in22 = in2->in(2);
0N/A const TypeInt* tcon = phase->type(in22)->isa_int();
0N/A if (tcon != NULL && tcon->is_con()) {
4022N/A Node* sub2 = phase->transform( new (phase->C) SubINode(in1, in21) );
0N/A Node* neg_c0 = phase->intcon(- tcon->get_con());
4022N/A return new (phase->C) AddINode(sub2, neg_c0);
0N/A }
0N/A }
0N/A
0N/A const Type *t1 = phase->type( in1 );
0N/A if( t1 == Type::TOP ) return NULL;
0N/A
0N/A#ifdef ASSERT
0N/A // Check for dead loop
0N/A if( ( op2 == Op_AddI || op2 == Op_SubI ) &&
0N/A ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
0N/A phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) )
0N/A assert(false, "dead loop in SubINode::Ideal");
0N/A#endif
0N/A
0N/A // Convert "x - (x+y)" into "-y"
0N/A if( op2 == Op_AddI &&
0N/A phase->eqv( in1, in2->in(1) ) )
4022N/A return new (phase->C) SubINode( phase->intcon(0),in2->in(2));
0N/A // Convert "(x-y) - x" into "-y"
0N/A if( op1 == Op_SubI &&
0N/A phase->eqv( in1->in(1), in2 ) )
4022N/A return new (phase->C) SubINode( phase->intcon(0),in1->in(2));
0N/A // Convert "x - (y+x)" into "-y"
0N/A if( op2 == Op_AddI &&
0N/A phase->eqv( in1, in2->in(2) ) )
4022N/A return new (phase->C) SubINode( phase->intcon(0),in2->in(1));
0N/A
0N/A // Convert "0 - (x-y)" into "y-x"
0N/A if( t1 == TypeInt::ZERO && op2 == Op_SubI )
4022N/A return new (phase->C) SubINode( in2->in(2), in2->in(1) );
0N/A
0N/A // Convert "0 - (x+con)" into "-con-x"
0N/A jint con;
0N/A if( t1 == TypeInt::ZERO && op2 == Op_AddI &&
0N/A (con = in2->in(2)->find_int_con(0)) != 0 )
4022N/A return new (phase->C) SubINode( phase->intcon(-con), in2->in(1) );
0N/A
0N/A // Convert "(X+A) - (X+B)" into "A - B"
0N/A if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) )
4022N/A return new (phase->C) SubINode( in1->in(2), in2->in(2) );
0N/A
0N/A // Convert "(A+X) - (B+X)" into "A - B"
0N/A if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) )
4022N/A return new (phase->C) SubINode( in1->in(1), in2->in(1) );
0N/A
400N/A // Convert "(A+X) - (X+B)" into "A - B"
400N/A if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) )
4022N/A return new (phase->C) SubINode( in1->in(1), in2->in(2) );
400N/A
400N/A // Convert "(X+A) - (B+X)" into "A - B"
400N/A if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) )
4022N/A return new (phase->C) SubINode( in1->in(2), in2->in(1) );
400N/A
0N/A // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
0N/A // nicer to optimize than subtract.
0N/A if( op2 == Op_SubI && in2->outcnt() == 1) {
4022N/A Node *add1 = phase->transform( new (phase->C) AddINode( in1, in2->in(2) ) );
4022N/A return new (phase->C) SubINode( add1, in2->in(1) );
0N/A }
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------sub--------------------------------------------
0N/A// A subtract node differences it's two inputs.
0N/Aconst Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
0N/A const TypeInt *r0 = t1->is_int(); // Handy access
0N/A const TypeInt *r1 = t2->is_int();
0N/A int32 lo = r0->_lo - r1->_hi;
0N/A int32 hi = r0->_hi - r1->_lo;
0N/A
0N/A // We next check for 32-bit overflow.
0N/A // If that happens, we just assume all integers are possible.
0N/A if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
0N/A ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
0N/A (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
0N/A ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
0N/A return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
0N/A else // Overflow; assume all integers
0N/A return TypeInt::INT;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A Node *in1 = in(1);
0N/A Node *in2 = in(2);
0N/A uint op1 = in1->Opcode();
0N/A uint op2 = in2->Opcode();
0N/A
0N/A#ifdef ASSERT
0N/A // Check for dead loop
0N/A if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
0N/A ( op1 == Op_AddL || op1 == Op_SubL ) &&
0N/A ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
0N/A phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) )
0N/A assert(false, "dead loop in SubLNode::Ideal");
0N/A#endif
0N/A
0N/A if( phase->type( in2 ) == Type::TOP ) return NULL;
0N/A const TypeLong *i = phase->type( in2 )->isa_long();
0N/A // Convert "x-c0" into "x+ -c0".
0N/A if( i && // Might be bottom or top...
0N/A i->is_con() )
4022N/A return new (phase->C) AddLNode(in1, phase->longcon(-i->get_con()));
0N/A
0N/A // Convert "(x+c0) - y" into (x-y) + c0"
0N/A // Do not collapse (x+c0)-y if "+" is a loop increment or
0N/A // if "y" is a loop induction variable.
0N/A if( op1 == Op_AddL && ok_to_convert(in1, in2) ) {
0N/A Node *in11 = in1->in(1);
0N/A const Type *tadd = phase->type( in1->in(2) );
0N/A if( tadd->singleton() && tadd != Type::TOP ) {
4022N/A Node *sub2 = phase->transform( new (phase->C) SubLNode( in11, in2 ));
4022N/A return new (phase->C) AddLNode( sub2, in1->in(2) );
0N/A }
0N/A }
0N/A
0N/A // Convert "x - (y+c0)" into "(x-y) - c0"
0N/A // Need the same check as in above optimization but reversed.
0N/A if (op2 == Op_AddL && ok_to_convert(in2, in1)) {
0N/A Node* in21 = in2->in(1);
0N/A Node* in22 = in2->in(2);
0N/A const TypeLong* tcon = phase->type(in22)->isa_long();
0N/A if (tcon != NULL && tcon->is_con()) {
4022N/A Node* sub2 = phase->transform( new (phase->C) SubLNode(in1, in21) );
0N/A Node* neg_c0 = phase->longcon(- tcon->get_con());
4022N/A return new (phase->C) AddLNode(sub2, neg_c0);
0N/A }
0N/A }
0N/A
0N/A const Type *t1 = phase->type( in1 );
0N/A if( t1 == Type::TOP ) return NULL;
0N/A
0N/A#ifdef ASSERT
0N/A // Check for dead loop
0N/A if( ( op2 == Op_AddL || op2 == Op_SubL ) &&
0N/A ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
0N/A phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) )
0N/A assert(false, "dead loop in SubLNode::Ideal");
0N/A#endif
0N/A
0N/A // Convert "x - (x+y)" into "-y"
0N/A if( op2 == Op_AddL &&
0N/A phase->eqv( in1, in2->in(1) ) )
4022N/A return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2));
0N/A // Convert "x - (y+x)" into "-y"
0N/A if( op2 == Op_AddL &&
0N/A phase->eqv( in1, in2->in(2) ) )
4022N/A return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1));
0N/A
0N/A // Convert "0 - (x-y)" into "y-x"
0N/A if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL )
4022N/A return new (phase->C) SubLNode( in2->in(2), in2->in(1) );
0N/A
0N/A // Convert "(X+A) - (X+B)" into "A - B"
0N/A if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
4022N/A return new (phase->C) SubLNode( in1->in(2), in2->in(2) );
0N/A
0N/A // Convert "(A+X) - (B+X)" into "A - B"
0N/A if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
4022N/A return new (phase->C) SubLNode( in1->in(1), in2->in(1) );
0N/A
0N/A // Convert "A-(B-C)" into (A+C)-B"
0N/A if( op2 == Op_SubL && in2->outcnt() == 1) {
4022N/A Node *add1 = phase->transform( new (phase->C) AddLNode( in1, in2->in(2) ) );
4022N/A return new (phase->C) SubLNode( add1, in2->in(1) );
0N/A }
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------sub--------------------------------------------
0N/A// A subtract node differences it's two inputs.
0N/Aconst Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
0N/A const TypeLong *r0 = t1->is_long(); // Handy access
0N/A const TypeLong *r1 = t2->is_long();
0N/A jlong lo = r0->_lo - r1->_hi;
0N/A jlong hi = r0->_hi - r1->_lo;
0N/A
0N/A // We next check for 32-bit overflow.
0N/A // If that happens, we just assume all integers are possible.
0N/A if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
0N/A ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
0N/A (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
0N/A ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
0N/A return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
0N/A else // Overflow; assume all integers
0N/A return TypeLong::LONG;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Value------------------------------------------
0N/A// A subtract node differences its two inputs.
0N/Aconst Type *SubFPNode::Value( PhaseTransform *phase ) const {
0N/A const Node* in1 = in(1);
0N/A const Node* in2 = in(2);
0N/A // Either input is TOP ==> the result is TOP
0N/A const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
0N/A if( t1 == Type::TOP ) return Type::TOP;
0N/A const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
0N/A if( t2 == Type::TOP ) return Type::TOP;
0N/A
0N/A // if both operands are infinity of same sign, the result is NaN; do
0N/A // not replace with zero
0N/A if( (t1->is_finite() && t2->is_finite()) ) {
0N/A if( phase->eqv(in1, in2) ) return add_id();
0N/A }
0N/A
0N/A // Either input is BOTTOM ==> the result is the local BOTTOM
0N/A const Type *bot = bottom_type();
0N/A if( (t1 == bot) || (t2 == bot) ||
0N/A (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
0N/A return bot;
0N/A
0N/A return sub(t1,t2); // Local flavor of type subtraction
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A const Type *t2 = phase->type( in(2) );
0N/A // Convert "x-c0" into "x+ -c0".
0N/A if( t2->base() == Type::FloatCon ) { // Might be bottom or top...
0N/A // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) );
0N/A }
0N/A
0N/A // Not associative because of boundary conditions (infinity)
0N/A if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
0N/A // Convert "x - (x+y)" into "-y"
0N/A if( in(2)->is_Add() &&
0N/A phase->eqv(in(1),in(2)->in(1) ) )
4022N/A return new (phase->C) SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2));
0N/A }
0N/A
0N/A // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes
0N/A // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0.
0N/A //if( phase->type(in(1)) == TypeF::ZERO )
0N/A //return new (phase->C, 2) NegFNode(in(2));
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------sub--------------------------------------------
0N/A// A subtract node differences its two inputs.
0N/Aconst Type *SubFNode::sub( const Type *t1, const Type *t2 ) const {
0N/A // no folding if one of operands is infinity or NaN, do not do constant folding
0N/A if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) {
0N/A return TypeF::make( t1->getf() - t2->getf() );
0N/A }
0N/A else if( g_isnan(t1->getf()) ) {
0N/A return t1;
0N/A }
0N/A else if( g_isnan(t2->getf()) ) {
0N/A return t2;
0N/A }
0N/A else {
0N/A return Type::FLOAT;
0N/A }
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){
0N/A const Type *t2 = phase->type( in(2) );
0N/A // Convert "x-c0" into "x+ -c0".
0N/A if( t2->base() == Type::DoubleCon ) { // Might be bottom or top...
0N/A // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) );
0N/A }
0N/A
0N/A // Not associative because of boundary conditions (infinity)
0N/A if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
0N/A // Convert "x - (x+y)" into "-y"
0N/A if( in(2)->is_Add() &&
0N/A phase->eqv(in(1),in(2)->in(1) ) )
4022N/A return new (phase->C) SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2));
0N/A }
0N/A
0N/A // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes
0N/A // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0.
0N/A //if( phase->type(in(1)) == TypeD::ZERO )
0N/A //return new (phase->C, 2) NegDNode(in(2));
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------sub--------------------------------------------
0N/A// A subtract node differences its two inputs.
0N/Aconst Type *SubDNode::sub( const Type *t1, const Type *t2 ) const {
0N/A // no folding if one of operands is infinity or NaN, do not do constant folding
0N/A if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
0N/A return TypeD::make( t1->getd() - t2->getd() );
0N/A }
0N/A else if( g_isnan(t1->getd()) ) {
0N/A return t1;
0N/A }
0N/A else if( g_isnan(t2->getd()) ) {
0N/A return t2;
0N/A }
0N/A else {
0N/A return Type::DOUBLE;
0N/A }
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Idealize---------------------------------------
0N/A// Unlike SubNodes, compare must still flatten return value to the
0N/A// range -1, 0, 1.
0N/A// And optimizations like those for (X + Y) - X fail if overflow happens.
0N/ANode *CmpNode::Identity( PhaseTransform *phase ) {
0N/A return this;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------cmp--------------------------------------------
0N/A// Simplify a CmpI (compare 2 integers) node, based on local information.
0N/A// If both inputs are constants, compare them.
0N/Aconst Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
0N/A const TypeInt *r0 = t1->is_int(); // Handy access
0N/A const TypeInt *r1 = t2->is_int();
0N/A
0N/A if( r0->_hi < r1->_lo ) // Range is always low?
0N/A return TypeInt::CC_LT;
0N/A else if( r0->_lo > r1->_hi ) // Range is always high?
0N/A return TypeInt::CC_GT;
0N/A
0N/A else if( r0->is_con() && r1->is_con() ) { // comparing constants?
0N/A assert(r0->get_con() == r1->get_con(), "must be equal");
0N/A return TypeInt::CC_EQ; // Equal results.
0N/A } else if( r0->_hi == r1->_lo ) // Range is never high?
0N/A return TypeInt::CC_LE;
0N/A else if( r0->_lo == r1->_hi ) // Range is never low?
0N/A return TypeInt::CC_GE;
0N/A return TypeInt::CC; // else use worst case results
0N/A}
0N/A
0N/A// Simplify a CmpU (compare 2 integers) node, based on local information.
0N/A// If both inputs are constants, compare them.
0N/Aconst Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
0N/A assert(!t1->isa_ptr(), "obsolete usage of CmpU");
0N/A
0N/A // comparing two unsigned ints
0N/A const TypeInt *r0 = t1->is_int(); // Handy access
0N/A const TypeInt *r1 = t2->is_int();
0N/A
0N/A // Current installed version
0N/A // Compare ranges for non-overlap
0N/A juint lo0 = r0->_lo;
0N/A juint hi0 = r0->_hi;
0N/A juint lo1 = r1->_lo;
0N/A juint hi1 = r1->_hi;
0N/A
0N/A // If either one has both negative and positive values,
0N/A // it therefore contains both 0 and -1, and since [0..-1] is the
0N/A // full unsigned range, the type must act as an unsigned bottom.
0N/A bool bot0 = ((jint)(lo0 ^ hi0) < 0);
0N/A bool bot1 = ((jint)(lo1 ^ hi1) < 0);
0N/A
0N/A if (bot0 || bot1) {
0N/A // All unsigned values are LE -1 and GE 0.
0N/A if (lo0 == 0 && hi0 == 0) {
0N/A return TypeInt::CC_LE; // 0 <= bot
0N/A } else if (lo1 == 0 && hi1 == 0) {
0N/A return TypeInt::CC_GE; // bot >= 0
0N/A }
0N/A } else {
0N/A // We can use ranges of the form [lo..hi] if signs are the same.
0N/A assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
0N/A // results are reversed, '-' > '+' for unsigned compare
0N/A if (hi0 < lo1) {
0N/A return TypeInt::CC_LT; // smaller
0N/A } else if (lo0 > hi1) {
0N/A return TypeInt::CC_GT; // greater
0N/A } else if (hi0 == lo1 && lo0 == hi1) {
0N/A return TypeInt::CC_EQ; // Equal results
0N/A } else if (lo0 >= hi1) {
0N/A return TypeInt::CC_GE;
0N/A } else if (hi0 <= lo1) {
0N/A // Check for special case in Hashtable::get. (See below.)
3873N/A if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
0N/A return TypeInt::CC_LT;
0N/A return TypeInt::CC_LE;
0N/A }
0N/A }
0N/A // Check for special case in Hashtable::get - the hash index is
0N/A // mod'ed to the table size so the following range check is useless.
0N/A // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
0N/A // to be positive.
0N/A // (This is a gross hack, since the sub method never
0N/A // looks at the structure of the node in any other case.)
3873N/A if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
0N/A return TypeInt::CC_LT;
0N/A return TypeInt::CC; // else use worst case results
0N/A}
0N/A
3873N/Abool CmpUNode::is_index_range_check() const {
3873N/A // Check for the "(X ModI Y) CmpU Y" shape
3873N/A return (in(1)->Opcode() == Op_ModI &&
3873N/A in(1)->in(2)->eqv_uncast(in(2)));
3873N/A}
3873N/A
0N/A//------------------------------Idealize---------------------------------------
0N/ANode *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
0N/A if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
0N/A switch (in(1)->Opcode()) {
0N/A case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
4022N/A return new (phase->C) CmpLNode(in(1)->in(1),in(1)->in(2));
0N/A case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
4022N/A return new (phase->C) CmpFNode(in(1)->in(1),in(1)->in(2));
0N/A case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
4022N/A return new (phase->C) CmpDNode(in(1)->in(1),in(1)->in(2));
0N/A //case Op_SubI:
0N/A // If (x - y) cannot overflow, then ((x - y) <?> 0)
0N/A // can be turned into (x <?> y).
0N/A // This is handled (with more general cases) by Ideal_sub_algebra.
0N/A }
0N/A }
0N/A return NULL; // No change
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A// Simplify a CmpL (compare 2 longs ) node, based on local information.
0N/A// If both inputs are constants, compare them.
0N/Aconst Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
0N/A const TypeLong *r0 = t1->is_long(); // Handy access
0N/A const TypeLong *r1 = t2->is_long();
0N/A
0N/A if( r0->_hi < r1->_lo ) // Range is always low?
0N/A return TypeInt::CC_LT;
0N/A else if( r0->_lo > r1->_hi ) // Range is always high?
0N/A return TypeInt::CC_GT;
0N/A
0N/A else if( r0->is_con() && r1->is_con() ) { // comparing constants?
0N/A assert(r0->get_con() == r1->get_con(), "must be equal");
0N/A return TypeInt::CC_EQ; // Equal results.
0N/A } else if( r0->_hi == r1->_lo ) // Range is never high?
0N/A return TypeInt::CC_LE;
0N/A else if( r0->_lo == r1->_hi ) // Range is never low?
0N/A return TypeInt::CC_GE;
0N/A return TypeInt::CC; // else use worst case results
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------sub--------------------------------------------
0N/A// Simplify an CmpP (compare 2 pointers) node, based on local information.
0N/A// If both inputs are constants, compare them.
0N/Aconst Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
0N/A const TypePtr *r0 = t1->is_ptr(); // Handy access
0N/A const TypePtr *r1 = t2->is_ptr();
0N/A
0N/A // Undefined inputs makes for an undefined result
0N/A if( TypePtr::above_centerline(r0->_ptr) ||
0N/A TypePtr::above_centerline(r1->_ptr) )
0N/A return Type::TOP;
0N/A
0N/A if (r0 == r1 && r0->singleton()) {
0N/A // Equal pointer constants (klasses, nulls, etc.)
0N/A return TypeInt::CC_EQ;
0N/A }
0N/A
0N/A // See if it is 2 unrelated classes.
0N/A const TypeOopPtr* p0 = r0->isa_oopptr();
0N/A const TypeOopPtr* p1 = r1->isa_oopptr();
0N/A if (p0 && p1) {
33N/A Node* in1 = in(1)->uncast();
33N/A Node* in2 = in(2)->uncast();
33N/A AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
33N/A AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
33N/A if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
33N/A return TypeInt::CC_GT; // different pointers
33N/A }
0N/A ciKlass* klass0 = p0->klass();
0N/A bool xklass0 = p0->klass_is_exact();
0N/A ciKlass* klass1 = p1->klass();
0N/A bool xklass1 = p1->klass_is_exact();
0N/A int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
0N/A if (klass0 && klass1 &&
0N/A kps != 1 && // both or neither are klass pointers
668N/A klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces
783N/A klass1->is_loaded() && !klass1->is_interface() &&
783N/A (!klass0->is_obj_array_klass() ||
783N/A !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) &&
783N/A (!klass1->is_obj_array_klass() ||
783N/A !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) {
296N/A bool unrelated_classes = false;
0N/A // See if neither subclasses the other, or if the class on top
296N/A // is precise. In either of these cases, the compare is known
296N/A // to fail if at least one of the pointers is provably not null.
0N/A if (klass0->equals(klass1) || // if types are unequal but klasses are
0N/A !klass0->is_java_klass() || // types not part of Java language?
0N/A !klass1->is_java_klass()) { // types not part of Java language?
0N/A // Do nothing; we know nothing for imprecise types
0N/A } else if (klass0->is_subtype_of(klass1)) {
296N/A // If klass1's type is PRECISE, then classes are unrelated.
296N/A unrelated_classes = xklass1;
0N/A } else if (klass1->is_subtype_of(klass0)) {
296N/A // If klass0's type is PRECISE, then classes are unrelated.
296N/A unrelated_classes = xklass0;
0N/A } else { // Neither subtypes the other
296N/A unrelated_classes = true;
296N/A }
296N/A if (unrelated_classes) {
296N/A // The oops classes are known to be unrelated. If the joined PTRs of
296N/A // two oops is not Null and not Bottom, then we are sure that one
296N/A // of the two oops is non-null, and the comparison will always fail.
296N/A TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
296N/A if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
296N/A return TypeInt::CC_GT;
296N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Known constants can be compared exactly
0N/A // Null can be distinguished from any NotNull pointers
0N/A // Unknown inputs makes an unknown result
0N/A if( r0->singleton() ) {
0N/A intptr_t bits0 = r0->get_con();
0N/A if( r1->singleton() )
0N/A return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
0N/A return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
0N/A } else if( r1->singleton() ) {
0N/A intptr_t bits1 = r1->get_con();
0N/A return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
0N/A } else
0N/A return TypeInt::CC;
0N/A}
0N/A
3798N/Astatic inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
3798N/A // Return the klass node for
3798N/A // LoadP(AddP(foo:Klass, #java_mirror))
3798N/A // or NULL if not matching.
3798N/A if (n->Opcode() != Op_LoadP) return NULL;
3798N/A
3798N/A const TypeInstPtr* tp = phase->type(n)->isa_instptr();
3798N/A if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
3798N/A
3798N/A Node* adr = n->in(MemNode::Address);
3798N/A intptr_t off = 0;
3798N/A Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
3798N/A if (k == NULL) return NULL;
3798N/A const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
3798N/A if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
3798N/A
3798N/A // We've found the klass node of a Java mirror load.
3798N/A return k;
3798N/A}
3798N/A
3798N/Astatic inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) {
3798N/A // for ConP(Foo.class) return ConP(Foo.klass)
3798N/A // otherwise return NULL
3798N/A if (!n->is_Con()) return NULL;
3798N/A
3798N/A const TypeInstPtr* tp = phase->type(n)->isa_instptr();
3798N/A if (!tp) return NULL;
3798N/A
3798N/A ciType* mirror_type = tp->java_mirror_type();
3798N/A // TypeInstPtr::java_mirror_type() returns non-NULL for compile-
3798N/A // time Class constants only.
3798N/A if (!mirror_type) return NULL;
3798N/A
3798N/A // x.getClass() == int.class can never be true (for all primitive types)
3798N/A // Return a ConP(NULL) node for this case.
3798N/A if (mirror_type->is_classless()) {
3798N/A return phase->makecon(TypePtr::NULL_PTR);
3798N/A }
3798N/A
3798N/A // return the ConP(Foo.klass)
3798N/A assert(mirror_type->is_klass(), "mirror_type should represent a klassOop");
3798N/A return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
3798N/A}
3798N/A
0N/A//------------------------------Ideal------------------------------------------
3798N/A// Normalize comparisons between Java mirror loads to compare the klass instead.
3798N/A//
3798N/A// Also check for the case of comparing an unknown klass loaded from the primary
0N/A// super-type array vs a known klass with no subtypes. This amounts to
0N/A// checking to see an unknown klass subtypes a known klass with no subtypes;
0N/A// this only happens on an exact match. We can shorten this test by 1 load.
0N/ANode *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
3798N/A // Normalize comparisons between Java mirrors into comparisons of the low-
3798N/A // level klass, where a dependent load could be shortened.
3798N/A //
3798N/A // The new pattern has a nice effect of matching the same pattern used in the
3798N/A // fast path of instanceof/checkcast/Class.isInstance(), which allows
3798N/A // redundant exact type check be optimized away by GVN.
3798N/A // For example, in
3798N/A // if (x.getClass() == Foo.class) {
3798N/A // Foo foo = (Foo) x;
3798N/A // // ... use a ...
3798N/A // }
3798N/A // a CmpPNode could be shared between if_acmpne and checkcast
3798N/A {
3798N/A Node* k1 = isa_java_mirror_load(phase, in(1));
3798N/A Node* k2 = isa_java_mirror_load(phase, in(2));
3798N/A Node* conk2 = isa_const_java_mirror(phase, in(2));
3798N/A
3798N/A if (k1 && (k2 || conk2)) {
3798N/A Node* lhs = k1;
3798N/A Node* rhs = (k2 != NULL) ? k2 : conk2;
3798N/A this->set_req(1, lhs);
3798N/A this->set_req(2, rhs);
3798N/A return this;
3798N/A }
3798N/A }
3798N/A
0N/A // Constant pointer on right?
0N/A const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
0N/A if (t2 == NULL || !t2->klass_is_exact())
0N/A return NULL;
0N/A // Get the constant klass we are comparing to.
0N/A ciKlass* superklass = t2->klass();
0N/A
0N/A // Now check for LoadKlass on left.
0N/A Node* ldk1 = in(1);
293N/A if (ldk1->is_DecodeN()) {
293N/A ldk1 = ldk1->in(1);
293N/A if (ldk1->Opcode() != Op_LoadNKlass )
293N/A return NULL;
293N/A } else if (ldk1->Opcode() != Op_LoadKlass )
0N/A return NULL;
0N/A // Take apart the address of the LoadKlass:
0N/A Node* adr1 = ldk1->in(MemNode::Address);
0N/A intptr_t con2 = 0;
0N/A Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2);
0N/A if (ldk2 == NULL)
0N/A return NULL;
0N/A if (con2 == oopDesc::klass_offset_in_bytes()) {
0N/A // We are inspecting an object's concrete class.
0N/A // Short-circuit the check if the query is abstract.
0N/A if (superklass->is_interface() ||
0N/A superklass->is_abstract()) {
0N/A // Make it come out always false:
0N/A this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
0N/A return this;
0N/A }
0N/A }
0N/A
0N/A // Check for a LoadKlass from primary supertype array.
0N/A // Any nested loadklass from loadklass+con must be from the p.s. array.
293N/A if (ldk2->is_DecodeN()) {
293N/A // Keep ldk2 as DecodeN since it could be used in CmpP below.
293N/A if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
293N/A return NULL;
293N/A } else if (ldk2->Opcode() != Op_LoadKlass)
0N/A return NULL;
0N/A
0N/A // Verify that we understand the situation
0N/A if (con2 != (intptr_t) superklass->super_check_offset())
0N/A return NULL; // Might be element-klass loading from array klass
0N/A
0N/A // If 'superklass' has no subklasses and is not an interface, then we are
0N/A // assured that the only input which will pass the type check is
0N/A // 'superklass' itself.
0N/A //
0N/A // We could be more liberal here, and allow the optimization on interfaces
0N/A // which have a single implementor. This would require us to increase the
0N/A // expressiveness of the add_dependency() mechanism.
0N/A // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
0N/A
0N/A // Object arrays must have their base element have no subtypes
0N/A while (superklass->is_obj_array_klass()) {
0N/A ciType* elem = superklass->as_obj_array_klass()->element_type();
0N/A superklass = elem->as_klass();
0N/A }
0N/A if (superklass->is_instance_klass()) {
0N/A ciInstanceKlass* ik = superklass->as_instance_klass();
0N/A if (ik->has_subklass() || ik->is_interface()) return NULL;
0N/A // Add a dependency if there is a chance that a subclass will be added later.
0N/A if (!ik->is_final()) {
0N/A phase->C->dependencies()->assert_leaf_type(ik);
0N/A }
0N/A }
0N/A
0N/A // Bypass the dependent load, and compare directly
0N/A this->set_req(1,ldk2);
0N/A
0N/A return this;
0N/A}
0N/A
0N/A//=============================================================================
113N/A//------------------------------sub--------------------------------------------
113N/A// Simplify an CmpN (compare 2 pointers) node, based on local information.
113N/A// If both inputs are constants, compare them.
113N/Aconst Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const {
221N/A const TypePtr *r0 = t1->make_ptr(); // Handy access
221N/A const TypePtr *r1 = t2->make_ptr();
113N/A
113N/A // Undefined inputs makes for an undefined result
4505N/A if ((r0 == NULL) || (r1 == NULL) ||
4505N/A TypePtr::above_centerline(r0->_ptr) ||
4505N/A TypePtr::above_centerline(r1->_ptr)) {
113N/A return Type::TOP;
4505N/A }
113N/A if (r0 == r1 && r0->singleton()) {
113N/A // Equal pointer constants (klasses, nulls, etc.)
113N/A return TypeInt::CC_EQ;
113N/A }
113N/A
113N/A // See if it is 2 unrelated classes.
113N/A const TypeOopPtr* p0 = r0->isa_oopptr();
113N/A const TypeOopPtr* p1 = r1->isa_oopptr();
113N/A if (p0 && p1) {
113N/A ciKlass* klass0 = p0->klass();
113N/A bool xklass0 = p0->klass_is_exact();
113N/A ciKlass* klass1 = p1->klass();
113N/A bool xklass1 = p1->klass_is_exact();
113N/A int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
113N/A if (klass0 && klass1 &&
113N/A kps != 1 && // both or neither are klass pointers
113N/A !klass0->is_interface() && // do not trust interfaces
113N/A !klass1->is_interface()) {
296N/A bool unrelated_classes = false;
113N/A // See if neither subclasses the other, or if the class on top
296N/A // is precise. In either of these cases, the compare is known
296N/A // to fail if at least one of the pointers is provably not null.
113N/A if (klass0->equals(klass1) || // if types are unequal but klasses are
113N/A !klass0->is_java_klass() || // types not part of Java language?
113N/A !klass1->is_java_klass()) { // types not part of Java language?
113N/A // Do nothing; we know nothing for imprecise types
113N/A } else if (klass0->is_subtype_of(klass1)) {
296N/A // If klass1's type is PRECISE, then classes are unrelated.
296N/A unrelated_classes = xklass1;
113N/A } else if (klass1->is_subtype_of(klass0)) {
296N/A // If klass0's type is PRECISE, then classes are unrelated.
296N/A unrelated_classes = xklass0;
113N/A } else { // Neither subtypes the other
296N/A unrelated_classes = true;
296N/A }
296N/A if (unrelated_classes) {
296N/A // The oops classes are known to be unrelated. If the joined PTRs of
296N/A // two oops is not Null and not Bottom, then we are sure that one
296N/A // of the two oops is non-null, and the comparison will always fail.
296N/A TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
296N/A if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
296N/A return TypeInt::CC_GT;
296N/A }
113N/A }
113N/A }
113N/A }
113N/A
113N/A // Known constants can be compared exactly
113N/A // Null can be distinguished from any NotNull pointers
113N/A // Unknown inputs makes an unknown result
113N/A if( r0->singleton() ) {
113N/A intptr_t bits0 = r0->get_con();
113N/A if( r1->singleton() )
113N/A return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
113N/A return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
113N/A } else if( r1->singleton() ) {
113N/A intptr_t bits1 = r1->get_con();
113N/A return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
113N/A } else
113N/A return TypeInt::CC;
113N/A}
113N/A
113N/A//------------------------------Ideal------------------------------------------
113N/ANode *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
113N/A return NULL;
113N/A}
113N/A
113N/A//=============================================================================
0N/A//------------------------------Value------------------------------------------
0N/A// Simplify an CmpF (compare 2 floats ) node, based on local information.
0N/A// If both inputs are constants, compare them.
0N/Aconst Type *CmpFNode::Value( PhaseTransform *phase ) const {
0N/A const Node* in1 = in(1);
0N/A const Node* in2 = in(2);
0N/A // Either input is TOP ==> the result is TOP
0N/A const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
0N/A if( t1 == Type::TOP ) return Type::TOP;
0N/A const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
0N/A if( t2 == Type::TOP ) return Type::TOP;
0N/A
0N/A // Not constants? Don't know squat - even if they are the same
0N/A // value! If they are NaN's they compare to LT instead of EQ.
0N/A const TypeF *tf1 = t1->isa_float_constant();
0N/A const TypeF *tf2 = t2->isa_float_constant();
0N/A if( !tf1 || !tf2 ) return TypeInt::CC;
0N/A
0N/A // This implements the Java bytecode fcmpl, so unordered returns -1.
0N/A if( tf1->is_nan() || tf2->is_nan() )
0N/A return TypeInt::CC_LT;
0N/A
0N/A if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
0N/A if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
0N/A assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
0N/A return TypeInt::CC_EQ;
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------Value------------------------------------------
0N/A// Simplify an CmpD (compare 2 doubles ) node, based on local information.
0N/A// If both inputs are constants, compare them.
0N/Aconst Type *CmpDNode::Value( PhaseTransform *phase ) const {
0N/A const Node* in1 = in(1);
0N/A const Node* in2 = in(2);
0N/A // Either input is TOP ==> the result is TOP
0N/A const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
0N/A if( t1 == Type::TOP ) return Type::TOP;
0N/A const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
0N/A if( t2 == Type::TOP ) return Type::TOP;
0N/A
0N/A // Not constants? Don't know squat - even if they are the same
0N/A // value! If they are NaN's they compare to LT instead of EQ.
0N/A const TypeD *td1 = t1->isa_double_constant();
0N/A const TypeD *td2 = t2->isa_double_constant();
0N/A if( !td1 || !td2 ) return TypeInt::CC;
0N/A
0N/A // This implements the Java bytecode dcmpl, so unordered returns -1.
0N/A if( td1->is_nan() || td2->is_nan() )
0N/A return TypeInt::CC_LT;
0N/A
0N/A if( td1->_d < td2->_d ) return TypeInt::CC_LT;
0N/A if( td1->_d > td2->_d ) return TypeInt::CC_GT;
0N/A assert( td1->_d == td2->_d, "do not understand FP behavior" );
0N/A return TypeInt::CC_EQ;
0N/A}
0N/A
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){
0N/A // Check if we can change this to a CmpF and remove a ConvD2F operation.
0N/A // Change (CMPD (F2D (float)) (ConD value))
0N/A // To (CMPF (float) (ConF value))
0N/A // Valid when 'value' does not lose precision as a float.
0N/A // Benefits: eliminates conversion, does not require 24-bit mode
0N/A
0N/A // NaNs prevent commuting operands. This transform works regardless of the
0N/A // order of ConD and ConvF2D inputs by preserving the original order.
0N/A int idx_f2d = 1; // ConvF2D on left side?
0N/A if( in(idx_f2d)->Opcode() != Op_ConvF2D )
0N/A idx_f2d = 2; // No, swap to check for reversed args
0N/A int idx_con = 3-idx_f2d; // Check for the constant on other input
0N/A
0N/A if( ConvertCmpD2CmpF &&
0N/A in(idx_f2d)->Opcode() == Op_ConvF2D &&
0N/A in(idx_con)->Opcode() == Op_ConD ) {
0N/A const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant();
0N/A double t2_value_as_double = t2->_d;
0N/A float t2_value_as_float = (float)t2_value_as_double;
0N/A if( t2_value_as_double == (double)t2_value_as_float ) {
0N/A // Test value can be represented as a float
0N/A // Eliminate the conversion to double and create new comparison
0N/A Node *new_in1 = in(idx_f2d)->in(1);
0N/A Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
0N/A if( idx_f2d != 1 ) { // Must flip args to match original order
0N/A Node *tmp = new_in1;
0N/A new_in1 = new_in2;
0N/A new_in2 = tmp;
0N/A }
0N/A CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
4022N/A ? new (phase->C) CmpF3Node( new_in1, new_in2 )
4022N/A : new (phase->C) CmpFNode ( new_in1, new_in2 ) ;
0N/A return new_cmp; // Changed to CmpFNode
0N/A }
0N/A // Testing value required the precision of a double
0N/A }
0N/A return NULL; // No change
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------cc2logical-------------------------------------
0N/A// Convert a condition code type to a logical type
0N/Aconst Type *BoolTest::cc2logical( const Type *CC ) const {
0N/A if( CC == Type::TOP ) return Type::TOP;
0N/A if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
0N/A const TypeInt *ti = CC->is_int();
0N/A if( ti->is_con() ) { // Only 1 kind of condition codes set?
0N/A // Match low order 2 bits
0N/A int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
0N/A if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
0N/A return TypeInt::make(tmp); // Boolean result
0N/A }
0N/A
0N/A if( CC == TypeInt::CC_GE ) {
0N/A if( _test == ge ) return TypeInt::ONE;
0N/A if( _test == lt ) return TypeInt::ZERO;
0N/A }
0N/A if( CC == TypeInt::CC_LE ) {
0N/A if( _test == le ) return TypeInt::ONE;
0N/A if( _test == gt ) return TypeInt::ZERO;
0N/A }
0N/A
0N/A return TypeInt::BOOL;
0N/A}
0N/A
0N/A//------------------------------dump_spec-------------------------------------
0N/A// Print special per-node info
0N/A#ifndef PRODUCT
0N/Avoid BoolTest::dump_on(outputStream *st) const {
0N/A const char *msg[] = {"eq","gt","??","lt","ne","le","??","ge"};
0N/A st->print(msg[_test]);
0N/A}
0N/A#endif
0N/A
0N/A//=============================================================================
0N/Auint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
0N/Auint BoolNode::size_of() const { return sizeof(BoolNode); }
0N/A
0N/A//------------------------------operator==-------------------------------------
0N/Auint BoolNode::cmp( const Node &n ) const {
0N/A const BoolNode *b = (const BoolNode *)&n; // Cast up
0N/A return (_test._test == b->_test._test);
0N/A}
0N/A
0N/A//------------------------------clone_cmp--------------------------------------
0N/A// Clone a compare/bool tree
0N/Astatic Node *clone_cmp( Node *cmp, Node *cmp1, Node *cmp2, PhaseGVN *gvn, BoolTest::mask test ) {
0N/A Node *ncmp = cmp->clone();
0N/A ncmp->set_req(1,cmp1);
0N/A ncmp->set_req(2,cmp2);
0N/A ncmp = gvn->transform( ncmp );
4022N/A return new (gvn->C) BoolNode( ncmp, test );
0N/A}
0N/A
0N/A//-------------------------------make_predicate--------------------------------
0N/ANode* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
0N/A if (test_value->is_Con()) return test_value;
0N/A if (test_value->is_Bool()) return test_value;
0N/A Compile* C = phase->C;
0N/A if (test_value->is_CMove() &&
0N/A test_value->in(CMoveNode::Condition)->is_Bool()) {
0N/A BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool();
0N/A const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
0N/A const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
0N/A if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
0N/A return bol;
0N/A } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
0N/A return phase->transform( bol->negate(phase) );
0N/A }
0N/A // Else fall through. The CMove gets in the way of the test.
0N/A // It should be the case that make_predicate(bol->as_int_value()) == bol.
0N/A }
4022N/A Node* cmp = new (C) CmpINode(test_value, phase->intcon(0));
0N/A cmp = phase->transform(cmp);
4022N/A Node* bol = new (C) BoolNode(cmp, BoolTest::ne);
0N/A return phase->transform(bol);
0N/A}
0N/A
0N/A//--------------------------------as_int_value---------------------------------
0N/ANode* BoolNode::as_int_value(PhaseGVN* phase) {
0N/A // Inverse to make_predicate. The CMove probably boils down to a Conv2B.
0N/A Node* cmov = CMoveNode::make(phase->C, NULL, this,
0N/A phase->intcon(0), phase->intcon(1),
0N/A TypeInt::BOOL);
0N/A return phase->transform(cmov);
0N/A}
0N/A
0N/A//----------------------------------negate-------------------------------------
0N/ABoolNode* BoolNode::negate(PhaseGVN* phase) {
0N/A Compile* C = phase->C;
4022N/A return new (C) BoolNode(in(1), _test.negate());
0N/A}
0N/A
0N/A
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
0N/A // This moves the constant to the right. Helps value-numbering.
0N/A Node *cmp = in(1);
0N/A if( !cmp->is_Sub() ) return NULL;
0N/A int cop = cmp->Opcode();
0N/A if( cop == Op_FastLock || cop == Op_FastUnlock ) return NULL;
0N/A Node *cmp1 = cmp->in(1);
0N/A Node *cmp2 = cmp->in(2);
0N/A if( !cmp1 ) return NULL;
0N/A
0N/A // Constant on left?
0N/A Node *con = cmp1;
0N/A uint op2 = cmp2->Opcode();
0N/A // Move constants to the right of compare's to canonicalize.
0N/A // Do not muck with Opaque1 nodes, as this indicates a loop
0N/A // guard that cannot change shape.
0N/A if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 &&
0N/A // Because of NaN's, CmpD and CmpF are not commutative
0N/A cop != Op_CmpD && cop != Op_CmpF &&
0N/A // Protect against swapping inputs to a compare when it is used by a
0N/A // counted loop exit, which requires maintaining the loop-limit as in(2)
0N/A !is_counted_loop_exit_test() ) {
0N/A // Ok, commute the constant to the right of the cmp node.
0N/A // Clone the Node, getting a new Node of the same class
0N/A cmp = cmp->clone();
0N/A // Swap inputs to the clone
0N/A cmp->swap_edges(1, 2);
0N/A cmp = phase->transform( cmp );
4022N/A return new (phase->C) BoolNode( cmp, _test.commute() );
0N/A }
0N/A
0N/A // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)".
0N/A // The XOR-1 is an idiom used to flip the sense of a bool. We flip the
0N/A // test instead.
0N/A int cmp1_op = cmp1->Opcode();
0N/A const TypeInt* cmp2_type = phase->type(cmp2)-> Error!

 

There was an error!

null

java.lang.NullPointerException