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