Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/divnode.cpp
32285 views
/*1* Copyright (c) 1997, 2012, 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/divnode.hpp"29#include "opto/machnode.hpp"30#include "opto/matcher.hpp"31#include "opto/mulnode.hpp"32#include "opto/phaseX.hpp"33#include "opto/subnode.hpp"3435// Portions of code courtesy of Clifford Click3637// Optimization - Graph Style3839#include <math.h>4041//----------------------magic_int_divide_constants-----------------------------42// Compute magic multiplier and shift constant for converting a 32 bit divide43// by constant into a multiply/shift/add series. Return false if calculations44// fail.45//46// Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with47// minor type name and parameter changes.48static bool magic_int_divide_constants(jint d, jint &M, jint &s) {49int32_t p;50uint32_t ad, anc, delta, q1, r1, q2, r2, t;51const uint32_t two31 = 0x80000000L; // 2**31.5253ad = ABS(d);54if (d == 0 || d == 1) return false;55t = two31 + ((uint32_t)d >> 31);56anc = t - 1 - t%ad; // Absolute value of nc.57p = 31; // Init. p.58q1 = two31/anc; // Init. q1 = 2**p/|nc|.59r1 = two31 - q1*anc; // Init. r1 = rem(2**p, |nc|).60q2 = two31/ad; // Init. q2 = 2**p/|d|.61r2 = two31 - q2*ad; // Init. r2 = rem(2**p, |d|).62do {63p = p + 1;64q1 = 2*q1; // Update q1 = 2**p/|nc|.65r1 = 2*r1; // Update r1 = rem(2**p, |nc|).66if (r1 >= anc) { // (Must be an unsigned67q1 = q1 + 1; // comparison here).68r1 = r1 - anc;69}70q2 = 2*q2; // Update q2 = 2**p/|d|.71r2 = 2*r2; // Update r2 = rem(2**p, |d|).72if (r2 >= ad) { // (Must be an unsigned73q2 = q2 + 1; // comparison here).74r2 = r2 - ad;75}76delta = ad - r2;77} while (q1 < delta || (q1 == delta && r1 == 0));7879M = q2 + 1;80if (d < 0) M = -M; // Magic number and81s = p - 32; // shift amount to return.8283return true;84}8586//--------------------------transform_int_divide-------------------------------87// Convert a division by constant divisor into an alternate Ideal graph.88// Return NULL if no transformation occurs.89static Node *transform_int_divide( PhaseGVN *phase, Node *dividend, jint divisor ) {9091// Check for invalid divisors92assert( divisor != 0 && divisor != min_jint,93"bad divisor for transforming to long multiply" );9495bool d_pos = divisor >= 0;96jint d = d_pos ? divisor : -divisor;97const int N = 32;9899// Result100Node *q = NULL;101102if (d == 1) {103// division by +/- 1104if (!d_pos) {105// Just negate the value106q = new (phase->C) SubINode(phase->intcon(0), dividend);107}108} else if ( is_power_of_2(d) ) {109// division by +/- a power of 2110111// See if we can simply do a shift without rounding112bool needs_rounding = true;113const Type *dt = phase->type(dividend);114const TypeInt *dti = dt->isa_int();115if (dti && dti->_lo >= 0) {116// we don't need to round a positive dividend117needs_rounding = false;118} else if( dividend->Opcode() == Op_AndI ) {119// An AND mask of sufficient size clears the low bits and120// I can avoid rounding.121const TypeInt *andconi_t = phase->type( dividend->in(2) )->isa_int();122if( andconi_t && andconi_t->is_con() ) {123jint andconi = andconi_t->get_con();124if( andconi < 0 && is_power_of_2(-andconi) && (-andconi) >= d ) {125if( (-andconi) == d ) // Remove AND if it clears bits which will be shifted126dividend = dividend->in(1);127needs_rounding = false;128}129}130}131132// Add rounding to the shift to handle the sign bit133int l = log2_jint(d-1)+1;134if (needs_rounding) {135// Divide-by-power-of-2 can be made into a shift, but you have to do136// more math for the rounding. You need to add 0 for positive137// numbers, and "i-1" for negative numbers. Example: i=4, so the138// shift is by 2. You need to add 3 to negative dividends and 0 to139// positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,140// (-2+3)>>2 becomes 0, etc.141142// Compute 0 or -1, based on sign bit143Node *sign = phase->transform(new (phase->C) RShiftINode(dividend, phase->intcon(N - 1)));144// Mask sign bit to the low sign bits145Node *round = phase->transform(new (phase->C) URShiftINode(sign, phase->intcon(N - l)));146// Round up before shifting147dividend = phase->transform(new (phase->C) AddINode(dividend, round));148}149150// Shift for division151q = new (phase->C) RShiftINode(dividend, phase->intcon(l));152153if (!d_pos) {154q = new (phase->C) SubINode(phase->intcon(0), phase->transform(q));155}156} else {157// Attempt the jint constant divide -> multiply transform found in158// "Division by Invariant Integers using Multiplication"159// by Granlund and Montgomery160// See also "Hacker's Delight", chapter 10 by Warren.161162jint magic_const;163jint shift_const;164if (magic_int_divide_constants(d, magic_const, shift_const)) {165Node *magic = phase->longcon(magic_const);166Node *dividend_long = phase->transform(new (phase->C) ConvI2LNode(dividend));167168// Compute the high half of the dividend x magic multiplication169Node *mul_hi = phase->transform(new (phase->C) MulLNode(dividend_long, magic));170171if (magic_const < 0) {172mul_hi = phase->transform(new (phase->C) RShiftLNode(mul_hi, phase->intcon(N)));173mul_hi = phase->transform(new (phase->C) ConvL2INode(mul_hi));174175// The magic multiplier is too large for a 32 bit constant. We've adjusted176// it down by 2^32, but have to add 1 dividend back in after the multiplication.177// This handles the "overflow" case described by Granlund and Montgomery.178mul_hi = phase->transform(new (phase->C) AddINode(dividend, mul_hi));179180// Shift over the (adjusted) mulhi181if (shift_const != 0) {182mul_hi = phase->transform(new (phase->C) RShiftINode(mul_hi, phase->intcon(shift_const)));183}184} else {185// No add is required, we can merge the shifts together.186mul_hi = phase->transform(new (phase->C) RShiftLNode(mul_hi, phase->intcon(N + shift_const)));187mul_hi = phase->transform(new (phase->C) ConvL2INode(mul_hi));188}189190// Get a 0 or -1 from the sign of the dividend.191Node *addend0 = mul_hi;192Node *addend1 = phase->transform(new (phase->C) RShiftINode(dividend, phase->intcon(N-1)));193194// If the divisor is negative, swap the order of the input addends;195// this has the effect of negating the quotient.196if (!d_pos) {197Node *temp = addend0; addend0 = addend1; addend1 = temp;198}199200// Adjust the final quotient by subtracting -1 (adding 1)201// from the mul_hi.202q = new (phase->C) SubINode(addend0, addend1);203}204}205206return q;207}208209//---------------------magic_long_divide_constants-----------------------------210// Compute magic multiplier and shift constant for converting a 64 bit divide211// by constant into a multiply/shift/add series. Return false if calculations212// fail.213//214// Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with215// minor type name and parameter changes. Adjusted to 64 bit word width.216static bool magic_long_divide_constants(jlong d, jlong &M, jint &s) {217int64_t p;218uint64_t ad, anc, delta, q1, r1, q2, r2, t;219const uint64_t two63 = 0x8000000000000000LL; // 2**63.220221ad = ABS(d);222if (d == 0 || d == 1) return false;223t = two63 + ((uint64_t)d >> 63);224anc = t - 1 - t%ad; // Absolute value of nc.225p = 63; // Init. p.226q1 = two63/anc; // Init. q1 = 2**p/|nc|.227r1 = two63 - q1*anc; // Init. r1 = rem(2**p, |nc|).228q2 = two63/ad; // Init. q2 = 2**p/|d|.229r2 = two63 - q2*ad; // Init. r2 = rem(2**p, |d|).230do {231p = p + 1;232q1 = 2*q1; // Update q1 = 2**p/|nc|.233r1 = 2*r1; // Update r1 = rem(2**p, |nc|).234if (r1 >= anc) { // (Must be an unsigned235q1 = q1 + 1; // comparison here).236r1 = r1 - anc;237}238q2 = 2*q2; // Update q2 = 2**p/|d|.239r2 = 2*r2; // Update r2 = rem(2**p, |d|).240if (r2 >= ad) { // (Must be an unsigned241q2 = q2 + 1; // comparison here).242r2 = r2 - ad;243}244delta = ad - r2;245} while (q1 < delta || (q1 == delta && r1 == 0));246247M = q2 + 1;248if (d < 0) M = -M; // Magic number and249s = p - 64; // shift amount to return.250251return true;252}253254//---------------------long_by_long_mulhi--------------------------------------255// Generate ideal node graph for upper half of a 64 bit x 64 bit multiplication256static Node* long_by_long_mulhi(PhaseGVN* phase, Node* dividend, jlong magic_const) {257// If the architecture supports a 64x64 mulhi, there is258// no need to synthesize it in ideal nodes.259if (Matcher::has_match_rule(Op_MulHiL)) {260Node* v = phase->longcon(magic_const);261return new (phase->C) MulHiLNode(dividend, v);262}263264// Taken from Hacker's Delight, Fig. 8-2. Multiply high signed.265// (http://www.hackersdelight.org/HDcode/mulhs.c)266//267// int mulhs(int u, int v) {268// unsigned u0, v0, w0;269// int u1, v1, w1, w2, t;270//271// u0 = u & 0xFFFF; u1 = u >> 16;272// v0 = v & 0xFFFF; v1 = v >> 16;273// w0 = u0*v0;274// t = u1*v0 + (w0 >> 16);275// w1 = t & 0xFFFF;276// w2 = t >> 16;277// w1 = u0*v1 + w1;278// return u1*v1 + w2 + (w1 >> 16);279// }280//281// Note: The version above is for 32x32 multiplications, while the282// following inline comments are adapted to 64x64.283284const int N = 64;285286// Dummy node to keep intermediate nodes alive during construction287Node* hook = new (phase->C) Node(4);288289// u0 = u & 0xFFFFFFFF; u1 = u >> 32;290Node* u0 = phase->transform(new (phase->C) AndLNode(dividend, phase->longcon(0xFFFFFFFF)));291Node* u1 = phase->transform(new (phase->C) RShiftLNode(dividend, phase->intcon(N / 2)));292hook->init_req(0, u0);293hook->init_req(1, u1);294295// v0 = v & 0xFFFFFFFF; v1 = v >> 32;296Node* v0 = phase->longcon(magic_const & 0xFFFFFFFF);297Node* v1 = phase->longcon(magic_const >> (N / 2));298299// w0 = u0*v0;300Node* w0 = phase->transform(new (phase->C) MulLNode(u0, v0));301302// t = u1*v0 + (w0 >> 32);303Node* u1v0 = phase->transform(new (phase->C) MulLNode(u1, v0));304Node* temp = phase->transform(new (phase->C) URShiftLNode(w0, phase->intcon(N / 2)));305Node* t = phase->transform(new (phase->C) AddLNode(u1v0, temp));306hook->init_req(2, t);307308// w1 = t & 0xFFFFFFFF;309Node* w1 = phase->transform(new (phase->C) AndLNode(t, phase->longcon(0xFFFFFFFF)));310hook->init_req(3, w1);311312// w2 = t >> 32;313Node* w2 = phase->transform(new (phase->C) RShiftLNode(t, phase->intcon(N / 2)));314315// w1 = u0*v1 + w1;316Node* u0v1 = phase->transform(new (phase->C) MulLNode(u0, v1));317w1 = phase->transform(new (phase->C) AddLNode(u0v1, w1));318319// return u1*v1 + w2 + (w1 >> 32);320Node* u1v1 = phase->transform(new (phase->C) MulLNode(u1, v1));321Node* temp1 = phase->transform(new (phase->C) AddLNode(u1v1, w2));322Node* temp2 = phase->transform(new (phase->C) RShiftLNode(w1, phase->intcon(N / 2)));323324// Remove the bogus extra edges used to keep things alive325PhaseIterGVN* igvn = phase->is_IterGVN();326if (igvn != NULL) {327igvn->remove_dead_node(hook);328} else {329for (int i = 0; i < 4; i++) {330hook->set_req(i, NULL);331}332}333334return new (phase->C) AddLNode(temp1, temp2);335}336337338//--------------------------transform_long_divide------------------------------339// Convert a division by constant divisor into an alternate Ideal graph.340// Return NULL if no transformation occurs.341static Node *transform_long_divide( PhaseGVN *phase, Node *dividend, jlong divisor ) {342// Check for invalid divisors343assert( divisor != 0L && divisor != min_jlong,344"bad divisor for transforming to long multiply" );345346bool d_pos = divisor >= 0;347jlong d = d_pos ? divisor : -divisor;348const int N = 64;349350// Result351Node *q = NULL;352353if (d == 1) {354// division by +/- 1355if (!d_pos) {356// Just negate the value357q = new (phase->C) SubLNode(phase->longcon(0), dividend);358}359} else if ( is_power_of_2_long(d) ) {360361// division by +/- a power of 2362363// See if we can simply do a shift without rounding364bool needs_rounding = true;365const Type *dt = phase->type(dividend);366const TypeLong *dtl = dt->isa_long();367368if (dtl && dtl->_lo > 0) {369// we don't need to round a positive dividend370needs_rounding = false;371} else if( dividend->Opcode() == Op_AndL ) {372// An AND mask of sufficient size clears the low bits and373// I can avoid rounding.374const TypeLong *andconl_t = phase->type( dividend->in(2) )->isa_long();375if( andconl_t && andconl_t->is_con() ) {376jlong andconl = andconl_t->get_con();377if( andconl < 0 && is_power_of_2_long(-andconl) && (-andconl) >= d ) {378if( (-andconl) == d ) // Remove AND if it clears bits which will be shifted379dividend = dividend->in(1);380needs_rounding = false;381}382}383}384385// Add rounding to the shift to handle the sign bit386int l = log2_long(d-1)+1;387if (needs_rounding) {388// Divide-by-power-of-2 can be made into a shift, but you have to do389// more math for the rounding. You need to add 0 for positive390// numbers, and "i-1" for negative numbers. Example: i=4, so the391// shift is by 2. You need to add 3 to negative dividends and 0 to392// positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,393// (-2+3)>>2 becomes 0, etc.394395// Compute 0 or -1, based on sign bit396Node *sign = phase->transform(new (phase->C) RShiftLNode(dividend, phase->intcon(N - 1)));397// Mask sign bit to the low sign bits398Node *round = phase->transform(new (phase->C) URShiftLNode(sign, phase->intcon(N - l)));399// Round up before shifting400dividend = phase->transform(new (phase->C) AddLNode(dividend, round));401}402403// Shift for division404q = new (phase->C) RShiftLNode(dividend, phase->intcon(l));405406if (!d_pos) {407q = new (phase->C) SubLNode(phase->longcon(0), phase->transform(q));408}409} else if ( !Matcher::use_asm_for_ldiv_by_con(d) ) { // Use hardware DIV instruction when410// it is faster than code generated below.411// Attempt the jlong constant divide -> multiply transform found in412// "Division by Invariant Integers using Multiplication"413// by Granlund and Montgomery414// See also "Hacker's Delight", chapter 10 by Warren.415416jlong magic_const;417jint shift_const;418if (magic_long_divide_constants(d, magic_const, shift_const)) {419// Compute the high half of the dividend x magic multiplication420Node *mul_hi = phase->transform(long_by_long_mulhi(phase, dividend, magic_const));421422// The high half of the 128-bit multiply is computed.423if (magic_const < 0) {424// The magic multiplier is too large for a 64 bit constant. We've adjusted425// it down by 2^64, but have to add 1 dividend back in after the multiplication.426// This handles the "overflow" case described by Granlund and Montgomery.427mul_hi = phase->transform(new (phase->C) AddLNode(dividend, mul_hi));428}429430// Shift over the (adjusted) mulhi431if (shift_const != 0) {432mul_hi = phase->transform(new (phase->C) RShiftLNode(mul_hi, phase->intcon(shift_const)));433}434435// Get a 0 or -1 from the sign of the dividend.436Node *addend0 = mul_hi;437Node *addend1 = phase->transform(new (phase->C) RShiftLNode(dividend, phase->intcon(N-1)));438439// If the divisor is negative, swap the order of the input addends;440// this has the effect of negating the quotient.441if (!d_pos) {442Node *temp = addend0; addend0 = addend1; addend1 = temp;443}444445// Adjust the final quotient by subtracting -1 (adding 1)446// from the mul_hi.447q = new (phase->C) SubLNode(addend0, addend1);448}449}450451return q;452}453454//=============================================================================455//------------------------------Identity---------------------------------------456// If the divisor is 1, we are an identity on the dividend.457Node *DivINode::Identity( PhaseTransform *phase ) {458return (phase->type( in(2) )->higher_equal(TypeInt::ONE)) ? in(1) : this;459}460461//------------------------------Idealize---------------------------------------462// Divides can be changed to multiplies and/or shifts463Node *DivINode::Ideal(PhaseGVN *phase, bool can_reshape) {464if (in(0) && remove_dead_region(phase, can_reshape)) return this;465// Don't bother trying to transform a dead node466if( in(0) && in(0)->is_top() ) return NULL;467468const Type *t = phase->type( in(2) );469if( t == TypeInt::ONE ) // Identity?470return NULL; // Skip it471472const TypeInt *ti = t->isa_int();473if( !ti ) return NULL;474if( !ti->is_con() ) return NULL;475jint i = ti->get_con(); // Get divisor476477if (i == 0) return NULL; // Dividing by zero constant does not idealize478479set_req(0,NULL); // Dividing by a not-zero constant; no faulting480481// Dividing by MININT does not optimize as a power-of-2 shift.482if( i == min_jint ) return NULL;483484return transform_int_divide( phase, in(1), i );485}486487//------------------------------Value------------------------------------------488// A DivINode divides its inputs. The third input is a Control input, used to489// prevent hoisting the divide above an unsafe test.490const Type *DivINode::Value( PhaseTransform *phase ) const {491// Either input is TOP ==> the result is TOP492const Type *t1 = phase->type( in(1) );493const Type *t2 = phase->type( in(2) );494if( t1 == Type::TOP ) return Type::TOP;495if( t2 == Type::TOP ) return Type::TOP;496497// x/x == 1 since we always generate the dynamic divisor check for 0.498if( phase->eqv( in(1), in(2) ) )499return TypeInt::ONE;500501// Either input is BOTTOM ==> the result is the local BOTTOM502const Type *bot = bottom_type();503if( (t1 == bot) || (t2 == bot) ||504(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )505return bot;506507// Divide the two numbers. We approximate.508// If divisor is a constant and not zero509const TypeInt *i1 = t1->is_int();510const TypeInt *i2 = t2->is_int();511int widen = MAX2(i1->_widen, i2->_widen);512513if( i2->is_con() && i2->get_con() != 0 ) {514int32 d = i2->get_con(); // Divisor515jint lo, hi;516if( d >= 0 ) {517lo = i1->_lo/d;518hi = i1->_hi/d;519} else {520if( d == -1 && i1->_lo == min_jint ) {521// 'min_jint/-1' throws arithmetic exception during compilation522lo = min_jint;523// do not support holes, 'hi' must go to either min_jint or max_jint:524// [min_jint, -10]/[-1,-1] ==> [min_jint] UNION [10,max_jint]525hi = i1->_hi == min_jint ? min_jint : max_jint;526} else {527lo = i1->_hi/d;528hi = i1->_lo/d;529}530}531return TypeInt::make(lo, hi, widen);532}533534// If the dividend is a constant535if( i1->is_con() ) {536int32 d = i1->get_con();537if( d < 0 ) {538if( d == min_jint ) {539// (-min_jint) == min_jint == (min_jint / -1)540return TypeInt::make(min_jint, max_jint/2 + 1, widen);541} else {542return TypeInt::make(d, -d, widen);543}544}545return TypeInt::make(-d, d, widen);546}547548// Otherwise we give up all hope549return TypeInt::INT;550}551552553//=============================================================================554//------------------------------Identity---------------------------------------555// If the divisor is 1, we are an identity on the dividend.556Node *DivLNode::Identity( PhaseTransform *phase ) {557return (phase->type( in(2) )->higher_equal(TypeLong::ONE)) ? in(1) : this;558}559560//------------------------------Idealize---------------------------------------561// Dividing by a power of 2 is a shift.562Node *DivLNode::Ideal( PhaseGVN *phase, bool can_reshape) {563if (in(0) && remove_dead_region(phase, can_reshape)) return this;564// Don't bother trying to transform a dead node565if( in(0) && in(0)->is_top() ) return NULL;566567const Type *t = phase->type( in(2) );568if( t == TypeLong::ONE ) // Identity?569return NULL; // Skip it570571const TypeLong *tl = t->isa_long();572if( !tl ) return NULL;573if( !tl->is_con() ) return NULL;574jlong l = tl->get_con(); // Get divisor575576if (l == 0) return NULL; // Dividing by zero constant does not idealize577578set_req(0,NULL); // Dividing by a not-zero constant; no faulting579580// Dividing by MINLONG does not optimize as a power-of-2 shift.581if( l == min_jlong ) return NULL;582583return transform_long_divide( phase, in(1), l );584}585586//------------------------------Value------------------------------------------587// A DivLNode divides its inputs. The third input is a Control input, used to588// prevent hoisting the divide above an unsafe test.589const Type *DivLNode::Value( PhaseTransform *phase ) const {590// Either input is TOP ==> the result is TOP591const Type *t1 = phase->type( in(1) );592const Type *t2 = phase->type( in(2) );593if( t1 == Type::TOP ) return Type::TOP;594if( t2 == Type::TOP ) return Type::TOP;595596// x/x == 1 since we always generate the dynamic divisor check for 0.597if( phase->eqv( in(1), in(2) ) )598return TypeLong::ONE;599600// Either input is BOTTOM ==> the result is the local BOTTOM601const Type *bot = bottom_type();602if( (t1 == bot) || (t2 == bot) ||603(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )604return bot;605606// Divide the two numbers. We approximate.607// If divisor is a constant and not zero608const TypeLong *i1 = t1->is_long();609const TypeLong *i2 = t2->is_long();610int widen = MAX2(i1->_widen, i2->_widen);611612if( i2->is_con() && i2->get_con() != 0 ) {613jlong d = i2->get_con(); // Divisor614jlong lo, hi;615if( d >= 0 ) {616lo = i1->_lo/d;617hi = i1->_hi/d;618} else {619if( d == CONST64(-1) && i1->_lo == min_jlong ) {620// 'min_jlong/-1' throws arithmetic exception during compilation621lo = min_jlong;622// do not support holes, 'hi' must go to either min_jlong or max_jlong:623// [min_jlong, -10]/[-1,-1] ==> [min_jlong] UNION [10,max_jlong]624hi = i1->_hi == min_jlong ? min_jlong : max_jlong;625} else {626lo = i1->_hi/d;627hi = i1->_lo/d;628}629}630return TypeLong::make(lo, hi, widen);631}632633// If the dividend is a constant634if( i1->is_con() ) {635jlong d = i1->get_con();636if( d < 0 ) {637if( d == min_jlong ) {638// (-min_jlong) == min_jlong == (min_jlong / -1)639return TypeLong::make(min_jlong, max_jlong/2 + 1, widen);640} else {641return TypeLong::make(d, -d, widen);642}643}644return TypeLong::make(-d, d, widen);645}646647// Otherwise we give up all hope648return TypeLong::LONG;649}650651652//=============================================================================653//------------------------------Value------------------------------------------654// An DivFNode divides its inputs. The third input is a Control input, used to655// prevent hoisting the divide above an unsafe test.656const Type *DivFNode::Value( PhaseTransform *phase ) const {657// Either input is TOP ==> the result is TOP658const Type *t1 = phase->type( in(1) );659const Type *t2 = phase->type( in(2) );660if( t1 == Type::TOP ) return Type::TOP;661if( t2 == Type::TOP ) return Type::TOP;662663// Either input is BOTTOM ==> the result is the local BOTTOM664const Type *bot = bottom_type();665if( (t1 == bot) || (t2 == bot) ||666(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )667return bot;668669// x/x == 1, we ignore 0/0.670// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)671// Does not work for variables because of NaN's672if( phase->eqv( in(1), in(2) ) && t1->base() == Type::FloatCon)673if (!g_isnan(t1->getf()) && g_isfinite(t1->getf()) && t1->getf() != 0.0) // could be negative ZERO or NaN674return TypeF::ONE;675676if( t2 == TypeF::ONE )677return t1;678679// If divisor is a constant and not zero, divide them numbers680if( t1->base() == Type::FloatCon &&681t2->base() == Type::FloatCon &&682t2->getf() != 0.0 ) // could be negative zero683return TypeF::make( t1->getf()/t2->getf() );684685// If the dividend is a constant zero686// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)687// Test TypeF::ZERO is not sufficient as it could be negative zero688689if( t1 == TypeF::ZERO && !g_isnan(t2->getf()) && t2->getf() != 0.0 )690return TypeF::ZERO;691692// Otherwise we give up all hope693return Type::FLOAT;694}695696//------------------------------isA_Copy---------------------------------------697// Dividing by self is 1.698// If the divisor is 1, we are an identity on the dividend.699Node *DivFNode::Identity( PhaseTransform *phase ) {700return (phase->type( in(2) ) == TypeF::ONE) ? in(1) : this;701}702703704//------------------------------Idealize---------------------------------------705Node *DivFNode::Ideal(PhaseGVN *phase, bool can_reshape) {706if (in(0) && remove_dead_region(phase, can_reshape)) return this;707// Don't bother trying to transform a dead node708if( in(0) && in(0)->is_top() ) return NULL;709710const Type *t2 = phase->type( in(2) );711if( t2 == TypeF::ONE ) // Identity?712return NULL; // Skip it713714const TypeF *tf = t2->isa_float_constant();715if( !tf ) return NULL;716if( tf->base() != Type::FloatCon ) return NULL;717718// Check for out of range values719if( tf->is_nan() || !tf->is_finite() ) return NULL;720721// Get the value722float f = tf->getf();723int exp;724725// Only for special case of dividing by a power of 2726if( frexp((double)f, &exp) != 0.5 ) return NULL;727728// Limit the range of acceptable exponents729if( exp < -126 || exp > 126 ) return NULL;730731// Compute the reciprocal732float reciprocal = ((float)1.0) / f;733734assert( frexp((double)reciprocal, &exp) == 0.5, "reciprocal should be power of 2" );735736// return multiplication by the reciprocal737return (new (phase->C) MulFNode(in(1), phase->makecon(TypeF::make(reciprocal))));738}739740//=============================================================================741//------------------------------Value------------------------------------------742// An DivDNode divides its inputs. The third input is a Control input, used to743// prevent hoisting the divide above an unsafe test.744const Type *DivDNode::Value( PhaseTransform *phase ) const {745// Either input is TOP ==> the result is TOP746const Type *t1 = phase->type( in(1) );747const Type *t2 = phase->type( in(2) );748if( t1 == Type::TOP ) return Type::TOP;749if( t2 == Type::TOP ) return Type::TOP;750751// Either input is BOTTOM ==> the result is the local BOTTOM752const Type *bot = bottom_type();753if( (t1 == bot) || (t2 == bot) ||754(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )755return bot;756757// x/x == 1, we ignore 0/0.758// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)759// Does not work for variables because of NaN's760if( phase->eqv( in(1), in(2) ) && t1->base() == Type::DoubleCon)761if (!g_isnan(t1->getd()) && g_isfinite(t1->getd()) && t1->getd() != 0.0) // could be negative ZERO or NaN762return TypeD::ONE;763764if( t2 == TypeD::ONE )765return t1;766767#if defined(IA32)768if (!phase->C->method()->is_strict())769// Can't trust native compilers to properly fold strict double770// division with round-to-zero on this platform.771#endif772{773// If divisor is a constant and not zero, divide them numbers774if( t1->base() == Type::DoubleCon &&775t2->base() == Type::DoubleCon &&776t2->getd() != 0.0 ) // could be negative zero777return TypeD::make( t1->getd()/t2->getd() );778}779780// If the dividend is a constant zero781// Note: if t1 and t2 are zero then result is NaN (JVMS page 213)782// Test TypeF::ZERO is not sufficient as it could be negative zero783if( t1 == TypeD::ZERO && !g_isnan(t2->getd()) && t2->getd() != 0.0 )784return TypeD::ZERO;785786// Otherwise we give up all hope787return Type::DOUBLE;788}789790791//------------------------------isA_Copy---------------------------------------792// Dividing by self is 1.793// If the divisor is 1, we are an identity on the dividend.794Node *DivDNode::Identity( PhaseTransform *phase ) {795return (phase->type( in(2) ) == TypeD::ONE) ? in(1) : this;796}797798//------------------------------Idealize---------------------------------------799Node *DivDNode::Ideal(PhaseGVN *phase, bool can_reshape) {800if (in(0) && remove_dead_region(phase, can_reshape)) return this;801// Don't bother trying to transform a dead node802if( in(0) && in(0)->is_top() ) return NULL;803804const Type *t2 = phase->type( in(2) );805if( t2 == TypeD::ONE ) // Identity?806return NULL; // Skip it807808const TypeD *td = t2->isa_double_constant();809if( !td ) return NULL;810if( td->base() != Type::DoubleCon ) return NULL;811812// Check for out of range values813if( td->is_nan() || !td->is_finite() ) return NULL;814815// Get the value816double d = td->getd();817int exp;818819// Only for special case of dividing by a power of 2820if( frexp(d, &exp) != 0.5 ) return NULL;821822// Limit the range of acceptable exponents823if( exp < -1021 || exp > 1022 ) return NULL;824825// Compute the reciprocal826double reciprocal = 1.0 / d;827828assert( frexp(reciprocal, &exp) == 0.5, "reciprocal should be power of 2" );829830// return multiplication by the reciprocal831return (new (phase->C) MulDNode(in(1), phase->makecon(TypeD::make(reciprocal))));832}833834//=============================================================================835//------------------------------Idealize---------------------------------------836Node *ModINode::Ideal(PhaseGVN *phase, bool can_reshape) {837// Check for dead control input838if( in(0) && remove_dead_region(phase, can_reshape) ) return this;839// Don't bother trying to transform a dead node840if( in(0) && in(0)->is_top() ) return NULL;841842// Get the modulus843const Type *t = phase->type( in(2) );844if( t == Type::TOP ) return NULL;845const TypeInt *ti = t->is_int();846847// Check for useless control input848// Check for excluding mod-zero case849if( in(0) && (ti->_hi < 0 || ti->_lo > 0) ) {850set_req(0, NULL); // Yank control input851return this;852}853854// See if we are MOD'ing by 2^k or 2^k-1.855if( !ti->is_con() ) return NULL;856jint con = ti->get_con();857858Node *hook = new (phase->C) Node(1);859860// First, special check for modulo 2^k-1861if( con >= 0 && con < max_jint && is_power_of_2(con+1) ) {862uint k = exact_log2(con+1); // Extract k863864// Basic algorithm by David Detlefs. See fastmod_int.java for gory details.865static 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*/};866int trip_count = 1;867if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k];868869// If the unroll factor is not too large, and if conditional moves are870// ok, then use this case871if( trip_count <= 5 && ConditionalMoveLimit != 0 ) {872Node *x = in(1); // Value being mod'd873Node *divisor = in(2); // Also is mask874875hook->init_req(0, x); // Add a use to x to prevent him from dying876// Generate code to reduce X rapidly to nearly 2^k-1.877for( int i = 0; i < trip_count; i++ ) {878Node *xl = phase->transform( new (phase->C) AndINode(x,divisor) );879Node *xh = phase->transform( new (phase->C) RShiftINode(x,phase->intcon(k)) ); // Must be signed880x = phase->transform( new (phase->C) AddINode(xh,xl) );881hook->set_req(0, x);882}883884// Generate sign-fixup code. Was original value positive?885// int hack_res = (i >= 0) ? divisor : 1;886Node *cmp1 = phase->transform( new (phase->C) CmpINode( in(1), phase->intcon(0) ) );887Node *bol1 = phase->transform( new (phase->C) BoolNode( cmp1, BoolTest::ge ) );888Node *cmov1= phase->transform( new (phase->C) CMoveINode(bol1, phase->intcon(1), divisor, TypeInt::POS) );889// if( x >= hack_res ) x -= divisor;890Node *sub = phase->transform( new (phase->C) SubINode( x, divisor ) );891Node *cmp2 = phase->transform( new (phase->C) CmpINode( x, cmov1 ) );892Node *bol2 = phase->transform( new (phase->C) BoolNode( cmp2, BoolTest::ge ) );893// Convention is to not transform the return value of an Ideal894// since Ideal is expected to return a modified 'this' or a new node.895Node *cmov2= new (phase->C) CMoveINode(bol2, x, sub, TypeInt::INT);896// cmov2 is now the mod897898// Now remove the bogus extra edges used to keep things alive899if (can_reshape) {900phase->is_IterGVN()->remove_dead_node(hook);901} else {902hook->set_req(0, NULL); // Just yank bogus edge during Parse phase903}904return cmov2;905}906}907908// Fell thru, the unroll case is not appropriate. Transform the modulo909// into a long multiply/int multiply/subtract case910911// Cannot handle mod 0, and min_jint isn't handled by the transform912if( con == 0 || con == min_jint ) return NULL;913914// Get the absolute value of the constant; at this point, we can use this915jint pos_con = (con >= 0) ? con : -con;916917// integer Mod 1 is always 0918if( pos_con == 1 ) return new (phase->C) ConINode(TypeInt::ZERO);919920int log2_con = -1;921922// If this is a power of two, they maybe we can mask it923if( is_power_of_2(pos_con) ) {924log2_con = log2_intptr((intptr_t)pos_con);925926const Type *dt = phase->type(in(1));927const TypeInt *dti = dt->isa_int();928929// See if this can be masked, if the dividend is non-negative930if( dti && dti->_lo >= 0 )931return ( new (phase->C) AndINode( in(1), phase->intcon( pos_con-1 ) ) );932}933934// Save in(1) so that it cannot be changed or deleted935hook->init_req(0, in(1));936937// Divide using the transform from DivI to MulL938Node *result = transform_int_divide( phase, in(1), pos_con );939if (result != NULL) {940Node *divide = phase->transform(result);941942// Re-multiply, using a shift if this is a power of two943Node *mult = NULL;944945if( log2_con >= 0 )946mult = phase->transform( new (phase->C) LShiftINode( divide, phase->intcon( log2_con ) ) );947else948mult = phase->transform( new (phase->C) MulINode( divide, phase->intcon( pos_con ) ) );949950// Finally, subtract the multiplied divided value from the original951result = new (phase->C) SubINode( in(1), mult );952}953954// Now remove the bogus extra edges used to keep things alive955if (can_reshape) {956phase->is_IterGVN()->remove_dead_node(hook);957} else {958hook->set_req(0, NULL); // Just yank bogus edge during Parse phase959}960961// return the value962return result;963}964965//------------------------------Value------------------------------------------966const Type *ModINode::Value( PhaseTransform *phase ) const {967// Either input is TOP ==> the result is TOP968const Type *t1 = phase->type( in(1) );969const Type *t2 = phase->type( in(2) );970if( t1 == Type::TOP ) return Type::TOP;971if( t2 == Type::TOP ) return Type::TOP;972973// We always generate the dynamic check for 0.974// 0 MOD X is 0975if( t1 == TypeInt::ZERO ) return TypeInt::ZERO;976// X MOD X is 0977if( phase->eqv( in(1), in(2) ) ) return TypeInt::ZERO;978979// Either input is BOTTOM ==> the result is the local BOTTOM980const Type *bot = bottom_type();981if( (t1 == bot) || (t2 == bot) ||982(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )983return bot;984985const TypeInt *i1 = t1->is_int();986const TypeInt *i2 = t2->is_int();987if( !i1->is_con() || !i2->is_con() ) {988if( i1->_lo >= 0 && i2->_lo >= 0 )989return TypeInt::POS;990// If both numbers are not constants, we know little.991return TypeInt::INT;992}993// Mod by zero? Throw exception at runtime!994if( !i2->get_con() ) return TypeInt::POS;995996// We must be modulo'ing 2 float constants.997// Check for min_jint % '-1', result is defined to be '0'.998if( i1->get_con() == min_jint && i2->get_con() == -1 )999return TypeInt::ZERO;10001001return TypeInt::make( i1->get_con() % i2->get_con() );1002}100310041005//=============================================================================1006//------------------------------Idealize---------------------------------------1007Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) {1008// Check for dead control input1009if( in(0) && remove_dead_region(phase, can_reshape) ) return this;1010// Don't bother trying to transform a dead node1011if( in(0) && in(0)->is_top() ) return NULL;10121013// Get the modulus1014const Type *t = phase->type( in(2) );1015if( t == Type::TOP ) return NULL;1016const TypeLong *tl = t->is_long();10171018// Check for useless control input1019// Check for excluding mod-zero case1020if( in(0) && (tl->_hi < 0 || tl->_lo > 0) ) {1021set_req(0, NULL); // Yank control input1022return this;1023}10241025// See if we are MOD'ing by 2^k or 2^k-1.1026if( !tl->is_con() ) return NULL;1027jlong con = tl->get_con();10281029Node *hook = new (phase->C) Node(1);10301031// Expand mod1032if( con >= 0 && con < max_jlong && is_power_of_2_long(con+1) ) {1033uint k = exact_log2_long(con+1); // Extract k10341035// Basic algorithm by David Detlefs. See fastmod_long.java for gory details.1036// Used to help a popular random number generator which does a long-mod1037// of 2^31-1 and shows up in SpecJBB and SciMark.1038static 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*/};1039int trip_count = 1;1040if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k];10411042// If the unroll factor is not too large, and if conditional moves are1043// ok, then use this case1044if( trip_count <= 5 && ConditionalMoveLimit != 0 ) {1045Node *x = in(1); // Value being mod'd1046Node *divisor = in(2); // Also is mask10471048hook->init_req(0, x); // Add a use to x to prevent him from dying1049// Generate code to reduce X rapidly to nearly 2^k-1.1050for( int i = 0; i < trip_count; i++ ) {1051Node *xl = phase->transform( new (phase->C) AndLNode(x,divisor) );1052Node *xh = phase->transform( new (phase->C) RShiftLNode(x,phase->intcon(k)) ); // Must be signed1053x = phase->transform( new (phase->C) AddLNode(xh,xl) );1054hook->set_req(0, x); // Add a use to x to prevent him from dying1055}10561057// Generate sign-fixup code. Was original value positive?1058// long hack_res = (i >= 0) ? divisor : CONST64(1);1059Node *cmp1 = phase->transform( new (phase->C) CmpLNode( in(1), phase->longcon(0) ) );1060Node *bol1 = phase->transform( new (phase->C) BoolNode( cmp1, BoolTest::ge ) );1061Node *cmov1= phase->transform( new (phase->C) CMoveLNode(bol1, phase->longcon(1), divisor, TypeLong::LONG) );1062// if( x >= hack_res ) x -= divisor;1063Node *sub = phase->transform( new (phase->C) SubLNode( x, divisor ) );1064Node *cmp2 = phase->transform( new (phase->C) CmpLNode( x, cmov1 ) );1065Node *bol2 = phase->transform( new (phase->C) BoolNode( cmp2, BoolTest::ge ) );1066// Convention is to not transform the return value of an Ideal1067// since Ideal is expected to return a modified 'this' or a new node.1068Node *cmov2= new (phase->C) CMoveLNode(bol2, x, sub, TypeLong::LONG);1069// cmov2 is now the mod10701071// Now remove the bogus extra edges used to keep things alive1072if (can_reshape) {1073phase->is_IterGVN()->remove_dead_node(hook);1074} else {1075hook->set_req(0, NULL); // Just yank bogus edge during Parse phase1076}1077return cmov2;1078}1079}10801081// Fell thru, the unroll case is not appropriate. Transform the modulo1082// into a long multiply/int multiply/subtract case10831084// Cannot handle mod 0, and min_jlong isn't handled by the transform1085if( con == 0 || con == min_jlong ) return NULL;10861087// Get the absolute value of the constant; at this point, we can use this1088jlong pos_con = (con >= 0) ? con : -con;10891090// integer Mod 1 is always 01091if( pos_con == 1 ) return new (phase->C) ConLNode(TypeLong::ZERO);10921093int log2_con = -1;10941095// If this is a power of two, then maybe we can mask it1096if( is_power_of_2_long(pos_con) ) {1097log2_con = exact_log2_long(pos_con);10981099const Type *dt = phase->type(in(1));1100const TypeLong *dtl = dt->isa_long();11011102// See if this can be masked, if the dividend is non-negative1103if( dtl && dtl->_lo >= 0 )1104return ( new (phase->C) AndLNode( in(1), phase->longcon( pos_con-1 ) ) );1105}11061107// Save in(1) so that it cannot be changed or deleted1108hook->init_req(0, in(1));11091110// Divide using the transform from DivL to MulL1111Node *result = transform_long_divide( phase, in(1), pos_con );1112if (result != NULL) {1113Node *divide = phase->transform(result);11141115// Re-multiply, using a shift if this is a power of two1116Node *mult = NULL;11171118if( log2_con >= 0 )1119mult = phase->transform( new (phase->C) LShiftLNode( divide, phase->intcon( log2_con ) ) );1120else1121mult = phase->transform( new (phase->C) MulLNode( divide, phase->longcon( pos_con ) ) );11221123// Finally, subtract the multiplied divided value from the original1124result = new (phase->C) SubLNode( in(1), mult );1125}11261127// Now remove the bogus extra edges used to keep things alive1128if (can_reshape) {1129phase->is_IterGVN()->remove_dead_node(hook);1130} else {1131hook->set_req(0, NULL); // Just yank bogus edge during Parse phase1132}11331134// return the value1135return result;1136}11371138//------------------------------Value------------------------------------------1139const Type *ModLNode::Value( PhaseTransform *phase ) const {1140// Either input is TOP ==> the result is TOP1141const Type *t1 = phase->type( in(1) );1142const Type *t2 = phase->type( in(2) );1143if( t1 == Type::TOP ) return Type::TOP;1144if( t2 == Type::TOP ) return Type::TOP;11451146// We always generate the dynamic check for 0.1147// 0 MOD X is 01148if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;1149// X MOD X is 01150if( phase->eqv( in(1), in(2) ) ) return TypeLong::ZERO;11511152// Either input is BOTTOM ==> the result is the local BOTTOM1153const Type *bot = bottom_type();1154if( (t1 == bot) || (t2 == bot) ||1155(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )1156return bot;11571158const TypeLong *i1 = t1->is_long();1159const TypeLong *i2 = t2->is_long();1160if( !i1->is_con() || !i2->is_con() ) {1161if( i1->_lo >= CONST64(0) && i2->_lo >= CONST64(0) )1162return TypeLong::POS;1163// If both numbers are not constants, we know little.1164return TypeLong::LONG;1165}1166// Mod by zero? Throw exception at runtime!1167if( !i2->get_con() ) return TypeLong::POS;11681169// We must be modulo'ing 2 float constants.1170// Check for min_jint % '-1', result is defined to be '0'.1171if( i1->get_con() == min_jlong && i2->get_con() == -1 )1172return TypeLong::ZERO;11731174return TypeLong::make( i1->get_con() % i2->get_con() );1175}117611771178//=============================================================================1179//------------------------------Value------------------------------------------1180const Type *ModFNode::Value( PhaseTransform *phase ) const {1181// Either input is TOP ==> the result is TOP1182const Type *t1 = phase->type( in(1) );1183const Type *t2 = phase->type( in(2) );1184if( t1 == Type::TOP ) return Type::TOP;1185if( t2 == Type::TOP ) return Type::TOP;11861187// Either input is BOTTOM ==> the result is the local BOTTOM1188const Type *bot = bottom_type();1189if( (t1 == bot) || (t2 == bot) ||1190(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )1191return bot;11921193// If either number is not a constant, we know nothing.1194if ((t1->base() != Type::FloatCon) || (t2->base() != Type::FloatCon)) {1195return Type::FLOAT; // note: x%x can be either NaN or 01196}11971198float f1 = t1->getf();1199float f2 = t2->getf();1200jint x1 = jint_cast(f1); // note: *(int*)&f1, not just (int)f11201jint x2 = jint_cast(f2);12021203// If either is a NaN, return an input NaN1204if (g_isnan(f1)) return t1;1205if (g_isnan(f2)) return t2;12061207// If an operand is infinity or the divisor is +/- zero, punt.1208if (!g_isfinite(f1) || !g_isfinite(f2) || x2 == 0 || x2 == min_jint)1209return Type::FLOAT;12101211// We must be modulo'ing 2 float constants.1212// Make sure that the sign of the fmod is equal to the sign of the dividend1213jint xr = jint_cast(fmod(f1, f2));1214if ((x1 ^ xr) < 0) {1215xr ^= min_jint;1216}12171218return TypeF::make(jfloat_cast(xr));1219}122012211222//=============================================================================1223//------------------------------Value------------------------------------------1224const Type *ModDNode::Value( PhaseTransform *phase ) const {1225// Either input is TOP ==> the result is TOP1226const Type *t1 = phase->type( in(1) );1227const Type *t2 = phase->type( in(2) );1228if( t1 == Type::TOP ) return Type::TOP;1229if( t2 == Type::TOP ) return Type::TOP;12301231// Either input is BOTTOM ==> the result is the local BOTTOM1232const Type *bot = bottom_type();1233if( (t1 == bot) || (t2 == bot) ||1234(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )1235return bot;12361237// If either number is not a constant, we know nothing.1238if ((t1->base() != Type::DoubleCon) || (t2->base() != Type::DoubleCon)) {1239return Type::DOUBLE; // note: x%x can be either NaN or 01240}12411242double f1 = t1->getd();1243double f2 = t2->getd();1244jlong x1 = jlong_cast(f1); // note: *(long*)&f1, not just (long)f11245jlong x2 = jlong_cast(f2);12461247// If either is a NaN, return an input NaN1248if (g_isnan(f1)) return t1;1249if (g_isnan(f2)) return t2;12501251// If an operand is infinity or the divisor is +/- zero, punt.1252if (!g_isfinite(f1) || !g_isfinite(f2) || x2 == 0 || x2 == min_jlong)1253return Type::DOUBLE;12541255// We must be modulo'ing 2 double constants.1256// Make sure that the sign of the fmod is equal to the sign of the dividend1257jlong xr = jlong_cast(fmod(f1, f2));1258if ((x1 ^ xr) < 0) {1259xr ^= min_jlong;1260}12611262return TypeD::make(jdouble_cast(xr));1263}12641265//=============================================================================12661267DivModNode::DivModNode( Node *c, Node *dividend, Node *divisor ) : MultiNode(3) {1268init_req(0, c);1269init_req(1, dividend);1270init_req(2, divisor);1271}12721273//------------------------------make------------------------------------------1274DivModINode* DivModINode::make(Compile* C, Node* div_or_mod) {1275Node* n = div_or_mod;1276assert(n->Opcode() == Op_DivI || n->Opcode() == Op_ModI,1277"only div or mod input pattern accepted");12781279DivModINode* divmod = new (C) DivModINode(n->in(0), n->in(1), n->in(2));1280Node* dproj = new (C) ProjNode(divmod, DivModNode::div_proj_num);1281Node* mproj = new (C) ProjNode(divmod, DivModNode::mod_proj_num);1282return divmod;1283}12841285//------------------------------make------------------------------------------1286DivModLNode* DivModLNode::make(Compile* C, Node* div_or_mod) {1287Node* n = div_or_mod;1288assert(n->Opcode() == Op_DivL || n->Opcode() == Op_ModL,1289"only div or mod input pattern accepted");12901291DivModLNode* divmod = new (C) DivModLNode(n->in(0), n->in(1), n->in(2));1292Node* dproj = new (C) ProjNode(divmod, DivModNode::div_proj_num);1293Node* mproj = new (C) ProjNode(divmod, DivModNode::mod_proj_num);1294return divmod;1295}12961297//------------------------------match------------------------------------------1298// return result(s) along with their RegMask info1299Node *DivModINode::match( const ProjNode *proj, const Matcher *match ) {1300uint ideal_reg = proj->ideal_reg();1301RegMask rm;1302if (proj->_con == div_proj_num) {1303rm = match->divI_proj_mask();1304} else {1305assert(proj->_con == mod_proj_num, "must be div or mod projection");1306rm = match->modI_proj_mask();1307}1308return new (match->C)MachProjNode(this, proj->_con, rm, ideal_reg);1309}131013111312//------------------------------match------------------------------------------1313// return result(s) along with their RegMask info1314Node *DivModLNode::match( const ProjNode *proj, const Matcher *match ) {1315uint ideal_reg = proj->ideal_reg();1316RegMask rm;1317if (proj->_con == div_proj_num) {1318rm = match->divL_proj_mask();1319} else {1320assert(proj->_con == mod_proj_num, "must be div or mod projection");1321rm = match->modL_proj_mask();1322}1323return new (match->C)MachProjNode(this, proj->_con, rm, ideal_reg);1324}132513261327