author | kvn |
Thu, 27 Sep 2012 09:38:42 -0700 | |
changeset 13895 | f6dfe4123709 |
parent 12956 | 1078d92535e8 |
child 13963 | e5b53c306fb5 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7115
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4583
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4583
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4583
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "memory/allocation.inline.hpp" |
|
27 |
#include "opto/addnode.hpp" |
|
28 |
#include "opto/connode.hpp" |
|
29 |
#include "opto/divnode.hpp" |
|
30 |
#include "opto/machnode.hpp" |
|
31 |
#include "opto/matcher.hpp" |
|
32 |
#include "opto/mulnode.hpp" |
|
33 |
#include "opto/phaseX.hpp" |
|
34 |
#include "opto/subnode.hpp" |
|
35 |
||
1 | 36 |
// Portions of code courtesy of Clifford Click |
37 |
||
38 |
// Optimization - Graph Style |
|
39 |
||
40 |
#include <math.h> |
|
41 |
||
392 | 42 |
//----------------------magic_int_divide_constants----------------------------- |
43 |
// Compute magic multiplier and shift constant for converting a 32 bit divide |
|
44 |
// by constant into a multiply/shift/add series. Return false if calculations |
|
45 |
// fail. |
|
46 |
// |
|
2131 | 47 |
// Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with |
392 | 48 |
// minor type name and parameter changes. |
49 |
static bool magic_int_divide_constants(jint d, jint &M, jint &s) { |
|
50 |
int32_t p; |
|
51 |
uint32_t ad, anc, delta, q1, r1, q2, r2, t; |
|
52 |
const uint32_t two31 = 0x80000000L; // 2**31. |
|
53 |
||
54 |
ad = ABS(d); |
|
55 |
if (d == 0 || d == 1) return false; |
|
56 |
t = two31 + ((uint32_t)d >> 31); |
|
57 |
anc = t - 1 - t%ad; // Absolute value of nc. |
|
58 |
p = 31; // Init. p. |
|
59 |
q1 = two31/anc; // Init. q1 = 2**p/|nc|. |
|
60 |
r1 = two31 - q1*anc; // Init. r1 = rem(2**p, |nc|). |
|
61 |
q2 = two31/ad; // Init. q2 = 2**p/|d|. |
|
62 |
r2 = two31 - q2*ad; // Init. r2 = rem(2**p, |d|). |
|
63 |
do { |
|
64 |
p = p + 1; |
|
65 |
q1 = 2*q1; // Update q1 = 2**p/|nc|. |
|
66 |
r1 = 2*r1; // Update r1 = rem(2**p, |nc|). |
|
67 |
if (r1 >= anc) { // (Must be an unsigned |
|
68 |
q1 = q1 + 1; // comparison here). |
|
69 |
r1 = r1 - anc; |
|
70 |
} |
|
71 |
q2 = 2*q2; // Update q2 = 2**p/|d|. |
|
72 |
r2 = 2*r2; // Update r2 = rem(2**p, |d|). |
|
73 |
if (r2 >= ad) { // (Must be an unsigned |
|
74 |
q2 = q2 + 1; // comparison here). |
|
75 |
r2 = r2 - ad; |
|
76 |
} |
|
77 |
delta = ad - r2; |
|
78 |
} while (q1 < delta || (q1 == delta && r1 == 0)); |
|
79 |
||
80 |
M = q2 + 1; |
|
81 |
if (d < 0) M = -M; // Magic number and |
|
82 |
s = p - 32; // shift amount to return. |
|
83 |
||
84 |
return true; |
|
85 |
} |
|
86 |
||
87 |
//--------------------------transform_int_divide------------------------------- |
|
88 |
// Convert a division by constant divisor into an alternate Ideal graph. |
|
89 |
// Return NULL if no transformation occurs. |
|
90 |
static Node *transform_int_divide( PhaseGVN *phase, Node *dividend, jint divisor ) { |
|
1 | 91 |
|
92 |
// Check for invalid divisors |
|
392 | 93 |
assert( divisor != 0 && divisor != min_jint, |
94 |
"bad divisor for transforming to long multiply" ); |
|
1 | 95 |
|
392 | 96 |
bool d_pos = divisor >= 0; |
97 |
jint d = d_pos ? divisor : -divisor; |
|
98 |
const int N = 32; |
|
1 | 99 |
|
100 |
// Result |
|
392 | 101 |
Node *q = NULL; |
1 | 102 |
|
103 |
if (d == 1) { |
|
392 | 104 |
// division by +/- 1 |
105 |
if (!d_pos) { |
|
106 |
// Just negate the value |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
107 |
q = new (phase->C) SubINode(phase->intcon(0), dividend); |
1 | 108 |
} |
392 | 109 |
} else if ( is_power_of_2(d) ) { |
110 |
// division by +/- a power of 2 |
|
1 | 111 |
|
112 |
// See if we can simply do a shift without rounding |
|
113 |
bool needs_rounding = true; |
|
114 |
const Type *dt = phase->type(dividend); |
|
115 |
const TypeInt *dti = dt->isa_int(); |
|
392 | 116 |
if (dti && dti->_lo >= 0) { |
117 |
// we don't need to round a positive dividend |
|
1 | 118 |
needs_rounding = false; |
392 | 119 |
} else if( dividend->Opcode() == Op_AndI ) { |
120 |
// An AND mask of sufficient size clears the low bits and |
|
121 |
// I can avoid rounding. |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
122 |
const TypeInt *andconi_t = phase->type( dividend->in(2) )->isa_int(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
123 |
if( andconi_t && andconi_t->is_con() ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
124 |
jint andconi = andconi_t->get_con(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
125 |
if( andconi < 0 && is_power_of_2(-andconi) && (-andconi) >= d ) { |
4583
b36d52bd2d19
6910484: incorrect integer optimization (loosing and op-r in a given example)
kvn
parents:
2746
diff
changeset
|
126 |
if( (-andconi) == d ) // Remove AND if it clears bits which will be shifted |
b36d52bd2d19
6910484: incorrect integer optimization (loosing and op-r in a given example)
kvn
parents:
2746
diff
changeset
|
127 |
dividend = dividend->in(1); |
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
128 |
needs_rounding = false; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
129 |
} |
1 | 130 |
} |
131 |
} |
|
132 |
||
133 |
// Add rounding to the shift to handle the sign bit |
|
392 | 134 |
int l = log2_intptr(d-1)+1; |
135 |
if (needs_rounding) { |
|
136 |
// Divide-by-power-of-2 can be made into a shift, but you have to do |
|
137 |
// more math for the rounding. You need to add 0 for positive |
|
138 |
// numbers, and "i-1" for negative numbers. Example: i=4, so the |
|
139 |
// shift is by 2. You need to add 3 to negative dividends and 0 to |
|
140 |
// positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1, |
|
141 |
// (-2+3)>>2 becomes 0, etc. |
|
142 |
||
143 |
// Compute 0 or -1, based on sign bit |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
144 |
Node *sign = phase->transform(new (phase->C) RShiftINode(dividend, phase->intcon(N - 1))); |
392 | 145 |
// Mask sign bit to the low sign bits |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
146 |
Node *round = phase->transform(new (phase->C) URShiftINode(sign, phase->intcon(N - l))); |
392 | 147 |
// Round up before shifting |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
148 |
dividend = phase->transform(new (phase->C) AddINode(dividend, round)); |
1 | 149 |
} |
150 |
||
392 | 151 |
// Shift for division |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
152 |
q = new (phase->C) RShiftINode(dividend, phase->intcon(l)); |
1 | 153 |
|
392 | 154 |
if (!d_pos) { |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
155 |
q = new (phase->C) SubINode(phase->intcon(0), phase->transform(q)); |
392 | 156 |
} |
157 |
} else { |
|
158 |
// Attempt the jint constant divide -> multiply transform found in |
|
159 |
// "Division by Invariant Integers using Multiplication" |
|
160 |
// by Granlund and Montgomery |
|
161 |
// See also "Hacker's Delight", chapter 10 by Warren. |
|
162 |
||
163 |
jint magic_const; |
|
164 |
jint shift_const; |
|
165 |
if (magic_int_divide_constants(d, magic_const, shift_const)) { |
|
166 |
Node *magic = phase->longcon(magic_const); |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
167 |
Node *dividend_long = phase->transform(new (phase->C) ConvI2LNode(dividend)); |
392 | 168 |
|
169 |
// Compute the high half of the dividend x magic multiplication |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
170 |
Node *mul_hi = phase->transform(new (phase->C) MulLNode(dividend_long, magic)); |
392 | 171 |
|
172 |
if (magic_const < 0) { |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
173 |
mul_hi = phase->transform(new (phase->C) RShiftLNode(mul_hi, phase->intcon(N))); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
174 |
mul_hi = phase->transform(new (phase->C) ConvL2INode(mul_hi)); |
392 | 175 |
|
176 |
// The magic multiplier is too large for a 32 bit constant. We've adjusted |
|
177 |
// it down by 2^32, but have to add 1 dividend back in after the multiplication. |
|
178 |
// This handles the "overflow" case described by Granlund and Montgomery. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
179 |
mul_hi = phase->transform(new (phase->C) AddINode(dividend, mul_hi)); |
392 | 180 |
|
181 |
// Shift over the (adjusted) mulhi |
|
182 |
if (shift_const != 0) { |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
183 |
mul_hi = phase->transform(new (phase->C) RShiftINode(mul_hi, phase->intcon(shift_const))); |
392 | 184 |
} |
185 |
} else { |
|
186 |
// No add is required, we can merge the shifts together. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
187 |
mul_hi = phase->transform(new (phase->C) RShiftLNode(mul_hi, phase->intcon(N + shift_const))); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
188 |
mul_hi = phase->transform(new (phase->C) ConvL2INode(mul_hi)); |
392 | 189 |
} |
190 |
||
191 |
// Get a 0 or -1 from the sign of the dividend. |
|
192 |
Node *addend0 = mul_hi; |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
193 |
Node *addend1 = phase->transform(new (phase->C) RShiftINode(dividend, phase->intcon(N-1))); |
392 | 194 |
|
195 |
// If the divisor is negative, swap the order of the input addends; |
|
196 |
// this has the effect of negating the quotient. |
|
197 |
if (!d_pos) { |
|
198 |
Node *temp = addend0; addend0 = addend1; addend1 = temp; |
|
199 |
} |
|
200 |
||
201 |
// Adjust the final quotient by subtracting -1 (adding 1) |
|
202 |
// from the mul_hi. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
203 |
q = new (phase->C) SubINode(addend0, addend1); |
392 | 204 |
} |
205 |
} |
|
206 |
||
207 |
return q; |
|
208 |
} |
|
209 |
||
210 |
//---------------------magic_long_divide_constants----------------------------- |
|
211 |
// Compute magic multiplier and shift constant for converting a 64 bit divide |
|
212 |
// by constant into a multiply/shift/add series. Return false if calculations |
|
213 |
// fail. |
|
214 |
// |
|
2131 | 215 |
// Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with |
392 | 216 |
// minor type name and parameter changes. Adjusted to 64 bit word width. |
217 |
static bool magic_long_divide_constants(jlong d, jlong &M, jint &s) { |
|
218 |
int64_t p; |
|
219 |
uint64_t ad, anc, delta, q1, r1, q2, r2, t; |
|
220 |
const uint64_t two63 = 0x8000000000000000LL; // 2**63. |
|
221 |
||
222 |
ad = ABS(d); |
|
223 |
if (d == 0 || d == 1) return false; |
|
224 |
t = two63 + ((uint64_t)d >> 63); |
|
225 |
anc = t - 1 - t%ad; // Absolute value of nc. |
|
226 |
p = 63; // Init. p. |
|
227 |
q1 = two63/anc; // Init. q1 = 2**p/|nc|. |
|
228 |
r1 = two63 - q1*anc; // Init. r1 = rem(2**p, |nc|). |
|
229 |
q2 = two63/ad; // Init. q2 = 2**p/|d|. |
|
230 |
r2 = two63 - q2*ad; // Init. r2 = rem(2**p, |d|). |
|
231 |
do { |
|
232 |
p = p + 1; |
|
233 |
q1 = 2*q1; // Update q1 = 2**p/|nc|. |
|
234 |
r1 = 2*r1; // Update r1 = rem(2**p, |nc|). |
|
235 |
if (r1 >= anc) { // (Must be an unsigned |
|
236 |
q1 = q1 + 1; // comparison here). |
|
237 |
r1 = r1 - anc; |
|
238 |
} |
|
239 |
q2 = 2*q2; // Update q2 = 2**p/|d|. |
|
240 |
r2 = 2*r2; // Update r2 = rem(2**p, |d|). |
|
241 |
if (r2 >= ad) { // (Must be an unsigned |
|
242 |
q2 = q2 + 1; // comparison here). |
|
243 |
r2 = r2 - ad; |
|
244 |
} |
|
245 |
delta = ad - r2; |
|
246 |
} while (q1 < delta || (q1 == delta && r1 == 0)); |
|
247 |
||
248 |
M = q2 + 1; |
|
249 |
if (d < 0) M = -M; // Magic number and |
|
250 |
s = p - 64; // shift amount to return. |
|
251 |
||
252 |
return true; |
|
253 |
} |
|
254 |
||
255 |
//---------------------long_by_long_mulhi-------------------------------------- |
|
256 |
// Generate ideal node graph for upper half of a 64 bit x 64 bit multiplication |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
257 |
static Node* long_by_long_mulhi(PhaseGVN* phase, Node* dividend, jlong magic_const) { |
392 | 258 |
// If the architecture supports a 64x64 mulhi, there is |
259 |
// no need to synthesize it in ideal nodes. |
|
260 |
if (Matcher::has_match_rule(Op_MulHiL)) { |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
261 |
Node* v = phase->longcon(magic_const); |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
262 |
return new (phase->C) MulHiLNode(dividend, v); |
1 | 263 |
} |
264 |
||
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
265 |
// Taken from Hacker's Delight, Fig. 8-2. Multiply high signed. |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
266 |
// (http://www.hackersdelight.org/HDcode/mulhs.c) |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
267 |
// |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
268 |
// int mulhs(int u, int v) { |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
269 |
// unsigned u0, v0, w0; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
270 |
// int u1, v1, w1, w2, t; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
271 |
// |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
272 |
// u0 = u & 0xFFFF; u1 = u >> 16; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
273 |
// v0 = v & 0xFFFF; v1 = v >> 16; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
274 |
// w0 = u0*v0; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
275 |
// t = u1*v0 + (w0 >> 16); |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
276 |
// w1 = t & 0xFFFF; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
277 |
// w2 = t >> 16; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
278 |
// w1 = u0*v1 + w1; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
279 |
// return u1*v1 + w2 + (w1 >> 16); |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
280 |
// } |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
281 |
// |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
282 |
// Note: The version above is for 32x32 multiplications, while the |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
283 |
// following inline comments are adapted to 64x64. |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
284 |
|
392 | 285 |
const int N = 64; |
286 |
||
12956
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
287 |
// Dummy node to keep intermediate nodes alive during construction |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
288 |
Node* hook = new (phase->C) Node(4); |
12956
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
289 |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
290 |
// u0 = u & 0xFFFFFFFF; u1 = u >> 32; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
291 |
Node* u0 = phase->transform(new (phase->C) AndLNode(dividend, phase->longcon(0xFFFFFFFF))); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
292 |
Node* u1 = phase->transform(new (phase->C) RShiftLNode(dividend, phase->intcon(N / 2))); |
12956
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
293 |
hook->init_req(0, u0); |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
294 |
hook->init_req(1, u1); |
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
295 |
|
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
296 |
// v0 = v & 0xFFFFFFFF; v1 = v >> 32; |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
297 |
Node* v0 = phase->longcon(magic_const & 0xFFFFFFFF); |
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
298 |
Node* v1 = phase->longcon(magic_const >> (N / 2)); |
392 | 299 |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
300 |
// w0 = u0*v0; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
301 |
Node* w0 = phase->transform(new (phase->C) MulLNode(u0, v0)); |
392 | 302 |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
303 |
// t = u1*v0 + (w0 >> 32); |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
304 |
Node* u1v0 = phase->transform(new (phase->C) MulLNode(u1, v0)); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
305 |
Node* temp = phase->transform(new (phase->C) URShiftLNode(w0, phase->intcon(N / 2))); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
306 |
Node* t = phase->transform(new (phase->C) AddLNode(u1v0, temp)); |
12956
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
307 |
hook->init_req(2, t); |
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
308 |
|
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
309 |
// w1 = t & 0xFFFFFFFF; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
310 |
Node* w1 = phase->transform(new (phase->C) AndLNode(t, phase->longcon(0xFFFFFFFF))); |
12956
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
311 |
hook->init_req(3, w1); |
392 | 312 |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
313 |
// w2 = t >> 32; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
314 |
Node* w2 = phase->transform(new (phase->C) RShiftLNode(t, phase->intcon(N / 2))); |
1056
da0241911ea8
6732154: REG: Printing an Image using image/gif doc flavor crashes the VM, Solsparc
rasbold
parents:
670
diff
changeset
|
315 |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
316 |
// w1 = u0*v1 + w1; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
317 |
Node* u0v1 = phase->transform(new (phase->C) MulLNode(u0, v1)); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
318 |
w1 = phase->transform(new (phase->C) AddLNode(u0v1, w1)); |
1056
da0241911ea8
6732154: REG: Printing an Image using image/gif doc flavor crashes the VM, Solsparc
rasbold
parents:
670
diff
changeset
|
319 |
|
2031
24e034f56dcb
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
1436
diff
changeset
|
320 |
// return u1*v1 + w2 + (w1 >> 32); |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
321 |
Node* u1v1 = phase->transform(new (phase->C) MulLNode(u1, v1)); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
322 |
Node* temp1 = phase->transform(new (phase->C) AddLNode(u1v1, w2)); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
323 |
Node* temp2 = phase->transform(new (phase->C) RShiftLNode(w1, phase->intcon(N / 2))); |
392 | 324 |
|
12956
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
325 |
// Remove the bogus extra edges used to keep things alive |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
326 |
PhaseIterGVN* igvn = phase->is_IterGVN(); |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
327 |
if (igvn != NULL) { |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
328 |
igvn->remove_dead_node(hook); |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
329 |
} else { |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
330 |
for (int i = 0; i < 4; i++) { |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
331 |
hook->set_req(i, NULL); |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
332 |
} |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
333 |
} |
1078d92535e8
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
kvn
parents:
7397
diff
changeset
|
334 |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
335 |
return new (phase->C) AddLNode(temp1, temp2); |
392 | 336 |
} |
337 |
||
338 |
||
339 |
//--------------------------transform_long_divide------------------------------ |
|
340 |
// Convert a division by constant divisor into an alternate Ideal graph. |
|
341 |
// Return NULL if no transformation occurs. |
|
342 |
static Node *transform_long_divide( PhaseGVN *phase, Node *dividend, jlong divisor ) { |
|
343 |
// Check for invalid divisors |
|
344 |
assert( divisor != 0L && divisor != min_jlong, |
|
345 |
"bad divisor for transforming to long multiply" ); |
|
346 |
||
347 |
bool d_pos = divisor >= 0; |
|
348 |
jlong d = d_pos ? divisor : -divisor; |
|
349 |
const int N = 64; |
|
350 |
||
351 |
// Result |
|
352 |
Node *q = NULL; |
|
353 |
||
354 |
if (d == 1) { |
|
355 |
// division by +/- 1 |
|
356 |
if (!d_pos) { |
|
357 |
// Just negate the value |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
358 |
q = new (phase->C) SubLNode(phase->longcon(0), dividend); |
392 | 359 |
} |
360 |
} else if ( is_power_of_2_long(d) ) { |
|
361 |
||
362 |
// division by +/- a power of 2 |
|
363 |
||
364 |
// See if we can simply do a shift without rounding |
|
365 |
bool needs_rounding = true; |
|
366 |
const Type *dt = phase->type(dividend); |
|
367 |
const TypeLong *dtl = dt->isa_long(); |
|
1 | 368 |
|
392 | 369 |
if (dtl && dtl->_lo > 0) { |
370 |
// we don't need to round a positive dividend |
|
371 |
needs_rounding = false; |
|
372 |
} else if( dividend->Opcode() == Op_AndL ) { |
|
373 |
// An AND mask of sufficient size clears the low bits and |
|
374 |
// I can avoid rounding. |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
375 |
const TypeLong *andconl_t = phase->type( dividend->in(2) )->isa_long(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
376 |
if( andconl_t && andconl_t->is_con() ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
377 |
jlong andconl = andconl_t->get_con(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
378 |
if( andconl < 0 && is_power_of_2_long(-andconl) && (-andconl) >= d ) { |
4583
b36d52bd2d19
6910484: incorrect integer optimization (loosing and op-r in a given example)
kvn
parents:
2746
diff
changeset
|
379 |
if( (-andconl) == d ) // Remove AND if it clears bits which will be shifted |
b36d52bd2d19
6910484: incorrect integer optimization (loosing and op-r in a given example)
kvn
parents:
2746
diff
changeset
|
380 |
dividend = dividend->in(1); |
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
381 |
needs_rounding = false; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1067
diff
changeset
|
382 |
} |
392 | 383 |
} |
384 |
} |
|
385 |
||
386 |
// Add rounding to the shift to handle the sign bit |
|
387 |
int l = log2_long(d-1)+1; |
|
388 |
if (needs_rounding) { |
|
389 |
// Divide-by-power-of-2 can be made into a shift, but you have to do |
|
390 |
// more math for the rounding. You need to add 0 for positive |
|
391 |
// numbers, and "i-1" for negative numbers. Example: i=4, so the |
|
392 |
// shift is by 2. You need to add 3 to negative dividends and 0 to |
|
393 |
// positive ones. So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1, |
|
394 |
// (-2+3)>>2 becomes 0, etc. |
|
395 |
||
396 |
// Compute 0 or -1, based on sign bit |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
397 |
Node *sign = phase->transform(new (phase->C) RShiftLNode(dividend, phase->intcon(N - 1))); |
392 | 398 |
// Mask sign bit to the low sign bits |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
399 |
Node *round = phase->transform(new (phase->C) URShiftLNode(sign, phase->intcon(N - l))); |
392 | 400 |
// Round up before shifting |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
401 |
dividend = phase->transform(new (phase->C) AddLNode(dividend, round)); |
392 | 402 |
} |
403 |
||
404 |
// Shift for division |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
405 |
q = new (phase->C) RShiftLNode(dividend, phase->intcon(l)); |
392 | 406 |
|
407 |
if (!d_pos) { |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
408 |
q = new (phase->C) SubLNode(phase->longcon(0), phase->transform(q)); |
392 | 409 |
} |
7115
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
410 |
} else if ( !Matcher::use_asm_for_ldiv_by_con(d) ) { // Use hardware DIV instruction when |
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
411 |
// it is faster than code generated below. |
392 | 412 |
// Attempt the jlong constant divide -> multiply transform found in |
413 |
// "Division by Invariant Integers using Multiplication" |
|
414 |
// by Granlund and Montgomery |
|
415 |
// See also "Hacker's Delight", chapter 10 by Warren. |
|
416 |
||
417 |
jlong magic_const; |
|
418 |
jint shift_const; |
|
419 |
if (magic_long_divide_constants(d, magic_const, shift_const)) { |
|
420 |
// Compute the high half of the dividend x magic multiplication |
|
421 |
Node *mul_hi = phase->transform(long_by_long_mulhi(phase, dividend, magic_const)); |
|
422 |
||
423 |
// The high half of the 128-bit multiply is computed. |
|
424 |
if (magic_const < 0) { |
|
425 |
// The magic multiplier is too large for a 64 bit constant. We've adjusted |
|
426 |
// it down by 2^64, but have to add 1 dividend back in after the multiplication. |
|
427 |
// This handles the "overflow" case described by Granlund and Montgomery. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
428 |
mul_hi = phase->transform(new (phase->C) AddLNode(dividend, mul_hi)); |
392 | 429 |
} |
430 |
||
431 |
// Shift over the (adjusted) mulhi |
|
432 |
if (shift_const != 0) { |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
433 |
mul_hi = phase->transform(new (phase->C) RShiftLNode(mul_hi, phase->intcon(shift_const))); |
392 | 434 |
} |
435 |
||
436 |
// Get a 0 or -1 from the sign of the dividend. |
|
437 |
Node *addend0 = mul_hi; |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
438 |
Node *addend1 = phase->transform(new (phase->C) RShiftLNode(dividend, phase->intcon(N-1))); |
392 | 439 |
|
440 |
// If the divisor is negative, swap the order of the input addends; |
|
441 |
// this has the effect of negating the quotient. |
|
442 |
if (!d_pos) { |
|
443 |
Node *temp = addend0; addend0 = addend1; addend1 = temp; |
|
444 |
} |
|
445 |
||
446 |
// Adjust the final quotient by subtracting -1 (adding 1) |
|
447 |
// from the mul_hi. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
448 |
q = new (phase->C) SubLNode(addend0, addend1); |
392 | 449 |
} |
1 | 450 |
} |
451 |
||
392 | 452 |
return q; |
1 | 453 |
} |
454 |
||
455 |
//============================================================================= |
|
456 |
//------------------------------Identity--------------------------------------- |
|
457 |
// If the divisor is 1, we are an identity on the dividend. |
|
458 |
Node *DivINode::Identity( PhaseTransform *phase ) { |
|
459 |
return (phase->type( in(2) )->higher_equal(TypeInt::ONE)) ? in(1) : this; |
|
460 |
} |
|
461 |
||
462 |
//------------------------------Idealize--------------------------------------- |
|
463 |
// Divides can be changed to multiplies and/or shifts |
|
464 |
Node *DivINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
465 |
if (in(0) && remove_dead_region(phase, can_reshape)) return this; |
|
1067 | 466 |
// Don't bother trying to transform a dead node |
467 |
if( in(0) && in(0)->is_top() ) return NULL; |
|
1 | 468 |
|
469 |
const Type *t = phase->type( in(2) ); |
|
470 |
if( t == TypeInt::ONE ) // Identity? |
|
471 |
return NULL; // Skip it |
|
472 |
||
473 |
const TypeInt *ti = t->isa_int(); |
|
474 |
if( !ti ) return NULL; |
|
475 |
if( !ti->is_con() ) return NULL; |
|
392 | 476 |
jint i = ti->get_con(); // Get divisor |
1 | 477 |
|
478 |
if (i == 0) return NULL; // Dividing by zero constant does not idealize |
|
479 |
||
480 |
set_req(0,NULL); // Dividing by a not-zero constant; no faulting |
|
481 |
||
482 |
// Dividing by MININT does not optimize as a power-of-2 shift. |
|
483 |
if( i == min_jint ) return NULL; |
|
484 |
||
392 | 485 |
return transform_int_divide( phase, in(1), i ); |
1 | 486 |
} |
487 |
||
488 |
//------------------------------Value------------------------------------------ |
|
489 |
// A DivINode divides its inputs. The third input is a Control input, used to |
|
490 |
// prevent hoisting the divide above an unsafe test. |
|
491 |
const Type *DivINode::Value( PhaseTransform *phase ) const { |
|
492 |
// Either input is TOP ==> the result is TOP |
|
493 |
const Type *t1 = phase->type( in(1) ); |
|
494 |
const Type *t2 = phase->type( in(2) ); |
|
495 |
if( t1 == Type::TOP ) return Type::TOP; |
|
496 |
if( t2 == Type::TOP ) return Type::TOP; |
|
497 |
||
498 |
// x/x == 1 since we always generate the dynamic divisor check for 0. |
|
499 |
if( phase->eqv( in(1), in(2) ) ) |
|
500 |
return TypeInt::ONE; |
|
501 |
||
502 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
503 |
const Type *bot = bottom_type(); |
|
504 |
if( (t1 == bot) || (t2 == bot) || |
|
505 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
506 |
return bot; |
|
507 |
||
508 |
// Divide the two numbers. We approximate. |
|
509 |
// If divisor is a constant and not zero |
|
510 |
const TypeInt *i1 = t1->is_int(); |
|
511 |
const TypeInt *i2 = t2->is_int(); |
|
512 |
int widen = MAX2(i1->_widen, i2->_widen); |
|
513 |
||
514 |
if( i2->is_con() && i2->get_con() != 0 ) { |
|
515 |
int32 d = i2->get_con(); // Divisor |
|
516 |
jint lo, hi; |
|
517 |
if( d >= 0 ) { |
|
518 |
lo = i1->_lo/d; |
|
519 |
hi = i1->_hi/d; |
|
520 |
} else { |
|
521 |
if( d == -1 && i1->_lo == min_jint ) { |
|
522 |
// 'min_jint/-1' throws arithmetic exception during compilation |
|
523 |
lo = min_jint; |
|
524 |
// do not support holes, 'hi' must go to either min_jint or max_jint: |
|
525 |
// [min_jint, -10]/[-1,-1] ==> [min_jint] UNION [10,max_jint] |
|
526 |
hi = i1->_hi == min_jint ? min_jint : max_jint; |
|
527 |
} else { |
|
528 |
lo = i1->_hi/d; |
|
529 |
hi = i1->_lo/d; |
|
530 |
} |
|
531 |
} |
|
532 |
return TypeInt::make(lo, hi, widen); |
|
533 |
} |
|
534 |
||
535 |
// If the dividend is a constant |
|
536 |
if( i1->is_con() ) { |
|
537 |
int32 d = i1->get_con(); |
|
538 |
if( d < 0 ) { |
|
539 |
if( d == min_jint ) { |
|
540 |
// (-min_jint) == min_jint == (min_jint / -1) |
|
541 |
return TypeInt::make(min_jint, max_jint/2 + 1, widen); |
|
542 |
} else { |
|
543 |
return TypeInt::make(d, -d, widen); |
|
544 |
} |
|
545 |
} |
|
546 |
return TypeInt::make(-d, d, widen); |
|
547 |
} |
|
548 |
||
549 |
// Otherwise we give up all hope |
|
550 |
return TypeInt::INT; |
|
551 |
} |
|
552 |
||
553 |
||
554 |
//============================================================================= |
|
555 |
//------------------------------Identity--------------------------------------- |
|
556 |
// If the divisor is 1, we are an identity on the dividend. |
|
557 |
Node *DivLNode::Identity( PhaseTransform *phase ) { |
|
558 |
return (phase->type( in(2) )->higher_equal(TypeLong::ONE)) ? in(1) : this; |
|
559 |
} |
|
560 |
||
561 |
//------------------------------Idealize--------------------------------------- |
|
562 |
// Dividing by a power of 2 is a shift. |
|
563 |
Node *DivLNode::Ideal( PhaseGVN *phase, bool can_reshape) { |
|
564 |
if (in(0) && remove_dead_region(phase, can_reshape)) return this; |
|
1067 | 565 |
// Don't bother trying to transform a dead node |
566 |
if( in(0) && in(0)->is_top() ) return NULL; |
|
1 | 567 |
|
568 |
const Type *t = phase->type( in(2) ); |
|
392 | 569 |
if( t == TypeLong::ONE ) // Identity? |
1 | 570 |
return NULL; // Skip it |
571 |
||
392 | 572 |
const TypeLong *tl = t->isa_long(); |
573 |
if( !tl ) return NULL; |
|
574 |
if( !tl->is_con() ) return NULL; |
|
575 |
jlong l = tl->get_con(); // Get divisor |
|
576 |
||
577 |
if (l == 0) return NULL; // Dividing by zero constant does not idealize |
|
578 |
||
579 |
set_req(0,NULL); // Dividing by a not-zero constant; no faulting |
|
1 | 580 |
|
7115
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
581 |
// Dividing by MINLONG does not optimize as a power-of-2 shift. |
392 | 582 |
if( l == min_jlong ) return NULL; |
1 | 583 |
|
392 | 584 |
return transform_long_divide( phase, in(1), l ); |
1 | 585 |
} |
586 |
||
587 |
//------------------------------Value------------------------------------------ |
|
588 |
// A DivLNode divides its inputs. The third input is a Control input, used to |
|
589 |
// prevent hoisting the divide above an unsafe test. |
|
590 |
const Type *DivLNode::Value( PhaseTransform *phase ) const { |
|
591 |
// Either input is TOP ==> the result is TOP |
|
592 |
const Type *t1 = phase->type( in(1) ); |
|
593 |
const Type *t2 = phase->type( in(2) ); |
|
594 |
if( t1 == Type::TOP ) return Type::TOP; |
|
595 |
if( t2 == Type::TOP ) return Type::TOP; |
|
596 |
||
597 |
// x/x == 1 since we always generate the dynamic divisor check for 0. |
|
598 |
if( phase->eqv( in(1), in(2) ) ) |
|
599 |
return TypeLong::ONE; |
|
600 |
||
601 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
602 |
const Type *bot = bottom_type(); |
|
603 |
if( (t1 == bot) || (t2 == bot) || |
|
604 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
605 |
return bot; |
|
606 |
||
607 |
// Divide the two numbers. We approximate. |
|
608 |
// If divisor is a constant and not zero |
|
609 |
const TypeLong *i1 = t1->is_long(); |
|
610 |
const TypeLong *i2 = t2->is_long(); |
|
611 |
int widen = MAX2(i1->_widen, i2->_widen); |
|
612 |
||
613 |
if( i2->is_con() && i2->get_con() != 0 ) { |
|
614 |
jlong d = i2->get_con(); // Divisor |
|
615 |
jlong lo, hi; |
|
616 |
if( d >= 0 ) { |
|
617 |
lo = i1->_lo/d; |
|
618 |
hi = i1->_hi/d; |
|
619 |
} else { |
|
620 |
if( d == CONST64(-1) && i1->_lo == min_jlong ) { |
|
621 |
// 'min_jlong/-1' throws arithmetic exception during compilation |
|
622 |
lo = min_jlong; |
|
623 |
// do not support holes, 'hi' must go to either min_jlong or max_jlong: |
|
624 |
// [min_jlong, -10]/[-1,-1] ==> [min_jlong] UNION [10,max_jlong] |
|
625 |
hi = i1->_hi == min_jlong ? min_jlong : max_jlong; |
|
626 |
} else { |
|
627 |
lo = i1->_hi/d; |
|
628 |
hi = i1->_lo/d; |
|
629 |
} |
|
630 |
} |
|
631 |
return TypeLong::make(lo, hi, widen); |
|
632 |
} |
|
633 |
||
634 |
// If the dividend is a constant |
|
635 |
if( i1->is_con() ) { |
|
636 |
jlong d = i1->get_con(); |
|
637 |
if( d < 0 ) { |
|
638 |
if( d == min_jlong ) { |
|
639 |
// (-min_jlong) == min_jlong == (min_jlong / -1) |
|
640 |
return TypeLong::make(min_jlong, max_jlong/2 + 1, widen); |
|
641 |
} else { |
|
642 |
return TypeLong::make(d, -d, widen); |
|
643 |
} |
|
644 |
} |
|
645 |
return TypeLong::make(-d, d, widen); |
|
646 |
} |
|
647 |
||
648 |
// Otherwise we give up all hope |
|
649 |
return TypeLong::LONG; |
|
650 |
} |
|
651 |
||
652 |
||
653 |
//============================================================================= |
|
654 |
//------------------------------Value------------------------------------------ |
|
655 |
// An DivFNode divides its inputs. The third input is a Control input, used to |
|
656 |
// prevent hoisting the divide above an unsafe test. |
|
657 |
const Type *DivFNode::Value( PhaseTransform *phase ) const { |
|
658 |
// Either input is TOP ==> the result is TOP |
|
659 |
const Type *t1 = phase->type( in(1) ); |
|
660 |
const Type *t2 = phase->type( in(2) ); |
|
661 |
if( t1 == Type::TOP ) return Type::TOP; |
|
662 |
if( t2 == Type::TOP ) return Type::TOP; |
|
663 |
||
664 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
665 |
const Type *bot = bottom_type(); |
|
666 |
if( (t1 == bot) || (t2 == bot) || |
|
667 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
668 |
return bot; |
|
669 |
||
670 |
// x/x == 1, we ignore 0/0. |
|
671 |
// Note: if t1 and t2 are zero then result is NaN (JVMS page 213) |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
672 |
// Does not work for variables because of NaN's |
1 | 673 |
if( phase->eqv( in(1), in(2) ) && t1->base() == Type::FloatCon) |
674 |
if (!g_isnan(t1->getf()) && g_isfinite(t1->getf()) && t1->getf() != 0.0) // could be negative ZERO or NaN |
|
675 |
return TypeF::ONE; |
|
676 |
||
677 |
if( t2 == TypeF::ONE ) |
|
678 |
return t1; |
|
679 |
||
680 |
// If divisor is a constant and not zero, divide them numbers |
|
681 |
if( t1->base() == Type::FloatCon && |
|
682 |
t2->base() == Type::FloatCon && |
|
683 |
t2->getf() != 0.0 ) // could be negative zero |
|
684 |
return TypeF::make( t1->getf()/t2->getf() ); |
|
685 |
||
686 |
// If the dividend is a constant zero |
|
687 |
// Note: if t1 and t2 are zero then result is NaN (JVMS page 213) |
|
688 |
// Test TypeF::ZERO is not sufficient as it could be negative zero |
|
689 |
||
690 |
if( t1 == TypeF::ZERO && !g_isnan(t2->getf()) && t2->getf() != 0.0 ) |
|
691 |
return TypeF::ZERO; |
|
692 |
||
693 |
// Otherwise we give up all hope |
|
694 |
return Type::FLOAT; |
|
695 |
} |
|
696 |
||
697 |
//------------------------------isA_Copy--------------------------------------- |
|
698 |
// Dividing by self is 1. |
|
699 |
// If the divisor is 1, we are an identity on the dividend. |
|
700 |
Node *DivFNode::Identity( PhaseTransform *phase ) { |
|
701 |
return (phase->type( in(2) ) == TypeF::ONE) ? in(1) : this; |
|
702 |
} |
|
703 |
||
704 |
||
705 |
//------------------------------Idealize--------------------------------------- |
|
706 |
Node *DivFNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
707 |
if (in(0) && remove_dead_region(phase, can_reshape)) return this; |
|
1067 | 708 |
// Don't bother trying to transform a dead node |
709 |
if( in(0) && in(0)->is_top() ) return NULL; |
|
1 | 710 |
|
711 |
const Type *t2 = phase->type( in(2) ); |
|
712 |
if( t2 == TypeF::ONE ) // Identity? |
|
713 |
return NULL; // Skip it |
|
714 |
||
715 |
const TypeF *tf = t2->isa_float_constant(); |
|
716 |
if( !tf ) return NULL; |
|
717 |
if( tf->base() != Type::FloatCon ) return NULL; |
|
718 |
||
719 |
// Check for out of range values |
|
720 |
if( tf->is_nan() || !tf->is_finite() ) return NULL; |
|
721 |
||
722 |
// Get the value |
|
723 |
float f = tf->getf(); |
|
724 |
int exp; |
|
725 |
||
726 |
// Only for special case of dividing by a power of 2 |
|
727 |
if( frexp((double)f, &exp) != 0.5 ) return NULL; |
|
728 |
||
729 |
// Limit the range of acceptable exponents |
|
730 |
if( exp < -126 || exp > 126 ) return NULL; |
|
731 |
||
732 |
// Compute the reciprocal |
|
733 |
float reciprocal = ((float)1.0) / f; |
|
734 |
||
735 |
assert( frexp((double)reciprocal, &exp) == 0.5, "reciprocal should be power of 2" ); |
|
736 |
||
737 |
// return multiplication by the reciprocal |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
738 |
return (new (phase->C) MulFNode(in(1), phase->makecon(TypeF::make(reciprocal)))); |
1 | 739 |
} |
740 |
||
741 |
//============================================================================= |
|
742 |
//------------------------------Value------------------------------------------ |
|
743 |
// An DivDNode divides its inputs. The third input is a Control input, used to |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
744 |
// prevent hoisting the divide above an unsafe test. |
1 | 745 |
const Type *DivDNode::Value( PhaseTransform *phase ) const { |
746 |
// Either input is TOP ==> the result is TOP |
|
747 |
const Type *t1 = phase->type( in(1) ); |
|
748 |
const Type *t2 = phase->type( in(2) ); |
|
749 |
if( t1 == Type::TOP ) return Type::TOP; |
|
750 |
if( t2 == Type::TOP ) return Type::TOP; |
|
751 |
||
752 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
753 |
const Type *bot = bottom_type(); |
|
754 |
if( (t1 == bot) || (t2 == bot) || |
|
755 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
756 |
return bot; |
|
757 |
||
758 |
// x/x == 1, we ignore 0/0. |
|
759 |
// Note: if t1 and t2 are zero then result is NaN (JVMS page 213) |
|
760 |
// Does not work for variables because of NaN's |
|
761 |
if( phase->eqv( in(1), in(2) ) && t1->base() == Type::DoubleCon) |
|
762 |
if (!g_isnan(t1->getd()) && g_isfinite(t1->getd()) && t1->getd() != 0.0) // could be negative ZERO or NaN |
|
763 |
return TypeD::ONE; |
|
764 |
||
765 |
if( t2 == TypeD::ONE ) |
|
766 |
return t1; |
|
767 |
||
1436
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
768 |
#if defined(IA32) |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
769 |
if (!phase->C->method()->is_strict()) |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
770 |
// Can't trust native compilers to properly fold strict double |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
771 |
// division with round-to-zero on this platform. |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
772 |
#endif |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
773 |
{ |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
774 |
// If divisor is a constant and not zero, divide them numbers |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
775 |
if( t1->base() == Type::DoubleCon && |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
776 |
t2->base() == Type::DoubleCon && |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
777 |
t2->getd() != 0.0 ) // could be negative zero |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
778 |
return TypeD::make( t1->getd()/t2->getd() ); |
6869d58f4f58
6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents:
1432
diff
changeset
|
779 |
} |
1 | 780 |
|
781 |
// If the dividend is a constant zero |
|
782 |
// Note: if t1 and t2 are zero then result is NaN (JVMS page 213) |
|
783 |
// Test TypeF::ZERO is not sufficient as it could be negative zero |
|
784 |
if( t1 == TypeD::ZERO && !g_isnan(t2->getd()) && t2->getd() != 0.0 ) |
|
785 |
return TypeD::ZERO; |
|
786 |
||
787 |
// Otherwise we give up all hope |
|
788 |
return Type::DOUBLE; |
|
789 |
} |
|
790 |
||
791 |
||
792 |
//------------------------------isA_Copy--------------------------------------- |
|
793 |
// Dividing by self is 1. |
|
794 |
// If the divisor is 1, we are an identity on the dividend. |
|
795 |
Node *DivDNode::Identity( PhaseTransform *phase ) { |
|
796 |
return (phase->type( in(2) ) == TypeD::ONE) ? in(1) : this; |
|
797 |
} |
|
798 |
||
799 |
//------------------------------Idealize--------------------------------------- |
|
800 |
Node *DivDNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
801 |
if (in(0) && remove_dead_region(phase, can_reshape)) return this; |
|
1067 | 802 |
// Don't bother trying to transform a dead node |
803 |
if( in(0) && in(0)->is_top() ) return NULL; |
|
1 | 804 |
|
805 |
const Type *t2 = phase->type( in(2) ); |
|
806 |
if( t2 == TypeD::ONE ) // Identity? |
|
807 |
return NULL; // Skip it |
|
808 |
||
809 |
const TypeD *td = t2->isa_double_constant(); |
|
810 |
if( !td ) return NULL; |
|
811 |
if( td->base() != Type::DoubleCon ) return NULL; |
|
812 |
||
813 |
// Check for out of range values |
|
814 |
if( td->is_nan() || !td->is_finite() ) return NULL; |
|
815 |
||
816 |
// Get the value |
|
817 |
double d = td->getd(); |
|
818 |
int exp; |
|
819 |
||
820 |
// Only for special case of dividing by a power of 2 |
|
821 |
if( frexp(d, &exp) != 0.5 ) return NULL; |
|
822 |
||
823 |
// Limit the range of acceptable exponents |
|
824 |
if( exp < -1021 || exp > 1022 ) return NULL; |
|
825 |
||
826 |
// Compute the reciprocal |
|
827 |
double reciprocal = 1.0 / d; |
|
828 |
||
829 |
assert( frexp(reciprocal, &exp) == 0.5, "reciprocal should be power of 2" ); |
|
830 |
||
831 |
// return multiplication by the reciprocal |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
832 |
return (new (phase->C) MulDNode(in(1), phase->makecon(TypeD::make(reciprocal)))); |
1 | 833 |
} |
834 |
||
835 |
//============================================================================= |
|
836 |
//------------------------------Idealize--------------------------------------- |
|
837 |
Node *ModINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
838 |
// Check for dead control input |
|
1067 | 839 |
if( in(0) && remove_dead_region(phase, can_reshape) ) return this; |
840 |
// Don't bother trying to transform a dead node |
|
841 |
if( in(0) && in(0)->is_top() ) return NULL; |
|
1 | 842 |
|
843 |
// Get the modulus |
|
844 |
const Type *t = phase->type( in(2) ); |
|
845 |
if( t == Type::TOP ) return NULL; |
|
846 |
const TypeInt *ti = t->is_int(); |
|
847 |
||
848 |
// Check for useless control input |
|
849 |
// Check for excluding mod-zero case |
|
850 |
if( in(0) && (ti->_hi < 0 || ti->_lo > 0) ) { |
|
851 |
set_req(0, NULL); // Yank control input |
|
852 |
return this; |
|
853 |
} |
|
854 |
||
855 |
// See if we are MOD'ing by 2^k or 2^k-1. |
|
856 |
if( !ti->is_con() ) return NULL; |
|
857 |
jint con = ti->get_con(); |
|
858 |
||
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
859 |
Node *hook = new (phase->C) Node(1); |
1 | 860 |
|
861 |
// First, special check for modulo 2^k-1 |
|
862 |
if( con >= 0 && con < max_jint && is_power_of_2(con+1) ) { |
|
863 |
uint k = exact_log2(con+1); // Extract k |
|
864 |
||
865 |
// Basic algorithm by David Detlefs. See fastmod_int.java for gory details. |
|
866 |
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*/}; |
|
867 |
int trip_count = 1; |
|
868 |
if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k]; |
|
869 |
||
870 |
// If the unroll factor is not too large, and if conditional moves are |
|
871 |
// ok, then use this case |
|
872 |
if( trip_count <= 5 && ConditionalMoveLimit != 0 ) { |
|
873 |
Node *x = in(1); // Value being mod'd |
|
874 |
Node *divisor = in(2); // Also is mask |
|
875 |
||
876 |
hook->init_req(0, x); // Add a use to x to prevent him from dying |
|
877 |
// Generate code to reduce X rapidly to nearly 2^k-1. |
|
878 |
for( int i = 0; i < trip_count; i++ ) { |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
879 |
Node *xl = phase->transform( new (phase->C) AndINode(x,divisor) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
880 |
Node *xh = phase->transform( new (phase->C) RShiftINode(x,phase->intcon(k)) ); // Must be signed |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
881 |
x = phase->transform( new (phase->C) AddINode(xh,xl) ); |
392 | 882 |
hook->set_req(0, x); |
1 | 883 |
} |
884 |
||
885 |
// Generate sign-fixup code. Was original value positive? |
|
886 |
// int hack_res = (i >= 0) ? divisor : 1; |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
887 |
Node *cmp1 = phase->transform( new (phase->C) CmpINode( in(1), phase->intcon(0) ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
888 |
Node *bol1 = phase->transform( new (phase->C) BoolNode( cmp1, BoolTest::ge ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
889 |
Node *cmov1= phase->transform( new (phase->C) CMoveINode(bol1, phase->intcon(1), divisor, TypeInt::POS) ); |
1 | 890 |
// if( x >= hack_res ) x -= divisor; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
891 |
Node *sub = phase->transform( new (phase->C) SubINode( x, divisor ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
892 |
Node *cmp2 = phase->transform( new (phase->C) CmpINode( x, cmov1 ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
893 |
Node *bol2 = phase->transform( new (phase->C) BoolNode( cmp2, BoolTest::ge ) ); |
1 | 894 |
// Convention is to not transform the return value of an Ideal |
895 |
// since Ideal is expected to return a modified 'this' or a new node. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
896 |
Node *cmov2= new (phase->C) CMoveINode(bol2, x, sub, TypeInt::INT); |
1 | 897 |
// cmov2 is now the mod |
898 |
||
899 |
// Now remove the bogus extra edges used to keep things alive |
|
900 |
if (can_reshape) { |
|
901 |
phase->is_IterGVN()->remove_dead_node(hook); |
|
902 |
} else { |
|
903 |
hook->set_req(0, NULL); // Just yank bogus edge during Parse phase |
|
904 |
} |
|
905 |
return cmov2; |
|
906 |
} |
|
907 |
} |
|
908 |
||
909 |
// Fell thru, the unroll case is not appropriate. Transform the modulo |
|
910 |
// into a long multiply/int multiply/subtract case |
|
911 |
||
912 |
// Cannot handle mod 0, and min_jint isn't handled by the transform |
|
913 |
if( con == 0 || con == min_jint ) return NULL; |
|
914 |
||
915 |
// Get the absolute value of the constant; at this point, we can use this |
|
916 |
jint pos_con = (con >= 0) ? con : -con; |
|
917 |
||
918 |
// integer Mod 1 is always 0 |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
919 |
if( pos_con == 1 ) return new (phase->C) ConINode(TypeInt::ZERO); |
1 | 920 |
|
921 |
int log2_con = -1; |
|
922 |
||
923 |
// If this is a power of two, they maybe we can mask it |
|
924 |
if( is_power_of_2(pos_con) ) { |
|
925 |
log2_con = log2_intptr((intptr_t)pos_con); |
|
926 |
||
927 |
const Type *dt = phase->type(in(1)); |
|
928 |
const TypeInt *dti = dt->isa_int(); |
|
929 |
||
930 |
// See if this can be masked, if the dividend is non-negative |
|
931 |
if( dti && dti->_lo >= 0 ) |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
932 |
return ( new (phase->C) AndINode( in(1), phase->intcon( pos_con-1 ) ) ); |
1 | 933 |
} |
934 |
||
935 |
// Save in(1) so that it cannot be changed or deleted |
|
936 |
hook->init_req(0, in(1)); |
|
937 |
||
938 |
// Divide using the transform from DivI to MulL |
|
392 | 939 |
Node *result = transform_int_divide( phase, in(1), pos_con ); |
940 |
if (result != NULL) { |
|
941 |
Node *divide = phase->transform(result); |
|
1 | 942 |
|
392 | 943 |
// Re-multiply, using a shift if this is a power of two |
944 |
Node *mult = NULL; |
|
1 | 945 |
|
392 | 946 |
if( log2_con >= 0 ) |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
947 |
mult = phase->transform( new (phase->C) LShiftINode( divide, phase->intcon( log2_con ) ) ); |
392 | 948 |
else |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
949 |
mult = phase->transform( new (phase->C) MulINode( divide, phase->intcon( pos_con ) ) ); |
1 | 950 |
|
392 | 951 |
// Finally, subtract the multiplied divided value from the original |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
952 |
result = new (phase->C) SubINode( in(1), mult ); |
392 | 953 |
} |
1 | 954 |
|
955 |
// Now remove the bogus extra edges used to keep things alive |
|
956 |
if (can_reshape) { |
|
957 |
phase->is_IterGVN()->remove_dead_node(hook); |
|
958 |
} else { |
|
959 |
hook->set_req(0, NULL); // Just yank bogus edge during Parse phase |
|
960 |
} |
|
961 |
||
962 |
// return the value |
|
963 |
return result; |
|
964 |
} |
|
965 |
||
966 |
//------------------------------Value------------------------------------------ |
|
967 |
const Type *ModINode::Value( PhaseTransform *phase ) const { |
|
968 |
// Either input is TOP ==> the result is TOP |
|
969 |
const Type *t1 = phase->type( in(1) ); |
|
970 |
const Type *t2 = phase->type( in(2) ); |
|
971 |
if( t1 == Type::TOP ) return Type::TOP; |
|
972 |
if( t2 == Type::TOP ) return Type::TOP; |
|
973 |
||
974 |
// We always generate the dynamic check for 0. |
|
975 |
// 0 MOD X is 0 |
|
976 |
if( t1 == TypeInt::ZERO ) return TypeInt::ZERO; |
|
977 |
// X MOD X is 0 |
|
978 |
if( phase->eqv( in(1), in(2) ) ) return TypeInt::ZERO; |
|
979 |
||
980 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
981 |
const Type *bot = bottom_type(); |
|
982 |
if( (t1 == bot) || (t2 == bot) || |
|
983 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
984 |
return bot; |
|
985 |
||
986 |
const TypeInt *i1 = t1->is_int(); |
|
987 |
const TypeInt *i2 = t2->is_int(); |
|
988 |
if( !i1->is_con() || !i2->is_con() ) { |
|
989 |
if( i1->_lo >= 0 && i2->_lo >= 0 ) |
|
990 |
return TypeInt::POS; |
|
991 |
// If both numbers are not constants, we know little. |
|
992 |
return TypeInt::INT; |
|
993 |
} |
|
994 |
// Mod by zero? Throw exception at runtime! |
|
995 |
if( !i2->get_con() ) return TypeInt::POS; |
|
996 |
||
997 |
// We must be modulo'ing 2 float constants. |
|
998 |
// Check for min_jint % '-1', result is defined to be '0'. |
|
999 |
if( i1->get_con() == min_jint && i2->get_con() == -1 ) |
|
1000 |
return TypeInt::ZERO; |
|
1001 |
||
1002 |
return TypeInt::make( i1->get_con() % i2->get_con() ); |
|
1003 |
} |
|
1004 |
||
1005 |
||
1006 |
//============================================================================= |
|
1007 |
//------------------------------Idealize--------------------------------------- |
|
1008 |
Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
1009 |
// Check for dead control input |
|
1067 | 1010 |
if( in(0) && remove_dead_region(phase, can_reshape) ) return this; |
1011 |
// Don't bother trying to transform a dead node |
|
1012 |
if( in(0) && in(0)->is_top() ) return NULL; |
|
1 | 1013 |
|
1014 |
// Get the modulus |
|
1015 |
const Type *t = phase->type( in(2) ); |
|
1016 |
if( t == Type::TOP ) return NULL; |
|
392 | 1017 |
const TypeLong *tl = t->is_long(); |
1 | 1018 |
|
1019 |
// Check for useless control input |
|
1020 |
// Check for excluding mod-zero case |
|
392 | 1021 |
if( in(0) && (tl->_hi < 0 || tl->_lo > 0) ) { |
1 | 1022 |
set_req(0, NULL); // Yank control input |
1023 |
return this; |
|
1024 |
} |
|
1025 |
||
1026 |
// See if we are MOD'ing by 2^k or 2^k-1. |
|
392 | 1027 |
if( !tl->is_con() ) return NULL; |
1028 |
jlong con = tl->get_con(); |
|
1029 |
||
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1030 |
Node *hook = new (phase->C) Node(1); |
1 | 1031 |
|
1032 |
// Expand mod |
|
392 | 1033 |
if( con >= 0 && con < max_jlong && is_power_of_2_long(con+1) ) { |
2032
1e27661bff28
6805724: ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant.
twisti
parents:
2031
diff
changeset
|
1034 |
uint k = exact_log2_long(con+1); // Extract k |
392 | 1035 |
|
1 | 1036 |
// Basic algorithm by David Detlefs. See fastmod_long.java for gory details. |
1037 |
// Used to help a popular random number generator which does a long-mod |
|
1038 |
// of 2^31-1 and shows up in SpecJBB and SciMark. |
|
1039 |
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*/}; |
|
1040 |
int trip_count = 1; |
|
1041 |
if( k < ARRAY_SIZE(unroll_factor)) trip_count = unroll_factor[k]; |
|
1042 |
||
392 | 1043 |
// If the unroll factor is not too large, and if conditional moves are |
1044 |
// ok, then use this case |
|
1045 |
if( trip_count <= 5 && ConditionalMoveLimit != 0 ) { |
|
1046 |
Node *x = in(1); // Value being mod'd |
|
1047 |
Node *divisor = in(2); // Also is mask |
|
1 | 1048 |
|
392 | 1049 |
hook->init_req(0, x); // Add a use to x to prevent him from dying |
1050 |
// Generate code to reduce X rapidly to nearly 2^k-1. |
|
1051 |
for( int i = 0; i < trip_count; i++ ) { |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1052 |
Node *xl = phase->transform( new (phase->C) AndLNode(x,divisor) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1053 |
Node *xh = phase->transform( new (phase->C) RShiftLNode(x,phase->intcon(k)) ); // Must be signed |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1054 |
x = phase->transform( new (phase->C) AddLNode(xh,xl) ); |
1 | 1055 |
hook->set_req(0, x); // Add a use to x to prevent him from dying |
392 | 1056 |
} |
1057 |
||
1058 |
// Generate sign-fixup code. Was original value positive? |
|
1059 |
// long hack_res = (i >= 0) ? divisor : CONST64(1); |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1060 |
Node *cmp1 = phase->transform( new (phase->C) CmpLNode( in(1), phase->longcon(0) ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1061 |
Node *bol1 = phase->transform( new (phase->C) BoolNode( cmp1, BoolTest::ge ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1062 |
Node *cmov1= phase->transform( new (phase->C) CMoveLNode(bol1, phase->longcon(1), divisor, TypeLong::LONG) ); |
392 | 1063 |
// if( x >= hack_res ) x -= divisor; |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1064 |
Node *sub = phase->transform( new (phase->C) SubLNode( x, divisor ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1065 |
Node *cmp2 = phase->transform( new (phase->C) CmpLNode( x, cmov1 ) ); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1066 |
Node *bol2 = phase->transform( new (phase->C) BoolNode( cmp2, BoolTest::ge ) ); |
392 | 1067 |
// Convention is to not transform the return value of an Ideal |
1068 |
// since Ideal is expected to return a modified 'this' or a new node. |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1069 |
Node *cmov2= new (phase->C) CMoveLNode(bol2, x, sub, TypeLong::LONG); |
392 | 1070 |
// cmov2 is now the mod |
1071 |
||
1072 |
// Now remove the bogus extra edges used to keep things alive |
|
1073 |
if (can_reshape) { |
|
1074 |
phase->is_IterGVN()->remove_dead_node(hook); |
|
1075 |
} else { |
|
1076 |
hook->set_req(0, NULL); // Just yank bogus edge during Parse phase |
|
1077 |
} |
|
1078 |
return cmov2; |
|
1 | 1079 |
} |
392 | 1080 |
} |
1081 |
||
1082 |
// Fell thru, the unroll case is not appropriate. Transform the modulo |
|
1083 |
// into a long multiply/int multiply/subtract case |
|
1084 |
||
7115
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
1085 |
// Cannot handle mod 0, and min_jlong isn't handled by the transform |
392 | 1086 |
if( con == 0 || con == min_jlong ) return NULL; |
1087 |
||
1088 |
// Get the absolute value of the constant; at this point, we can use this |
|
1089 |
jlong pos_con = (con >= 0) ? con : -con; |
|
1090 |
||
1091 |
// integer Mod 1 is always 0 |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1092 |
if( pos_con == 1 ) return new (phase->C) ConLNode(TypeLong::ZERO); |
392 | 1093 |
|
1094 |
int log2_con = -1; |
|
1095 |
||
2131 | 1096 |
// If this is a power of two, then maybe we can mask it |
392 | 1097 |
if( is_power_of_2_long(pos_con) ) { |
7115
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
1098 |
log2_con = exact_log2_long(pos_con); |
392 | 1099 |
|
1100 |
const Type *dt = phase->type(in(1)); |
|
1101 |
const TypeLong *dtl = dt->isa_long(); |
|
1102 |
||
1103 |
// See if this can be masked, if the dividend is non-negative |
|
1104 |
if( dtl && dtl->_lo >= 0 ) |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1105 |
return ( new (phase->C) AndLNode( in(1), phase->longcon( pos_con-1 ) ) ); |
392 | 1106 |
} |
1 | 1107 |
|
392 | 1108 |
// Save in(1) so that it cannot be changed or deleted |
1109 |
hook->init_req(0, in(1)); |
|
1110 |
||
7115
32300e243300
6987135: Performance regression on Intel platform with 32-bits edition between 6u13 and 6u14.
kvn
parents:
5547
diff
changeset
|
1111 |
// Divide using the transform from DivL to MulL |
392 | 1112 |
Node *result = transform_long_divide( phase, in(1), pos_con ); |
1113 |
if (result != NULL) { |
|
1114 |
Node *divide = phase->transform(result); |
|
1115 |
||
1116 |
// Re-multiply, using a shift if this is a power of two |
|
1117 |
Node *mult = NULL; |
|
1118 |
||
1119 |
if( log2_con >= 0 ) |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1120 |
mult = phase->transform( new (phase->C) LShiftLNode( divide, phase->intcon( log2_con ) ) ); |
392 | 1121 |
else |
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1122 |
mult = phase->transform( new (phase->C) MulLNode( divide, phase->longcon( pos_con ) ) ); |
392 | 1123 |
|
1124 |
// Finally, subtract the multiplied divided value from the original |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1125 |
result = new (phase->C) SubLNode( in(1), mult ); |
1 | 1126 |
} |
392 | 1127 |
|
1128 |
// Now remove the bogus extra edges used to keep things alive |
|
1129 |
if (can_reshape) { |
|
1130 |
phase->is_IterGVN()->remove_dead_node(hook); |
|
1131 |
} else { |
|
1132 |
hook->set_req(0, NULL); // Just yank bogus edge during Parse phase |
|
1133 |
} |
|
1134 |
||
1135 |
// return the value |
|
1136 |
return result; |
|
1 | 1137 |
} |
1138 |
||
1139 |
//------------------------------Value------------------------------------------ |
|
1140 |
const Type *ModLNode::Value( PhaseTransform *phase ) const { |
|
1141 |
// Either input is TOP ==> the result is TOP |
|
1142 |
const Type *t1 = phase->type( in(1) ); |
|
1143 |
const Type *t2 = phase->type( in(2) ); |
|
1144 |
if( t1 == Type::TOP ) return Type::TOP; |
|
1145 |
if( t2 == Type::TOP ) return Type::TOP; |
|
1146 |
||
1147 |
// We always generate the dynamic check for 0. |
|
1148 |
// 0 MOD X is 0 |
|
1149 |
if( t1 == TypeLong::ZERO ) return TypeLong::ZERO; |
|
1150 |
// X MOD X is 0 |
|
1151 |
if( phase->eqv( in(1), in(2) ) ) return TypeLong::ZERO; |
|
1152 |
||
1153 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
1154 |
const Type *bot = bottom_type(); |
|
1155 |
if( (t1 == bot) || (t2 == bot) || |
|
1156 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
1157 |
return bot; |
|
1158 |
||
1159 |
const TypeLong *i1 = t1->is_long(); |
|
1160 |
const TypeLong *i2 = t2->is_long(); |
|
1161 |
if( !i1->is_con() || !i2->is_con() ) { |
|
1162 |
if( i1->_lo >= CONST64(0) && i2->_lo >= CONST64(0) ) |
|
1163 |
return TypeLong::POS; |
|
1164 |
// If both numbers are not constants, we know little. |
|
1165 |
return TypeLong::LONG; |
|
1166 |
} |
|
1167 |
// Mod by zero? Throw exception at runtime! |
|
1168 |
if( !i2->get_con() ) return TypeLong::POS; |
|
1169 |
||
1170 |
// We must be modulo'ing 2 float constants. |
|
1171 |
// Check for min_jint % '-1', result is defined to be '0'. |
|
1172 |
if( i1->get_con() == min_jlong && i2->get_con() == -1 ) |
|
1173 |
return TypeLong::ZERO; |
|
1174 |
||
1175 |
return TypeLong::make( i1->get_con() % i2->get_con() ); |
|
1176 |
} |
|
1177 |
||
1178 |
||
1179 |
//============================================================================= |
|
1180 |
//------------------------------Value------------------------------------------ |
|
1181 |
const Type *ModFNode::Value( PhaseTransform *phase ) const { |
|
1182 |
// Either input is TOP ==> the result is TOP |
|
1183 |
const Type *t1 = phase->type( in(1) ); |
|
1184 |
const Type *t2 = phase->type( in(2) ); |
|
1185 |
if( t1 == Type::TOP ) return Type::TOP; |
|
1186 |
if( t2 == Type::TOP ) return Type::TOP; |
|
1187 |
||
1188 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
1189 |
const Type *bot = bottom_type(); |
|
1190 |
if( (t1 == bot) || (t2 == bot) || |
|
1191 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
1192 |
return bot; |
|
1193 |
||
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1194 |
// If either number is not a constant, we know nothing. |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1195 |
if ((t1->base() != Type::FloatCon) || (t2->base() != Type::FloatCon)) { |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1196 |
return Type::FLOAT; // note: x%x can be either NaN or 0 |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1197 |
} |
1 | 1198 |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1199 |
float f1 = t1->getf(); |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1200 |
float f2 = t2->getf(); |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1201 |
jint x1 = jint_cast(f1); // note: *(int*)&f1, not just (int)f1 |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1202 |
jint x2 = jint_cast(f2); |
1 | 1203 |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1204 |
// If either is a NaN, return an input NaN |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1205 |
if (g_isnan(f1)) return t1; |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1206 |
if (g_isnan(f2)) return t2; |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1207 |
|
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1208 |
// If an operand is infinity or the divisor is +/- zero, punt. |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1209 |
if (!g_isfinite(f1) || !g_isfinite(f2) || x2 == 0 || x2 == min_jint) |
1 | 1210 |
return Type::FLOAT; |
1211 |
||
1212 |
// We must be modulo'ing 2 float constants. |
|
1213 |
// Make sure that the sign of the fmod is equal to the sign of the dividend |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1214 |
jint xr = jint_cast(fmod(f1, f2)); |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1215 |
if ((x1 ^ xr) < 0) { |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1216 |
xr ^= min_jint; |
1 | 1217 |
} |
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1218 |
|
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1219 |
return TypeF::make(jfloat_cast(xr)); |
1 | 1220 |
} |
1221 |
||
1222 |
||
1223 |
//============================================================================= |
|
1224 |
//------------------------------Value------------------------------------------ |
|
1225 |
const Type *ModDNode::Value( PhaseTransform *phase ) const { |
|
1226 |
// Either input is TOP ==> the result is TOP |
|
1227 |
const Type *t1 = phase->type( in(1) ); |
|
1228 |
const Type *t2 = phase->type( in(2) ); |
|
1229 |
if( t1 == Type::TOP ) return Type::TOP; |
|
1230 |
if( t2 == Type::TOP ) return Type::TOP; |
|
1231 |
||
1232 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
1233 |
const Type *bot = bottom_type(); |
|
1234 |
if( (t1 == bot) || (t2 == bot) || |
|
1235 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
1236 |
return bot; |
|
1237 |
||
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1238 |
// If either number is not a constant, we know nothing. |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1239 |
if ((t1->base() != Type::DoubleCon) || (t2->base() != Type::DoubleCon)) { |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1240 |
return Type::DOUBLE; // note: x%x can be either NaN or 0 |
1 | 1241 |
} |
1242 |
||
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1243 |
double f1 = t1->getd(); |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1244 |
double f2 = t2->getd(); |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1245 |
jlong x1 = jlong_cast(f1); // note: *(long*)&f1, not just (long)f1 |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1246 |
jlong x2 = jlong_cast(f2); |
1 | 1247 |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1248 |
// If either is a NaN, return an input NaN |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1249 |
if (g_isnan(f1)) return t1; |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1250 |
if (g_isnan(f2)) return t2; |
1 | 1251 |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1252 |
// If an operand is infinity or the divisor is +/- zero, punt. |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1253 |
if (!g_isfinite(f1) || !g_isfinite(f2) || x2 == 0 || x2 == min_jlong) |
1 | 1254 |
return Type::DOUBLE; |
1255 |
||
1256 |
// We must be modulo'ing 2 double constants. |
|
378
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1257 |
// Make sure that the sign of the fmod is equal to the sign of the dividend |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1258 |
jlong xr = jlong_cast(fmod(f1, f2)); |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1259 |
if ((x1 ^ xr) < 0) { |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1260 |
xr ^= min_jlong; |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1261 |
} |
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1262 |
|
39fb2dc78042
6695288: runThese tests expr30303 and drem00301m1 fail when compiled code executes without deopt
jrose
parents:
1
diff
changeset
|
1263 |
return TypeD::make(jdouble_cast(xr)); |
1 | 1264 |
} |
1265 |
||
1266 |
//============================================================================= |
|
1267 |
||
1268 |
DivModNode::DivModNode( Node *c, Node *dividend, Node *divisor ) : MultiNode(3) { |
|
1269 |
init_req(0, c); |
|
1270 |
init_req(1, dividend); |
|
1271 |
init_req(2, divisor); |
|
1272 |
} |
|
1273 |
||
1274 |
//------------------------------make------------------------------------------ |
|
1275 |
DivModINode* DivModINode::make(Compile* C, Node* div_or_mod) { |
|
1276 |
Node* n = div_or_mod; |
|
1277 |
assert(n->Opcode() == Op_DivI || n->Opcode() == Op_ModI, |
|
1278 |
"only div or mod input pattern accepted"); |
|
1279 |
||
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1280 |
DivModINode* divmod = new (C) DivModINode(n->in(0), n->in(1), n->in(2)); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1281 |
Node* dproj = new (C) ProjNode(divmod, DivModNode::div_proj_num); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1282 |
Node* mproj = new (C) ProjNode(divmod, DivModNode::mod_proj_num); |
1 | 1283 |
return divmod; |
1284 |
} |
|
1285 |
||
1286 |
//------------------------------make------------------------------------------ |
|
1287 |
DivModLNode* DivModLNode::make(Compile* C, Node* div_or_mod) { |
|
1288 |
Node* n = div_or_mod; |
|
1289 |
assert(n->Opcode() == Op_DivL || n->Opcode() == Op_ModL, |
|
1290 |
"only div or mod input pattern accepted"); |
|
1291 |
||
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1292 |
DivModLNode* divmod = new (C) DivModLNode(n->in(0), n->in(1), n->in(2)); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1293 |
Node* dproj = new (C) ProjNode(divmod, DivModNode::div_proj_num); |
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1294 |
Node* mproj = new (C) ProjNode(divmod, DivModNode::mod_proj_num); |
1 | 1295 |
return divmod; |
1296 |
} |
|
1297 |
||
1298 |
//------------------------------match------------------------------------------ |
|
1299 |
// return result(s) along with their RegMask info |
|
1300 |
Node *DivModINode::match( const ProjNode *proj, const Matcher *match ) { |
|
1301 |
uint ideal_reg = proj->ideal_reg(); |
|
1302 |
RegMask rm; |
|
1303 |
if (proj->_con == div_proj_num) { |
|
1304 |
rm = match->divI_proj_mask(); |
|
1305 |
} else { |
|
1306 |
assert(proj->_con == mod_proj_num, "must be div or mod projection"); |
|
1307 |
rm = match->modI_proj_mask(); |
|
1308 |
} |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1309 |
return new (match->C)MachProjNode(this, proj->_con, rm, ideal_reg); |
1 | 1310 |
} |
1311 |
||
1312 |
||
1313 |
//------------------------------match------------------------------------------ |
|
1314 |
// return result(s) along with their RegMask info |
|
1315 |
Node *DivModLNode::match( const ProjNode *proj, const Matcher *match ) { |
|
1316 |
uint ideal_reg = proj->ideal_reg(); |
|
1317 |
RegMask rm; |
|
1318 |
if (proj->_con == div_proj_num) { |
|
1319 |
rm = match->divL_proj_mask(); |
|
1320 |
} else { |
|
1321 |
assert(proj->_con == mod_proj_num, "must be div or mod projection"); |
|
1322 |
rm = match->modL_proj_mask(); |
|
1323 |
} |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
12956
diff
changeset
|
1324 |
return new (match->C)MachProjNode(this, proj->_con, rm, ideal_reg); |
1 | 1325 |
} |