0N/A/*
1879N/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 "memory/allocation.inline.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/machnode.hpp"
1879N/A#include "opto/mulnode.hpp"
1879N/A#include "opto/phaseX.hpp"
1879N/A#include "opto/subnode.hpp"
0N/A
1879N/A// Portions of code courtesy of Clifford Click
0N/A
0N/A// Classic Add functionality. This covers all the usual 'add' behaviors for
0N/A// an algebraic ring. Add-integer, add-float, add-double, and binary-or are
0N/A// all inherited from this class. The various identity values are supplied
0N/A// by virtual functions.
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------hash-------------------------------------------
0N/A// Hash function over AddNodes. Needs to be commutative; i.e., I swap
0N/A// (commute) inputs to AddNodes willy-nilly so the hash function must return
0N/A// the same value in the presence of edge swapping.
0N/Auint AddNode::hash() const {
0N/A return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
0N/A}
0N/A
0N/A//------------------------------Identity---------------------------------------
0N/A// If either input is a constant 0, return the other input.
0N/ANode *AddNode::Identity( PhaseTransform *phase ) {
0N/A const Type *zero = add_id(); // The additive identity
0N/A if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
0N/A if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
0N/A return this;
0N/A}
0N/A
0N/A//------------------------------commute----------------------------------------
0N/A// Commute operands to move loads and constants to the right.
0N/Astatic bool commute( Node *add, int con_left, int con_right ) {
0N/A Node *in1 = add->in(1);
0N/A Node *in2 = add->in(2);
0N/A
0N/A // Convert "1+x" into "x+1".
0N/A // Right is a constant; leave it
0N/A if( con_right ) return false;
0N/A // Left is a constant; move it right.
0N/A if( con_left ) {
0N/A add->swap_edges(1, 2);
0N/A return true;
0N/A }
0N/A
0N/A // Convert "Load+x" into "x+Load".
0N/A // Now check for loads
99N/A if (in2->is_Load()) {
99N/A if (!in1->is_Load()) {
99N/A // already x+Load to return
99N/A return false;
99N/A }
99N/A // both are loads, so fall through to sort inputs by idx
99N/A } else if( in1->is_Load() ) {
99N/A // Left is a Load and Right is not; move it right.
0N/A add->swap_edges(1, 2);
0N/A return true;
0N/A }
0N/A
0N/A PhiNode *phi;
0N/A // Check for tight loop increments: Loop-phi of Add of loop-phi
0N/A if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add)
0N/A return false;
0N/A if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){
0N/A add->swap_edges(1, 2);
0N/A return true;
0N/A }
0N/A
0N/A // Otherwise, sort inputs (commutativity) to help value numbering.
0N/A if( in1->_idx > in2->_idx ) {
0N/A add->swap_edges(1, 2);
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A//------------------------------Idealize---------------------------------------
0N/A// If we get here, we assume we are associative!
0N/ANode *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A const Type *t1 = phase->type( in(1) );
0N/A const Type *t2 = phase->type( in(2) );
0N/A int con_left = t1->singleton();
0N/A int con_right = t2->singleton();
0N/A
0N/A // Check for commutative operation desired
0N/A if( commute(this,con_left,con_right) ) return this;
0N/A
0N/A AddNode *progress = NULL; // Progress flag
0N/A
0N/A // Convert "(x+1)+2" into "x+(1+2)". If the right input is a
0N/A // constant, and the left input is an add of a constant, flatten the
0N/A // expression tree.
0N/A Node *add1 = in(1);
0N/A Node *add2 = in(2);
0N/A int add1_op = add1->Opcode();
0N/A int this_op = Opcode();
0N/A if( con_right && t2 != Type::TOP && // Right input is a constant?
0N/A add1_op == this_op ) { // Left input is an Add?
0N/A
0N/A // Type of left _in right input
0N/A const Type *t12 = phase->type( add1->in(2) );
0N/A if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
0N/A // Check for rare case of closed data cycle which can happen inside
0N/A // unreachable loops. In these cases the computation is undefined.
0N/A#ifdef ASSERT
0N/A Node *add11 = add1->in(1);
0N/A int add11_op = add11->Opcode();
0N/A if( (add1 == add1->in(1))
0N/A || (add11_op == this_op && add11->in(1) == add1) ) {
0N/A assert(false, "dead loop in AddNode::Ideal");
0N/A }
0N/A#endif
0N/A // The Add of the flattened expression
0N/A Node *x1 = add1->in(1);
0N/A Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 ));
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
0N/A if( igvn ) {
0N/A set_req_X(2,x2,igvn);
0N/A set_req_X(1,x1,igvn);
0N/A } else {
0N/A set_req(2,x2);
0N/A set_req(1,x1);
0N/A }
0N/A progress = this; // Made progress
0N/A add1 = in(1);
0N/A add1_op = add1->Opcode();
0N/A }
0N/A }
0N/A
0N/A // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree.
0N/A if( add1_op == this_op && !con_right ) {
0N/A Node *a12 = add1->in(2);
0N/A const Type *t12 = phase->type( a12 );
400N/A if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
400N/A !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
320N/A assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
0N/A add2 = add1->clone();
0N/A add2->set_req(2, in(2));
0N/A add2 = phase->transform(add2);
0N/A set_req(1, add2);
0N/A set_req(2, a12);
0N/A progress = this;
0N/A add2 = a12;
0N/A }
0N/A }
0N/A
0N/A // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree.
0N/A int add2_op = add2->Opcode();
0N/A if( add2_op == this_op && !con_left ) {
0N/A Node *a22 = add2->in(2);
0N/A const Type *t22 = phase->type( a22 );
400N/A if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
400N/A !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
320N/A assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
0N/A Node *addx = add2->clone();
0N/A addx->set_req(1, in(1));
0N/A addx->set_req(2, add2->in(1));
0N/A addx = phase->transform(addx);
0N/A set_req(1, addx);
0N/A set_req(2, a22);
0N/A progress = this;
4127N/A PhaseIterGVN *igvn = phase->is_IterGVN();
4127N/A if (add2->outcnt() == 0 && igvn) {
4127N/A // add disconnected.
4127N/A igvn->_worklist.push(add2);
4127N/A }
0N/A }
0N/A }
0N/A
0N/A return progress;
0N/A}
0N/A
0N/A//------------------------------Value-----------------------------------------
0N/A// An add node sums it's two _in. If one input is an RSD, we must mixin
0N/A// the other input's symbols.
0N/Aconst Type *AddNode::Value( PhaseTransform *phase ) const {
0N/A // Either input is TOP ==> the result is TOP
0N/A const Type *t1 = phase->type( in(1) );
0N/A const Type *t2 = phase->type( in(2) );
0N/A if( t1 == Type::TOP ) return Type::TOP;
0N/A if( t2 == Type::TOP ) return Type::TOP;
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 // Check for an addition involving the additive identity
0N/A const Type *tadd = add_of_identity( t1, t2 );
0N/A if( tadd ) return tadd;
0N/A
0N/A return add_ring(t1,t2); // Local flavor of type addition
0N/A}
0N/A
0N/A//------------------------------add_identity-----------------------------------
0N/A// Check for addition of the identity
0N/Aconst Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {
0N/A const Type *zero = add_id(); // The additive identity
0N/A if( t1->higher_equal( zero ) ) return t2;
0N/A if( t2->higher_equal( zero ) ) return t1;
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------Idealize---------------------------------------
0N/ANode *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
400N/A Node* in1 = in(1);
400N/A Node* in2 = in(2);
400N/A int op1 = in1->Opcode();
400N/A int op2 = in2->Opcode();
0N/A // Fold (con1-x)+con2 into (con1+con2)-x
400N/A if ( op1 == Op_AddI && op2 == Op_SubI ) {
400N/A // Swap edges to try optimizations below
400N/A in1 = in2;
400N/A in2 = in(1);
400N/A op1 = op2;
400N/A op2 = in2->Opcode();
400N/A }
0N/A if( op1 == Op_SubI ) {
400N/A const Type *t_sub1 = phase->type( in1->in(1) );
400N/A const Type *t_2 = phase->type( in2 );
0N/A if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
4022N/A return new (phase->C) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ),
400N/A in1->in(2) );
0N/A // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
0N/A if( op2 == Op_SubI ) {
0N/A // Check for dead cycle: d = (a-b)+(c-d)
400N/A assert( in1->in(2) != this && in2->in(2) != this,
0N/A "dead loop in AddINode::Ideal" );
4022N/A Node *sub = new (phase->C) SubINode(NULL, NULL);
4022N/A sub->init_req(1, phase->transform(new (phase->C) AddINode(in1->in(1), in2->in(1) ) ));
4022N/A sub->init_req(2, phase->transform(new (phase->C) AddINode(in1->in(2), in2->in(2) ) ));
0N/A return sub;
0N/A }
400N/A // Convert "(a-b)+(b+c)" into "(a+c)"
400N/A if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
400N/A assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
4022N/A return new (phase->C) AddINode(in1->in(1), in2->in(2));
400N/A }
400N/A // Convert "(a-b)+(c+b)" into "(a+c)"
400N/A if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
400N/A assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
4022N/A return new (phase->C) AddINode(in1->in(1), in2->in(1));
400N/A }
400N/A // Convert "(a-b)+(b-c)" into "(a-c)"
400N/A if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
400N/A assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
4022N/A return new (phase->C) SubINode(in1->in(1), in2->in(2));
400N/A }
400N/A // Convert "(a-b)+(c-a)" into "(c-b)"
400N/A if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
400N/A assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
4022N/A return new (phase->C) SubINode(in2->in(1), in1->in(2));
400N/A }
0N/A }
0N/A
0N/A // Convert "x+(0-y)" into "(x-y)"
400N/A if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
4022N/A return new (phase->C) SubINode(in1, in2->in(2) );
0N/A
0N/A // Convert "(0-y)+x" into "(x-y)"
400N/A if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
4022N/A return new (phase->C) SubINode( in2, in1->in(2) );
0N/A
0N/A // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
0N/A // Helps with array allocation math constant folding
0N/A // See 4790063:
0N/A // Unrestricted transformation is unsafe for some runtime values of 'x'
0N/A // ( x == 0, z == 1, y == -1 ) fails
0N/A // ( x == -5, z == 1, y == 1 ) fails
0N/A // Transform works for small z and small negative y when the addition
0N/A // (x + (y << z)) does not cross zero.
0N/A // Implement support for negative y and (x >= -(y << z))
0N/A // Have not observed cases where type information exists to support
0N/A // positive y and (x <= -(y << z))
0N/A if( op1 == Op_URShiftI && op2 == Op_ConI &&
400N/A in1->in(2)->Opcode() == Op_ConI ) {
400N/A jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
400N/A jint y = phase->type( in2 )->is_int()->get_con();
0N/A
0N/A if( z < 5 && -5 < y && y < 0 ) {
400N/A const Type *t_in11 = phase->type(in1->in(1));
0N/A if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
4022N/A Node *a = phase->transform( new (phase->C) AddINode( in1->in(1), phase->intcon(y<<z) ) );
4022N/A return new (phase->C) URShiftINode( a, in1->in(2) );
0N/A }
0N/A }
0N/A }
0N/A
0N/A return AddNode::Ideal(phase, can_reshape);
0N/A}
0N/A
0N/A
0N/A//------------------------------Identity---------------------------------------
0N/A// Fold (x-y)+y OR y+(x-y) into x
0N/ANode *AddINode::Identity( PhaseTransform *phase ) {
0N/A if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
0N/A return in(1)->in(1);
0N/A }
0N/A else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
0N/A return in(2)->in(1);
0N/A }
0N/A return AddNode::Identity(phase);
0N/A}
0N/A
0N/A
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs. Guaranteed never
0N/A// to be passed a TOP or BOTTOM type, these are filtered out by
0N/A// pre-check.
0N/Aconst Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeInt *r0 = t0->is_int(); // Handy access
0N/A const TypeInt *r1 = t1->is_int();
0N/A int lo = r0->_lo + r1->_lo;
0N/A int hi = r0->_hi + r1->_hi;
0N/A if( !(r0->is_con() && r1->is_con()) ) {
0N/A // Not both constants, compute approximate result
0N/A if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
0N/A lo = min_jint; hi = max_jint; // Underflow on the low side
0N/A }
0N/A if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
0N/A lo = min_jint; hi = max_jint; // Overflow on the high side
0N/A }
0N/A if( lo > hi ) { // Handle overflow
0N/A lo = min_jint; hi = max_jint;
0N/A }
0N/A } else {
0N/A // both constants, compute precise result using 'lo' and 'hi'
0N/A // Semantics define overflow and underflow for integer addition
0N/A // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0
0N/A }
0N/A return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------Idealize---------------------------------------
0N/ANode *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
400N/A Node* in1 = in(1);
400N/A Node* in2 = in(2);
400N/A int op1 = in1->Opcode();
400N/A int op2 = in2->Opcode();
400N/A // Fold (con1-x)+con2 into (con1+con2)-x
400N/A if ( op1 == Op_AddL && op2 == Op_SubL ) {
400N/A // Swap edges to try optimizations below
400N/A in1 = in2;
400N/A in2 = in(1);
400N/A op1 = op2;
400N/A op2 = in2->Opcode();
400N/A }
0N/A // Fold (con1-x)+con2 into (con1+con2)-x
0N/A if( op1 == Op_SubL ) {
400N/A const Type *t_sub1 = phase->type( in1->in(1) );
400N/A const Type *t_2 = phase->type( in2 );
0N/A if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
4022N/A return new (phase->C) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ),
400N/A in1->in(2) );
0N/A // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
0N/A if( op2 == Op_SubL ) {
0N/A // Check for dead cycle: d = (a-b)+(c-d)
400N/A assert( in1->in(2) != this && in2->in(2) != this,
0N/A "dead loop in AddLNode::Ideal" );
4022N/A Node *sub = new (phase->C) SubLNode(NULL, NULL);
4022N/A sub->init_req(1, phase->transform(new (phase->C) AddLNode(in1->in(1), in2->in(1) ) ));
4022N/A sub->init_req(2, phase->transform(new (phase->C) AddLNode(in1->in(2), in2->in(2) ) ));
0N/A return sub;
0N/A }
400N/A // Convert "(a-b)+(b+c)" into "(a+c)"
400N/A if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
400N/A assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
4022N/A return new (phase->C) AddLNode(in1->in(1), in2->in(2));
400N/A }
400N/A // Convert "(a-b)+(c+b)" into "(a+c)"
400N/A if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
400N/A assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
4022N/A return new (phase->C) AddLNode(in1->in(1), in2->in(1));
400N/A }
400N/A // Convert "(a-b)+(b-c)" into "(a-c)"
400N/A if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
400N/A assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
4022N/A return new (phase->C) SubLNode(in1->in(1), in2->in(2));
400N/A }
400N/A // Convert "(a-b)+(c-a)" into "(c-b)"
400N/A if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
400N/A assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
4022N/A return new (phase->C) SubLNode(in2->in(1), in1->in(2));
400N/A }
0N/A }
0N/A
0N/A // Convert "x+(0-y)" into "(x-y)"
400N/A if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
4022N/A return new (phase->C) SubLNode( in1, in2->in(2) );
400N/A
400N/A // Convert "(0-y)+x" into "(x-y)"
400N/A if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
4022N/A return new (phase->C) SubLNode( in2, in1->in(2) );
0N/A
0N/A // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
0N/A // into "(X<<1)+Y" and let shift-folding happen.
0N/A if( op2 == Op_AddL &&
400N/A in2->in(1) == in1 &&
0N/A op1 != Op_ConL &&
0N/A 0 ) {
4022N/A Node *shift = phase->transform(new (phase->C) LShiftLNode(in1,phase->intcon(1)));
4022N/A return new (phase->C) AddLNode(shift,in2->in(2));
0N/A }
0N/A
0N/A return AddNode::Ideal(phase, can_reshape);
0N/A}
0N/A
0N/A
0N/A//------------------------------Identity---------------------------------------
0N/A// Fold (x-y)+y OR y+(x-y) into x
0N/ANode *AddLNode::Identity( PhaseTransform *phase ) {
0N/A if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
0N/A return in(1)->in(1);
0N/A }
0N/A else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
0N/A return in(2)->in(1);
0N/A }
0N/A return AddNode::Identity(phase);
0N/A}
0N/A
0N/A
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs. Guaranteed never
0N/A// to be passed a TOP or BOTTOM type, these are filtered out by
0N/A// pre-check.
0N/Aconst Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeLong *r0 = t0->is_long(); // Handy access
0N/A const TypeLong *r1 = t1->is_long();
0N/A jlong lo = r0->_lo + r1->_lo;
0N/A jlong hi = r0->_hi + r1->_hi;
0N/A if( !(r0->is_con() && r1->is_con()) ) {
0N/A // Not both constants, compute approximate result
0N/A if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
0N/A lo =min_jlong; hi = max_jlong; // Underflow on the low side
0N/A }
0N/A if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
0N/A lo = min_jlong; hi = max_jlong; // Overflow on the high side
0N/A }
0N/A if( lo > hi ) { // Handle overflow
0N/A lo = min_jlong; hi = max_jlong;
0N/A }
0N/A } else {
0N/A // both constants, compute precise result using 'lo' and 'hi'
0N/A // Semantics define overflow and underflow for integer addition
0N/A // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0
0N/A }
0N/A return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------add_of_identity--------------------------------
0N/A// Check for addition of the identity
0N/Aconst Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const {
0N/A // x ADD 0 should return x unless 'x' is a -zero
0N/A //
0N/A // const Type *zero = add_id(); // The additive identity
0N/A // jfloat f1 = t1->getf();
0N/A // jfloat f2 = t2->getf();
0N/A //
0N/A // if( t1->higher_equal( zero ) ) return t2;
0N/A // if( t2->higher_equal( zero ) ) return t1;
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs.
0N/A// This also type-checks the inputs for sanity. Guaranteed never to
0N/A// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
0N/Aconst Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A // We must be adding 2 float constants.
0N/A return TypeF::make( t0->getf() + t1->getf() );
0N/A}
0N/A
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
0N/A return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
0N/A }
0N/A
0N/A // Floating point additions are not associative because of boundary conditions (infinity)
0N/A return commute(this,
0N/A phase->type( in(1) )->singleton(),
0N/A phase->type( in(2) )->singleton() ) ? this : NULL;
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------add_of_identity--------------------------------
0N/A// Check for addition of the identity
0N/Aconst Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const {
0N/A // x ADD 0 should return x unless 'x' is a -zero
0N/A //
0N/A // const Type *zero = add_id(); // The additive identity
0N/A // jfloat f1 = t1->getf();
0N/A // jfloat f2 = t2->getf();
0N/A //
0N/A // if( t1->higher_equal( zero ) ) return t2;
0N/A // if( t2->higher_equal( zero ) ) return t1;
0N/A
0N/A return NULL;
0N/A}
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs.
0N/A// This also type-checks the inputs for sanity. Guaranteed never to
0N/A// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
0N/Aconst Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A // We must be adding 2 double constants.
0N/A return TypeD::make( t0->getd() + t1->getd() );
0N/A}
0N/A
0N/A//------------------------------Ideal------------------------------------------
0N/ANode *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
0N/A return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
0N/A }
0N/A
0N/A // Floating point additions are not associative because of boundary conditions (infinity)
0N/A return commute(this,
0N/A phase->type( in(1) )->singleton(),
0N/A phase->type( in(2) )->singleton() ) ? this : NULL;
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------Identity---------------------------------------
0N/A// If one input is a constant 0, return the other input.
0N/ANode *AddPNode::Identity( PhaseTransform *phase ) {
0N/A return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;
0N/A}
0N/A
0N/A//------------------------------Idealize---------------------------------------
0N/ANode *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A // Bail out if dead inputs
0N/A if( phase->type( in(Address) ) == Type::TOP ) return NULL;
0N/A
0N/A // If the left input is an add of a constant, flatten the expression tree.
0N/A const Node *n = in(Address);
0N/A if (n->is_AddP() && n->in(Base) == in(Base)) {
0N/A const AddPNode *addp = n->as_AddP(); // Left input is an AddP
0N/A assert( !addp->in(Address)->is_AddP() ||
0N/A addp->in(Address)->as_AddP() != addp,
0N/A "dead loop in AddPNode::Ideal" );
0N/A // Type of left input's right input
0N/A const Type *t = phase->type( addp->in(Offset) );
0N/A if( t == Type::TOP ) return NULL;
0N/A const TypeX *t12 = t->is_intptr_t();
0N/A if( t12->is_con() ) { // Left input is an add of a constant?
0N/A // If the right input is a constant, combine constants
0N/A const Type *temp_t2 = phase->type( in(Offset) );
0N/A if( temp_t2 == Type::TOP ) return NULL;
0N/A const TypeX *t2 = temp_t2->is_intptr_t();
32N/A Node* address;
32N/A Node* offset;
0N/A if( t2->is_con() ) {
0N/A // The Add of the flattened expression
32N/A address = addp->in(Address);
32N/A offset = phase->MakeConX(t2->get_con() + t12->get_con());
32N/A } else {
32N/A // Else move the constant to the right. ((A+con)+B) into ((A+B)+con)
4022N/A address = phase->transform(new (phase->C) AddPNode(in(Base),addp->in(Address),in(Offset)));
32N/A offset = addp->in(Offset);
0N/A }
32N/A PhaseIterGVN *igvn = phase->is_IterGVN();
32N/A if( igvn ) {
32N/A set_req_X(Address,address,igvn);
32N/A set_req_X(Offset,offset,igvn);
32N/A } else {
32N/A set_req(Address,address);
32N/A set_req(Offset,offset);
32N/A }
0N/A return this;
0N/A }
0N/A }
0N/A
0N/A // Raw pointers?
0N/A if( in(Base)->bottom_type() == Type::TOP ) {
0N/A // If this is a NULL+long form (from unsafe accesses), switch to a rawptr.
0N/A if (phase->type(in(Address)) == TypePtr::NULL_PTR) {
0N/A Node* offset = in(Offset);
4022N/A return new (phase->C) CastX2PNode(offset);
0N/A }
0N/A }
0N/A
0N/A // If the right is an add of a constant, push the offset down.
0N/A // Convert: (ptr + (offset+con)) into (ptr+offset)+con.
0N/A // The idea is to merge array_base+scaled_index groups together,
0N/A // and only have different constant offsets from the same base.
0N/A const Node *add = in(Offset);
0N/A if( add->Opcode() == Op_AddX && add->in(1) != add ) {
0N/A const Type *t22 = phase->type( add->in(2) );
0N/A if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant?
4022N/A set_req(Address, phase->transform(new (phase->C) AddPNode(in(Base),in(Address),add->in(1))));
0N/A set_req(Offset, add->in(2));
4127N/A PhaseIterGVN *igvn = phase->is_IterGVN();
4127N/A if (add->outcnt() == 0 && igvn) {
4127N/A // add disconnected.
4127N/A igvn->_worklist.push((Node*)add);
4127N/A }
0N/A return this; // Made progress
0N/A }
0N/A }
0N/A
0N/A return NULL; // No progress
0N/A}
0N/A
0N/A//------------------------------bottom_type------------------------------------
0N/A// Bottom-type is the pointer-type with unknown offset.
0N/Aconst Type *AddPNode::bottom_type() const {
0N/A if (in(Address) == NULL) return TypePtr::BOTTOM;
0N/A const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
0N/A if( !tp ) return Type::TOP; // TOP input means TOP output
0N/A assert( in(Offset)->Opcode() != Op_ConP, "" );
0N/A const Type *t = in(Offset)->bottom_type();
0N/A if( t == Type::TOP )
0N/A return tp->add_offset(Type::OffsetTop);
0N/A const TypeX *tx = t->is_intptr_t();
0N/A intptr_t txoffset = Type::OffsetBot;
0N/A if (tx->is_con()) { // Left input is an add of a constant?
0N/A txoffset = tx->get_con();
0N/A }
0N/A return tp->add_offset(txoffset);
0N/A}
0N/A
0N/A//------------------------------Value------------------------------------------
0N/Aconst Type *AddPNode::Value( PhaseTransform *phase ) const {
0N/A // Either input is TOP ==> the result is TOP
0N/A const Type *t1 = phase->type( in(Address) );
0N/A const Type *t2 = phase->type( in(Offset) );
0N/A if( t1 == Type::TOP ) return Type::TOP;
0N/A if( t2 == Type::TOP ) return Type::TOP;
0N/A
0N/A // Left input is a pointer
0N/A const TypePtr *p1 = t1->isa_ptr();
0N/A // Right input is an int
0N/A const TypeX *p2 = t2->is_intptr_t();
0N/A // Add 'em
0N/A intptr_t p2offset = Type::OffsetBot;
0N/A if (p2->is_con()) { // Left input is an add of a constant?
0N/A p2offset = p2->get_con();
0N/A }
0N/A return p1->add_offset(p2offset);
0N/A}
0N/A
0N/A//------------------------Ideal_base_and_offset--------------------------------
0N/A// Split an oop pointer into a base and offset.
0N/A// (The offset might be Type::OffsetBot in the case of an array.)
0N/A// Return the base, or NULL if failure.
0N/ANode* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,
0N/A // second return value:
0N/A intptr_t& offset) {
0N/A if (ptr->is_AddP()) {
0N/A Node* base = ptr->in(AddPNode::Base);
0N/A Node* addr = ptr->in(AddPNode::Address);
0N/A Node* offs = ptr->in(AddPNode::Offset);
0N/A if (base == addr || base->is_top()) {
0N/A offset = phase->find_intptr_t_con(offs, Type::OffsetBot);
0N/A if (offset != Type::OffsetBot) {
0N/A return addr;
0N/A }
0N/A }
0N/A }
0N/A offset = Type::OffsetBot;
0N/A return NULL;
0N/A}
0N/A
17N/A//------------------------------unpack_offsets----------------------------------
17N/A// Collect the AddP offset values into the elements array, giving up
17N/A// if there are more than length.
17N/Aint AddPNode::unpack_offsets(Node* elements[], int length) {
17N/A int count = 0;
17N/A Node* addr = this;
17N/A Node* base = addr->in(AddPNode::Base);
17N/A while (addr->is_AddP()) {
17N/A if (addr->in(AddPNode::Base) != base) {
17N/A // give up
17N/A return -1;
17N/A }
17N/A elements[count++] = addr->in(AddPNode::Offset);
17N/A if (count == length) {
17N/A // give up
17N/A return -1;
17N/A }
17N/A addr = addr->in(AddPNode::Address);
17N/A }
1683N/A if (addr != base) {
1683N/A return -1;
1683N/A }
17N/A return count;
17N/A}
17N/A
0N/A//------------------------------match_edge-------------------------------------
0N/A// Do we Match on this edge index or not? Do not match base pointer edge
0N/Auint AddPNode::match_edge(uint idx) const {
0N/A return idx > Base;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Identity---------------------------------------
0N/ANode *OrINode::Identity( PhaseTransform *phase ) {
0N/A // x | x => x
0N/A if (phase->eqv(in(1), in(2))) {
0N/A return in(1);
0N/A }
0N/A
0N/A return AddNode::Identity(phase);
0N/A}
0N/A
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs IN THE CURRENT RING. For
0N/A// the logical operations the ring's ADD is really a logical OR function.
0N/A// This also type-checks the inputs for sanity. Guaranteed never to
0N/A// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
0N/Aconst Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeInt *r0 = t0->is_int(); // Handy access
0N/A const TypeInt *r1 = t1->is_int();
0N/A
0N/A // If both args are bool, can figure out better types
0N/A if ( r0 == TypeInt::BOOL ) {
0N/A if ( r1 == TypeInt::ONE) {
0N/A return TypeInt::ONE;
0N/A } else if ( r1 == TypeInt::BOOL ) {
0N/A return TypeInt::BOOL;
0N/A }
0N/A } else if ( r0 == TypeInt::ONE ) {
0N/A if ( r1 == TypeInt::BOOL ) {
0N/A return TypeInt::ONE;
0N/A }
0N/A }
0N/A
0N/A // If either input is not a constant, just return all integers.
0N/A if( !r0->is_con() || !r1->is_con() )
0N/A return TypeInt::INT; // Any integer, but still no symbols.
0N/A
0N/A // Otherwise just OR them bits.
0N/A return TypeInt::make( r0->get_con() | r1->get_con() );
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Identity---------------------------------------
0N/ANode *OrLNode::Identity( PhaseTransform *phase ) {
0N/A // x | x => x
0N/A if (phase->eqv(in(1), in(2))) {
0N/A return in(1);
0N/A }
0N/A
0N/A return AddNode::Identity(phase);
0N/A}
0N/A
0N/A//------------------------------add_ring---------------------------------------
0N/Aconst Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeLong *r0 = t0->is_long(); // Handy access
0N/A const TypeLong *r1 = t1->is_long();
0N/A
0N/A // If either input is not a constant, just return all integers.
0N/A if( !r0->is_con() || !r1->is_con() )
0N/A return TypeLong::LONG; // Any integer, but still no symbols.
0N/A
0N/A // Otherwise just OR them bits.
0N/A return TypeLong::make( r0->get_con() | r1->get_con() );
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs IN THE CURRENT RING. For
0N/A// the logical operations the ring's ADD is really a logical OR function.
0N/A// This also type-checks the inputs for sanity. Guaranteed never to
0N/A// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
0N/Aconst Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeInt *r0 = t0->is_int(); // Handy access
0N/A const TypeInt *r1 = t1->is_int();
0N/A
0N/A // Complementing a boolean?
0N/A if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE
0N/A || r1 == TypeInt::BOOL))
0N/A return TypeInt::BOOL;
0N/A
0N/A if( !r0->is_con() || !r1->is_con() ) // Not constants
0N/A return TypeInt::INT; // Any integer, but still no symbols.
0N/A
0N/A // Otherwise just XOR them bits.
0N/A return TypeInt::make( r0->get_con() ^ r1->get_con() );
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------add_ring---------------------------------------
0N/Aconst Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeLong *r0 = t0->is_long(); // Handy access
0N/A const TypeLong *r1 = t1->is_long();
0N/A
0N/A // If either input is not a constant, just return all integers.
0N/A if( !r0->is_con() || !r1->is_con() )
0N/A return TypeLong::LONG; // Any integer, but still no symbols.
0N/A
0N/A // Otherwise just OR them bits.
0N/A return TypeLong::make( r0->get_con() ^ r1->get_con() );
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs.
0N/Aconst Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeInt *r0 = t0->is_int(); // Handy access
0N/A const TypeInt *r1 = t1->is_int();
0N/A
0N/A // Otherwise just MAX them bits.
0N/A return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------Idealize---------------------------------------
0N/A// MINs show up in range-check loop limit calculations. Look for
0N/A// "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)"
0N/ANode *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A Node *progress = NULL;
0N/A // Force a right-spline graph
0N/A Node *l = in(1);
0N/A Node *r = in(2);
0N/A // Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) )
0N/A // to force a right-spline graph for the rest of MinINode::Ideal().
0N/A if( l->Opcode() == Op_MinI ) {
0N/A assert( l != l->in(1), "dead loop in MinINode::Ideal" );
4022N/A r = phase->transform(new (phase->C) MinINode(l->in(2),r));
0N/A l = l->in(1);
0N/A set_req(1, l);
0N/A set_req(2, r);
0N/A return this;
0N/A }
0N/A
0N/A // Get left input & constant
0N/A Node *x = l;
0N/A int x_off = 0;
0N/A if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant
0N/A x->in(2)->is_Con() ) {
0N/A const Type *t = x->in(2)->bottom_type();
0N/A if( t == Type::TOP ) return NULL; // No progress
0N/A x_off = t->is_int()->get_con();
0N/A x = x->in(1);
0N/A }
0N/A
0N/A // Scan a right-spline-tree for MINs
0N/A Node *y = r;
0N/A int y_off = 0;
0N/A // Check final part of MIN tree
0N/A if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant
0N/A y->in(2)->is_Con() ) {
0N/A const Type *t = y->in(2)->bottom_type();
0N/A if( t == Type::TOP ) return NULL; // No progress
0N/A y_off = t->is_int()->get_con();
0N/A y = y->in(1);
0N/A }
0N/A if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {
0N/A swap_edges(1, 2);
0N/A return this;
0N/A }
0N/A
0N/A
0N/A if( r->Opcode() == Op_MinI ) {
0N/A assert( r != r->in(2), "dead loop in MinINode::Ideal" );
0N/A y = r->in(1);
0N/A // Check final part of MIN tree
0N/A if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant
0N/A y->in(2)->is_Con() ) {
0N/A const Type *t = y->in(2)->bottom_type();
0N/A if( t == Type::TOP ) return NULL; // No progress
0N/A y_off = t->is_int()->get_con();
0N/A y = y->in(1);
0N/A }
0N/A
0N/A if( x->_idx > y->_idx )
4022N/A return new (phase->C) MinINode(r->in(1),phase->transform(new (phase->C) MinINode(l,r->in(2))));
0N/A
0N/A // See if covers: MIN2(x+c0,MIN2(y+c1,z))
0N/A if( !phase->eqv(x,y) ) return NULL;
0N/A // If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into
0N/A // MIN2(x+c0 or x+c1 which less, z).
4022N/A return new (phase->C) MinINode(phase->transform(new (phase->C) AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2));
0N/A } else {
0N/A // See if covers: MIN2(x+c0,y+c1)
0N/A if( !phase->eqv(x,y) ) return NULL;
0N/A // If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less.
4022N/A return new (phase->C) AddINode(x,phase->intcon(MIN2(x_off,y_off)));
0N/A }
0N/A
0N/A}
0N/A
0N/A//------------------------------add_ring---------------------------------------
0N/A// Supplied function returns the sum of the inputs.
0N/Aconst Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {
0N/A const TypeInt *r0 = t0->is_int(); // Handy access
0N/A const TypeInt *r1 = t1->is_int();
0N/A
0N/A // Otherwise just MIN them bits.
0N/A return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
0N/A}