duke@435: /* duke@435: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // Portions of code courtesy of Clifford Click duke@435: duke@435: // Optimization - Graph Style duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_divnode.cpp.incl" duke@435: #include duke@435: duke@435: // Implement the integer constant divide -> long multiply transform found in duke@435: // "Division by Invariant Integers using Multiplication" duke@435: // by Granlund and Montgomery duke@435: static Node *transform_int_divide_to_long_multiply( PhaseGVN *phase, Node *dividend, int divisor ) { duke@435: duke@435: // Check for invalid divisors duke@435: assert( divisor != 0 && divisor != min_jint && divisor != 1, duke@435: "bad divisor for transforming to long multiply" ); duke@435: duke@435: // Compute l = ceiling(log2(d)) duke@435: // presumes d is more likely small duke@435: bool d_pos = divisor >= 0; duke@435: int d = d_pos ? divisor : -divisor; duke@435: unsigned ud = (unsigned)d; duke@435: const int N = 32; duke@435: int l = log2_intptr(d-1)+1; duke@435: int sh_post = l; duke@435: duke@435: const uint64_t U1 = (uint64_t)1; duke@435: duke@435: // Cliff pointed out how to prevent overflow (from the paper) duke@435: uint64_t m_low = (((U1 << l) - ud) << N) / ud + (U1 << N); duke@435: uint64_t m_high = ((((U1 << l) - ud) << N) + (U1 << (l+1))) / ud + (U1 << N); duke@435: duke@435: // Reduce to lowest terms duke@435: for ( ; sh_post > 0; sh_post-- ) { duke@435: uint64_t m_low_1 = m_low >> 1; duke@435: uint64_t m_high_1 = m_high >> 1; duke@435: if ( m_low_1 >= m_high_1 ) duke@435: break; duke@435: m_low = m_low_1; duke@435: m_high = m_high_1; duke@435: } duke@435: duke@435: // Result duke@435: Node *q; duke@435: duke@435: // division by +/- 1 duke@435: if (d == 1) { duke@435: // Filtered out as identity above duke@435: if (d_pos) duke@435: return NULL; duke@435: duke@435: // Just negate the value duke@435: else { duke@435: q = new (phase->C, 3) SubINode(phase->intcon(0), dividend); duke@435: } duke@435: } duke@435: duke@435: // division by +/- a power of 2 duke@435: else if ( is_power_of_2(d) ) { duke@435: duke@435: // See if we can simply do a shift without rounding duke@435: bool needs_rounding = true; duke@435: const Type *dt = phase->type(dividend); duke@435: const TypeInt *dti = dt->isa_int(); duke@435: duke@435: // we don't need to round a positive dividend duke@435: if (dti && dti->_lo >= 0) duke@435: needs_rounding = false; duke@435: duke@435: // An AND mask of sufficient size clears the low bits and duke@435: // I can avoid rounding. duke@435: else if( dividend->Opcode() == Op_AndI ) { duke@435: const TypeInt *andconi = phase->type( dividend->in(2) )->isa_int(); duke@435: if( andconi && andconi->is_con(-d) ) { duke@435: dividend = dividend->in(1); duke@435: needs_rounding = false; duke@435: } duke@435: } duke@435: duke@435: // Add rounding to the shift to handle the sign bit duke@435: if( needs_rounding ) { duke@435: Node *t1 = phase->transform(new (phase->C, 3) RShiftINode(dividend, phase->intcon(l - 1))); duke@435: Node *t2 = phase->transform(new (phase->C, 3) URShiftINode(t1, phase->intcon(N - l))); duke@435: dividend = phase->transform(new (phase->C, 3) AddINode(dividend, t2)); duke@435: } duke@435: duke@435: q = new (phase->C, 3) RShiftINode(dividend, phase->intcon(l)); duke@435: duke@435: if (!d_pos) duke@435: q = new (phase->C, 3) SubINode(phase->intcon(0), phase->transform(q)); duke@435: } duke@435: duke@435: // division by something else duke@435: else if (m_high < (U1 << (N-1))) { duke@435: Node *t1 = phase->transform(new (phase->C, 2) ConvI2LNode(dividend)); duke@435: Node *t2 = phase->transform(new (phase->C, 3) MulLNode(t1, phase->longcon(m_high))); duke@435: Node *t3 = phase->transform(new (phase->C, 3) RShiftLNode(t2, phase->intcon(sh_post+N))); duke@435: Node *t4 = phase->transform(new (phase->C, 2) ConvL2INode(t3)); duke@435: Node *t5 = phase->transform(new (phase->C, 3) RShiftINode(dividend, phase->intcon(N-1))); duke@435: duke@435: q = new (phase->C, 3) SubINode(d_pos ? t4 : t5, d_pos ? t5 : t4); duke@435: } duke@435: duke@435: // This handles that case where m_high is >= 2**(N-1). In that case, duke@435: // we subtract out 2**N from the multiply and add it in later as duke@435: // "dividend" in the equation (t5). This case computes the same result duke@435: // as the immediately preceeding case, save that rounding and overflow duke@435: // are accounted for. duke@435: else { duke@435: Node *t1 = phase->transform(new (phase->C, 2) ConvI2LNode(dividend)); duke@435: Node *t2 = phase->transform(new (phase->C, 3) MulLNode(t1, phase->longcon(m_high - (U1 << N)))); duke@435: Node *t3 = phase->transform(new (phase->C, 3) RShiftLNode(t2, phase->intcon(N))); duke@435: Node *t4 = phase->transform(new (phase->C, 2) ConvL2INode(t3)); duke@435: Node *t5 = phase->transform(new (phase->C, 3) AddINode(dividend, t4)); duke@435: Node *t6 = phase->transform(new (phase->C, 3) RShiftINode(t5, phase->intcon(sh_post))); duke@435: Node *t7 = phase->transform(new (phase->C, 3) RShiftINode(dividend, phase->intcon(N-1))); duke@435: duke@435: q = new (phase->C, 3) SubINode(d_pos ? t6 : t7, d_pos ? t7 : t6); duke@435: } duke@435: duke@435: return (q); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Identity--------------------------------------- duke@435: // If the divisor is 1, we are an identity on the dividend. duke@435: Node *DivINode::Identity( PhaseTransform *phase ) { duke@435: return (phase->type( in(2) )->higher_equal(TypeInt::ONE)) ? in(1) : this; duke@435: } duke@435: duke@435: //------------------------------Idealize--------------------------------------- duke@435: // Divides can be changed to multiplies and/or shifts duke@435: Node *DivINode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if (in(0) && remove_dead_region(phase, can_reshape)) return this; duke@435: duke@435: const Type *t = phase->type( in(2) ); duke@435: if( t == TypeInt::ONE ) // Identity? duke@435: return NULL; // Skip it duke@435: duke@435: const TypeInt *ti = t->isa_int(); duke@435: if( !ti ) return NULL; duke@435: if( !ti->is_con() ) return NULL; duke@435: int i = ti->get_con(); // Get divisor duke@435: duke@435: if (i == 0) return NULL; // Dividing by zero constant does not idealize duke@435: duke@435: set_req(0,NULL); // Dividing by a not-zero constant; no faulting duke@435: duke@435: // Dividing by MININT does not optimize as a power-of-2 shift. duke@435: if( i == min_jint ) return NULL; duke@435: duke@435: return transform_int_divide_to_long_multiply( phase, in(1), i ); duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: // A DivINode divides its inputs. The third input is a Control input, used to duke@435: // prevent hoisting the divide above an unsafe test. duke@435: const Type *DivINode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // x/x == 1 since we always generate the dynamic divisor check for 0. duke@435: if( phase->eqv( in(1), in(2) ) ) duke@435: return TypeInt::ONE; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: // Divide the two numbers. We approximate. duke@435: // If divisor is a constant and not zero duke@435: const TypeInt *i1 = t1->is_int(); duke@435: const TypeInt *i2 = t2->is_int(); duke@435: int widen = MAX2(i1->_widen, i2->_widen); duke@435: duke@435: if( i2->is_con() && i2->get_con() != 0 ) { duke@435: int32 d = i2->get_con(); // Divisor duke@435: jint lo, hi; duke@435: if( d >= 0 ) { duke@435: lo = i1->_lo/d; duke@435: hi = i1->_hi/d; duke@435: } else { duke@435: if( d == -1 && i1->_lo == min_jint ) { duke@435: // 'min_jint/-1' throws arithmetic exception during compilation duke@435: lo = min_jint; duke@435: // do not support holes, 'hi' must go to either min_jint or max_jint: duke@435: // [min_jint, -10]/[-1,-1] ==> [min_jint] UNION [10,max_jint] duke@435: hi = i1->_hi == min_jint ? min_jint : max_jint; duke@435: } else { duke@435: lo = i1->_hi/d; duke@435: hi = i1->_lo/d; duke@435: } duke@435: } duke@435: return TypeInt::make(lo, hi, widen); duke@435: } duke@435: duke@435: // If the dividend is a constant duke@435: if( i1->is_con() ) { duke@435: int32 d = i1->get_con(); duke@435: if( d < 0 ) { duke@435: if( d == min_jint ) { duke@435: // (-min_jint) == min_jint == (min_jint / -1) duke@435: return TypeInt::make(min_jint, max_jint/2 + 1, widen); duke@435: } else { duke@435: return TypeInt::make(d, -d, widen); duke@435: } duke@435: } duke@435: return TypeInt::make(-d, d, widen); duke@435: } duke@435: duke@435: // Otherwise we give up all hope duke@435: return TypeInt::INT; duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Identity--------------------------------------- duke@435: // If the divisor is 1, we are an identity on the dividend. duke@435: Node *DivLNode::Identity( PhaseTransform *phase ) { duke@435: return (phase->type( in(2) )->higher_equal(TypeLong::ONE)) ? in(1) : this; duke@435: } duke@435: duke@435: //------------------------------Idealize--------------------------------------- duke@435: // Dividing by a power of 2 is a shift. duke@435: Node *DivLNode::Ideal( PhaseGVN *phase, bool can_reshape) { duke@435: if (in(0) && remove_dead_region(phase, can_reshape)) return this; duke@435: duke@435: const Type *t = phase->type( in(2) ); duke@435: if( t == TypeLong::ONE ) // Identity? duke@435: return NULL; // Skip it duke@435: duke@435: const TypeLong *ti = t->isa_long(); duke@435: if( !ti ) return NULL; duke@435: if( !ti->is_con() ) return NULL; duke@435: jlong i = ti->get_con(); // Get divisor duke@435: if( i ) set_req(0, NULL); // Dividing by a not-zero constant; no faulting duke@435: duke@435: // Dividing by MININT does not optimize as a power-of-2 shift. duke@435: if( i == min_jlong ) return NULL; duke@435: duke@435: // Check for negative power of 2 divisor, if so, negate it and set a flag duke@435: // to indicate result needs to be negated. Note that negating the dividend duke@435: // here does not work when it has the value MININT duke@435: Node *dividend = in(1); duke@435: bool negate_res = false; duke@435: if (is_power_of_2_long(-i)) { duke@435: i = -i; // Flip divisor duke@435: negate_res = true; duke@435: } duke@435: duke@435: // Check for power of 2 duke@435: if (!is_power_of_2_long(i)) // Is divisor a power of 2? duke@435: return NULL; // Not a power of 2 duke@435: duke@435: // Compute number of bits to shift duke@435: int log_i = log2_long(i); duke@435: duke@435: // See if we can simply do a shift without rounding duke@435: bool needs_rounding = true; duke@435: const Type *dt = phase->type(dividend); duke@435: const TypeLong *dtl = dt->isa_long(); duke@435: duke@435: if (dtl && dtl->_lo > 0) { duke@435: // we don't need to round a positive dividend duke@435: needs_rounding = false; duke@435: } else if( dividend->Opcode() == Op_AndL ) { duke@435: // An AND mask of sufficient size clears the low bits and duke@435: // I can avoid rounding. duke@435: const TypeLong *andconi = phase->type( dividend->in(2) )->isa_long(); duke@435: if( andconi && duke@435: andconi->is_con() && duke@435: andconi->get_con() == -i ) { duke@435: dividend = dividend->in(1); duke@435: needs_rounding = false; duke@435: } duke@435: } duke@435: duke@435: if (!needs_rounding) { duke@435: Node *result = new (phase->C, 3) RShiftLNode(dividend, phase->intcon(log_i)); duke@435: if (negate_res) { duke@435: result = phase->transform(result); duke@435: result = new (phase->C, 3) SubLNode(phase->longcon(0), result); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: // Divide-by-power-of-2 can be made into a shift, but you have to do duke@435: // more math for the rounding. You need to add 0 for positive duke@435: // numbers, and "i-1" for negative numbers. Example: i=4, so the duke@435: // shift is by 2. You need to add 3 to negative dividends and 0 to duke@435: // positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1, duke@435: // (-2+3)>>2 becomes 0, etc. duke@435: duke@435: // Compute 0 or -1, based on sign bit duke@435: Node *sign = phase->transform(new (phase->C, 3) RShiftLNode(dividend,phase->intcon(63))); duke@435: // Mask sign bit to the low sign bits duke@435: Node *round = phase->transform(new (phase->C, 3) AndLNode(sign,phase->longcon(i-1))); duke@435: // Round up before shifting duke@435: Node *sum = phase->transform(new (phase->C, 3) AddLNode(dividend,round)); duke@435: // Shift for division duke@435: Node *result = new (phase->C, 3) RShiftLNode(sum, phase->intcon(log_i)); duke@435: if (negate_res) { duke@435: result = phase->transform(result); duke@435: result = new (phase->C, 3) SubLNode(phase->longcon(0), result); duke@435: } duke@435: duke@435: return result; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: // A DivLNode divides its inputs. The third input is a Control input, used to duke@435: // prevent hoisting the divide above an unsafe test. duke@435: const Type *DivLNode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // x/x == 1 since we always generate the dynamic divisor check for 0. duke@435: if( phase->eqv( in(1), in(2) ) ) duke@435: return TypeLong::ONE; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: // Divide the two numbers. We approximate. duke@435: // If divisor is a constant and not zero duke@435: const TypeLong *i1 = t1->is_long(); duke@435: const TypeLong *i2 = t2->is_long(); duke@435: int widen = MAX2(i1->_widen, i2->_widen); duke@435: duke@435: if( i2->is_con() && i2->get_con() != 0 ) { duke@435: jlong d = i2->get_con(); // Divisor duke@435: jlong lo, hi; duke@435: if( d >= 0 ) { duke@435: lo = i1->_lo/d; duke@435: hi = i1->_hi/d; duke@435: } else { duke@435: if( d == CONST64(-1) && i1->_lo == min_jlong ) { duke@435: // 'min_jlong/-1' throws arithmetic exception during compilation duke@435: lo = min_jlong; duke@435: // do not support holes, 'hi' must go to either min_jlong or max_jlong: duke@435: // [min_jlong, -10]/[-1,-1] ==> [min_jlong] UNION [10,max_jlong] duke@435: hi = i1->_hi == min_jlong ? min_jlong : max_jlong; duke@435: } else { duke@435: lo = i1->_hi/d; duke@435: hi = i1->_lo/d; duke@435: } duke@435: } duke@435: return TypeLong::make(lo, hi, widen); duke@435: } duke@435: duke@435: // If the dividend is a constant duke@435: if( i1->is_con() ) { duke@435: jlong d = i1->get_con(); duke@435: if( d < 0 ) { duke@435: if( d == min_jlong ) { duke@435: // (-min_jlong) == min_jlong == (min_jlong / -1) duke@435: return TypeLong::make(min_jlong, max_jlong/2 + 1, widen); duke@435: } else { duke@435: return TypeLong::make(d, -d, widen); duke@435: } duke@435: } duke@435: return TypeLong::make(-d, d, widen); duke@435: } duke@435: duke@435: // Otherwise we give up all hope duke@435: return TypeLong::LONG; duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: // An DivFNode divides its inputs. The third input is a Control input, used to duke@435: // prevent hoisting the divide above an unsafe test. duke@435: const Type *DivFNode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: // x/x == 1, we ignore 0/0. duke@435: // Note: if t1 and t2 are zero then result is NaN (JVMS page 213) duke@435: // does not work for variables because of NaN's duke@435: if( phase->eqv( in(1), in(2) ) && t1->base() == Type::FloatCon) duke@435: if (!g_isnan(t1->getf()) && g_isfinite(t1->getf()) && t1->getf() != 0.0) // could be negative ZERO or NaN duke@435: return TypeF::ONE; duke@435: duke@435: if( t2 == TypeF::ONE ) duke@435: return t1; duke@435: duke@435: // If divisor is a constant and not zero, divide them numbers duke@435: if( t1->base() == Type::FloatCon && duke@435: t2->base() == Type::FloatCon && duke@435: t2->getf() != 0.0 ) // could be negative zero duke@435: return TypeF::make( t1->getf()/t2->getf() ); duke@435: duke@435: // If the dividend is a constant zero duke@435: // Note: if t1 and t2 are zero then result is NaN (JVMS page 213) duke@435: // Test TypeF::ZERO is not sufficient as it could be negative zero duke@435: duke@435: if( t1 == TypeF::ZERO && !g_isnan(t2->getf()) && t2->getf() != 0.0 ) duke@435: return TypeF::ZERO; duke@435: duke@435: // Otherwise we give up all hope duke@435: return Type::FLOAT; duke@435: } duke@435: duke@435: //------------------------------isA_Copy--------------------------------------- duke@435: // Dividing by self is 1. duke@435: // If the divisor is 1, we are an identity on the dividend. duke@435: Node *DivFNode::Identity( PhaseTransform *phase ) { duke@435: return (phase->type( in(2) ) == TypeF::ONE) ? in(1) : this; duke@435: } duke@435: duke@435: duke@435: //------------------------------Idealize--------------------------------------- duke@435: Node *DivFNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if (in(0) && remove_dead_region(phase, can_reshape)) return this; duke@435: duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t2 == TypeF::ONE ) // Identity? duke@435: return NULL; // Skip it duke@435: duke@435: const TypeF *tf = t2->isa_float_constant(); duke@435: if( !tf ) return NULL; duke@435: if( tf->base() != Type::FloatCon ) return NULL; duke@435: duke@435: // Check for out of range values duke@435: if( tf->is_nan() || !tf->is_finite() ) return NULL; duke@435: duke@435: // Get the value duke@435: float f = tf->getf(); duke@435: int exp; duke@435: duke@435: // Only for special case of dividing by a power of 2 duke@435: if( frexp((double)f, &exp) != 0.5 ) return NULL; duke@435: duke@435: // Limit the range of acceptable exponents duke@435: if( exp < -126 || exp > 126 ) return NULL; duke@435: duke@435: // Compute the reciprocal duke@435: float reciprocal = ((float)1.0) / f; duke@435: duke@435: assert( frexp((double)reciprocal, &exp) == 0.5, "reciprocal should be power of 2" ); duke@435: duke@435: // return multiplication by the reciprocal duke@435: return (new (phase->C, 3) MulFNode(in(1), phase->makecon(TypeF::make(reciprocal)))); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: // An DivDNode divides its inputs. The third input is a Control input, used to duke@435: // prvent hoisting the divide above an unsafe test. duke@435: const Type *DivDNode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: // x/x == 1, we ignore 0/0. duke@435: // Note: if t1 and t2 are zero then result is NaN (JVMS page 213) duke@435: // Does not work for variables because of NaN's duke@435: if( phase->eqv( in(1), in(2) ) && t1->base() == Type::DoubleCon) duke@435: if (!g_isnan(t1->getd()) && g_isfinite(t1->getd()) && t1->getd() != 0.0) // could be negative ZERO or NaN duke@435: return TypeD::ONE; duke@435: duke@435: if( t2 == TypeD::ONE ) duke@435: return t1; duke@435: duke@435: // If divisor is a constant and not zero, divide them numbers duke@435: if( t1->base() == Type::DoubleCon && duke@435: t2->base() == Type::DoubleCon && duke@435: t2->getd() != 0.0 ) // could be negative zero duke@435: return TypeD::make( t1->getd()/t2->getd() ); duke@435: duke@435: // If the dividend is a constant zero duke@435: // Note: if t1 and t2 are zero then result is NaN (JVMS page 213) duke@435: // Test TypeF::ZERO is not sufficient as it could be negative zero duke@435: if( t1 == TypeD::ZERO && !g_isnan(t2->getd()) && t2->getd() != 0.0 ) duke@435: return TypeD::ZERO; duke@435: duke@435: // Otherwise we give up all hope duke@435: return Type::DOUBLE; duke@435: } duke@435: duke@435: duke@435: //------------------------------isA_Copy--------------------------------------- duke@435: // Dividing by self is 1. duke@435: // If the divisor is 1, we are an identity on the dividend. duke@435: Node *DivDNode::Identity( PhaseTransform *phase ) { duke@435: return (phase->type( in(2) ) == TypeD::ONE) ? in(1) : this; duke@435: } duke@435: duke@435: //------------------------------Idealize--------------------------------------- duke@435: Node *DivDNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: if (in(0) && remove_dead_region(phase, can_reshape)) return this; duke@435: duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t2 == TypeD::ONE ) // Identity? duke@435: return NULL; // Skip it duke@435: duke@435: const TypeD *td = t2->isa_double_constant(); duke@435: if( !td ) return NULL; duke@435: if( td->base() != Type::DoubleCon ) return NULL; duke@435: duke@435: // Check for out of range values duke@435: if( td->is_nan() || !td->is_finite() ) return NULL; duke@435: duke@435: // Get the value duke@435: double d = td->getd(); duke@435: int exp; duke@435: duke@435: // Only for special case of dividing by a power of 2 duke@435: if( frexp(d, &exp) != 0.5 ) return NULL; duke@435: duke@435: // Limit the range of acceptable exponents duke@435: if( exp < -1021 || exp > 1022 ) return NULL; duke@435: duke@435: // Compute the reciprocal duke@435: double reciprocal = 1.0 / d; duke@435: duke@435: assert( frexp(reciprocal, &exp) == 0.5, "reciprocal should be power of 2" ); duke@435: duke@435: // return multiplication by the reciprocal duke@435: return (new (phase->C, 3) MulDNode(in(1), phase->makecon(TypeD::make(reciprocal)))); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------Idealize--------------------------------------- duke@435: Node *ModINode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: // Check for dead control input duke@435: if( remove_dead_region(phase, can_reshape) ) return this; duke@435: duke@435: // Get the modulus duke@435: const Type *t = phase->type( in(2) ); duke@435: if( t == Type::TOP ) return NULL; duke@435: const TypeInt *ti = t->is_int(); duke@435: duke@435: // Check for useless control input duke@435: // Check for excluding mod-zero case duke@435: if( in(0) && (ti->_hi < 0 || ti->_lo > 0) ) { duke@435: set_req(0, NULL); // Yank control input duke@435: return this; duke@435: } duke@435: duke@435: // See if we are MOD'ing by 2^k or 2^k-1. duke@435: if( !ti->is_con() ) return NULL; duke@435: jint con = ti->get_con(); duke@435: duke@435: Node *hook = new (phase->C, 1) Node(1); duke@435: duke@435: // First, special check for modulo 2^k-1 duke@435: if( con >= 0 && con < max_jint && is_power_of_2(con+1) ) { duke@435: uint k = exact_log2(con+1); // Extract k duke@435: duke@435: // Basic algorithm by David Detlefs. See fastmod_int.java for gory details. duke@435: static 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*/}; duke@435: int trip_count = 1; duke@435: if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k]; duke@435: duke@435: // If the unroll factor is not too large, and if conditional moves are duke@435: // ok, then use this case duke@435: if( trip_count <= 5 && ConditionalMoveLimit != 0 ) { duke@435: Node *x = in(1); // Value being mod'd duke@435: Node *divisor = in(2); // Also is mask duke@435: duke@435: hook->init_req(0, x); // Add a use to x to prevent him from dying duke@435: // Generate code to reduce X rapidly to nearly 2^k-1. duke@435: for( int i = 0; i < trip_count; i++ ) { duke@435: Node *xl = phase->transform( new (phase->C, 3) AndINode(x,divisor) ); duke@435: Node *xh = phase->transform( new (phase->C, 3) RShiftINode(x,phase->intcon(k)) ); // Must be signed duke@435: x = phase->transform( new (phase->C, 3) AddINode(xh,xl) ); duke@435: hook->set_req(0, x); duke@435: } duke@435: duke@435: // Generate sign-fixup code. Was original value positive? duke@435: // int hack_res = (i >= 0) ? divisor : 1; duke@435: Node *cmp1 = phase->transform( new (phase->C, 3) CmpINode( in(1), phase->intcon(0) ) ); duke@435: Node *bol1 = phase->transform( new (phase->C, 2) BoolNode( cmp1, BoolTest::ge ) ); duke@435: Node *cmov1= phase->transform( new (phase->C, 4) CMoveINode(bol1, phase->intcon(1), divisor, TypeInt::POS) ); duke@435: // if( x >= hack_res ) x -= divisor; duke@435: Node *sub = phase->transform( new (phase->C, 3) SubINode( x, divisor ) ); duke@435: Node *cmp2 = phase->transform( new (phase->C, 3) CmpINode( x, cmov1 ) ); duke@435: Node *bol2 = phase->transform( new (phase->C, 2) BoolNode( cmp2, BoolTest::ge ) ); duke@435: // Convention is to not transform the return value of an Ideal duke@435: // since Ideal is expected to return a modified 'this' or a new node. duke@435: Node *cmov2= new (phase->C, 4) CMoveINode(bol2, x, sub, TypeInt::INT); duke@435: // cmov2 is now the mod duke@435: duke@435: // Now remove the bogus extra edges used to keep things alive duke@435: if (can_reshape) { duke@435: phase->is_IterGVN()->remove_dead_node(hook); duke@435: } else { duke@435: hook->set_req(0, NULL); // Just yank bogus edge during Parse phase duke@435: } duke@435: return cmov2; duke@435: } duke@435: } duke@435: duke@435: // Fell thru, the unroll case is not appropriate. Transform the modulo duke@435: // into a long multiply/int multiply/subtract case duke@435: duke@435: // Cannot handle mod 0, and min_jint isn't handled by the transform duke@435: if( con == 0 || con == min_jint ) return NULL; duke@435: duke@435: // Get the absolute value of the constant; at this point, we can use this duke@435: jint pos_con = (con >= 0) ? con : -con; duke@435: duke@435: // integer Mod 1 is always 0 duke@435: if( pos_con == 1 ) return new (phase->C, 1) ConINode(TypeInt::ZERO); duke@435: duke@435: int log2_con = -1; duke@435: duke@435: // If this is a power of two, they maybe we can mask it duke@435: if( is_power_of_2(pos_con) ) { duke@435: log2_con = log2_intptr((intptr_t)pos_con); duke@435: duke@435: const Type *dt = phase->type(in(1)); duke@435: const TypeInt *dti = dt->isa_int(); duke@435: duke@435: // See if this can be masked, if the dividend is non-negative duke@435: if( dti && dti->_lo >= 0 ) duke@435: return ( new (phase->C, 3) AndINode( in(1), phase->intcon( pos_con-1 ) ) ); duke@435: } duke@435: duke@435: // Save in(1) so that it cannot be changed or deleted duke@435: hook->init_req(0, in(1)); duke@435: duke@435: // Divide using the transform from DivI to MulL duke@435: Node *divide = phase->transform( transform_int_divide_to_long_multiply( phase, in(1), pos_con ) ); duke@435: duke@435: // Re-multiply, using a shift if this is a power of two duke@435: Node *mult = NULL; duke@435: duke@435: if( log2_con >= 0 ) duke@435: mult = phase->transform( new (phase->C, 3) LShiftINode( divide, phase->intcon( log2_con ) ) ); duke@435: else duke@435: mult = phase->transform( new (phase->C, 3) MulINode( divide, phase->intcon( pos_con ) ) ); duke@435: duke@435: // Finally, subtract the multiplied divided value from the original duke@435: Node *result = new (phase->C, 3) SubINode( in(1), mult ); duke@435: duke@435: // Now remove the bogus extra edges used to keep things alive duke@435: if (can_reshape) { duke@435: phase->is_IterGVN()->remove_dead_node(hook); duke@435: } else { duke@435: hook->set_req(0, NULL); // Just yank bogus edge during Parse phase duke@435: } duke@435: duke@435: // return the value duke@435: return result; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ModINode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // We always generate the dynamic check for 0. duke@435: // 0 MOD X is 0 duke@435: if( t1 == TypeInt::ZERO ) return TypeInt::ZERO; duke@435: // X MOD X is 0 duke@435: if( phase->eqv( in(1), in(2) ) ) return TypeInt::ZERO; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: const TypeInt *i1 = t1->is_int(); duke@435: const TypeInt *i2 = t2->is_int(); duke@435: if( !i1->is_con() || !i2->is_con() ) { duke@435: if( i1->_lo >= 0 && i2->_lo >= 0 ) duke@435: return TypeInt::POS; duke@435: // If both numbers are not constants, we know little. duke@435: return TypeInt::INT; duke@435: } duke@435: // Mod by zero? Throw exception at runtime! duke@435: if( !i2->get_con() ) return TypeInt::POS; duke@435: duke@435: // We must be modulo'ing 2 float constants. duke@435: // Check for min_jint % '-1', result is defined to be '0'. duke@435: if( i1->get_con() == min_jint && i2->get_con() == -1 ) duke@435: return TypeInt::ZERO; duke@435: duke@435: return TypeInt::make( i1->get_con() % i2->get_con() ); duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Idealize--------------------------------------- duke@435: Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: // Check for dead control input duke@435: if( remove_dead_region(phase, can_reshape) ) return this; duke@435: duke@435: // Get the modulus duke@435: const Type *t = phase->type( in(2) ); duke@435: if( t == Type::TOP ) return NULL; duke@435: const TypeLong *ti = t->is_long(); duke@435: duke@435: // Check for useless control input duke@435: // Check for excluding mod-zero case duke@435: if( in(0) && (ti->_hi < 0 || ti->_lo > 0) ) { duke@435: set_req(0, NULL); // Yank control input duke@435: return this; duke@435: } duke@435: duke@435: // See if we are MOD'ing by 2^k or 2^k-1. duke@435: if( !ti->is_con() ) return NULL; duke@435: jlong con = ti->get_con(); duke@435: bool m1 = false; duke@435: if( !is_power_of_2_long(con) ) { // Not 2^k duke@435: if( !is_power_of_2_long(con+1) ) // Not 2^k-1? duke@435: return NULL; // No interesting mod hacks duke@435: m1 = true; // Found 2^k-1 duke@435: con++; // Convert to 2^k form duke@435: } duke@435: uint k = log2_long(con); // Extract k duke@435: duke@435: // Expand mod duke@435: if( !m1 ) { // Case 2^k duke@435: } else { // Case 2^k-1 duke@435: // Basic algorithm by David Detlefs. See fastmod_long.java for gory details. duke@435: // Used to help a popular random number generator which does a long-mod duke@435: // of 2^31-1 and shows up in SpecJBB and SciMark. duke@435: static 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*/}; duke@435: int trip_count = 1; duke@435: if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k]; duke@435: if( trip_count > 4 ) return NULL; // Too much unrolling duke@435: if (ConditionalMoveLimit == 0) return NULL; // cmov is required duke@435: duke@435: Node *x = in(1); // Value being mod'd duke@435: Node *divisor = in(2); // Also is mask duke@435: duke@435: Node *hook = new (phase->C, 1) Node(x); duke@435: // Generate code to reduce X rapidly to nearly 2^k-1. duke@435: for( int i = 0; i < trip_count; i++ ) { duke@435: Node *xl = phase->transform( new (phase->C, 3) AndLNode(x,divisor) ); duke@435: Node *xh = phase->transform( new (phase->C, 3) RShiftLNode(x,phase->intcon(k)) ); // Must be signed duke@435: x = phase->transform( new (phase->C, 3) AddLNode(xh,xl) ); duke@435: hook->set_req(0, x); // Add a use to x to prevent him from dying duke@435: } duke@435: // Generate sign-fixup code. Was original value positive? duke@435: // long hack_res = (i >= 0) ? divisor : CONST64(1); duke@435: Node *cmp1 = phase->transform( new (phase->C, 3) CmpLNode( in(1), phase->longcon(0) ) ); duke@435: Node *bol1 = phase->transform( new (phase->C, 2) BoolNode( cmp1, BoolTest::ge ) ); duke@435: Node *cmov1= phase->transform( new (phase->C, 4) CMoveLNode(bol1, phase->longcon(1), divisor, TypeLong::LONG) ); duke@435: // if( x >= hack_res ) x -= divisor; duke@435: Node *sub = phase->transform( new (phase->C, 3) SubLNode( x, divisor ) ); duke@435: Node *cmp2 = phase->transform( new (phase->C, 3) CmpLNode( x, cmov1 ) ); duke@435: Node *bol2 = phase->transform( new (phase->C, 2) BoolNode( cmp2, BoolTest::ge ) ); duke@435: // Convention is to not transform the return value of an Ideal duke@435: // since Ideal is expected to return a modified 'this' or a new node. duke@435: Node *cmov2= new (phase->C, 4) CMoveLNode(bol2, x, sub, TypeLong::LONG); duke@435: // cmov2 is now the mod duke@435: duke@435: // Now remove the bogus extra edges used to keep things alive duke@435: if (can_reshape) { duke@435: phase->is_IterGVN()->remove_dead_node(hook); duke@435: } else { duke@435: hook->set_req(0, NULL); // Just yank bogus edge during Parse phase duke@435: } duke@435: return cmov2; duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ModLNode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // We always generate the dynamic check for 0. duke@435: // 0 MOD X is 0 duke@435: if( t1 == TypeLong::ZERO ) return TypeLong::ZERO; duke@435: // X MOD X is 0 duke@435: if( phase->eqv( in(1), in(2) ) ) return TypeLong::ZERO; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: const TypeLong *i1 = t1->is_long(); duke@435: const TypeLong *i2 = t2->is_long(); duke@435: if( !i1->is_con() || !i2->is_con() ) { duke@435: if( i1->_lo >= CONST64(0) && i2->_lo >= CONST64(0) ) duke@435: return TypeLong::POS; duke@435: // If both numbers are not constants, we know little. duke@435: return TypeLong::LONG; duke@435: } duke@435: // Mod by zero? Throw exception at runtime! duke@435: if( !i2->get_con() ) return TypeLong::POS; duke@435: duke@435: // We must be modulo'ing 2 float constants. duke@435: // Check for min_jint % '-1', result is defined to be '0'. duke@435: if( i1->get_con() == min_jlong && i2->get_con() == -1 ) duke@435: return TypeLong::ZERO; duke@435: duke@435: return TypeLong::make( i1->get_con() % i2->get_con() ); duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ModFNode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: // If either is a NaN, return an input NaN duke@435: if( g_isnan(t1->getf()) ) return t1; duke@435: if( g_isnan(t2->getf()) ) return t2; duke@435: duke@435: // It is not worth trying to constant fold this stuff! duke@435: return Type::FLOAT; duke@435: duke@435: /* duke@435: // If dividend is infinity or divisor is zero, or both, the result is NaN duke@435: if( !g_isfinite(t1->getf()) || ((t2->getf() == 0.0) || (jint_cast(t2->getf()) == 0x80000000)) ) duke@435: duke@435: // X MOD infinity = X duke@435: if( !g_isfinite(t2->getf()) && !g_isnan(t2->getf()) ) return t1; duke@435: // 0 MOD finite = dividend (positive or negative zero) duke@435: // Not valid for: NaN MOD any; any MOD nan; 0 MOD 0; or for 0 MOD NaN duke@435: // NaNs are handled previously. duke@435: if( !(t2->getf() == 0.0) && !((int)t2->getf() == 0x80000000)) { duke@435: if (((t1->getf() == 0.0) || ((int)t1->getf() == 0x80000000)) && g_isfinite(t2->getf()) ) { duke@435: return t1; duke@435: } duke@435: } duke@435: // X MOD X is 0 duke@435: // Does not work for variables because of NaN's duke@435: if( phase->eqv( in(1), in(2) ) && t1->base() == Type::FloatCon) duke@435: if (!g_isnan(t1->getf()) && (t1->getf() != 0.0) && ((int)t1->getf() != 0x80000000)) { duke@435: if(t1->getf() < 0.0) { duke@435: float result = jfloat_cast(0x80000000); duke@435: return TypeF::make( result ); duke@435: } duke@435: else duke@435: return TypeF::ZERO; duke@435: } duke@435: duke@435: // If both numbers are not constants, we know nothing. duke@435: if( (t1->base() != Type::FloatCon) || (t2->base() != Type::FloatCon) ) duke@435: return Type::FLOAT; duke@435: duke@435: // We must be modulo'ing 2 float constants. duke@435: // Make sure that the sign of the fmod is equal to the sign of the dividend duke@435: float result = (float)fmod( t1->getf(), t2->getf() ); duke@435: float dividend = t1->getf(); duke@435: if( (dividend < 0.0) || ((int)dividend == 0x80000000) ) { duke@435: if( result > 0.0 ) duke@435: result = 0.0 - result; duke@435: else if( result == 0.0 ) { duke@435: result = jfloat_cast(0x80000000); duke@435: } duke@435: } duke@435: return TypeF::make( result ); duke@435: */ duke@435: } duke@435: duke@435: duke@435: //============================================================================= duke@435: //------------------------------Value------------------------------------------ duke@435: const Type *ModDNode::Value( PhaseTransform *phase ) const { duke@435: // Either input is TOP ==> the result is TOP duke@435: const Type *t1 = phase->type( in(1) ); duke@435: const Type *t2 = phase->type( in(2) ); duke@435: if( t1 == Type::TOP ) return Type::TOP; duke@435: if( t2 == Type::TOP ) return Type::TOP; duke@435: duke@435: // Either input is BOTTOM ==> the result is the local BOTTOM duke@435: const Type *bot = bottom_type(); duke@435: if( (t1 == bot) || (t2 == bot) || duke@435: (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) duke@435: return bot; duke@435: duke@435: // If either is a NaN, return an input NaN duke@435: if( g_isnan(t1->getd()) ) return t1; duke@435: if( g_isnan(t2->getd()) ) return t2; duke@435: // X MOD infinity = X duke@435: if( !g_isfinite(t2->getd())) return t1; duke@435: // 0 MOD finite = dividend (positive or negative zero) duke@435: // Not valid for: NaN MOD any; any MOD nan; 0 MOD 0; or for 0 MOD NaN duke@435: // NaNs are handled previously. duke@435: if( !(t2->getd() == 0.0) ) { duke@435: if( t1->getd() == 0.0 && g_isfinite(t2->getd()) ) { duke@435: return t1; duke@435: } duke@435: } duke@435: duke@435: // X MOD X is 0 duke@435: // does not work for variables because of NaN's duke@435: if( phase->eqv( in(1), in(2) ) && t1->base() == Type::DoubleCon ) duke@435: if (!g_isnan(t1->getd()) && t1->getd() != 0.0) duke@435: return TypeD::ZERO; duke@435: duke@435: duke@435: // If both numbers are not constants, we know nothing. duke@435: if( (t1->base() != Type::DoubleCon) || (t2->base() != Type::DoubleCon) ) duke@435: return Type::DOUBLE; duke@435: duke@435: // We must be modulo'ing 2 double constants. duke@435: return TypeD::make( fmod( t1->getd(), t2->getd() ) ); duke@435: } duke@435: duke@435: //============================================================================= duke@435: duke@435: DivModNode::DivModNode( Node *c, Node *dividend, Node *divisor ) : MultiNode(3) { duke@435: init_req(0, c); duke@435: init_req(1, dividend); duke@435: init_req(2, divisor); duke@435: } duke@435: duke@435: //------------------------------make------------------------------------------ duke@435: DivModINode* DivModINode::make(Compile* C, Node* div_or_mod) { duke@435: Node* n = div_or_mod; duke@435: assert(n->Opcode() == Op_DivI || n->Opcode() == Op_ModI, duke@435: "only div or mod input pattern accepted"); duke@435: duke@435: DivModINode* divmod = new (C, 3) DivModINode(n->in(0), n->in(1), n->in(2)); duke@435: Node* dproj = new (C, 1) ProjNode(divmod, DivModNode::div_proj_num); duke@435: Node* mproj = new (C, 1) ProjNode(divmod, DivModNode::mod_proj_num); duke@435: return divmod; duke@435: } duke@435: duke@435: //------------------------------make------------------------------------------ duke@435: DivModLNode* DivModLNode::make(Compile* C, Node* div_or_mod) { duke@435: Node* n = div_or_mod; duke@435: assert(n->Opcode() == Op_DivL || n->Opcode() == Op_ModL, duke@435: "only div or mod input pattern accepted"); duke@435: duke@435: DivModLNode* divmod = new (C, 3) DivModLNode(n->in(0), n->in(1), n->in(2)); duke@435: Node* dproj = new (C, 1) ProjNode(divmod, DivModNode::div_proj_num); duke@435: Node* mproj = new (C, 1) ProjNode(divmod, DivModNode::mod_proj_num); duke@435: return divmod; duke@435: } duke@435: duke@435: //------------------------------match------------------------------------------ duke@435: // return result(s) along with their RegMask info duke@435: Node *DivModINode::match( const ProjNode *proj, const Matcher *match ) { duke@435: uint ideal_reg = proj->ideal_reg(); duke@435: RegMask rm; duke@435: if (proj->_con == div_proj_num) { duke@435: rm = match->divI_proj_mask(); duke@435: } else { duke@435: assert(proj->_con == mod_proj_num, "must be div or mod projection"); duke@435: rm = match->modI_proj_mask(); duke@435: } duke@435: return new (match->C, 1)MachProjNode(this, proj->_con, rm, ideal_reg); duke@435: } duke@435: duke@435: duke@435: //------------------------------match------------------------------------------ duke@435: // return result(s) along with their RegMask info duke@435: Node *DivModLNode::match( const ProjNode *proj, const Matcher *match ) { duke@435: uint ideal_reg = proj->ideal_reg(); duke@435: RegMask rm; duke@435: if (proj->_con == div_proj_num) { duke@435: rm = match->divL_proj_mask(); duke@435: } else { duke@435: assert(proj->_con == mod_proj_num, "must be div or mod projection"); duke@435: rm = match->modL_proj_mask(); duke@435: } duke@435: return new (match->C, 1)MachProjNode(this, proj->_con, rm, ideal_reg); duke@435: }