Path: blob/master/src/hotspot/share/opto/divnode.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/connode.hpp"28#include "opto/convertnode.hpp"29#include "opto/divnode.hpp"30#include "opto/machnode.hpp"31#include "opto/movenode.hpp"32#include "opto/matcher.hpp"33#include "opto/mulnode.hpp"34#include "opto/phaseX.hpp"35#include "opto/subnode.hpp"36#include "utilities/powerOfTwo.hpp"3738// Portions of code courtesy of Clifford Click3940// Optimization - Graph Style4142#include <math.h>4344//----------------------magic_int_divide_constants-----------------------------45// Compute magic multiplier and shift constant for converting a 32 bit divide46// by constant into a multiply/shift/add series. Return false if calculations47// fail.48//49// Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with50// minor type name and parameter changes.51static bool magic_int_divide_constants(jint d, jint &M, jint &s) {52int32_t p;53uint32_t ad, anc, delta, q1, r1, q2, r2, t;54const uint32_t two31 = 0x80000000L; // 2**31.5556ad = ABS(d);57if (d == 0 || d == 1) return false;58t = two31 + ((uint32_t)d >> 31);59anc = t - 1 - t%ad; // Absolute value of nc.60p = 31; // Init. p.61q1 = two31/anc; // Init. q1 = 2**p/|nc|.62r1 = two31 - q1*anc; // Init. r1 = rem(2**p, |nc|).63q2 = two31/ad; // Init. q2 = 2**p/|d|.64r2 = two31 - q2*ad; // Init. r2 = rem(2**p, |d|).65do {66p = p + 1;67q1 = 2*q1; // Update q1 = 2**p/|nc|.68r1 = 2*r1; // Update r1 = rem(2**p, |nc|).69if (r1 >= anc) { // (Must be an unsigned70q1 = q1 + 1; // comparison here).71r1 = r1 - anc;72}73q2 = 2*q2; // Update q2 = 2**p/|d|.74r2 = 2*r2; // Update r2 = rem(2**p, |d|).75if (r2 >= ad) { // (Must be an unsigned76q2 = q2 + 1; // comparison here).77r2 = r2 - ad;78}79delta = ad - r2;80} while (q1 < delta || (q1 == delta && r1 == 0));8182M = q2 + 1;83if (d < 0) M = -M; // Magic number and84s = p - 32; // shift amount to return.8586return true;87}8889//--------------------------transform_int_divide-------------------------------90// Convert a division by constant divisor into an alternate Ideal graph.91// Return NULL if no transformation occurs.92static Node *transform_int_divide( PhaseGVN *phase, Node *dividend, jint divisor ) {9394// Check for invalid divisors95assert( divisor != 0 && divisor != min_jint,96"bad divisor for transforming to long multiply" );9798bool d_pos = divisor >= 0;99jint d = d_pos ? divisor : -divisor;100const int N = 32;101102// Result103Node *q = NULL;104105if (d == 1) {106// division by +/- 1107if (!d_pos) {108// Just negate the value109q = new SubINode(phase->intcon(0), dividend);110}111} else if ( is_power_of_2(d) ) {112// division by +/- a power of 2113114// See if we can simply do a shift without rounding115bool needs_rounding = true;116const Type *dt = phase->type(dividend);117const TypeInt *dti = dt->isa_int();118if (dti && dti->_lo >= 0) {119// we don't need to round a positive dividend120needs_rounding = false;121} else if( dividend->Opcode() == Op_AndI ) {122// An AND mask of sufficient size clears the low bits and123// I can avoid rounding.124const TypeInt *andconi_t = phase->type( dividend->in(2) )->isa_int();125if( andconi_t && andconi_t->is_con() ) {126jint andconi = andconi_t->get_con();127if( andconi < 0 && is_power_of_2(-andconi) && (-andconi) >= d ) {128if( (-andconi) == d ) // Remove AND if it clears bits which will be shifted129dividend = dividend->in(1);130needs_rounding = false;131}132}133}134135// Add rounding to the shift to handle the sign bit136int l = log2i_graceful(d - 1) + 1;137if (needs_rounding) {138// Divide-by-power-of-2 can be made into a shift, but you have to do139// more math for the rounding. You need to add 0 for positive140// numbers, and "i-1" for negative numbers. Example: i=4, so the141// shift is by 2. You need to add 3 to negative dividends and 0 to142// positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,143// (-2+3)>>2 becomes 0, etc.144145// Compute 0 or -1, based on sign bit146Node *sign = phase->transform(new RShiftINode(dividend, phase->intcon(N - 1)));147// Mask sign bit to the low sign bits148Node *round = phase->transform(new URShiftINode(sign, phase->intcon(N - l)));149// Round up before shifting150dividend = phase->transform(new AddINode(dividend, round));151}152153// Shift for division154q = new RShiftINode(dividend, phase->intcon(l));155156if (!d_pos) {157q = new SubINode(phase->intcon(0), phase->transform(q));158}159} else {160// Attempt the jint constant divide -> multiply transform found in161// "Division by Invariant Integers using Multiplication"162// by Granlund and Montgomery163// See also "Hacker's Delight", chapter 10 by Warren.164165jint magic_const;166jint shift_const;167if (magic_int_divide_constants(d, magic_const, shift_const)) {168Node *magic = phase->longcon(magic_const);169Node *dividend_long = phase->transform(new ConvI2LNode(dividend));170171// Compute the high half of the dividend x magic multiplication172Node *mul_hi = phase->transform(new MulLNode(dividend_long, magic));173174if (magic_const < 0) {175mul_hi = phase->transform(new RShiftLNode(mul_hi, phase->intcon(N)));176mul_hi = phase->transform(new ConvL2INode(mul_hi));177178// The magic multiplier is too large for a 32 bit constant. We've adjusted179// it down by 2^32, but have to add 1 dividend back in after the multiplication.180// This handles the "overflow" case described by Granlund and Montgomery.181mul_hi = phase->transform(new AddINode(dividend, mul_hi));182183// Shift over the (adjusted) mulhi184if (shift_const != 0) {185mul_hi = phase->transform(new RShiftINode(mul_hi, phase->intcon(shift_const)));186}187} else {188// No add is required, we can merge the shifts together.189mul_hi = phase->transform(new RShiftLNode(mul_hi, phase->intcon(N + shift_const)));190mul_hi = phase->transform(new ConvL2INode(mul_hi));191}192193// Get a 0 or -1 from the sign of the dividend.194Node *addend0 = mul_hi;195Node *addend1 = phase->transform(new RShiftINode(dividend, phase->intcon(N-1)));196197// If the divisor is negative, swap the order of the input addends;198// this has the effect of negating the quotient.199if (!d_pos) {200Node *temp = addend0; addend0 = addend1; addend1 = temp;201}202203// Adjust the final quotient by subtracting -1 (adding 1)204// from the mul_hi.205q = new SubINode(addend0, addend1);206}207}208209return q;210}211212//---------------------magic_long_divide_constants-----------------------------213// Compute magic multiplier and shift constant for converting a 64 bit divide214// by constant into a multiply/shift/add series. Return false if calculations215// fail.216//217// Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with218// minor type name and parameter changes. Adjusted to 64 bit word width.219static bool magic_long_divide_constants(jlong d, jlong &M, jint &s) {220int64_t p;221uint64_t ad, anc, delta, q1, r1, q2, r2, t;222const uint64_t two63 = UCONST64(0x8000000000000000); // 2**63.223224ad = ABS(d);225if (d == 0 || d == 1) return false;226t = two63 + ((uint64_t)d >> 63);227anc = t - 1 - t%ad; // Absolute value of nc.228p = 63; // Init. p.229q1 = two63/anc; // Init. q1 = 2**p/|nc|.230r1 = two63 - q1*anc; // Init. r1 = rem(2**p, |nc|).231q2 = two63/ad; // Init. q2 = 2**p/|d|.232r2 = two63 - q2*ad; // Init. r2 = rem(2**p, |d|).233do {234p = p + 1;235q1 = 2*q1; // Update q1 = 2**p/|nc|.236r1 = 2*r1; // Update r1 = rem(2**p, |nc|).237if (r1 >= anc) { // (Must be an unsigned238q1 = q1 + 1; // comparison here).239r1 = r1 - anc;240}241q2 = 2*q2; // Update q2 = 2**p/|d|.242r2 = 2*r2; // Update r2 = rem(2**p, |d|).243if (r2 >= ad) { // (Must be an unsigned244q2 = q2 + 1; // comparison here).245r2 = r2 - ad;246}247delta = ad - r2;248} while (q1 < delta || (q1 == delta && r1 == 0));249250M = q2 + 1;251if (d < 0) M = -M; // Magic number and252s = p - 64; // shift amount to return.253254return true;255}256257//---------------------long_by_long_mulhi--------------------------------------258// Generate ideal node graph for upper half of a 64 bit x 64 bit multiplication259static Node* long_by_long_mulhi(PhaseGVN* phase, Node* dividend, jlong magic_const) {260// If the architecture supports a 64x64 mulhi, there is261// no need to synthesize it in ideal nodes.262if (Matcher::has_match_rule(Op_MulHiL)) {263Node* v = phase->longcon(magic_const);264return new MulHiLNode(dividend, v);265}266267// Taken from Hacker's Delight, Fig. 8-2. Multiply high signed.268// (http://www.hackersdelight.org/HDcode/mulhs.c)269//270// int mulhs(int u, int v) {271// unsigned u0, v0, w0;272// int u1, v1, w1, w2, t;273//274// u0 = u & 0xFFFF; u1 = u >> 16;275// v0 = v & 0xFFFF; v1 = v >> 16;276// w0 = u0*v0;277// t = u1*v0 + (w0 >> 16);278// w1 = t & 0xFFFF;279// w2 = t >> 16;280// w1 = u0*v1 + w1;281// return u1*v1 + w2 + (w1 >> 16);282// }283//284// Note: The version above is for 32x32 multiplications, while the285// following inline comments are adapted to 64x64.286287const int N = 64;288289// Dummy node to keep intermediate nodes alive during construction290Node* hook = new Node(4);291292// u0 = u & 0xFFFFFFFF; u1 = u >> 32;293Node* u0 = phase->transform(new AndLNode(dividend, phase->longcon(0xFFFFFFFF)));294Node* u1 = phase->transform(new RShiftLNode(dividend, phase->intcon(N / 2)));295hook->init_req(0, u0);296hook->init_req(1, u1);297298// v0 = v & 0xFFFFFFFF; v1 = v >> 32;299Node* v0 = phase->longcon(magic_const & 0xFFFFFFFF);300Node* v1 = phase->longcon(magic_const >> (N / 2));301302// w0 = u0*v0;303Node* w0 = phase->transform(new MulLNode(u0, v0));304305// t = u1*v0 + (w0 >> 32);306Node* u1v0 = phase->transform(new MulLNode(u1, v0));307Node* temp = phase->transform(new URShiftLNode(w0, phase->intcon(N / 2)));308Node* t = phase->transform(new AddLNode(u1v0, temp));309hook->init_req(2, t);310311// w1 = t & 0xFFFFFFFF;312Node* w1 = phase->transform(new AndLNode(t, phase->longcon(0xFFFFFFFF)));313hook->init_req(3, w1);314315// w2 = t >> 32;316Node* w2 = phase->transform(new RShiftLNode(t, phase->intcon(N / 2)));317318// w1 = u0*v1 + w1;319Node* u0v1 = phase->transform(new MulLNode(u0, v1));320w1 = phase->transform(new AddLNode(u0v1, w1));321322// return u1*v1 + w2 + (w1 >> 32);323Node* u1v1 = phase->transform(new MulLNode(u1, v1));324Node* temp1 = phase->transform(new AddLNode(u1v1, w2));325Node* temp2 = phase->transform(new RShiftLNode(w1, phase->intcon(N / 2)));326327// Remove the bogus extra edges used to keep things alive328hook->destruct(phase);329330return new AddLNode(temp1, temp2);331}332333334//--------------------------transform_long_divide------------------------------335// Convert a division by constant divisor into an alternate Ideal graph.336// Return NULL if no transformation occurs.337static Node *transform_long_divide( PhaseGVN *phase, Node *dividend, jlong divisor ) {338// Check for invalid divisors339assert( divisor != 0L && divisor != min_jlong,340"bad divisor for transforming to long multiply" );341342bool d_pos = divisor >= 0;343jlong d = d_pos ? divisor : -divisor;344const int N = 64;345346// Result347Node *q = NULL;348349if (d == 1) {350// division by +/- 1351if (!d_pos) {352// Just negate the value353q = new SubLNode(phase->longcon(0), dividend);354}355} else if ( is_power_of_2(d) ) {356357// division by +/- a power of 2358359// See if we can simply do a shift without rounding360bool needs_rounding = true;361const Type *dt = phase->type(dividend);362const TypeLong *dtl = dt->isa_long();363364if (dtl && dtl->_lo > 0) {365// we don't need to round a positive dividend366needs_rounding = false;367} else if( dividend->Opcode() == Op_AndL ) {368// An AND mask of sufficient size clears the low bits and369// I can avoid rounding.370const TypeLong *andconl_t = phase->type( dividend->in(2) )->isa_long();371if( andconl_t && andconl_t->is_con() ) {372jlong andconl = andconl_t->get_con();373if( andconl < 0 && is_power_of_2(-andconl) && (-andconl) >= d ) {374if( (-andconl) == d ) // Remove AND if it clears bits which will be shifted375dividend = dividend->in(1);376needs_rounding = false;377}378}379}380381// Add rounding to the shift to handle the sign bit382int l = log2i_graceful(d - 1) + 1;383if (needs_rounding) {384// Divide-by-power-of-2 can be made into a shift, but you have to do385// more math for the rounding. You need to add 0 for positive386// numbers, and "i-1" for negative numbers. Example: i=4, so the387// shift is by 2. You need to add 3 to negative dividends and 0 to388// positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,389// (-2+3)>>2 becomes 0, etc.390391// Compute 0 or -1, based on sign bit392Node *sign = phase->transform(new RShiftLNode(dividend, phase->intcon(N - 1)));393// Mask sign bit to the low sign bits394Node *round = phase->transform(new URShiftLNode(sign, phase->intcon(N - l)));395// Round up before shifting396dividend = phase->transform(new AddLNode(dividend, round));397}398399// Shift for division400q = new RShiftLNode(dividend, phase->intcon(l));401402if (!d_pos) {403q = new SubLNode(phase->longcon(0), phase->transform(q));404}405} else if ( !Matcher::use_asm_for_ldiv_by_con(d) ) { // Use hardware DIV instruction when406// it is faster than code generated below.407// Attempt the jlong constant divide -> multiply transform found in408// "Division by Invariant Integers using Multiplication"409// by Granlund and Montgomery410// See also "Hacker's Delight", chapter 10 by Warren.411412jlong magic_const;413jint shift_const;414if (magic_long_divide_constants(d, magic_const, shift_const)) {415// Compute the high half of the dividend x magic multiplication416Node *mul_hi = phase->transform(long_by_long_mulhi(phase, dividend, magic_const));417418// The high half of the 128-bit multiply is computed.419if (magic_const < 0) {420// The magic multiplier is too large for a 64 bit constant. We've adjusted421// it down by 2^64, but have to add 1 dividend back in after the multiplication.422// This handles the "overflow" case described by Granlund and Montgomery.423mul_hi = phase->transform(new AddLNode(dividend, mul_hi));424}425426// Shift over the (adjusted) mulhi427if (shift_const != 0) {428mul_hi = phase->transform(new RShiftLNode(mul_hi, phase->intcon(shift_const)));429}430431// Get a 0 or -1 from the sign of the dividend.432Node *addend0 = mul_hi;433Node *addend1 = phase->transform(new RShiftLNode(dividend, phase->intcon(N-1)));434435// If the divisor is negative, swap the order of the input addends;436// this has the effect of negating the quotient.437if (!d_pos) {438Node *temp = addend0; addend0 = addend1; addend1 = temp;439}440441// Adjust the final quotient by subtracting -1 (adding 1)442// from the mul_hi.443q = new SubLNode(addend0, addend1);444}445}446447return q;448}449450//=============================================================================451//------------------------------Identity---------------------------------------452// If the divisor is 1, we are an identity on the dividend.453Node* DivINode::Identity(PhaseGVN* phase) {454return (phase->type( in(2) )->higher_equal(TypeInt::ONE)) ? in(1) : this;455}456457//------------------------------Idealize---------------------------------------458// Divides can be changed to multiplies and/or shifts459Node *DivINode::Ideal(PhaseGVN *phase, bool can_reshape) {460if (in(0) && remove_dead_region(phase, can_reshape)) return this;461// Don't bother trying to transform a dead node462if( in(0) && in(0)->is_top() ) return NULL;463464const Type *t = phase->type( in(2) );465if( t == TypeInt::ONE ) // Identity?466return NULL; // Skip it467468const TypeInt *ti = t->isa_int();469if( !ti ) return NULL;470471// Check for useless control input472// Check for excluding div-zero case473if (in(0) && (ti->_hi < 0 || ti->_lo > 0)) {474set_req(0, NULL); // Yank control input475return this;476}477478if( !ti->is_con() ) return NULL;479jint i = ti->get_con(); // Get divisor480481if (i == 0) return NULL; // Dividing by zero constant does not idealize482483// Dividing by MININT does not optimize as a power-of-2 shift.484if( i == min_jint ) return NULL;485486return transform_int_divide( phase, in(1), i );487}488489//------------------------------Value------------------------------------------490// A DivINode divides its inputs. The third input is a Control input, used to491// prevent hoisting the divide above an unsafe test.492const Type* DivINode::Value(PhaseGVN* phase) const {493// Either input is TOP ==> the result is TOP494const Type *t1 = phase->type( in(1) );495const Type *t2 = phase->type( in(2) );496if( t1 == Type::TOP ) return Type::TOP;497if( t2 == Type::TOP ) return Type::TOP;498499// x/x == 1 since we always generate the dynamic divisor check for 0.500if (in(1) == in(2)) {501return TypeInt::ONE;502}503504// Either input is BOTTOM ==> the result is the local BOTTOM505const Type *bot = bottom_type();506if( (t1 == bot) || (t2 == bot) ||507(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )508return bot;509510// Divide the two numbers. We approximate.511// If divisor is a constant and not zero512const TypeInt *i1 = t1->is_int();513const TypeInt *i2 = t2->is_int();514int widen = MAX2(i1->_widen, i2->_widen);515516if( i2->is_con() && i2->get_con() != 0 ) {517int32_t d = i2->get_con(); // Divisor518jint lo, hi;519if( d >= 0 ) {520lo = i1->_lo/d;521hi = i1->_hi/d;522} else {523if( d == -1 && i1->_lo == min_jint ) {524// 'min_jint/-1' throws arithmetic exception during compilation525lo = min_jint;526// do not support holes, 'hi' must go to either min_jint or max_jint:527// [min_jint, -10]/[-1,-1] ==> [min_jint] UNION [10,max_jint]528hi = i1->_hi == min_jint ? min_jint : max_jint;529} else {530lo = i1->_hi/d;531hi = i1->_lo/d;532}533}534return TypeInt::make(lo, hi, widen);535}536537// If the dividend is a constant538if( i1->is_con() ) {539int32_t d = i1->get_con();540if( d < 0 ) {541if( d == min_jint ) {542// (-min_jint) == min_jint == (min_jint / -1)543return TypeInt::make(min_jint, max_jint/2 + 1, widen);544} else {545return TypeInt::make(d, -d, widen);546}547}548return TypeInt::make(-d, d, widen);549}550551// Otherwise we give up all hope552return TypeInt::INT;553}554555556//=============================================================================557//------------------------------Identity---------------------------------------558// If the divisor is 1, we are an identity on the dividend.559Node* DivLNode::Identity(PhaseGVN* phase) {560return (phase->type( in(2) )->higher_equal(TypeLong::ONE)) ? in(1) : this;561}562563//------------------------------Idealize---------------------------------------564// Dividing by a power of 2 is a shift.565Node *DivLNode::Ideal( PhaseGVN *phase, bool can_reshape) {566if (in(0) && remove_dead_region(phase, can_reshape)) return this;567// Don't bother trying to transform a dead node568if( in(0) && in(0)->is_top() ) return NULL;569570const Type *t = phase->type( in(2) );571if( t == TypeLong::ONE ) // Identity?572return NULL; // Skip it573574const TypeLong *tl = t->isa_long();575if( !tl ) return NULL;576577// Check for useless control input578// Check for excluding div-zero case579if (in(0) && (tl->_hi < 0 || tl->_lo > 0)) {580set_req(0, NULL); // Yank control input581return this;582}583584if( !tl->is_con() ) return NULL;585jlong l = tl->get_con(); // Get divisor586587if (l == 0) return NULL; // Dividing by zero constant does not idealize588589// Dividing by MINLONG does not optimize as a power-of-2 shift.590if( l == min_jlong ) return NULL;591592return transform_long_divide( phase, in(1), l );593}594595//------------------------------Value------------------------------------------596// A DivLNode divides its inputs. The third input is a Control input, used to597// prevent hoisting the divide above an unsafe test.598const Type* DivLNode::Value(PhaseGVN* phase) const {599// Either input is TOP ==> the result is TOP600const Type *t1 = phase->type( in(1) );601const Type *t2 = phase->type( in(2) );602if( t1 == Type::TOP ) return Type::TOP;603if( t2 == Type::TOP ) return Type::TOP;604605// x/x == 1 since we always generate the dynamic divisor check for 0.606if (in(1) == in(2)) {607return TypeLong::ONE;608}609610// Either input is BOTTOM ==> the result is the local BOTTOM611const Type *bot = bottom_type();612if( (t1 == bot) || (t2 == bot) ||613(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )614return bot;615616// Divide the two numbers. We approximate.617// If divisor is a constant and not zero618const TypeLong *i1 = t1->is_long();619const TypeLong *i2 = t2->is_long();620int widen = MAX2(i1->_widen, i2->_widen);621622if( i2->is_con() && i2->get_con() != 0 ) {623jlong d = i2->get_con(); // Divisor624jlong lo, hi;625if( d >= 0 ) {626lo = i1->_lo/d;627hi = i1->_hi/d;628} else {629if( d == CONST64(-1) && i1->_lo == min_jlong ) {630// 'min_jlong/-1' throws arithmetic exception during compilation631lo = min_jlong;632// do not support holes, 'hi' must go to either min_jlong or max_jlong:633// [min_jlong, -10]/[-1,-1] ==> [min_jlong] UNION [10,max_jlong]634hi = i1->_hi == min_jlong ? min_jlong : max_jlong;635} else {636lo = i1->_hi/d;637hi = i1->_lo/d;638}639}640return TypeLong::make(lo, hi, widen);641}642643// If the dividend is a constant644if( i1->is_con() ) {645jlong d = i1->get_con();646if( d < 0 ) {647if( d == min_jlong ) {648// (-min_jlong) == min_jlong == (min_jlong / -1)649return TypeLong::make(min_jlong, max_jlong/2 + 1, widen);650} else {651return TypeLong::make(d, -d, widen);652}653}654return TypeLong::make(-d, d, widen);655}656657// Otherwise we give up all hope658return TypeLong::LONG;659}660661662//=============================================================================663//------------------------------Value------------------------------------------664// An DivFNode divides its inputs. The third input is a Control input, used to665// prevent hoisting the divide above an unsafe test.666const Type* DivFNode::Value(PhaseGVN* phase) const {667// Either input is TOP ==> the result is TOP668const Type *t1 = phase->type( in(1) );669const Type *t2 = phase->type( in(2) );670if( t1 == Type::TOP ) return Type::TOP;671if( t2 == Type::TOP ) return Type::TOP;672673// Either input is BOTTOM ==> the result is the local BOTTOM674const Type *bot = bottom_type();675if( (t1 == bot) || (t2 == bot) ||676(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )677return bot;678679// x/x == 1, we ignore 0/0.680// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)681// Does not work for variables because of NaN's682if (in(1) == in(2) && t1->base() == Type::FloatCon &&683!g_isnan(t1->getf()) && g_isfinite(t1->getf()) && t1->getf() != 0.0) { // could be negative ZERO or NaN684return TypeF::ONE;685}686687if( t2 == TypeF::ONE )688return t1;689690// If divisor is a constant and not zero, divide them numbers691if( t1->base() == Type::FloatCon &&692t2->base() == Type::FloatCon &&693t2->getf() != 0.0 ) // could be negative zero694return TypeF::make( t1->getf()/t2->getf() );695696// If the dividend is a constant zero697// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)698// Test TypeF::ZERO is not sufficient as it could be negative zero699700if( t1 == TypeF::ZERO && !g_isnan(t2->getf()) && t2->getf() != 0.0 )701return TypeF::ZERO;702703// Otherwise we give up all hope704return Type::FLOAT;705}706707//------------------------------isA_Copy---------------------------------------708// Dividing by self is 1.709// If the divisor is 1, we are an identity on the dividend.710Node* DivFNode::Identity(PhaseGVN* phase) {711return (phase->type( in(2) ) == TypeF::ONE) ? in(1) : this;712}713714715//------------------------------Idealize---------------------------------------716Node *DivFNode::Ideal(PhaseGVN *phase, bool can_reshape) {717if (in(0) && remove_dead_region(phase, can_reshape)) return this;718// Don't bother trying to transform a dead node719if( in(0) && in(0)->is_top() ) return NULL;720721const Type *t2 = phase->type( in(2) );722if( t2 == TypeF::ONE ) // Identity?723return NULL; // Skip it724725const TypeF *tf = t2->isa_float_constant();726if( !tf ) return NULL;727if( tf->base() != Type::FloatCon ) return NULL;728729// Check for out of range values730if( tf->is_nan() || !tf->is_finite() ) return NULL;731732// Get the value733float f = tf->getf();734int exp;735736// Only for special case of dividing by a power of 2737if( frexp((double)f, &exp) != 0.5 ) return NULL;738739// Limit the range of acceptable exponents740if( exp < -126 || exp > 126 ) return NULL;741742// Compute the reciprocal743float reciprocal = ((float)1.0) / f;744745assert( frexp((double)reciprocal, &exp) == 0.5, "reciprocal should be power of 2" );746747// return multiplication by the reciprocal748return (new MulFNode(in(1), phase->makecon(TypeF::make(reciprocal))));749}750751//=============================================================================752//------------------------------Value------------------------------------------753// An DivDNode divides its inputs. The third input is a Control input, used to754// prevent hoisting the divide above an unsafe test.755const Type* DivDNode::Value(PhaseGVN* phase) const {756// Either input is TOP ==> the result is TOP757const Type *t1 = phase->type( in(1) );758const Type *t2 = phase->type( in(2) );759if( t1 == Type::TOP ) return Type::TOP;760if( t2 == Type::TOP ) return Type::TOP;761762// Either input is BOTTOM ==> the result is the local BOTTOM763const Type *bot = bottom_type();764if( (t1 == bot) || (t2 == bot) ||765(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )766return bot;767768// x/x == 1, we ignore 0/0.769// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)770// Does not work for variables because of NaN's771if (in(1) == in(2) && t1->base() == Type::DoubleCon &&772!g_isnan(t1->getd()) && g_isfinite(t1->getd()) && t1->getd() != 0.0) { // could be negative ZERO or NaN773return TypeD::ONE;774}775776if( t2 == TypeD::ONE )777return t1;778779// IA32 would only execute this for non-strict FP, which is never the780// case now.781#if ! defined(IA32)782// If divisor is a constant and not zero, divide them numbers783if( t1->base() == Type::DoubleCon &&784t2->base() == Type::DoubleCon &&785t2->getd() != 0.0 ) // could be negative zero786return TypeD::make( t1->getd()/t2->getd() );787#endif788789// If the dividend is a constant zero790// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)791// Test TypeF::ZERO is not sufficient as it could be negative zero792if( t1 == TypeD::ZERO && !g_isnan(t2->getd()) && t2->getd() != 0.0 )793return TypeD::ZERO;794795// Otherwise we give up all hope796return Type::DOUBLE;797}798799800//------------------------------isA_Copy---------------------------------------801// Dividing by self is 1.802// If the divisor is 1, we are an identity on the dividend.803Node* DivDNode::Identity(PhaseGVN* phase) {804return (phase->type( in(2) ) == TypeD::ONE) ? in(1) : this;805}806807//------------------------------Idealize---------------------------------------808Node *DivDNode::Ideal(PhaseGVN *phase, bool can_reshape) {809if (in(0) && remove_dead_region(phase, can_reshape)) return this;810// Don't bother trying to transform a dead node811if( in(0) && in(0)->is_top() ) return NULL;812813const Type *t2 = phase->type( in(2) );814if( t2 == TypeD::ONE ) // Identity?815return NULL; // Skip it816817const TypeD *td = t2->isa_double_constant();818if( !td ) return NULL;819if( td->base() != Type::DoubleCon ) return NULL;820821// Check for out of range values822if( td->is_nan() || !td->is_finite() ) return NULL;823824// Get the value825double d = td->getd();826int exp;827828// Only for special case of dividing by a power of 2829if( frexp(d, &exp) != 0.5 ) return NULL;830831// Limit the range of acceptable exponents832if( exp < -1021 || exp > 1022 ) return NULL;833834// Compute the reciprocal835double reciprocal = 1.0 / d;836837assert( frexp(reciprocal, &exp) == 0.5, "reciprocal should be power of 2" );838839// return multiplication by the reciprocal840return (new MulDNode(in(1), phase->makecon(TypeD::make(reciprocal))));841}842843//=============================================================================844//------------------------------Idealize---------------------------------------845Node *ModINode::Ideal(PhaseGVN *phase, bool can_reshape) {846// Check for dead control input847if( in(0) && remove_dead_region(phase, can_reshape) ) return this;848// Don't bother trying to transform a dead node849if( in(0) && in(0)->is_top() ) return NULL;850851// Get the modulus852const Type *t = phase->type( in(2) );853if( t == Type::TOP ) return NULL;854const TypeInt *ti = t->is_int();855856// Check for useless control input857// Check for excluding mod-zero case858if (in(0) && (ti->_hi < 0 || ti->_lo > 0)) {859set_req(0, NULL); // Yank control input860return this;861}862863// See if we are MOD'ing by 2^k or 2^k-1.864if( !ti->is_con() ) return NULL;865jint con = ti->get_con();866867Node *hook = new Node(1);868869// First, special check for modulo 2^k-1870if( con >= 0 && con < max_jint && is_power_of_2(con+1) ) {871uint k = exact_log2(con+1); // Extract k872873// Basic algorithm by David Detlefs. See fastmod_int.java for gory details.874static int unroll_factor[] = { 999, 999, 29, 14, 9, 7, 5, 4, 4, 3, 3, 2, 2, 2, 2, 2, 1 /*past here we assume 1 forever*/};875int trip_count = 1;876if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k];877878// If the unroll factor is not too large, and if conditional moves are879// ok, then use this case880if( trip_count <= 5 && ConditionalMoveLimit != 0 ) {881Node *x = in(1); // Value being mod'd882Node *divisor = in(2); // Also is mask883884hook->init_req(0, x); // Add a use to x to prevent him from dying885// Generate code to reduce X rapidly to nearly 2^k-1.886for( int i = 0; i < trip_count; i++ ) {887Node *xl = phase->transform( new AndINode(x,divisor) );888Node *xh = phase->transform( new RShiftINode(x,phase->intcon(k)) ); // Must be signed889x = phase->transform( new AddINode(xh,xl) );890hook->set_req(0, x);891}892893// Generate sign-fixup code. Was original value positive?894// int hack_res = (i >= 0) ? divisor : 1;895Node *cmp1 = phase->transform( new CmpINode( in(1), phase->intcon(0) ) );896Node *bol1 = phase->transform( new BoolNode( cmp1, BoolTest::ge ) );897Node *cmov1= phase->transform( new CMoveINode(bol1, phase->intcon(1), divisor, TypeInt::POS) );898// if( x >= hack_res ) x -= divisor;899Node *sub = phase->transform( new SubINode( x, divisor ) );900Node *cmp2 = phase->transform( new CmpINode( x, cmov1 ) );901Node *bol2 = phase->transform( new BoolNode( cmp2, BoolTest::ge ) );902// Convention is to not transform the return value of an Ideal903// since Ideal is expected to return a modified 'this' or a new node.904Node *cmov2= new CMoveINode(bol2, x, sub, TypeInt::INT);905// cmov2 is now the mod906907// Now remove the bogus extra edges used to keep things alive908hook->destruct(phase);909return cmov2;910}911}912913// Fell thru, the unroll case is not appropriate. Transform the modulo914// into a long multiply/int multiply/subtract case915916// Cannot handle mod 0, and min_jint isn't handled by the transform917if( con == 0 || con == min_jint ) return NULL;918919// Get the absolute value of the constant; at this point, we can use this920jint pos_con = (con >= 0) ? con : -con;921922// integer Mod 1 is always 0923if( pos_con == 1 ) return new ConINode(TypeInt::ZERO);924925int log2_con = -1;926927// If this is a power of two, they maybe we can mask it928if (is_power_of_2(pos_con)) {929log2_con = log2i_exact(pos_con);930931const Type *dt = phase->type(in(1));932const TypeInt *dti = dt->isa_int();933934// See if this can be masked, if the dividend is non-negative935if( dti && dti->_lo >= 0 )936return ( new AndINode( in(1), phase->intcon( pos_con-1 ) ) );937}938939// Save in(1) so that it cannot be changed or deleted940hook->init_req(0, in(1));941942// Divide using the transform from DivI to MulL943Node *result = transform_int_divide( phase, in(1), pos_con );944if (result != NULL) {945Node *divide = phase->transform(result);946947// Re-multiply, using a shift if this is a power of two948Node *mult = NULL;949950if( log2_con >= 0 )951mult = phase->transform( new LShiftINode( divide, phase->intcon( log2_con ) ) );952else953mult = phase->transform( new MulINode( divide, phase->intcon( pos_con ) ) );954955// Finally, subtract the multiplied divided value from the original956result = new SubINode( in(1), mult );957}958959// Now remove the bogus extra edges used to keep things alive960hook->destruct(phase);961962// return the value963return result;964}965966//------------------------------Value------------------------------------------967const Type* ModINode::Value(PhaseGVN* phase) const {968// Either input is TOP ==> the result is TOP969const Type *t1 = phase->type( in(1) );970const Type *t2 = phase->type( in(2) );971if( t1 == Type::TOP ) return Type::TOP;972if( t2 == Type::TOP ) return Type::TOP;973974// We always generate the dynamic check for 0.975// 0 MOD X is 0976if( t1 == TypeInt::ZERO ) return TypeInt::ZERO;977// X MOD X is 0978if (in(1) == in(2)) {979return TypeInt::ZERO;980}981982// Either input is BOTTOM ==> the result is the local BOTTOM983const Type *bot = bottom_type();984if( (t1 == bot) || (t2 == bot) ||985(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )986return bot;987988const TypeInt *i1 = t1->is_int();989const TypeInt *i2 = t2->is_int();990if( !i1->is_con() || !i2->is_con() ) {991if( i1->_lo >= 0 && i2->_lo >= 0 )992return TypeInt::POS;993// If both numbers are not constants, we know little.994return TypeInt::INT;995}996// Mod by zero? Throw exception at runtime!997if( !i2->get_con() ) return TypeInt::POS;998999// We must be modulo'ing 2 float constants.1000// Check for min_jint % '-1', result is defined to be '0'.1001if( i1->get_con() == min_jint && i2->get_con() == -1 )1002return TypeInt::ZERO;10031004return TypeInt::make( i1->get_con() % i2->get_con() );1005}100610071008//=============================================================================1009//------------------------------Idealize---------------------------------------1010Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) {1011// Check for dead control input1012if( in(0) && remove_dead_region(phase, can_reshape) ) return this;1013// Don't bother trying to transform a dead node1014if( in(0) && in(0)->is_top() ) return NULL;10151016// Get the modulus1017const Type *t = phase->type( in(2) );1018if( t == Type::TOP ) return NULL;1019const TypeLong *tl = t->is_long();10201021// Check for useless control input1022// Check for excluding mod-zero case1023if (in(0) && (tl->_hi < 0 || tl->_lo > 0)) {1024set_req(0, NULL); // Yank control input1025return this;1026}10271028// See if we are MOD'ing by 2^k or 2^k-1.1029if( !tl->is_con() ) return NULL;1030jlong con = tl->get_con();10311032Node *hook = new Node(1);10331034// Expand mod1035if(con >= 0 && con < max_jlong && is_power_of_2(con + 1)) {1036uint k = log2i_exact(con + 1); // Extract k10371038// Basic algorithm by David Detlefs. See fastmod_long.java for gory details.1039// Used to help a popular random number generator which does a long-mod1040// of 2^31-1 and shows up in SpecJBB and SciMark.1041static int unroll_factor[] = { 999, 999, 61, 30, 20, 15, 12, 10, 8, 7, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 /*past here we assume 1 forever*/};1042int trip_count = 1;1043if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k];10441045// If the unroll factor is not too large, and if conditional moves are1046// ok, then use this case1047if( trip_count <= 5 && ConditionalMoveLimit != 0 ) {1048Node *x = in(1); // Value being mod'd1049Node *divisor = in(2); // Also is mask10501051hook->init_req(0, x); // Add a use to x to prevent him from dying1052// Generate code to reduce X rapidly to nearly 2^k-1.1053for( int i = 0; i < trip_count; i++ ) {1054Node *xl = phase->transform( new AndLNode(x,divisor) );1055Node *xh = phase->transform( new RShiftLNode(x,phase->intcon(k)) ); // Must be signed1056x = phase->transform( new AddLNode(xh,xl) );1057hook->set_req(0, x); // Add a use to x to prevent him from dying1058}10591060// Generate sign-fixup code. Was original value positive?1061// long hack_res = (i >= 0) ? divisor : CONST64(1);1062Node *cmp1 = phase->transform( new CmpLNode( in(1), phase->longcon(0) ) );1063Node *bol1 = phase->transform( new BoolNode( cmp1, BoolTest::ge ) );1064Node *cmov1= phase->transform( new CMoveLNode(bol1, phase->longcon(1), divisor, TypeLong::LONG) );1065// if( x >= hack_res ) x -= divisor;1066Node *sub = phase->transform( new SubLNode( x, divisor ) );1067Node *cmp2 = phase->transform( new CmpLNode( x, cmov1 ) );1068Node *bol2 = phase->transform( new BoolNode( cmp2, BoolTest::ge ) );1069// Convention is to not transform the return value of an Ideal1070// since Ideal is expected to return a modified 'this' or a new node.1071Node *cmov2= new CMoveLNode(bol2, x, sub, TypeLong::LONG);1072// cmov2 is now the mod10731074// Now remove the bogus extra edges used to keep things alive1075hook->destruct(phase);1076return cmov2;1077}1078}10791080// Fell thru, the unroll case is not appropriate. Transform the modulo1081// into a long multiply/int multiply/subtract case10821083// Cannot handle mod 0, and min_jlong isn't handled by the transform1084if( con == 0 || con == min_jlong ) return NULL;10851086// Get the absolute value of the constant; at this point, we can use this1087jlong pos_con = (con >= 0) ? con : -con;10881089// integer Mod 1 is always 01090if( pos_con == 1 ) return new ConLNode(TypeLong::ZERO);10911092int log2_con = -1;10931094// If this is a power of two, then maybe we can mask it1095if (is_power_of_2(pos_con)) {1096log2_con = log2i_exact(pos_con);10971098const Type *dt = phase->type(in(1));1099const TypeLong *dtl = dt->isa_long();11001101// See if this can be masked, if the dividend is non-negative1102if( dtl && dtl->_lo >= 0 )1103return ( new AndLNode( in(1), phase->longcon( pos_con-1 ) ) );1104}11051106// Save in(1) so that it cannot be changed or deleted1107hook->init_req(0, in(1));11081109// Divide using the transform from DivL to MulL1110Node *result = transform_long_divide( phase, in(1), pos_con );1111if (result != NULL) {1112Node *divide = phase->transform(result);11131114// Re-multiply, using a shift if this is a power of two1115Node *mult = NULL;11161117if( log2_con >= 0 )1118mult = phase->transform( new LShiftLNode( divide, phase->intcon( log2_con ) ) );1119else1120mult = phase->transform( new MulLNode( divide, phase->longcon( pos_con ) ) );11211122// Finally, subtract the multiplied divided value from the original1123result = new SubLNode( in(1), mult );1124}11251126// Now remove the bogus extra edges used to keep things alive1127hook->destruct(phase);11281129// return the value1130return result;1131}11321133//------------------------------Value------------------------------------------1134const Type* ModLNode::Value(PhaseGVN* phase) const {1135// Either input is TOP ==> the result is TOP1136const Type *t1 = phase->type( in(1) );1137const Type *t2 = phase->type( in(2) );1138if( t1 == Type::TOP ) return Type::TOP;1139if( t2 == Type::TOP ) return Type::TOP;11401141// We always generate the dynamic check for 0.1142// 0 MOD X is 01143if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;1144// X MOD X is 01145if (in(1) == in(2)) {1146return TypeLong::ZERO;1147}11481149// Either input is BOTTOM ==> the result is the local BOTTOM1150const Type *bot = bottom_type();1151if( (t1 == bot) || (t2 == bot) ||1152(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )1153return bot;11541155const TypeLong *i1 = t1->is_long();1156const TypeLong *i2 = t2->is_long();1157if( !i1->is_con() || !i2->is_con() ) {1158if( i1->_lo >= CONST64(0) && i2->_lo >= CONST64(0) )1159return TypeLong::POS;1160// If both numbers are not constants, we know little.1161return TypeLong::LONG;1162}1163// Mod by zero? Throw exception at runtime!1164if( !i2->get_con() ) return TypeLong::POS;11651166// We must be modulo'ing 2 float constants.1167// Check for min_jint % '-1', result is defined to be '0'.1168if( i1->get_con() == min_jlong && i2->get_con() == -1 )1169return TypeLong::ZERO;11701171return TypeLong::make( i1->get_con() % i2->get_con() );1172}117311741175//=============================================================================1176//------------------------------Value------------------------------------------1177const Type* ModFNode::Value(PhaseGVN* phase) const {1178// Either input is TOP ==> the result is TOP1179const Type *t1 = phase->type( in(1) );1180const Type *t2 = phase->type( in(2) );1181if( t1 == Type::TOP ) return Type::TOP;1182if( t2 == Type::TOP ) return Type::TOP;11831184// Either input is BOTTOM ==> the result is the local BOTTOM1185const Type *bot = bottom_type();1186if( (t1 == bot) || (t2 == bot) ||1187(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )1188return bot;11891190// If either number is not a constant, we know nothing.1191if ((t1->base() != Type::FloatCon) || (t2->base() != Type::FloatCon)) {1192return Type::FLOAT; // note: x%x can be either NaN or 01193}11941195float f1 = t1->getf();1196float f2 = t2->getf();1197jint x1 = jint_cast(f1); // note: *(int*)&f1, not just (int)f11198jint x2 = jint_cast(f2);11991200// If either is a NaN, return an input NaN1201if (g_isnan(f1)) return t1;1202if (g_isnan(f2)) return t2;12031204// If an operand is infinity or the divisor is +/- zero, punt.1205if (!g_isfinite(f1) || !g_isfinite(f2) || x2 == 0 || x2 == min_jint)1206return Type::FLOAT;12071208// We must be modulo'ing 2 float constants.1209// Make sure that the sign of the fmod is equal to the sign of the dividend1210jint xr = jint_cast(fmod(f1, f2));1211if ((x1 ^ xr) < 0) {1212xr ^= min_jint;1213}12141215return TypeF::make(jfloat_cast(xr));1216}121712181219//=============================================================================1220//------------------------------Value------------------------------------------1221const Type* ModDNode::Value(PhaseGVN* phase) const {1222// Either input is TOP ==> the result is TOP1223const Type *t1 = phase->type( in(1) );1224const Type *t2 = phase->type( in(2) );1225if( t1 == Type::TOP ) return Type::TOP;1226if( t2 == Type::TOP ) return Type::TOP;12271228// Either input is BOTTOM ==> the result is the local BOTTOM1229const Type *bot = bottom_type();1230if( (t1 == bot) || (t2 == bot) ||1231(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )1232return bot;12331234// If either number is not a constant, we know nothing.1235if ((t1->base() != Type::DoubleCon) || (t2->base() != Type::DoubleCon)) {1236return Type::DOUBLE; // note: x%x can be either NaN or 01237}12381239double f1 = t1->getd();1240double f2 = t2->getd();1241jlong x1 = jlong_cast(f1); // note: *(long*)&f1, not just (long)f11242jlong x2 = jlong_cast(f2);12431244// If either is a NaN, return an input NaN1245if (g_isnan(f1)) return t1;1246if (g_isnan(f2)) return t2;12471248// If an operand is infinity or the divisor is +/- zero, punt.1249if (!g_isfinite(f1) || !g_isfinite(f2) || x2 == 0 || x2 == min_jlong)1250return Type::DOUBLE;12511252// We must be modulo'ing 2 double constants.1253// Make sure that the sign of the fmod is equal to the sign of the dividend1254jlong xr = jlong_cast(fmod(f1, f2));1255if ((x1 ^ xr) < 0) {1256xr ^= min_jlong;1257}12581259return TypeD::make(jdouble_cast(xr));1260}12611262//=============================================================================12631264DivModNode::DivModNode( Node *c, Node *dividend, Node *divisor ) : MultiNode(3) {1265init_req(0, c);1266init_req(1, dividend);1267init_req(2, divisor);1268}12691270//------------------------------make------------------------------------------1271DivModINode* DivModINode::make(Node* div_or_mod) {1272Node* n = div_or_mod;1273assert(n->Opcode() == Op_DivI || n->Opcode() == Op_ModI,1274"only div or mod input pattern accepted");12751276DivModINode* divmod = new DivModINode(n->in(0), n->in(1), n->in(2));1277Node* dproj = new ProjNode(divmod, DivModNode::div_proj_num);1278Node* mproj = new ProjNode(divmod, DivModNode::mod_proj_num);1279return divmod;1280}12811282//------------------------------make------------------------------------------1283DivModLNode* DivModLNode::make(Node* div_or_mod) {1284Node* n = div_or_mod;1285assert(n->Opcode() == Op_DivL || n->Opcode() == Op_ModL,1286"only div or mod input pattern accepted");12871288DivModLNode* divmod = new DivModLNode(n->in(0), n->in(1), n->in(2));1289Node* dproj = new ProjNode(divmod, DivModNode::div_proj_num);1290Node* mproj = new ProjNode(divmod, DivModNode::mod_proj_num);1291return divmod;1292}12931294//------------------------------match------------------------------------------1295// return result(s) along with their RegMask info1296Node *DivModINode::match( const ProjNode *proj, const Matcher *match ) {1297uint ideal_reg = proj->ideal_reg();1298RegMask rm;1299if (proj->_con == div_proj_num) {1300rm = match->divI_proj_mask();1301} else {1302assert(proj->_con == mod_proj_num, "must be div or mod projection");1303rm = match->modI_proj_mask();1304}1305return new MachProjNode(this, proj->_con, rm, ideal_reg);1306}130713081309//------------------------------match------------------------------------------1310// return result(s) along with their RegMask info1311Node *DivModLNode::match( const ProjNode *proj, const Matcher *match ) {1312uint ideal_reg = proj->ideal_reg();1313RegMask rm;1314if (proj->_con == div_proj_num) {1315rm = match->divL_proj_mask();1316} else {1317assert(proj->_con == mod_proj_num, "must be div or mod projection");1318rm = match->modL_proj_mask();1319}1320return new MachProjNode(this, proj->_con, rm, ideal_reg);1321}132213231324