Path: blob/master/src/hotspot/share/opto/addnode.cpp
40930 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}364365return AddNode::Ideal(phase, can_reshape);366}367368369//------------------------------Identity---------------------------------------370// Fold (x-y)+y OR y+(x-y) into x371Node* AddINode::Identity(PhaseGVN* phase) {372if (in(1)->Opcode() == Op_SubI && in(1)->in(2) == in(2)) {373return in(1)->in(1);374} else if (in(2)->Opcode() == Op_SubI && in(2)->in(2) == in(1)) {375return in(2)->in(1);376}377return AddNode::Identity(phase);378}379380381//------------------------------add_ring---------------------------------------382// Supplied function returns the sum of the inputs. Guaranteed never383// to be passed a TOP or BOTTOM type, these are filtered out by384// pre-check.385const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {386const TypeInt *r0 = t0->is_int(); // Handy access387const TypeInt *r1 = t1->is_int();388int lo = java_add(r0->_lo, r1->_lo);389int hi = java_add(r0->_hi, r1->_hi);390if( !(r0->is_con() && r1->is_con()) ) {391// Not both constants, compute approximate result392if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {393lo = min_jint; hi = max_jint; // Underflow on the low side394}395if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {396lo = min_jint; hi = max_jint; // Overflow on the high side397}398if( lo > hi ) { // Handle overflow399lo = min_jint; hi = max_jint;400}401} else {402// both constants, compute precise result using 'lo' and 'hi'403// Semantics define overflow and underflow for integer addition404// as expected. In particular: 0x80000000 + 0x80000000 --> 0x0405}406return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );407}408409410//=============================================================================411//------------------------------Idealize---------------------------------------412Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {413Node* in1 = in(1);414Node* in2 = in(2);415int op1 = in1->Opcode();416int op2 = in2->Opcode();417// Fold (con1-x)+con2 into (con1+con2)-x418if ( op1 == Op_AddL && op2 == Op_SubL ) {419// Swap edges to try optimizations below420in1 = in2;421in2 = in(1);422op1 = op2;423op2 = in2->Opcode();424}425// Fold (con1-x)+con2 into (con1+con2)-x426if( op1 == Op_SubL ) {427const Type *t_sub1 = phase->type( in1->in(1) );428const Type *t_2 = phase->type( in2 );429if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )430return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );431// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"432if( op2 == Op_SubL ) {433// Check for dead cycle: d = (a-b)+(c-d)434assert( in1->in(2) != this && in2->in(2) != this,435"dead loop in AddLNode::Ideal" );436Node *sub = new SubLNode(NULL, NULL);437sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));438sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));439return sub;440}441// Convert "(a-b)+(b+c)" into "(a+c)"442if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {443assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");444return new AddLNode(in1->in(1), in2->in(2));445}446// Convert "(a-b)+(c+b)" into "(a+c)"447if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {448assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");449return new AddLNode(in1->in(1), in2->in(1));450}451// Convert "(a-b)+(b-c)" into "(a-c)"452if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {453assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");454return new SubLNode(in1->in(1), in2->in(2));455}456// Convert "(a-b)+(c-a)" into "(c-b)"457if( op2 == Op_SubL && in1->in(1) == in2->in(2) ) {458assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");459return new SubLNode(in2->in(1), in1->in(2));460}461}462463// Convert "x+(0-y)" into "(x-y)"464if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )465return new SubLNode( in1, in2->in(2) );466467// Convert "(0-y)+x" into "(x-y)"468if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeLong::ZERO )469return new SubLNode( in2, in1->in(2) );470471// Convert (x >>> rshift) + (x << lshift) into RotateRight(x, rshift)472if (Matcher::match_rule_supported(Op_RotateRight) &&473((op1 == Op_URShiftL && op2 == Op_LShiftL) || (op1 == Op_LShiftL && op2 == Op_URShiftL)) &&474in1->in(1) != NULL && in1->in(1) == in2->in(1)) {475Node* rshift = op1 == Op_URShiftL ? in1->in(2) : in2->in(2);476Node* lshift = op1 == Op_URShiftL ? in2->in(2) : in1->in(2);477if (rshift != NULL && lshift != NULL) {478const TypeInt* rshift_t = phase->type(rshift)->isa_int();479const TypeInt* lshift_t = phase->type(lshift)->isa_int();480if (lshift_t != NULL && lshift_t->is_con() &&481rshift_t != NULL && rshift_t->is_con() &&482((lshift_t->get_con() & 0x3F) == (64 - (rshift_t->get_con() & 0x3F)))) {483return new RotateRightNode(in1->in(1), phase->intcon(rshift_t->get_con() & 0x3F), TypeLong::LONG);484}485}486}487488489return AddNode::Ideal(phase, can_reshape);490}491492493//------------------------------Identity---------------------------------------494// Fold (x-y)+y OR y+(x-y) into x495Node* AddLNode::Identity(PhaseGVN* phase) {496if (in(1)->Opcode() == Op_SubL && in(1)->in(2) == in(2)) {497return in(1)->in(1);498} else if (in(2)->Opcode() == Op_SubL && in(2)->in(2) == in(1)) {499return in(2)->in(1);500}501return AddNode::Identity(phase);502}503504505//------------------------------add_ring---------------------------------------506// Supplied function returns the sum of the inputs. Guaranteed never507// to be passed a TOP or BOTTOM type, these are filtered out by508// pre-check.509const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {510const TypeLong *r0 = t0->is_long(); // Handy access511const TypeLong *r1 = t1->is_long();512jlong lo = java_add(r0->_lo, r1->_lo);513jlong hi = java_add(r0->_hi, r1->_hi);514if( !(r0->is_con() && r1->is_con()) ) {515// Not both constants, compute approximate result516if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {517lo =min_jlong; hi = max_jlong; // Underflow on the low side518}519if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {520lo = min_jlong; hi = max_jlong; // Overflow on the high side521}522if( lo > hi ) { // Handle overflow523lo = min_jlong; hi = max_jlong;524}525} else {526// both constants, compute precise result using 'lo' and 'hi'527// Semantics define overflow and underflow for integer addition528// as expected. In particular: 0x80000000 + 0x80000000 --> 0x0529}530return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) );531}532533534//=============================================================================535//------------------------------add_of_identity--------------------------------536// Check for addition of the identity537const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const {538// x ADD 0 should return x unless 'x' is a -zero539//540// const Type *zero = add_id(); // The additive identity541// jfloat f1 = t1->getf();542// jfloat f2 = t2->getf();543//544// if( t1->higher_equal( zero ) ) return t2;545// if( t2->higher_equal( zero ) ) return t1;546547return NULL;548}549550//------------------------------add_ring---------------------------------------551// Supplied function returns the sum of the inputs.552// This also type-checks the inputs for sanity. Guaranteed never to553// be passed a TOP or BOTTOM type, these are filtered out by pre-check.554const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const {555// We must be adding 2 float constants.556return TypeF::make( t0->getf() + t1->getf() );557}558559//------------------------------Ideal------------------------------------------560Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) {561// Floating point additions are not associative because of boundary conditions (infinity)562return commute(phase, this) ? this : NULL;563}564565566//=============================================================================567//------------------------------add_of_identity--------------------------------568// Check for addition of the identity569const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const {570// x ADD 0 should return x unless 'x' is a -zero571//572// const Type *zero = add_id(); // The additive identity573// jfloat f1 = t1->getf();574// jfloat f2 = t2->getf();575//576// if( t1->higher_equal( zero ) ) return t2;577// if( t2->higher_equal( zero ) ) return t1;578579return NULL;580}581//------------------------------add_ring---------------------------------------582// Supplied function returns the sum of the inputs.583// This also type-checks the inputs for sanity. Guaranteed never to584// be passed a TOP or BOTTOM type, these are filtered out by pre-check.585const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const {586// We must be adding 2 double constants.587return TypeD::make( t0->getd() + t1->getd() );588}589590//------------------------------Ideal------------------------------------------591Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {592// Floating point additions are not associative because of boundary conditions (infinity)593return commute(phase, this) ? this : NULL;594}595596597//=============================================================================598//------------------------------Identity---------------------------------------599// If one input is a constant 0, return the other input.600Node* AddPNode::Identity(PhaseGVN* phase) {601return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;602}603604//------------------------------Idealize---------------------------------------605Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {606// Bail out if dead inputs607if( phase->type( in(Address) ) == Type::TOP ) return NULL;608609// If the left input is an add of a constant, flatten the expression tree.610const Node *n = in(Address);611if (n->is_AddP() && n->in(Base) == in(Base)) {612const AddPNode *addp = n->as_AddP(); // Left input is an AddP613assert( !addp->in(Address)->is_AddP() ||614addp->in(Address)->as_AddP() != addp,615"dead loop in AddPNode::Ideal" );616// Type of left input's right input617const Type *t = phase->type( addp->in(Offset) );618if( t == Type::TOP ) return NULL;619const TypeX *t12 = t->is_intptr_t();620if( t12->is_con() ) { // Left input is an add of a constant?621// If the right input is a constant, combine constants622const Type *temp_t2 = phase->type( in(Offset) );623if( temp_t2 == Type::TOP ) return NULL;624const TypeX *t2 = temp_t2->is_intptr_t();625Node* address;626Node* offset;627if( t2->is_con() ) {628// The Add of the flattened expression629address = addp->in(Address);630offset = phase->MakeConX(t2->get_con() + t12->get_con());631} else {632// Else move the constant to the right. ((A+con)+B) into ((A+B)+con)633address = phase->transform(new AddPNode(in(Base),addp->in(Address),in(Offset)));634offset = addp->in(Offset);635}636set_req_X(Address, address, phase);637set_req_X(Offset, offset, phase);638return this;639}640}641642// Raw pointers?643if( in(Base)->bottom_type() == Type::TOP ) {644// If this is a NULL+long form (from unsafe accesses), switch to a rawptr.645if (phase->type(in(Address)) == TypePtr::NULL_PTR) {646Node* offset = in(Offset);647return new CastX2PNode(offset);648}649}650651// If the right is an add of a constant, push the offset down.652// Convert: (ptr + (offset+con)) into (ptr+offset)+con.653// The idea is to merge array_base+scaled_index groups together,654// and only have different constant offsets from the same base.655const Node *add = in(Offset);656if( add->Opcode() == Op_AddX && add->in(1) != add ) {657const Type *t22 = phase->type( add->in(2) );658if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant?659set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));660set_req(Offset, add->in(2));661PhaseIterGVN* igvn = phase->is_IterGVN();662if (add->outcnt() == 0 && igvn) {663// add disconnected.664igvn->_worklist.push((Node*)add);665}666return this; // Made progress667}668}669670return NULL; // No progress671}672673//------------------------------bottom_type------------------------------------674// Bottom-type is the pointer-type with unknown offset.675const Type *AddPNode::bottom_type() const {676if (in(Address) == NULL) return TypePtr::BOTTOM;677const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();678if( !tp ) return Type::TOP; // TOP input means TOP output679assert( in(Offset)->Opcode() != Op_ConP, "" );680const Type *t = in(Offset)->bottom_type();681if( t == Type::TOP )682return tp->add_offset(Type::OffsetTop);683const TypeX *tx = t->is_intptr_t();684intptr_t txoffset = Type::OffsetBot;685if (tx->is_con()) { // Left input is an add of a constant?686txoffset = tx->get_con();687}688return tp->add_offset(txoffset);689}690691//------------------------------Value------------------------------------------692const Type* AddPNode::Value(PhaseGVN* phase) const {693// Either input is TOP ==> the result is TOP694const Type *t1 = phase->type( in(Address) );695const Type *t2 = phase->type( in(Offset) );696if( t1 == Type::TOP ) return Type::TOP;697if( t2 == Type::TOP ) return Type::TOP;698699// Left input is a pointer700const TypePtr *p1 = t1->isa_ptr();701// Right input is an int702const TypeX *p2 = t2->is_intptr_t();703// Add 'em704intptr_t p2offset = Type::OffsetBot;705if (p2->is_con()) { // Left input is an add of a constant?706p2offset = p2->get_con();707}708return p1->add_offset(p2offset);709}710711//------------------------Ideal_base_and_offset--------------------------------712// Split an oop pointer into a base and offset.713// (The offset might be Type::OffsetBot in the case of an array.)714// Return the base, or NULL if failure.715Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,716// second return value:717intptr_t& offset) {718if (ptr->is_AddP()) {719Node* base = ptr->in(AddPNode::Base);720Node* addr = ptr->in(AddPNode::Address);721Node* offs = ptr->in(AddPNode::Offset);722if (base == addr || base->is_top()) {723offset = phase->find_intptr_t_con(offs, Type::OffsetBot);724if (offset != Type::OffsetBot) {725return addr;726}727}728}729offset = Type::OffsetBot;730return NULL;731}732733//------------------------------unpack_offsets----------------------------------734// Collect the AddP offset values into the elements array, giving up735// if there are more than length.736int AddPNode::unpack_offsets(Node* elements[], int length) {737int count = 0;738Node* addr = this;739Node* base = addr->in(AddPNode::Base);740while (addr->is_AddP()) {741if (addr->in(AddPNode::Base) != base) {742// give up743return -1;744}745elements[count++] = addr->in(AddPNode::Offset);746if (count == length) {747// give up748return -1;749}750addr = addr->in(AddPNode::Address);751}752if (addr != base) {753return -1;754}755return count;756}757758//------------------------------match_edge-------------------------------------759// Do we Match on this edge index or not? Do not match base pointer edge760uint AddPNode::match_edge(uint idx) const {761return idx > Base;762}763764//=============================================================================765//------------------------------Identity---------------------------------------766Node* OrINode::Identity(PhaseGVN* phase) {767// x | x => x768if (in(1) == in(2)) {769return in(1);770}771772return AddNode::Identity(phase);773}774775// Find shift value for Integer or Long OR.776Node* rotate_shift(PhaseGVN* phase, Node* lshift, Node* rshift, int mask) {777// val << norm_con_shift | val >> ({32|64} - norm_con_shift) => rotate_left val, norm_con_shift778const TypeInt* lshift_t = phase->type(lshift)->isa_int();779const TypeInt* rshift_t = phase->type(rshift)->isa_int();780if (lshift_t != NULL && lshift_t->is_con() &&781rshift_t != NULL && rshift_t->is_con() &&782((lshift_t->get_con() & mask) == ((mask + 1) - (rshift_t->get_con() & mask)))) {783return phase->intcon(lshift_t->get_con() & mask);784}785// val << var_shift | val >> ({0|32|64} - var_shift) => rotate_left val, var_shift786if (rshift->Opcode() == Op_SubI && rshift->in(2) == lshift && rshift->in(1)->is_Con()){787const TypeInt* shift_t = phase->type(rshift->in(1))->isa_int();788if (shift_t != NULL && shift_t->is_con() &&789(shift_t->get_con() == 0 || shift_t->get_con() == (mask + 1))) {790return lshift;791}792}793return NULL;794}795796Node* OrINode::Ideal(PhaseGVN* phase, bool can_reshape) {797int lopcode = in(1)->Opcode();798int ropcode = in(2)->Opcode();799if (Matcher::match_rule_supported(Op_RotateLeft) &&800lopcode == Op_LShiftI && ropcode == Op_URShiftI && in(1)->in(1) == in(2)->in(1)) {801Node* lshift = in(1)->in(2);802Node* rshift = in(2)->in(2);803Node* shift = rotate_shift(phase, lshift, rshift, 0x1F);804if (shift != NULL) {805return new RotateLeftNode(in(1)->in(1), shift, TypeInt::INT);806}807return NULL;808}809if (Matcher::match_rule_supported(Op_RotateRight) &&810lopcode == Op_URShiftI && ropcode == Op_LShiftI && in(1)->in(1) == in(2)->in(1)) {811Node* rshift = in(1)->in(2);812Node* lshift = in(2)->in(2);813Node* shift = rotate_shift(phase, rshift, lshift, 0x1F);814if (shift != NULL) {815return new RotateRightNode(in(1)->in(1), shift, TypeInt::INT);816}817}818return NULL;819}820821//------------------------------add_ring---------------------------------------822// Supplied function returns the sum of the inputs IN THE CURRENT RING. For823// the logical operations the ring's ADD is really a logical OR function.824// This also type-checks the inputs for sanity. Guaranteed never to825// be passed a TOP or BOTTOM type, these are filtered out by pre-check.826const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {827const TypeInt *r0 = t0->is_int(); // Handy access828const TypeInt *r1 = t1->is_int();829830// If both args are bool, can figure out better types831if ( r0 == TypeInt::BOOL ) {832if ( r1 == TypeInt::ONE) {833return TypeInt::ONE;834} else if ( r1 == TypeInt::BOOL ) {835return TypeInt::BOOL;836}837} else if ( r0 == TypeInt::ONE ) {838if ( r1 == TypeInt::BOOL ) {839return TypeInt::ONE;840}841}842843// If either input is not a constant, just return all integers.844if( !r0->is_con() || !r1->is_con() )845return TypeInt::INT; // Any integer, but still no symbols.846847// Otherwise just OR them bits.848return TypeInt::make( r0->get_con() | r1->get_con() );849}850851//=============================================================================852//------------------------------Identity---------------------------------------853Node* OrLNode::Identity(PhaseGVN* phase) {854// x | x => x855if (in(1) == in(2)) {856return in(1);857}858859return AddNode::Identity(phase);860}861862Node* OrLNode::Ideal(PhaseGVN* phase, bool can_reshape) {863int lopcode = in(1)->Opcode();864int ropcode = in(2)->Opcode();865if (Matcher::match_rule_supported(Op_RotateLeft) &&866lopcode == Op_LShiftL && ropcode == Op_URShiftL && in(1)->in(1) == in(2)->in(1)) {867Node* lshift = in(1)->in(2);868Node* rshift = in(2)->in(2);869Node* shift = rotate_shift(phase, lshift, rshift, 0x3F);870if (shift != NULL) {871return new RotateLeftNode(in(1)->in(1), shift, TypeLong::LONG);872}873return NULL;874}875if (Matcher::match_rule_supported(Op_RotateRight) &&876lopcode == Op_URShiftL && ropcode == Op_LShiftL && in(1)->in(1) == in(2)->in(1)) {877Node* rshift = in(1)->in(2);878Node* lshift = in(2)->in(2);879Node* shift = rotate_shift(phase, rshift, lshift, 0x3F);880if (shift != NULL) {881return new RotateRightNode(in(1)->in(1), shift, TypeLong::LONG);882}883}884return NULL;885}886887//------------------------------add_ring---------------------------------------888const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {889const TypeLong *r0 = t0->is_long(); // Handy access890const TypeLong *r1 = t1->is_long();891892// If either input is not a constant, just return all integers.893if( !r0->is_con() || !r1->is_con() )894return TypeLong::LONG; // Any integer, but still no symbols.895896// Otherwise just OR them bits.897return TypeLong::make( r0->get_con() | r1->get_con() );898}899900//=============================================================================901902const Type* XorINode::Value(PhaseGVN* phase) const {903Node* in1 = in(1);904Node* in2 = in(2);905const Type* t1 = phase->type(in1);906const Type* t2 = phase->type(in2);907if (t1 == Type::TOP || t2 == Type::TOP) {908return Type::TOP;909}910// x ^ x ==> 0911if (in1->eqv_uncast(in2)) {912return add_id();913}914// result of xor can only have bits sets where any of the915// inputs have bits set. lo can always become 0.916const TypeInt* t1i = t1->is_int();917const TypeInt* t2i = t2->is_int();918if ((t1i->_lo >= 0) &&919(t1i->_hi > 0) &&920(t2i->_lo >= 0) &&921(t2i->_hi > 0)) {922// hi - set all bits below the highest bit. Using round_down to avoid overflow.923const TypeInt* t1x = TypeInt::make(0, round_down_power_of_2(t1i->_hi) + (round_down_power_of_2(t1i->_hi) - 1), t1i->_widen);924const TypeInt* t2x = TypeInt::make(0, round_down_power_of_2(t2i->_hi) + (round_down_power_of_2(t2i->_hi) - 1), t2i->_widen);925return t1x->meet(t2x);926}927return AddNode::Value(phase);928}929930931//------------------------------add_ring---------------------------------------932// Supplied function returns the sum of the inputs IN THE CURRENT RING. For933// the logical operations the ring's ADD is really a logical OR function.934// This also type-checks the inputs for sanity. Guaranteed never to935// be passed a TOP or BOTTOM type, these are filtered out by pre-check.936const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const {937const TypeInt *r0 = t0->is_int(); // Handy access938const TypeInt *r1 = t1->is_int();939940// Complementing a boolean?941if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE942|| r1 == TypeInt::BOOL))943return TypeInt::BOOL;944945if( !r0->is_con() || !r1->is_con() ) // Not constants946return TypeInt::INT; // Any integer, but still no symbols.947948// Otherwise just XOR them bits.949return TypeInt::make( r0->get_con() ^ r1->get_con() );950}951952//=============================================================================953//------------------------------add_ring---------------------------------------954const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {955const TypeLong *r0 = t0->is_long(); // Handy access956const TypeLong *r1 = t1->is_long();957958// If either input is not a constant, just return all integers.959if( !r0->is_con() || !r1->is_con() )960return TypeLong::LONG; // Any integer, but still no symbols.961962// Otherwise just OR them bits.963return TypeLong::make( r0->get_con() ^ r1->get_con() );964}965966const Type* XorLNode::Value(PhaseGVN* phase) const {967Node* in1 = in(1);968Node* in2 = in(2);969const Type* t1 = phase->type(in1);970const Type* t2 = phase->type(in2);971if (t1 == Type::TOP || t2 == Type::TOP) {972return Type::TOP;973}974// x ^ x ==> 0975if (in1->eqv_uncast(in2)) {976return add_id();977}978// result of xor can only have bits sets where any of the979// inputs have bits set. lo can always become 0.980const TypeLong* t1l = t1->is_long();981const TypeLong* t2l = t2->is_long();982if ((t1l->_lo >= 0) &&983(t1l->_hi > 0) &&984(t2l->_lo >= 0) &&985(t2l->_hi > 0)) {986// hi - set all bits below the highest bit. Using round_down to avoid overflow.987const TypeLong* t1x = TypeLong::make(0, round_down_power_of_2(t1l->_hi) + (round_down_power_of_2(t1l->_hi) - 1), t1l->_widen);988const TypeLong* t2x = TypeLong::make(0, round_down_power_of_2(t2l->_hi) + (round_down_power_of_2(t2l->_hi) - 1), t2l->_widen);989return t1x->meet(t2x);990}991return AddNode::Value(phase);992}993994Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) {995bool is_int = gvn.type(a)->isa_int();996assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");997assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");998Node* hook = NULL;999if (gvn.is_IterGVN()) {1000// Make sure a and b are not destroyed1001hook = new Node(2);1002hook->init_req(0, a);1003hook->init_req(1, b);1004}1005Node* res = NULL;1006if (!is_unsigned) {1007if (is_max) {1008if (is_int) {1009res = gvn.transform(new MaxINode(a, b));1010assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");1011} else {1012Node* cmp = gvn.transform(new CmpLNode(a, b));1013Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1014res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1015}1016} else {1017if (is_int) {1018Node* res = gvn.transform(new MinINode(a, b));1019assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");1020} else {1021Node* cmp = gvn.transform(new CmpLNode(b, a));1022Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1023res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1024}1025}1026} else {1027if (is_max) {1028if (is_int) {1029Node* cmp = gvn.transform(new CmpUNode(a, b));1030Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1031res = gvn.transform(new CMoveINode(bol, a, b, t->is_int()));1032} else {1033Node* cmp = gvn.transform(new CmpULNode(a, b));1034Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1035res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1036}1037} else {1038if (is_int) {1039Node* cmp = gvn.transform(new CmpUNode(b, a));1040Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1041res = gvn.transform(new CMoveINode(bol, a, b, t->is_int()));1042} else {1043Node* cmp = gvn.transform(new CmpULNode(b, a));1044Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1045res = gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));1046}1047}1048}1049if (hook != NULL) {1050hook->destruct(&gvn);1051}1052return res;1053}10541055Node* MaxNode::build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn) {1056bool is_int = gvn.type(a)->isa_int();1057assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");1058assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");1059Node* zero = NULL;1060if (is_int) {1061zero = gvn.intcon(0);1062} else {1063zero = gvn.longcon(0);1064}1065Node* hook = NULL;1066if (gvn.is_IterGVN()) {1067// Make sure a and b are not destroyed1068hook = new Node(2);1069hook->init_req(0, a);1070hook->init_req(1, b);1071}1072Node* res = NULL;1073if (is_max) {1074if (is_int) {1075Node* cmp = gvn.transform(new CmpINode(a, b));1076Node* sub = gvn.transform(new SubINode(a, b));1077Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1078res = gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));1079} else {1080Node* cmp = gvn.transform(new CmpLNode(a, b));1081Node* sub = gvn.transform(new SubLNode(a, b));1082Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1083res = gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));1084}1085} else {1086if (is_int) {1087Node* cmp = gvn.transform(new CmpINode(b, a));1088Node* sub = gvn.transform(new SubINode(a, b));1089Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1090res = gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));1091} else {1092Node* cmp = gvn.transform(new CmpLNode(b, a));1093Node* sub = gvn.transform(new SubLNode(a, b));1094Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));1095res = gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));1096}1097}1098if (hook != NULL) {1099hook->destruct(&gvn);1100}1101return res;1102}11031104//=============================================================================1105//------------------------------add_ring---------------------------------------1106// Supplied function returns the sum of the inputs.1107const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {1108const TypeInt *r0 = t0->is_int(); // Handy access1109const TypeInt *r1 = t1->is_int();11101111// Otherwise just MAX them bits.1112return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );1113}11141115// Check if addition of an integer with type 't' and a constant 'c' can overflow1116static bool can_overflow(const TypeInt* t, jint c) {1117jint t_lo = t->_lo;1118jint t_hi = t->_hi;1119return ((c < 0 && (java_add(t_lo, c) > t_lo)) ||1120(c > 0 && (java_add(t_hi, c) < t_hi)));1121}11221123//=============================================================================1124//------------------------------Idealize---------------------------------------1125// MINs show up in range-check loop limit calculations. Look for1126// "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)"1127Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {1128Node *progress = NULL;1129// Force a right-spline graph1130Node *l = in(1);1131Node *r = in(2);1132// Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) )1133// to force a right-spline graph for the rest of MinINode::Ideal().1134if( l->Opcode() == Op_MinI ) {1135assert( l != l->in(1), "dead loop in MinINode::Ideal" );1136r = phase->transform(new MinINode(l->in(2),r));1137l = l->in(1);1138set_req_X(1, l, phase);1139set_req_X(2, r, phase);1140return this;1141}11421143// Get left input & constant1144Node *x = l;1145jint x_off = 0;1146if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant1147x->in(2)->is_Con() ) {1148const Type *t = x->in(2)->bottom_type();1149if( t == Type::TOP ) return NULL; // No progress1150x_off = t->is_int()->get_con();1151x = x->in(1);1152}11531154// Scan a right-spline-tree for MINs1155Node *y = r;1156jint y_off = 0;1157// Check final part of MIN tree1158if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant1159y->in(2)->is_Con() ) {1160const Type *t = y->in(2)->bottom_type();1161if( t == Type::TOP ) return NULL; // No progress1162y_off = t->is_int()->get_con();1163y = y->in(1);1164}1165if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {1166swap_edges(1, 2);1167return this;1168}11691170const TypeInt* tx = phase->type(x)->isa_int();11711172if( r->Opcode() == Op_MinI ) {1173assert( r != r->in(2), "dead loop in MinINode::Ideal" );1174y = r->in(1);1175// Check final part of MIN tree1176if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant1177y->in(2)->is_Con() ) {1178const Type *t = y->in(2)->bottom_type();1179if( t == Type::TOP ) return NULL; // No progress1180y_off = t->is_int()->get_con();1181y = y->in(1);1182}11831184if( x->_idx > y->_idx )1185return new MinINode(r->in(1),phase->transform(new MinINode(l,r->in(2))));11861187// Transform MIN2(x + c0, MIN2(x + c1, z)) into MIN2(x + MIN2(c0, c1), z)1188// if x == y and the additions can't overflow.1189if (x == y && tx != NULL &&1190!can_overflow(tx, x_off) &&1191!can_overflow(tx, y_off)) {1192return new MinINode(phase->transform(new AddINode(x, phase->intcon(MIN2(x_off, y_off)))), r->in(2));1193}1194} else {1195// Transform MIN2(x + c0, y + c1) into x + MIN2(c0, c1)1196// if x == y and the additions can't overflow.1197if (x == y && tx != NULL &&1198!can_overflow(tx, x_off) &&1199!can_overflow(tx, y_off)) {1200return new AddINode(x,phase->intcon(MIN2(x_off,y_off)));1201}1202}1203return NULL;1204}12051206//------------------------------add_ring---------------------------------------1207// Supplied function returns the sum of the inputs.1208const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {1209const TypeInt *r0 = t0->is_int(); // Handy access1210const TypeInt *r1 = t1->is_int();12111212// Otherwise just MIN them bits.1213return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );1214}12151216//------------------------------add_ring---------------------------------------1217const Type *MinFNode::add_ring( const Type *t0, const Type *t1 ) const {1218const TypeF *r0 = t0->is_float_constant();1219const TypeF *r1 = t1->is_float_constant();12201221if (r0->is_nan()) {1222return r0;1223}1224if (r1->is_nan()) {1225return r1;1226}12271228float f0 = r0->getf();1229float f1 = r1->getf();1230if (f0 != 0.0f || f1 != 0.0f) {1231return f0 < f1 ? r0 : r1;1232}12331234// handle min of 0.0, -0.0 case.1235return (jint_cast(f0) < jint_cast(f1)) ? r0 : r1;1236}12371238//------------------------------add_ring---------------------------------------1239const Type *MinDNode::add_ring( const Type *t0, const Type *t1 ) const {1240const TypeD *r0 = t0->is_double_constant();1241const TypeD *r1 = t1->is_double_constant();12421243if (r0->is_nan()) {1244return r0;1245}1246if (r1->is_nan()) {1247return r1;1248}12491250double d0 = r0->getd();1251double d1 = r1->getd();1252if (d0 != 0.0 || d1 != 0.0) {1253return d0 < d1 ? r0 : r1;1254}12551256// handle min of 0.0, -0.0 case.1257return (jlong_cast(d0) < jlong_cast(d1)) ? r0 : r1;1258}12591260//------------------------------add_ring---------------------------------------1261const Type *MaxFNode::add_ring( const Type *t0, const Type *t1 ) const {1262const TypeF *r0 = t0->is_float_constant();1263const TypeF *r1 = t1->is_float_constant();12641265if (r0->is_nan()) {1266return r0;1267}1268if (r1->is_nan()) {1269return r1;1270}12711272float f0 = r0->getf();1273float f1 = r1->getf();1274if (f0 != 0.0f || f1 != 0.0f) {1275return f0 > f1 ? r0 : r1;1276}12771278// handle max of 0.0,-0.0 case.1279return (jint_cast(f0) > jint_cast(f1)) ? r0 : r1;1280}12811282//------------------------------add_ring---------------------------------------1283const Type *MaxDNode::add_ring( const Type *t0, const Type *t1 ) const {1284const TypeD *r0 = t0->is_double_constant();1285const TypeD *r1 = t1->is_double_constant();12861287if (r0->is_nan()) {1288return r0;1289}1290if (r1->is_nan()) {1291return r1;1292}12931294double d0 = r0->getd();1295double d1 = r1->getd();1296if (d0 != 0.0 || d1 != 0.0) {1297return d0 > d1 ? r0 : r1;1298}12991300// handle max of 0.0, -0.0 case.1301return (jlong_cast(d0) > jlong_cast(d1)) ? r0 : r1;1302}130313041305