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