Path: blob/master/src/hotspot/share/opto/addnode.cpp
64440 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "memory/allocation.inline.hpp"26#include "opto/addnode.hpp"27#include "opto/castnode.hpp"28#include "opto/cfgnode.hpp"29#include "opto/connode.hpp"30#include "opto/machnode.hpp"31#include "opto/movenode.hpp"32#include "opto/mulnode.hpp"33#include "opto/phaseX.hpp"34#include "opto/subnode.hpp"3536// Portions of code courtesy of Clifford Click3738// Classic Add functionality. This covers all the usual 'add' behaviors for39// an algebraic ring. Add-integer, add-float, add-double, and binary-or are40// all inherited from this class. The various identity values are supplied41// by virtual functions.424344//=============================================================================45//------------------------------hash-------------------------------------------46// Hash function over AddNodes. Needs to be commutative; i.e., I swap47// (commute) inputs to AddNodes willy-nilly so the hash function must return48// the same value in the presence of edge swapping.49uint AddNode::hash() const {50return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();51}5253//------------------------------Identity---------------------------------------54// If either input is a constant 0, return the other input.55Node* AddNode::Identity(PhaseGVN* phase) {56const Type *zero = add_id(); // The additive identity57if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);58if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);59return this;60}6162//------------------------------commute----------------------------------------63// Commute operands to move loads and constants to the right.64static bool commute(PhaseGVN* phase, Node* add) {65Node *in1 = add->in(1);66Node *in2 = add->in(2);6768// convert "max(a,b) + min(a,b)" into "a+b".69if ((in1->Opcode() == add->as_Add()->max_opcode() && in2->Opcode() == add->as_Add()->min_opcode())70|| (in1->Opcode() == add->as_Add()->min_opcode() && in2->Opcode() == add->as_Add()->max_opcode())) {71Node *in11 = in1->in(1);72Node *in12 = in1->in(2);7374Node *in21 = in2->in(1);75Node *in22 = in2->in(2);7677if ((in11 == in21 && in12 == in22) ||78(in11 == in22 && in12 == in21)) {79add->set_req(1, in11);80add->set_req(2, in12);81PhaseIterGVN* igvn = phase->is_IterGVN();82if (igvn) {83igvn->_worklist.push(in1);84igvn->_worklist.push(in2);85}86return true;87}88}8990bool con_left = phase->type(in1)->singleton();91bool con_right = phase->type(in2)->singleton();9293// Convert "1+x" into "x+1".94// Right is a constant; leave it95if( con_right ) return false;96// Left is a constant; move it right.97if( con_left ) {98add->swap_edges(1, 2);99return true;100}101102// Convert "Load+x" into "x+Load".103// Now check for loads104if (in2->is_Load()) {105if (!in1->is_Load()) {106// already x+Load to return107return false;108}109// both are loads, so fall through to sort inputs by idx110} else if( in1->is_Load() ) {111// Left is a Load and Right is not; move it right.112add->swap_edges(1, 2);113return true;114}115116PhiNode *phi;117// Check for tight loop increments: Loop-phi of Add of loop-phi118if (in1->is_Phi() && (phi = in1->as_Phi()) && phi->region()->is_Loop() && phi->in(2) == add)119return false;120if (in2->is_Phi() && (phi = in2->as_Phi()) && phi->region()->is_Loop() && phi->in(2) == add) {121add->swap_edges(1, 2);122return true;123}124125// Otherwise, sort inputs (commutativity) to help value numbering.126if( in1->_idx > in2->_idx ) {127add->swap_edges(1, 2);128return true;129}130return false;131}132133//------------------------------Idealize---------------------------------------134// If we get here, we assume we are associative!135Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {136const Type *t1 = phase->type(in(1));137const Type *t2 = phase->type(in(2));138bool con_left = t1->singleton();139bool con_right = t2->singleton();140141// Check for commutative operation desired142if (commute(phase, this)) return this;143144AddNode *progress = NULL; // Progress flag145146// Convert "(x+1)+2" into "x+(1+2)". If the right input is a147// constant, and the left input is an add of a constant, flatten the148// expression tree.149Node *add1 = in(1);150Node *add2 = in(2);151int add1_op = add1->Opcode();152int this_op = Opcode();153if (con_right && t2 != Type::TOP && // Right input is a constant?154add1_op == this_op) { // Left input is an Add?155156// Type of left _in right input157const Type *t12 = phase->type(add1->in(2));158if (t12->singleton() && t12 != Type::TOP) { // Left input is an add of a constant?159// Check for rare case of closed data cycle which can happen inside160// unreachable loops. In these cases the computation is undefined.161#ifdef ASSERT162Node *add11 = add1->in(1);163int add11_op = add11->Opcode();164if ((add1 == add1->in(1))165|| (add11_op == this_op && add11->in(1) == add1)) {166assert(false, "dead loop in AddNode::Ideal");167}168#endif169// The Add of the flattened expression170Node *x1 = add1->in(1);171Node *x2 = phase->makecon(add1->as_Add()->add_ring(t2, t12));172set_req_X(2, x2, phase);173set_req_X(1, x1, phase);174progress = this; // Made progress175add1 = in(1);176add1_op = add1->Opcode();177}178}179180// Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree.181if (add1_op == this_op && !con_right) {182Node *a12 = add1->in(2);183const Type *t12 = phase->type( a12 );184if (t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&185!(add1->in(1)->is_Phi() && (add1->in(1)->as_Phi()->is_tripcount(T_INT) || add1->in(1)->as_Phi()->is_tripcount(T_LONG)))) {186assert(add1->in(1) != this, "dead loop in AddNode::Ideal");187add2 = add1->clone();188add2->set_req(2, in(2));189add2 = phase->transform(add2);190set_req_X(1, add2, phase);191set_req_X(2, a12, phase);192progress = this;193add2 = a12;194}195}196197// Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree.198int add2_op = add2->Opcode();199if (add2_op == this_op && !con_left) {200Node *a22 = add2->in(2);201const Type *t22 = phase->type( a22 );202if (t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&203!(add2->in(1)->is_Phi() && (add2->in(1)->as_Phi()->is_tripcount(T_INT) || add2->in(1)->as_Phi()->is_tripcount(T_LONG)))) {204assert(add2->in(1) != this, "dead loop in AddNode::Ideal");205Node *addx = add2->clone();206addx->set_req(1, in(1));207addx->set_req(2, add2->in(1));208addx = phase->transform(addx);209set_req_X(1, addx, phase);210set_req_X(2, a22, phase);211progress = this;212}213}214215return progress;216}217218//------------------------------Value-----------------------------------------219// An add node sums it's two _in. If one input is an RSD, we must mixin220// the other input's symbols.221const Type* AddNode::Value(PhaseGVN* phase) const {222// Either input is TOP ==> the result is TOP223const Type *t1 = phase->type( in(1) );224const Type *t2 = phase->type( in(2) );225if( t1 == Type::TOP ) return Type::TOP;226if( t2 == Type::TOP ) return Type::TOP;227228// Either input is BOTTOM ==> the result is the local BOTTOM229const Type *bot = bottom_type();230if( (t1 == bot) || (t2 == bot) ||231(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )232return bot;233234// Check for an addition involving the additive identity235const Type *tadd = add_of_identity( t1, t2 );236if( tadd ) return tadd;237238return add_ring(t1,t2); // Local flavor of type addition239}240241//------------------------------add_identity-----------------------------------242// Check for addition of the identity243const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {244const Type *zero = add_id(); // The additive identity245if( t1->higher_equal( zero ) ) return t2;246if( t2->higher_equal( zero ) ) return t1;247248return NULL;249}250251AddNode* AddNode::make(Node* in1, Node* in2, BasicType bt) {252switch (bt) {253case T_INT:254return new AddINode(in1, in2);255case T_LONG:256return new AddLNode(in1, in2);257default:258fatal("Not implemented for %s", type2name(bt));259}260return NULL;261}262263//=============================================================================264//------------------------------Idealize---------------------------------------265Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {266Node* in1 = in(1);267Node* in2 = in(2);268int op1 = in1->Opcode();269int op2 = in2->Opcode();270// Fold (con1-x)+con2 into (con1+con2)-x271if ( op1 == Op_AddI && op2 == Op_SubI ) {272// Swap edges to try optimizations below273in1 = in2;274in2 = in(1);275op1 = op2;276op2 = in2->Opcode();277}278if( op1 == Op_SubI ) {279const Type *t_sub1 = phase->type( in1->in(1) );280const Type *t_2 = phase->type( in2 );281if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )282return new SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );283// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"284if( op2 == Op_SubI ) {285// Check for dead cycle: d = (a-b)+(c-d)286assert( in1->in(2) != this && in2->in(2) != this,287"dead loop in AddINode::Ideal" );288Node *sub = new SubINode(NULL, NULL);289sub->init_req(1, phase->transform(new AddINode(in1->in(1), in2->in(1) ) ));290sub->init_req(2, phase->transform(new AddINode(in1->in(2), in2->in(2) ) ));291return sub;292}293// Convert "(a-b)+(b+c)" into "(a+c)"294if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {295assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");296return new AddINode(in1->in(1), in2->in(2));297}298// Convert "(a-b)+(c+b)" into "(a+c)"299if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {300assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");301return new AddINode(in1->in(1), in2->in(1));302}303// Convert "(a-b)+(b-c)" into "(a-c)"304if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {305assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");306return new SubINode(in1->in(1), in2->in(2));307}308// Convert "(a-b)+(c-a)" into "(c-b)"309if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {310assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");311return new SubINode(in2->in(1), in1->in(2));312}313}314315// Convert "x+(0-y)" into "(x-y)"316if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )317return new SubINode(in1, in2->in(2) );318319// Convert "(0-y)+x" into "(x-y)"320if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )321return new SubINode( in2, in1->in(2) );322323// Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.324// Helps with array allocation math constant folding325// See 4790063:326// Unrestricted transformation is unsafe for some runtime values of 'x'327// ( x == 0, z == 1, y == -1 ) fails328// ( x == -5, z == 1, y == 1 ) fails329// Transform works for small z and small negative y when the addition330// (x + (y << z)) does not cross zero.331// Implement support for negative y and (x >= -(y << z))332// Have not observed cases where type information exists to support333// positive y and (x <= -(y << z))334if( op1 == Op_URShiftI && op2 == Op_ConI &&335in1->in(2)->Opcode() == Op_ConI ) {336jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter337jint y = phase->type( in2 )->is_int()->get_con();338339if( z < 5 && -5 < y && y < 0 ) {340const Type *t_in11 = phase->type(in1->in(1));341if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {342Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );343return new URShiftINode( a, in1->in(2) );344}345}346}347348// Convert (x >>> rshift) + (x << lshift) into RotateRight(x, rshift)349if (Matcher::match_rule_supported(Op_RotateRight) &&350((op1 == Op_URShiftI && op2 == Op_LShiftI) || (op1 == Op_LShiftI && op2 == Op_URShiftI)) &&351in1->in(1) != NULL && in1->in(1) == in2->in(1)) {352Node* rshift = op1 == Op_URShiftI ? in1->in(2) : in2->in(2);353Node* lshift = op1 == Op_URShiftI ? in2->in(2) : in1->in(2);354if (rshift != NULL && lshift != NULL) {355const TypeInt* rshift_t = phase->type(rshift)->isa_int();356const TypeInt* lshift_t = phase->type(lshift)->isa_int();357if (lshift_t != NULL && lshift_t->is_con() &&358rshift_t != NULL && rshift_t->is_con() &&359((lshift_t->get_con() & 0x1F) == (32 - (rshift_t->get_con() & 0x1F)))) {360return new RotateRightNode(in1->in(1), phase->intcon(rshift_t->get_con() & 0x1F), TypeInt::INT);361}362}363}364365// Convert (~x+1) into -x. Note there isn't a bitwise not bytecode,366// "~x" would typically represented as "x^(-1)", so (~x+1) will367// be (x^(-1))+1.368if (op1 == Op_XorI && phase->type(in2) == TypeInt::ONE &&369phase->type(in1->in(2)) == TypeInt::MINUS_1) {370return new SubINode(phase->makecon(TypeInt::ZERO), in1->in(1));371}372return AddNode::Ideal(phase, can_reshape);373}374375376//------------------------------Identity---------------------------------------377// Fold (x-y)+y OR y+(x-y) into x378Node* AddINode::Identity(PhaseGVN* phase) {379if (in(1)->Opcode() == Op_SubI && in(1)->in(2) == in(2)) {380return in(1)->in(1);381} else if (in(2)->Opcode() == Op_SubI && in(2)->in(2) == in(1)) {382return in(2)->in(1);383}384return AddNode::Identity(phase);385}386387388//------------------------------add_ring---------------------------------------389// Supplied function returns the sum of the inputs. Guaranteed never390// to be passed a TOP or BOTTOM type, these are filtered out by391// pre-check.392const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {393const TypeInt *r0 = t0->is_int(); // Handy access394const TypeInt *r1 = t1->is_int();395int lo = java_add(r0->_lo, r1->_lo);396int hi = java_add(r0->_hi, r1->_hi);397if( !(r0->is_con() && r1->is_con()) ) {398// Not both constants, compute approximate result399if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {400lo = min_jint; hi = max_jint; // Underflow on the low side401}402if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {403lo = min_jint; hi = max_jint; // Overflow on the high side404}405if( lo > hi ) { // Handle overflow406lo = min_jint; hi = max_jint;407}408} else {409// both constants, compute precise result using 'lo' and 'hi'410// Semantics define overflow and underflow for integer addition411// as expected. In particular: 0x80000000 + 0x80000000 --> 0x0412}413return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );414}415416417//=============================================================================418//------------------------------Idealize---------------------------------------419Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {420Node* in1 = in(1);421Node* in2 = in(2);422int op1 = in1->Opcode();423int op2 = in2->Opcode();424// Fold (con1-x)+con2 into (con1+con2)-x425if ( op1 == Op_AddL && op2 == Op_SubL ) {426// Swap edges to try optimizations below427in1 = in2;428in2 = in(1);429op1 = op2;430op2 = in2->Opcode();431}432// Fold (con1-x)+con2 into (con1+con2)-x433if( op1 == Op_SubL ) {434const Type *t_sub1 = phase->type( in1->in(1) );435const Type *t_2 = phase->type( in2 );436if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )437return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );438// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"439if( op2 == Op_SubL ) {440// Check for dead cycle: d = (a-b)+(c-d)441assert( in1->in(2) != this && in2->in(2) != this,442"dead loop in AddLNode::Ideal" );443Node *sub = new SubLNode(NULL, NULL);444sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));445sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));446return sub;447}448// Convert "(a-b)+(b+c)" into "(a+c)"449if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {450assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");451return new AddLNode(in1->in(1), in2->in(2));452}453// Convert "(a-b)+(c+b)" into "(a+c)"454if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {455assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");456return new AddLNode(in1->in(1), in2->in(1));457}458// Convert "(a-b)+(b-c)" into "(a-c)"459if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {460assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");461return new SubLNode(in1->in(1), in2->in(2));462}463// Convert "(a-b)+(c-a)" into "(c-b)"464if( op2 == Op_SubL && in1->in(1) == in2->in(2) ) {465assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");466return new SubLNode(in2->in(1), in1->in(2));467}468}469470// Convert "x+(0-y)" into "(x-y)"471if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )472return new SubLNode( in1, in2->in(2) );473474// Convert "(0-y)+x" into "(x-y)"475if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeLong::ZERO )476return new SubLNode( in2, in1->in(2) );477478// Convert (x >>> rshift) + (x << lshift) into RotateRight(x, rshift)479if (Matcher::match_rule_supported(Op_RotateRight) &&480((op1 == Op_URShiftL && op2 == Op_LShiftL) || (op1 == Op_LShiftL && op2 == Op_URShiftL)) &&481in1->in(1) != NULL && in1->in(1) == in2->in(1)) {482Node* rshift = op1 == Op_URShiftL ? in1->in(2) : in2->in(2);483Node* lshift = op1 == Op_URShiftL ? in2->in(2) : in1->in(2);484if (rshift != NULL && lshift != NULL) {485const TypeInt* rshift_t = phase->type(rshift)->isa_int();486const TypeInt* lshift_t = phase->type(lshift)->isa_int();487if (lshift_t != NULL && lshift_t->is_con() &&488rshift_t != NULL && rshift_t->is_con() &&489((lshift_t->get_con() & 0x3F) == (64 - (rshift_t->get_con() & 0x3F)))) {490return new RotateRightNode(in1->in(1), phase->intcon(rshift_t->get_con() & 0x3F), TypeLong::LONG);491}492}493}494495// Convert (~x+1) into -x. Note there isn't a bitwise not bytecode,496// "~x" would typically represented as "x^(-1)", so (~x+1) will497// be (x^(-1))+1498if (op1 == Op_XorL && phase->type(in2) == TypeLong::ONE &&499phase->type(in1->in(2)) == TypeLong::MINUS_1) {500return new SubLNode(phase->makecon(TypeLong::ZERO), in1->in(1));501}502return AddNode::Ideal(phase, can_reshape);503}504505506//------------------------------Identity---------------------------------------507// Fold (x-y)+y OR y+(x-y) into x508Node* AddLNode::Identity(PhaseGVN* phase) {509if (in(1)->Opcode() == Op_SubL && in(1)->in(2) == in(2)) {510return in(1)->in(1);511} else if (in(2)->Opcode() == Op_SubL && in(2)->in(2) == in(1)) {512return in(2)->in(1);513}514return AddNode::Identity(phase);515}516517518//------------------------------add_ring---------------------------------------519// Supplied function returns the sum of the inputs. Guaranteed never520// to be passed a TOP or BOTTOM type, these are filtered out by521// pre-check.522const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {523const TypeLong *r0 = t0->is_long(); // Handy access524const TypeLong *r1 = t1->is_long();525jlong lo = java_add(r0->_lo, r1->_lo);526jlong hi = java_add(r0->_hi, r1->_hi);527if( !(r0->is_con() && r1->is_con()) ) {528// Not both constants, compute approximate result529if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {530lo =min_jlong; hi = max_jlong; // Underflow on the low side531}532if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {533lo = min_jlong; hi = max_jlong; // Overflow on the high side534}535if( lo > hi ) { // Handle overflow536lo = min_jlong; hi = max_jlong;537}538} else {539// both constants, compute precise result using 'lo' and 'hi'540// Semantics define overflow and underflow for integer addition541// as expected. In particular: 0x80000000 + 0x80000000 --> 0x0542}543return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) );544}545546547//=============================================================================548//------------------------------add_of_identity--------------------------------549// Check for addition of the identity550const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const {551// x ADD 0 should return x unless 'x' is a -zero552//553// const Type *zero = add_id(); // The additive identity554// jfloat f1 = t1->getf();555// jfloat f2 = t2->getf();556//557// if( t1->higher_equal( zero ) ) return t2;558// if( t2->higher_equal( zero ) ) return t1;559560return NULL;561}562563//------------------------------add_ring---------------------------------------564// Supplied function returns the sum of the inputs.565// This also type-checks the inputs for sanity. Guaranteed never to566// be passed a TOP or BOTTOM type, these are filtered out by pre-check.567const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const {568// We must be adding 2 float constants.569return TypeF::make( t0->getf() + t1->getf() );570}571572//------------------------------Ideal------------------------------------------573Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) {574// Floating point additions are not associative because of boundary conditions (infinity)575return commute(phase, this) ? this : NULL;576}577578579//=============================================================================580//------------------------------add_of_identity--------------------------------581// Check for addition of the identity582const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const {583// x ADD 0 should return x unless 'x' is a -zero584//585// const Type *zero = add_id(); // The additive identity586// jfloat f1 = t1->getf();587// jfloat f2 = t2->getf();588//589// if( t1->higher_equal( zero ) ) return t2;590// if( t2->higher_equal( zero ) ) return t1;591592return NULL;593}594//------------------------------add_ring---------------------------------------595// Supplied function returns the sum of the inputs.596// This also type-checks the inputs for sanity. Guaranteed never to597// be passed a TOP or BOTTOM type, these are filtered out by pre-check.598const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const {599// We must be adding 2 double constants.600return TypeD::make( t0->getd() + t1->getd() );601}602603//------------------------------Ideal------------------------------------------604Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {605// Floating point additions are not associative because of boundary conditions (infinity)606return commute(phase, this) ? this : NULL;607}608609610//=============================================================================611//------------------------------Identity---------------------------------------612// If one input is a constant 0, return the other input.613Node* AddPNode::Identity(PhaseGVN* phase) {614return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;615}616617//------------------------------Idealize---------------------------------------618Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {619// Bail out if dead inputs620if( phase->type( in(Address) ) == Type::TOP ) return NULL;621622// If the left input is an add of a constant, flatten the expression tree.623const Node *n = in(Address);624if (n->is_AddP() && n->in(Base) == in(Base)) {625const AddPNode *addp = n->as_AddP(); // Left input is an AddP626assert( !addp->in(Address)->is_AddP() ||627addp->in(Address)->as_AddP() != addp,628"dead loop in AddPNode::Ideal" );629// Type of left input's right input630const Type *t = phase->type( addp->in(Offset) );631if( t == Type::TOP ) return NULL;632const TypeX *t12 = t->is_intptr_t();633if( t12->is_con() ) { // Left input is an add of a constant?634// If the right input is a constant, combine constants635const Type *temp_t2 = phase->type( in(Offset) );636if( temp_t2 == Type::TOP ) return NULL;637const TypeX *t2 = temp_t2->is_intptr_t();638Node* address;639Node* offset;640if( t2->is_con() ) {641// The Add of the flattened expression642address = addp->in(Address);643offset = phase->MakeConX(t2->get_con() + t12->get_con());644} else {645// Else move the constant to the right. ((A+con)+B) into ((A+B)+con)646address = phase->transform(new AddPNode(in(Base),addp->in(Address),in(Offset)));647offset = addp->in(Offset);648}649set_req_X(Address, address, phase);650set_req_X(Offset, offset, phase);651return this;652}653}654655// Raw pointers?656if( in(Base)->bottom_type() == Type::TOP ) {657// If this is a NULL+long form (from unsafe accesses), switch to a rawptr.658if (phase->type(in(Address)) == TypePtr::NULL_PTR) {659Node* offset = in(Offset);660return new CastX2PNode(offset);661}662}663664// If the right is an add of a constant, push the offset down.665// Convert: (ptr + (offset+con)) into (ptr+offset)+con.666// The idea is to merge array_base+scaled_index groups together,667// and only have different constant offsets from the same base.668const Node *add = in(Offset);669if( add->Opcode() == Op_AddX && add->in(1) != add ) {670const Type *t22 = phase->type( add->in(2) );671if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant?672set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));673set_req(Offset, add->in(2));674PhaseIterGVN* igvn = phase->is_IterGVN();675if (add->outcnt() == 0 && igvn) {676// add disconnected.677igvn->_worklist.push((Node*)add);678}679return this; // Made progress680}681}682683return NULL; // No progress684}685686//------------------------------bottom_type------------------------------------687// Bottom-type is the pointer-type with unknown offset.688const Type *AddPNode::bottom_type() const {689if (in(Address) == NULL) return TypePtr::BOTTOM;690const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();691if( !tp ) return Type::TOP; // TOP input means TOP output692assert( in(Offset)->Opcode() != Op_ConP, "" );693const Type *t = in(Offset)->bottom_type();694if( t == Type::TOP )695return tp->add_offset(Type::OffsetTop);696const TypeX *tx = t->is_intptr_t();697intptr_t txoffset = Type::OffsetBot;698if (tx->is_con()) { // Left input is an add of a constant?699txoffset = tx->get_con();700}701return tp->add_offset(txoffset);702}703704//------------------------------Value------------------------------------------705const Type* AddPNode::Value(PhaseGVN* phase) const {706// Either input is TOP ==> the result is TOP707const Type *t1 = phase->type( in(Address) );708const Type *t2 = phase->type( in(Offset) );709if( t1 == Type::TOP ) return Type::TOP;710if( t2 == Type::TOP ) return Type::TOP;711712// Left input is a pointer713const TypePtr *p1 = t1->isa_ptr();714// Right input is an int715const TypeX *p2 = t2->is_intptr_t();716// Add 'em717intptr_t p2offset = Type::OffsetBot;718if (p2->is_con()) { // Left input is an add of a constant?719p2offset = p2->get_con();720}721return p1->add_offset(p2offset);722}723724//------------------------Ideal_base_and_offset--------------------------------725// Split an oop pointer into a base and offset.726// (The offset might be Type::OffsetBot in the case of an array.)727// Return the base, or NULL if failure.728Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,729// second return value:730intptr_t& offset) {731if (ptr->is_AddP()) {732Node* base = ptr->in(AddPNode::Base);733Node* addr = ptr->in(AddPNode::Address);734Node* offs = ptr->in(AddPNode::Offset);735if (base == addr || base->is_top()) {736offset = phase->find_intptr_t_con(offs, Type::OffsetBot);737if (offset != Type::OffsetBot) {738return addr;739}740}741}742offset = Type::OffsetBot;743return NULL;744}745746//------------------------------unpack_offsets----------------------------------747// Collect the AddP offset values into the elements array, giving up748// if there are more than length.749int AddPNode::unpack_offsets(Node* elements[], int length) {750int count = 0;751Node* addr = this;752Node* base = addr->in(AddPNode::Base);753while (addr->is_AddP()) {754if (addr->in(AddPNode::Base) != base) {755// give up756return -1;757}758elements[count++] = addr->in(AddPNode::Offset);759if (count == length) {760// give up761return -1;762}763addr = addr->in(AddPNode::Address);764}765if (addr != base) {766return -1;767}768return count;769}770771//------------------------------match_edge-------------------------------------772// Do we Match on this edge index or not? Do not match base pointer edge773uint AddPNode::match_edge(uint idx) const {774return idx > Base;775}776777//=============================================================================778//------------------------------Identity---------------------------------------779Node* OrINode::Identity(PhaseGVN* phase) {780// x | x => x781if (in(1) == in(2)) {782return in(1);783}784785return AddNode::Identity(phase);786}787788// Find shift value for Integer or Long OR.789Node* rotate_shift(PhaseGVN* phase, Node* lshift, Node* rshift, int mask) {790// val << norm_con_shift | val >> ({32|64} - norm_con_shift) => rotate_left val, norm_con_shift791const TypeInt* lshift_t = phase->type(lshift)->isa_int();792const TypeInt* rshift_t = phase->type(rshift)->isa_int();793if (lshift_t != NULL && lshift_t->is_con() &&794rshift_t != NULL && rshift_t->is_con() &&795((lshift_t->get_con() & mask) == ((mask + 1) - (rshift_t->get_con() & mask)))) {796return phase->intcon(lshift_t->get_con() & mask);797}798// val << var_shift | val >> ({0|32|64} - var_shift) => rotate_left val, var_shift799if (rshift->Opcode() == Op_SubI && rshift->in(2) == lshift && rshift->in(1)->is_Con()){800const TypeInt* shift_t = phase->type(rshift->in(1))->isa_int();801if (shift_t != NULL && shift_t->is_con() &&802(shift_t->get_con() == 0 || shift_t->get_con() == (mask + 1))) {803return lshift;804}805}806return NULL;807}808809Node* OrINode::Ideal(PhaseGVN* phase, bool can_reshape) {810int lopcode = in(1)->Opcode();811int ropcode = in(2)->Opcode();812if (Matcher::match_rule_supported(Op_RotateLeft) &&813lopcode == Op_LShiftI && ropcode == Op_URShiftI && in(1)->in(1) == in(2)->in(1)) {814Node* lshift = in(1)->in(2);815Node* rshift = in(2)->in(2);816Node* shift = rotate_shift(phase, lshift, rshift, 0x1F);817if (shift != NULL) {818return new RotateLeftNode(in(1)->in(1), shift, TypeInt::INT);819}820return NULL;821}822if (Matcher::match_rule_supported(Op_RotateRight) &&823lopcode == Op_URShiftI && ropcode == Op_LShiftI && in(1)->in(1) == in(2)->in(1)) {824Node* rshift = in(1)->in(2);825Node* lshift = in(2)->in(2);826Node* shift = rotate_shift(phase, rshift, lshift, 0x1F);827if (shift != NULL) {828return new RotateRightNode(in(1)->in(1), shift, TypeInt::INT);829}830}831return NULL;832}833834//------------------------------add_ring---------------------------------------835// Supplied function returns the sum of the inputs IN THE CURRENT RING. For836// the logical operations the ring's ADD is really a logical OR function.837// This also type-checks the inputs for sanity. Guaranteed never to838// be passed a TOP or BOTTOM type, these are filtered out by pre-check.839const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {840const TypeInt *r0 = t0->is_int(); // Handy access841const TypeInt *r1 = t1->is_int();842843// If both args are bool, can figure out better types844if ( r0 == TypeInt::BOOL ) {845if ( r1 == TypeInt::ONE) {846return TypeInt::ONE;847} else if ( r1 == TypeInt::BOOL ) {848return TypeInt::BOOL;849}850} else if ( r0 == TypeInt::ONE ) {851if ( r1 == TypeInt::BOOL ) {852return TypeInt::ONE;853}854}855856// If either input is not a constant, just return all integers.857if( !r0->is_con() || !r1->is_con() )858return TypeInt::INT; // Any integer, but still no symbols.859860// Otherwise just OR them bits.861return TypeInt::make( r0->get_con() | r1->get_con() );862}863864//=============================================================================865//------------------------------Identity---------------------------------------866Node* OrLNode::Identity(PhaseGVN* phase) {867// x | x => x868if (in(1) == in(2)) {869return in(1);870}871872return AddNode::Identity(phase);873}874875Node* OrLNode::Ideal(PhaseGVN* phase, bool can_reshape) {876int lopcode = in(1)->Opcode();877int ropcode = in(2)->Opcode();878if (Matcher::match_rule_supported(Op_RotateLeft) &&879lopcode == Op_LShiftL && ropcode == Op_URShiftL && in(1)->in(1) == in(2)->in(1)) {880Node* lshift = in(1)->in(2);881Node* rshift = in(2)->in(2);882Node* shift = rotate_shift(phase, lshift, rshift, 0x3F);883if (shift != NULL) {884return new RotateLeftNode(in(1)->in(1), shift, TypeLong::LONG);885}886return NULL;887}888if (Matcher::match_rule_supported(Op_RotateRight) &&889lopcode == Op_URShiftL && ropcode == Op_LShiftL && in(1)->in(1) == in(2)->in(1)) {890Node* rshift = in(1)->in(2);891Node* lshift = in(2)->in(2);892Node* shift = rotate_shift(phase, rshift, lshift, 0x3F);893if (shift != NULL) {894return new RotateRightNode(in(1)->in(1), shift, TypeLong::LONG);895}896}897return NULL;898}899900//------------------------------add_ring---------------------------------------901const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {902const TypeLong *r0 = t0->is_long(); // Handy access903const TypeLong *r1 = t1->is_long();904905// If either input is not a constant, just return all integers.906if( !r0->is_con() || !r1->is_con() )907return TypeLong::LONG; // Any integer, but still no symbols.908909// Otherwise just OR them bits.910return TypeLong::make( r0->get_con() | r1->get_con() );911}912913//=============================================================================914//------------------------------Idealize---------------------------------------915Node* XorINode::Ideal(PhaseGVN* phase, bool can_reshape) {916Node* in1 = in(1);917Node* in2 = in(2);918int op1 = in1->Opcode();919// Convert ~(x-1) into -x. Note there isn't a bitwise not bytecode,920// "~x" would typically represented as "x^(-1)", and "x-c0" would921// convert into "x+ -c0" in SubXNode::Ideal. So ~(x-1) will eventually922// be (x+(-1))^-1.923if (op1 == Op_AddI && phase->type(in2) == TypeInt::MINUS_1 &&924phase->type(in1->in(2)) == TypeInt::MINUS_1) {925return new SubINode(phase->makecon(TypeInt::ZERO), in1->in(1));926}927return AddNode::Ideal(phase, can_reshape);928}929930const Type* XorINode::Value(PhaseGVN* phase) const {931Node* in1 = in(1);932Node* in2 = in(2);933const Type* t1 = phase->type(in1);934const Type* t2 = phase->type(in2);935if (t1 == Type::TOP || t2 == Type::TOP) {936return Type::TOP;937}938// x ^ x ==> 0939if (in1->eqv_uncast(in2)) {940return add_id();941}942// result of xor can only have bits sets where any of the943// inputs have bits set. lo can always become 0.944const TypeInt* t1i = t1->is_int();945const TypeInt* t2i = t2->is_int();946if ((t1i->_lo >= 0) &&947(t1i->_hi > 0) &&948(t2i->_lo >= 0) &&949(t2i->_hi > 0)) {950// hi - set all bits below the highest bit. Using round_down to avoid overflow.951const TypeInt* t1x = TypeInt::make(0, round_down_power_of_2(t1i->_hi) + (round_down_power_of_2(t1i->_hi) - 1), t1i->_widen);952const TypeInt* t2x = TypeInt::make(0, round_down_power_of_2(t2i->_hi) + (round_down_power_of_2(t2i->_hi) - 1), t2i->_widen);953return t1x->meet(t2x);954}955return AddNode::Value(phase);956}957958959//------------------------------add_ring---------------------------------------960// Supplied function returns the sum of the inputs IN THE CURRENT RING. For961// the logical operations the ring's ADD is really a logical OR function.962// This also type-checks the inputs for sanity. Guaranteed never to963// be passed a TOP or BOTTOM type, these are filtered out by pre-check.964const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const {965const TypeInt *r0 = t0->is_int(); // Handy access966const TypeInt *r1 = t1->is_int();967968// Complementing a boolean?969if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE970|| r1 == TypeInt::BOOL))971return TypeInt::BOOL;972973if( !r0->is_con() || !r1->is_con() ) // Not constants974return TypeInt::INT; // Any integer, but still no symbols.975976// Otherwise just XOR them bits.977return TypeInt::make( r0->get_con() ^ r1->get_con() );978}979980//=============================================================================981//------------------------------add_ring---------------------------------------982const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {983const TypeLong *r0 = t0->is_long(); // Handy access984const TypeLong *r1 = t1->is_long();985986// If either input is not a constant, just return all integers.987if( !r0->is_con() || !r1->is_con() )988return TypeLong::LONG; // Any integer, but still no symbols.989990// Otherwise just OR them bits.991return TypeLong::make( r0->get_con() ^ r1->get_con() );992}993994Node* XorLNode::Ideal(PhaseGVN* phase, bool can_reshape) {995Node* in1 = in(1);996Node* in2 = in(2);997int op1 = in1->Opcode();998// Convert ~(x-1) into -x. Note there isn't a bitwise not bytecode,999// "~x" would typically represented as "x^(-1)", and "x-c0" would1000// convert into "x+ -c0" in SubXNode::Ideal. So ~(x-1) will eventually1001// be (x+(-1))^-1.1002if (op1 == Op_AddL && phase->type(in2) == TypeLong::MINUS_1 &&1003phase->type(in1->in(2)) == TypeLong::MINUS_1) {1004return new SubLNode(phase->makecon(TypeLong::ZERO), in1->in(1));1005}1006return AddNode::Ideal(phase, can_reshape);1007}10081009const Type* XorLNode::Value(PhaseGVN* phase) const {1010Node* in1 = in(1);1011Node* in2 = in(2);1012const Type* t1 = phase->type(in1);1013const Type* t2 = phase->type(in2);1014if (t1 == Type::TOP || t2 == Type::TOP) {1015return Type::TOP;1016}1017// x ^ x ==> 01018if (in1->eqv_uncast(in2)) {1019return add_id();1020}1021// result of xor can only have bits sets where any of the1022// inputs have bits set. lo can always become 0.1023const TypeLong* t1l = t1->is_long();1024const TypeLong* t2l = t2->is_long();1025if ((t1l->_lo >= 0) &&1026(t1l->_hi > 0) &&1027(t2l->_lo >= 0) &&1028(t2l->_hi > 0)) {1029// hi - set all bits below the highest bit. Using round_down to avoid overflow.1030const TypeLong* t1x = TypeLong::make(0, round_down_power_of_2(t1l->_hi) + (round_down_power_of_2(t1l->_hi) - 1), t1l->_widen);1031const TypeLong* t2x = TypeLong::make(0, round_down_power_of_2(t2l->_hi) + (round_down_power_of_2(t2l->_hi) - 1), t2l->_widen);1032return t1x->meet(t2x);1033}1034return AddNode::Value(phase);1035}10361037Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) {1038bool is_int = gvn.type(a)->isa_int();1039assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");1040assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");1041Node* hook = NULL;1042if (gvn.is_IterGVN()) {1043// Make sure a and b are not destroyed1044hook = new Node(2);1045hook->init_req(0, a);1046hook->init_req(1, b);1047}1048Node* res = NULL;1049if (!is_unsigned) {1050if (is_max) {1051if (is_int) {1052res = gvn.transform(new MaxINode(a, b));1053assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");1054} else {1055Node* cmp = gvn.transform(new CmpLNode(a, b));1056Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1057res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1058}1059} else {1060if (is_int) {1061Node* res = gvn.transform(new MinINode(a, b));1062assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");1063} else {1064Node* cmp = gvn.transform(new CmpLNode(b, a));1065Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1066res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1067}1068}1069} else {1070if (is_max) {1071if (is_int) {1072Node* cmp = gvn.transform(new CmpUNode(a, b));1073Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1074res = gvn.transform(new CMoveINode(bol, a, b, t->is_int()));1075} else {1076Node* cmp = gvn.transform(new CmpULNode(a, b));1077Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1078res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1079}1080} else {1081if (is_int) {1082Node* cmp = gvn.transform(new CmpUNode(b, a));1083Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1084res = gvn.transform(new CMoveINode(bol, a, b, t->is_int()));1085} else {1086Node* cmp = gvn.transform(new CmpULNode(b, a));1087Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1088res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1089}1090}1091}1092if (hook != NULL) {1093hook->destruct(&gvn);1094}1095return res;1096}10971098Node* MaxNode::build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn) {1099bool is_int = gvn.type(a)->isa_int();1100assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");1101assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");1102Node* zero = NULL;1103if (is_int) {1104zero = gvn.intcon(0);1105} else {1106zero = gvn.longcon(0);1107}1108Node* hook = NULL;1109if (gvn.is_IterGVN()) {1110// Make sure a and b are not destroyed1111hook = new Node(2);1112hook->init_req(0, a);1113hook->init_req(1, b);1114}1115Node* res = NULL;1116if (is_max) {1117if (is_int) {1118Node* cmp = gvn.transform(new CmpINode(a, b));1119Node* sub = gvn.transform(new SubINode(a, b));1120Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1121res = gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));1122} else {1123Node* cmp = gvn.transform(new CmpLNode(a, b));1124Node* sub = gvn.transform(new SubLNode(a, b));1125Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1126res = gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));1127}1128} else {1129if (is_int) {1130Node* cmp = gvn.transform(new CmpINode(b, a));1131Node* sub = gvn.transform(new SubINode(a, b));1132Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1133res = gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));1134} else {1135Node* cmp = gvn.transform(new CmpLNode(b, a));1136Node* sub = gvn.transform(new SubLNode(a, b));1137Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1138res = gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));1139}1140}1141if (hook != NULL) {1142hook->destruct(&gvn);1143}1144return res;1145}11461147//=============================================================================1148//------------------------------add_ring---------------------------------------1149// Supplied function returns the sum of the inputs.1150const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {1151const TypeInt *r0 = t0->is_int(); // Handy access1152const TypeInt *r1 = t1->is_int();11531154// Otherwise just MAX them bits.1155return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );1156}11571158// Check if addition of an integer with type 't' and a constant 'c' can overflow1159static bool can_overflow(const TypeInt* t, jint c) {1160jint t_lo = t->_lo;1161jint t_hi = t->_hi;1162return ((c < 0 && (java_add(t_lo, c) > t_lo)) ||1163(c > 0 && (java_add(t_hi, c) < t_hi)));1164}11651166//=============================================================================1167//------------------------------Idealize---------------------------------------1168// MINs show up in range-check loop limit calculations. Look for1169// "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)"1170Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {1171Node *progress = NULL;1172// Force a right-spline graph1173Node *l = in(1);1174Node *r = in(2);1175// Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) )1176// to force a right-spline graph for the rest of MinINode::Ideal().1177if( l->Opcode() == Op_MinI ) {1178assert( l != l->in(1), "dead loop in MinINode::Ideal" );1179r = phase->transform(new MinINode(l->in(2),r));1180l = l->in(1);1181set_req_X(1, l, phase);1182set_req_X(2, r, phase);1183return this;1184}11851186// Get left input & constant1187Node *x = l;1188jint x_off = 0;1189if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant1190x->in(2)->is_Con() ) {1191const Type *t = x->in(2)->bottom_type();1192if( t == Type::TOP ) return NULL; // No progress1193x_off = t->is_int()->get_con();1194x = x->in(1);1195}11961197// Scan a right-spline-tree for MINs1198Node *y = r;1199jint y_off = 0;1200// Check final part of MIN tree1201if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant1202y->in(2)->is_Con() ) {1203const Type *t = y->in(2)->bottom_type();1204if( t == Type::TOP ) return NULL; // No progress1205y_off = t->is_int()->get_con();1206y = y->in(1);1207}1208if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {1209swap_edges(1, 2);1210return this;1211}12121213const TypeInt* tx = phase->type(x)->isa_int();12141215if( r->Opcode() == Op_MinI ) {1216assert( r != r->in(2), "dead loop in MinINode::Ideal" );1217y = r->in(1);1218// Check final part of MIN tree1219if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant1220y->in(2)->is_Con() ) {1221const Type *t = y->in(2)->bottom_type();1222if( t == Type::TOP ) return NULL; // No progress1223y_off = t->is_int()->get_con();1224y = y->in(1);1225}12261227if( x->_idx > y->_idx )1228return new MinINode(r->in(1),phase->transform(new MinINode(l,r->in(2))));12291230// Transform MIN2(x + c0, MIN2(x + c1, z)) into MIN2(x + MIN2(c0, c1), z)1231// if x == y and the additions can't overflow.1232if (x == y && tx != NULL &&1233!can_overflow(tx, x_off) &&1234!can_overflow(tx, y_off)) {1235return new MinINode(phase->transform(new AddINode(x, phase->intcon(MIN2(x_off, y_off)))), r->in(2));1236}1237} else {1238// Transform MIN2(x + c0, y + c1) into x + MIN2(c0, c1)1239// if x == y and the additions can't overflow.1240if (x == y && tx != NULL &&1241!can_overflow(tx, x_off) &&1242!can_overflow(tx, y_off)) {1243return new AddINode(x,phase->intcon(MIN2(x_off,y_off)));1244}1245}1246return NULL;1247}12481249//------------------------------add_ring---------------------------------------1250// Supplied function returns the sum of the inputs.1251const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {1252const TypeInt *r0 = t0->is_int(); // Handy access1253const TypeInt *r1 = t1->is_int();12541255// Otherwise just MIN them bits.1256return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );1257}12581259//------------------------------add_ring---------------------------------------1260const Type *MinFNode::add_ring( const Type *t0, const Type *t1 ) const {1261const TypeF *r0 = t0->is_float_constant();1262const TypeF *r1 = t1->is_float_constant();12631264if (r0->is_nan()) {1265return r0;1266}1267if (r1->is_nan()) {1268return r1;1269}12701271float f0 = r0->getf();1272float f1 = r1->getf();1273if (f0 != 0.0f || f1 != 0.0f) {1274return f0 < f1 ? r0 : r1;1275}12761277// handle min of 0.0, -0.0 case.1278return (jint_cast(f0) < jint_cast(f1)) ? r0 : r1;1279}12801281//------------------------------add_ring---------------------------------------1282const Type *MinDNode::add_ring( const Type *t0, const Type *t1 ) const {1283const TypeD *r0 = t0->is_double_constant();1284const TypeD *r1 = t1->is_double_constant();12851286if (r0->is_nan()) {1287return r0;1288}1289if (r1->is_nan()) {1290return r1;1291}12921293double d0 = r0->getd();1294double d1 = r1->getd();1295if (d0 != 0.0 || d1 != 0.0) {1296return d0 < d1 ? r0 : r1;1297}12981299// handle min of 0.0, -0.0 case.1300return (jlong_cast(d0) < jlong_cast(d1)) ? r0 : r1;1301}13021303//------------------------------add_ring---------------------------------------1304const Type *MaxFNode::add_ring( const Type *t0, const Type *t1 ) const {1305const TypeF *r0 = t0->is_float_constant();1306const TypeF *r1 = t1->is_float_constant();13071308if (r0->is_nan()) {1309return r0;1310}1311if (r1->is_nan()) {1312return r1;1313}13141315float f0 = r0->getf();1316float f1 = r1->getf();1317if (f0 != 0.0f || f1 != 0.0f) {1318return f0 > f1 ? r0 : r1;1319}13201321// handle max of 0.0,-0.0 case.1322return (jint_cast(f0) > jint_cast(f1)) ? r0 : r1;1323}13241325//------------------------------add_ring---------------------------------------1326const Type *MaxDNode::add_ring( const Type *t0, const Type *t1 ) const {1327const TypeD *r0 = t0->is_double_constant();1328const TypeD *r1 = t1->is_double_constant();13291330if (r0->is_nan()) {1331return r0;1332}1333if (r1->is_nan()) {1334return r1;1335}13361337double d0 = r0->getd();1338double d1 = r1->getd();1339if (d0 != 0.0 || d1 != 0.0) {1340return d0 > d1 ? r0 : r1;1341}13421343// handle max of 0.0, -0.0 case.1344return (jlong_cast(d0) > jlong_cast(d1)) ? r0 : r1;1345}134613471348