File: | jdk/src/hotspot/share/opto/subnode.cpp |
Warning: | line 1641, column 9 Value stored to 'l' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. |
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 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "compiler/compileLog.hpp" |
27 | #include "gc/shared/barrierSet.hpp" |
28 | #include "gc/shared/c2/barrierSetC2.hpp" |
29 | #include "memory/allocation.inline.hpp" |
30 | #include "opto/addnode.hpp" |
31 | #include "opto/callnode.hpp" |
32 | #include "opto/cfgnode.hpp" |
33 | #include "opto/loopnode.hpp" |
34 | #include "opto/matcher.hpp" |
35 | #include "opto/movenode.hpp" |
36 | #include "opto/mulnode.hpp" |
37 | #include "opto/opcodes.hpp" |
38 | #include "opto/phaseX.hpp" |
39 | #include "opto/subnode.hpp" |
40 | #include "runtime/sharedRuntime.hpp" |
41 | |
42 | // Portions of code courtesy of Clifford Click |
43 | |
44 | // Optimization - Graph Style |
45 | |
46 | #include "math.h" |
47 | |
48 | //============================================================================= |
49 | //------------------------------Identity--------------------------------------- |
50 | // If right input is a constant 0, return the left input. |
51 | Node* SubNode::Identity(PhaseGVN* phase) { |
52 | assert(in(1) != this, "Must already have called Value")do { if (!(in(1) != this)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 52, "assert(" "in(1) != this" ") failed", "Must already have called Value" ); ::breakpoint(); } } while (0); |
53 | assert(in(2) != this, "Must already have called Value")do { if (!(in(2) != this)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 53, "assert(" "in(2) != this" ") failed", "Must already have called Value" ); ::breakpoint(); } } while (0); |
54 | |
55 | // Remove double negation |
56 | const Type *zero = add_id(); |
57 | if( phase->type( in(1) )->higher_equal( zero ) && |
58 | in(2)->Opcode() == Opcode() && |
59 | phase->type( in(2)->in(1) )->higher_equal( zero ) ) { |
60 | return in(2)->in(2); |
61 | } |
62 | |
63 | // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y |
64 | if (in(1)->Opcode() == Op_AddI) { |
65 | if (in(1)->in(2) == in(2)) { |
66 | return in(1)->in(1); |
67 | } |
68 | if (in(1)->in(1) == in(2)) { |
69 | return in(1)->in(2); |
70 | } |
71 | |
72 | // Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying |
73 | // trip counter and X is likely to be loop-invariant (that's how O2 Nodes |
74 | // are originally used, although the optimizer sometimes jiggers things). |
75 | // This folding through an O2 removes a loop-exit use of a loop-varying |
76 | // value and generally lowers register pressure in and around the loop. |
77 | if (in(1)->in(2)->Opcode() == Op_Opaque2 && in(1)->in(2)->in(1) == in(2)) { |
78 | return in(1)->in(1); |
79 | } |
80 | } |
81 | |
82 | return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this; |
83 | } |
84 | |
85 | //------------------------------Value------------------------------------------ |
86 | // A subtract node differences it's two inputs. |
87 | const Type* SubNode::Value_common(PhaseTransform *phase) const { |
88 | const Node* in1 = in(1); |
89 | const Node* in2 = in(2); |
90 | // Either input is TOP ==> the result is TOP |
91 | const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); |
92 | if( t1 == Type::TOP ) return Type::TOP; |
93 | const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); |
94 | if( t2 == Type::TOP ) return Type::TOP; |
95 | |
96 | // Not correct for SubFnode and AddFNode (must check for infinity) |
97 | // Equal? Subtract is zero |
98 | if (in1->eqv_uncast(in2)) return add_id(); |
99 | |
100 | // Either input is BOTTOM ==> the result is the local BOTTOM |
101 | if( t1 == Type::BOTTOM || t2 == Type::BOTTOM ) |
102 | return bottom_type(); |
103 | |
104 | return NULL__null; |
105 | } |
106 | |
107 | const Type* SubNode::Value(PhaseGVN* phase) const { |
108 | const Type* t = Value_common(phase); |
109 | if (t != NULL__null) { |
110 | return t; |
111 | } |
112 | const Type* t1 = phase->type(in(1)); |
113 | const Type* t2 = phase->type(in(2)); |
114 | return sub(t1,t2); // Local flavor of type subtraction |
115 | |
116 | } |
117 | |
118 | SubNode* SubNode::make(Node* in1, Node* in2, BasicType bt) { |
119 | switch (bt) { |
120 | case T_INT: |
121 | return new SubINode(in1, in2); |
122 | case T_LONG: |
123 | return new SubLNode(in1, in2); |
124 | default: |
125 | fatal("Not implemented for %s", type2name(bt))do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 125, "Not implemented for %s", type2name(bt)); ::breakpoint (); } while (0); |
126 | } |
127 | return NULL__null; |
128 | } |
129 | |
130 | //============================================================================= |
131 | //------------------------------Helper function-------------------------------- |
132 | |
133 | static bool is_cloop_increment(Node* inc) { |
134 | precond(inc->Opcode() == Op_AddI || inc->Opcode() == Op_AddL)do { if (!(inc->Opcode() == Op_AddI || inc->Opcode() == Op_AddL)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 134, "assert(" "inc->Opcode() == Op_AddI || inc->Opcode() == Op_AddL" ") failed", "precond"); ::breakpoint(); } } while (0); |
135 | |
136 | if (!inc->in(1)->is_Phi()) { |
137 | return false; |
138 | } |
139 | const PhiNode* phi = inc->in(1)->as_Phi(); |
140 | |
141 | if (!phi->region()->is_CountedLoop()) { |
142 | return false; |
143 | } |
144 | |
145 | return inc == phi->region()->as_CountedLoop()->incr(); |
146 | } |
147 | |
148 | // Given the expression '(x + C) - v', or |
149 | // 'v - (x + C)', we examine nodes '+' and 'v': |
150 | // |
151 | // 1. Do not convert if '+' is a counted-loop increment, because the '-' is |
152 | // loop invariant and converting extends the live-range of 'x' to overlap |
153 | // with the '+', forcing another register to be used in the loop. |
154 | // |
155 | // 2. Do not convert if 'v' is a counted-loop induction variable, because |
156 | // 'x' might be invariant. |
157 | // |
158 | static bool ok_to_convert(Node* inc, Node* var) { |
159 | return !(is_cloop_increment(inc) || var->is_cloop_ind_var()); |
160 | } |
161 | |
162 | //------------------------------Ideal------------------------------------------ |
163 | Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){ |
164 | Node *in1 = in(1); |
165 | Node *in2 = in(2); |
166 | uint op1 = in1->Opcode(); |
167 | uint op2 = in2->Opcode(); |
168 | |
169 | #ifdef ASSERT1 |
170 | // Check for dead loop |
171 | if ((in1 == this) || (in2 == this) || |
172 | ((op1 == Op_AddI || op1 == Op_SubI) && |
173 | ((in1->in(1) == this) || (in1->in(2) == this) || |
174 | (in1->in(1) == in1) || (in1->in(2) == in1)))) { |
175 | assert(false, "dead loop in SubINode::Ideal")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 175, "assert(" "false" ") failed", "dead loop in SubINode::Ideal" ); ::breakpoint(); } } while (0); |
176 | } |
177 | #endif |
178 | |
179 | const Type *t2 = phase->type( in2 ); |
180 | if( t2 == Type::TOP ) return NULL__null; |
181 | // Convert "x-c0" into "x+ -c0". |
182 | if( t2->base() == Type::Int ){ // Might be bottom or top... |
183 | const TypeInt *i = t2->is_int(); |
184 | if( i->is_con() ) |
185 | return new AddINode(in1, phase->intcon(-i->get_con())); |
186 | } |
187 | |
188 | // Convert "(x+c0) - y" into (x-y) + c0" |
189 | // Do not collapse (x+c0)-y if "+" is a loop increment or |
190 | // if "y" is a loop induction variable. |
191 | if( op1 == Op_AddI && ok_to_convert(in1, in2) ) { |
192 | const Type *tadd = phase->type( in1->in(2) ); |
193 | if( tadd->singleton() && tadd != Type::TOP ) { |
194 | Node *sub2 = phase->transform( new SubINode( in1->in(1), in2 )); |
195 | return new AddINode( sub2, in1->in(2) ); |
196 | } |
197 | } |
198 | |
199 | // Convert "x - (y+c0)" into "(x-y) - c0" AND |
200 | // Convert "c1 - (y+c0)" into "(c1-c0) - y" |
201 | // Need the same check as in above optimization but reversed. |
202 | if (op2 == Op_AddI |
203 | && ok_to_convert(in2, in1) |
204 | && in2->in(2)->Opcode() == Op_ConI) { |
205 | jint c0 = phase->type(in2->in(2))->isa_int()->get_con(); |
206 | Node* in21 = in2->in(1); |
207 | if (in1->Opcode() == Op_ConI) { |
208 | // Match c1 |
209 | jint c1 = phase->type(in1)->isa_int()->get_con(); |
210 | Node* sub2 = phase->intcon(java_subtract(c1, c0)); |
211 | return new SubINode(sub2, in21); |
212 | } else { |
213 | // Match x |
214 | Node* sub2 = phase->transform(new SubINode(in1, in21)); |
215 | Node* neg_c0 = phase->intcon(-c0); |
216 | return new AddINode(sub2, neg_c0); |
217 | } |
218 | } |
219 | |
220 | const Type *t1 = phase->type( in1 ); |
221 | if( t1 == Type::TOP ) return NULL__null; |
222 | |
223 | #ifdef ASSERT1 |
224 | // Check for dead loop |
225 | if ((op2 == Op_AddI || op2 == Op_SubI) && |
226 | ((in2->in(1) == this) || (in2->in(2) == this) || |
227 | (in2->in(1) == in2) || (in2->in(2) == in2))) { |
228 | assert(false, "dead loop in SubINode::Ideal")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 228, "assert(" "false" ") failed", "dead loop in SubINode::Ideal" ); ::breakpoint(); } } while (0); |
229 | } |
230 | #endif |
231 | |
232 | // Convert "x - (x+y)" into "-y" |
233 | if (op2 == Op_AddI && in1 == in2->in(1)) { |
234 | return new SubINode(phase->intcon(0), in2->in(2)); |
235 | } |
236 | // Convert "(x-y) - x" into "-y" |
237 | if (op1 == Op_SubI && in1->in(1) == in2) { |
238 | return new SubINode(phase->intcon(0), in1->in(2)); |
239 | } |
240 | // Convert "x - (y+x)" into "-y" |
241 | if (op2 == Op_AddI && in1 == in2->in(2)) { |
242 | return new SubINode(phase->intcon(0), in2->in(1)); |
243 | } |
244 | |
245 | // Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity(). |
246 | if (t1 == TypeInt::ZERO && op2 == Op_SubI && phase->type(in2->in(1)) != TypeInt::ZERO) { |
247 | return new SubINode(in2->in(2), in2->in(1)); |
248 | } |
249 | |
250 | // Convert "0 - (x+con)" into "-con-x" |
251 | jint con; |
252 | if( t1 == TypeInt::ZERO && op2 == Op_AddI && |
253 | (con = in2->in(2)->find_int_con(0)) != 0 ) |
254 | return new SubINode( phase->intcon(-con), in2->in(1) ); |
255 | |
256 | // Convert "(X+A) - (X+B)" into "A - B" |
257 | if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) ) |
258 | return new SubINode( in1->in(2), in2->in(2) ); |
259 | |
260 | // Convert "(A+X) - (B+X)" into "A - B" |
261 | if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) ) |
262 | return new SubINode( in1->in(1), in2->in(1) ); |
263 | |
264 | // Convert "(A+X) - (X+B)" into "A - B" |
265 | if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) ) |
266 | return new SubINode( in1->in(1), in2->in(2) ); |
267 | |
268 | // Convert "(X+A) - (B+X)" into "A - B" |
269 | if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) |
270 | return new SubINode( in1->in(2), in2->in(1) ); |
271 | |
272 | // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally |
273 | // nicer to optimize than subtract. |
274 | if( op2 == Op_SubI && in2->outcnt() == 1) { |
275 | Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) ); |
276 | return new SubINode( add1, in2->in(1) ); |
277 | } |
278 | |
279 | // Associative |
280 | if (op1 == Op_MulI && op2 == Op_MulI) { |
281 | Node* sub_in1 = NULL__null; |
282 | Node* sub_in2 = NULL__null; |
283 | Node* mul_in = NULL__null; |
284 | |
285 | if (in1->in(1) == in2->in(1)) { |
286 | // Convert "a*b-a*c into a*(b-c) |
287 | sub_in1 = in1->in(2); |
288 | sub_in2 = in2->in(2); |
289 | mul_in = in1->in(1); |
290 | } else if (in1->in(2) == in2->in(1)) { |
291 | // Convert a*b-b*c into b*(a-c) |
292 | sub_in1 = in1->in(1); |
293 | sub_in2 = in2->in(2); |
294 | mul_in = in1->in(2); |
295 | } else if (in1->in(2) == in2->in(2)) { |
296 | // Convert a*c-b*c into (a-b)*c |
297 | sub_in1 = in1->in(1); |
298 | sub_in2 = in2->in(1); |
299 | mul_in = in1->in(2); |
300 | } else if (in1->in(1) == in2->in(2)) { |
301 | // Convert a*b-c*a into a*(b-c) |
302 | sub_in1 = in1->in(2); |
303 | sub_in2 = in2->in(1); |
304 | mul_in = in1->in(1); |
305 | } |
306 | |
307 | if (mul_in != NULL__null) { |
308 | Node* sub = phase->transform(new SubINode(sub_in1, sub_in2)); |
309 | return new MulINode(mul_in, sub); |
310 | } |
311 | } |
312 | |
313 | // Convert "0-(A>>31)" into "(A>>>31)" |
314 | if ( op2 == Op_RShiftI ) { |
315 | Node *in21 = in2->in(1); |
316 | Node *in22 = in2->in(2); |
317 | const TypeInt *zero = phase->type(in1)->isa_int(); |
318 | const TypeInt *t21 = phase->type(in21)->isa_int(); |
319 | const TypeInt *t22 = phase->type(in22)->isa_int(); |
320 | if ( t21 && t22 && zero == TypeInt::ZERO && t22->is_con(31) ) { |
321 | return new URShiftINode(in21, in22); |
322 | } |
323 | } |
324 | |
325 | return NULL__null; |
326 | } |
327 | |
328 | //------------------------------sub-------------------------------------------- |
329 | // A subtract node differences it's two inputs. |
330 | const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { |
331 | const TypeInt *r0 = t1->is_int(); // Handy access |
332 | const TypeInt *r1 = t2->is_int(); |
333 | int32_t lo = java_subtract(r0->_lo, r1->_hi); |
334 | int32_t hi = java_subtract(r0->_hi, r1->_lo); |
335 | |
336 | // We next check for 32-bit overflow. |
337 | // If that happens, we just assume all integers are possible. |
338 | if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR |
339 | ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND |
340 | (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR |
341 | ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs |
342 | return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); |
343 | else // Overflow; assume all integers |
344 | return TypeInt::INT; |
345 | } |
346 | |
347 | //============================================================================= |
348 | //------------------------------Ideal------------------------------------------ |
349 | Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
350 | Node *in1 = in(1); |
351 | Node *in2 = in(2); |
352 | uint op1 = in1->Opcode(); |
353 | uint op2 = in2->Opcode(); |
354 | |
355 | #ifdef ASSERT1 |
356 | // Check for dead loop |
357 | if ((in1 == this) || (in2 == this) || |
358 | ((op1 == Op_AddL || op1 == Op_SubL) && |
359 | ((in1->in(1) == this) || (in1->in(2) == this) || |
360 | (in1->in(1) == in1) || (in1->in(2) == in1)))) { |
361 | assert(false, "dead loop in SubLNode::Ideal")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 361, "assert(" "false" ") failed", "dead loop in SubLNode::Ideal" ); ::breakpoint(); } } while (0); |
362 | } |
363 | #endif |
364 | |
365 | if( phase->type( in2 ) == Type::TOP ) return NULL__null; |
366 | const TypeLong *i = phase->type( in2 )->isa_long(); |
367 | // Convert "x-c0" into "x+ -c0". |
368 | if( i && // Might be bottom or top... |
369 | i->is_con() ) |
370 | return new AddLNode(in1, phase->longcon(-i->get_con())); |
371 | |
372 | // Convert "(x+c0) - y" into (x-y) + c0" |
373 | // Do not collapse (x+c0)-y if "+" is a loop increment or |
374 | // if "y" is a loop induction variable. |
375 | if( op1 == Op_AddL && ok_to_convert(in1, in2) ) { |
376 | Node *in11 = in1->in(1); |
377 | const Type *tadd = phase->type( in1->in(2) ); |
378 | if( tadd->singleton() && tadd != Type::TOP ) { |
379 | Node *sub2 = phase->transform( new SubLNode( in11, in2 )); |
380 | return new AddLNode( sub2, in1->in(2) ); |
381 | } |
382 | } |
383 | |
384 | // Convert "x - (y+c0)" into "(x-y) - c0" AND |
385 | // Convert "c1 - (y+c0)" into "(c1-c0) - y" |
386 | // Need the same check as in above optimization but reversed. |
387 | if (op2 == Op_AddL |
388 | && ok_to_convert(in2, in1) |
389 | && in2->in(2)->Opcode() == Op_ConL) { |
390 | jlong c0 = phase->type(in2->in(2))->isa_long()->get_con(); |
391 | Node* in21 = in2->in(1); |
392 | if (in1->Opcode() == Op_ConL) { |
393 | // Match c1 |
394 | jlong c1 = phase->type(in1)->isa_long()->get_con(); |
395 | Node* sub2 = phase->longcon(java_subtract(c1, c0)); |
396 | return new SubLNode(sub2, in21); |
397 | } else { |
398 | Node* sub2 = phase->transform(new SubLNode(in1, in21)); |
399 | Node* neg_c0 = phase->longcon(-c0); |
400 | return new AddLNode(sub2, neg_c0); |
401 | } |
402 | } |
403 | |
404 | const Type *t1 = phase->type( in1 ); |
405 | if( t1 == Type::TOP ) return NULL__null; |
406 | |
407 | #ifdef ASSERT1 |
408 | // Check for dead loop |
409 | if ((op2 == Op_AddL || op2 == Op_SubL) && |
410 | ((in2->in(1) == this) || (in2->in(2) == this) || |
411 | (in2->in(1) == in2) || (in2->in(2) == in2))) { |
412 | assert(false, "dead loop in SubLNode::Ideal")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 412, "assert(" "false" ") failed", "dead loop in SubLNode::Ideal" ); ::breakpoint(); } } while (0); |
413 | } |
414 | #endif |
415 | |
416 | // Convert "x - (x+y)" into "-y" |
417 | if (op2 == Op_AddL && in1 == in2->in(1)) { |
418 | return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(2)); |
419 | } |
420 | // Convert "x - (y+x)" into "-y" |
421 | if (op2 == Op_AddL && in1 == in2->in(2)) { |
422 | return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(1)); |
423 | } |
424 | |
425 | // Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity. |
426 | if (t1 == TypeLong::ZERO && op2 == Op_SubL && phase->type(in2->in(1)) != TypeLong::ZERO) { |
427 | return new SubLNode(in2->in(2), in2->in(1)); |
428 | } |
429 | |
430 | // Convert "(X+A) - (X+B)" into "A - B" |
431 | if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) ) |
432 | return new SubLNode( in1->in(2), in2->in(2) ); |
433 | |
434 | // Convert "(A+X) - (B+X)" into "A - B" |
435 | if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) ) |
436 | return new SubLNode( in1->in(1), in2->in(1) ); |
437 | |
438 | // Convert "(A+X) - (X+B)" into "A - B" |
439 | if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(1) ) |
440 | return new SubLNode( in1->in(1), in2->in(2) ); |
441 | |
442 | // Convert "(X+A) - (B+X)" into "A - B" |
443 | if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(2) ) |
444 | return new SubLNode( in1->in(2), in2->in(1) ); |
445 | |
446 | // Convert "A-(B-C)" into (A+C)-B" |
447 | if( op2 == Op_SubL && in2->outcnt() == 1) { |
448 | Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) ); |
449 | return new SubLNode( add1, in2->in(1) ); |
450 | } |
451 | |
452 | // Associative |
453 | if (op1 == Op_MulL && op2 == Op_MulL) { |
454 | Node* sub_in1 = NULL__null; |
455 | Node* sub_in2 = NULL__null; |
456 | Node* mul_in = NULL__null; |
457 | |
458 | if (in1->in(1) == in2->in(1)) { |
459 | // Convert "a*b-a*c into a*(b+c) |
460 | sub_in1 = in1->in(2); |
461 | sub_in2 = in2->in(2); |
462 | mul_in = in1->in(1); |
463 | } else if (in1->in(2) == in2->in(1)) { |
464 | // Convert a*b-b*c into b*(a-c) |
465 | sub_in1 = in1->in(1); |
466 | sub_in2 = in2->in(2); |
467 | mul_in = in1->in(2); |
468 | } else if (in1->in(2) == in2->in(2)) { |
469 | // Convert a*c-b*c into (a-b)*c |
470 | sub_in1 = in1->in(1); |
471 | sub_in2 = in2->in(1); |
472 | mul_in = in1->in(2); |
473 | } else if (in1->in(1) == in2->in(2)) { |
474 | // Convert a*b-c*a into a*(b-c) |
475 | sub_in1 = in1->in(2); |
476 | sub_in2 = in2->in(1); |
477 | mul_in = in1->in(1); |
478 | } |
479 | |
480 | if (mul_in != NULL__null) { |
481 | Node* sub = phase->transform(new SubLNode(sub_in1, sub_in2)); |
482 | return new MulLNode(mul_in, sub); |
483 | } |
484 | } |
485 | |
486 | // Convert "0L-(A>>63)" into "(A>>>63)" |
487 | if ( op2 == Op_RShiftL ) { |
488 | Node *in21 = in2->in(1); |
489 | Node *in22 = in2->in(2); |
490 | const TypeLong *zero = phase->type(in1)->isa_long(); |
491 | const TypeLong *t21 = phase->type(in21)->isa_long(); |
492 | const TypeInt *t22 = phase->type(in22)->isa_int(); |
493 | if ( t21 && t22 && zero == TypeLong::ZERO && t22->is_con(63) ) { |
494 | return new URShiftLNode(in21, in22); |
495 | } |
496 | } |
497 | |
498 | return NULL__null; |
499 | } |
500 | |
501 | //------------------------------sub-------------------------------------------- |
502 | // A subtract node differences it's two inputs. |
503 | const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const { |
504 | const TypeLong *r0 = t1->is_long(); // Handy access |
505 | const TypeLong *r1 = t2->is_long(); |
506 | jlong lo = java_subtract(r0->_lo, r1->_hi); |
507 | jlong hi = java_subtract(r0->_hi, r1->_lo); |
508 | |
509 | // We next check for 32-bit overflow. |
510 | // If that happens, we just assume all integers are possible. |
511 | if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR |
512 | ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND |
513 | (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR |
514 | ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs |
515 | return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen)); |
516 | else // Overflow; assume all integers |
517 | return TypeLong::LONG; |
518 | } |
519 | |
520 | //============================================================================= |
521 | //------------------------------Value------------------------------------------ |
522 | // A subtract node differences its two inputs. |
523 | const Type* SubFPNode::Value(PhaseGVN* phase) const { |
524 | const Node* in1 = in(1); |
525 | const Node* in2 = in(2); |
526 | // Either input is TOP ==> the result is TOP |
527 | const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); |
528 | if( t1 == Type::TOP ) return Type::TOP; |
529 | const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); |
530 | if( t2 == Type::TOP ) return Type::TOP; |
531 | |
532 | // if both operands are infinity of same sign, the result is NaN; do |
533 | // not replace with zero |
534 | if (t1->is_finite() && t2->is_finite() && in1 == in2) { |
535 | return add_id(); |
536 | } |
537 | |
538 | // Either input is BOTTOM ==> the result is the local BOTTOM |
539 | const Type *bot = bottom_type(); |
540 | if( (t1 == bot) || (t2 == bot) || |
541 | (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
542 | return bot; |
543 | |
544 | return sub(t1,t2); // Local flavor of type subtraction |
545 | } |
546 | |
547 | |
548 | //============================================================================= |
549 | //------------------------------Ideal------------------------------------------ |
550 | Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
551 | const Type *t2 = phase->type( in(2) ); |
552 | // Convert "x-c0" into "x+ -c0". |
553 | if( t2->base() == Type::FloatCon ) { // Might be bottom or top... |
554 | // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) ); |
555 | } |
556 | |
557 | // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes |
558 | // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0. |
559 | //if( phase->type(in(1)) == TypeF::ZERO ) |
560 | //return new (phase->C, 2) NegFNode(in(2)); |
561 | |
562 | return NULL__null; |
563 | } |
564 | |
565 | //------------------------------sub-------------------------------------------- |
566 | // A subtract node differences its two inputs. |
567 | const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const { |
568 | // no folding if one of operands is infinity or NaN, do not do constant folding |
569 | if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) { |
570 | return TypeF::make( t1->getf() - t2->getf() ); |
571 | } |
572 | else if( g_isnan(t1->getf()) ) { |
573 | return t1; |
574 | } |
575 | else if( g_isnan(t2->getf()) ) { |
576 | return t2; |
577 | } |
578 | else { |
579 | return Type::FLOAT; |
580 | } |
581 | } |
582 | |
583 | //============================================================================= |
584 | //------------------------------Ideal------------------------------------------ |
585 | Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){ |
586 | const Type *t2 = phase->type( in(2) ); |
587 | // Convert "x-c0" into "x+ -c0". |
588 | if( t2->base() == Type::DoubleCon ) { // Might be bottom or top... |
589 | // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) ); |
590 | } |
591 | |
592 | // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes |
593 | // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0. |
594 | //if( phase->type(in(1)) == TypeD::ZERO ) |
595 | //return new (phase->C, 2) NegDNode(in(2)); |
596 | |
597 | return NULL__null; |
598 | } |
599 | |
600 | //------------------------------sub-------------------------------------------- |
601 | // A subtract node differences its two inputs. |
602 | const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const { |
603 | // no folding if one of operands is infinity or NaN, do not do constant folding |
604 | if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) { |
605 | return TypeD::make( t1->getd() - t2->getd() ); |
606 | } |
607 | else if( g_isnan(t1->getd()) ) { |
608 | return t1; |
609 | } |
610 | else if( g_isnan(t2->getd()) ) { |
611 | return t2; |
612 | } |
613 | else { |
614 | return Type::DOUBLE; |
615 | } |
616 | } |
617 | |
618 | //============================================================================= |
619 | //------------------------------Idealize--------------------------------------- |
620 | // Unlike SubNodes, compare must still flatten return value to the |
621 | // range -1, 0, 1. |
622 | // And optimizations like those for (X + Y) - X fail if overflow happens. |
623 | Node* CmpNode::Identity(PhaseGVN* phase) { |
624 | return this; |
625 | } |
626 | |
627 | #ifndef PRODUCT |
628 | //----------------------------related------------------------------------------ |
629 | // Related nodes of comparison nodes include all data inputs (until hitting a |
630 | // control boundary) as well as all outputs until and including control nodes |
631 | // as well as their projections. In compact mode, data inputs till depth 1 and |
632 | // all outputs till depth 1 are considered. |
633 | void CmpNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const { |
634 | if (compact) { |
635 | this->collect_nodes(in_rel, 1, false, true); |
636 | this->collect_nodes(out_rel, -1, false, false); |
637 | } else { |
638 | this->collect_nodes_in_all_data(in_rel, false); |
639 | this->collect_nodes_out_all_ctrl_boundary(out_rel); |
640 | // Now, find all control nodes in out_rel, and include their projections |
641 | // and projection targets (if any) in the result. |
642 | GrowableArray<Node*> proj(Compile::current()->unique()); |
643 | for (GrowableArrayIterator<Node*> it = out_rel->begin(); it != out_rel->end(); ++it) { |
644 | Node* n = *it; |
645 | if (n->is_CFG() && !n->is_Proj()) { |
646 | // Assume projections and projection targets are found at levels 1 and 2. |
647 | n->collect_nodes(&proj, -2, false, false); |
648 | for (GrowableArrayIterator<Node*> p = proj.begin(); p != proj.end(); ++p) { |
649 | out_rel->append_if_missing(*p); |
650 | } |
651 | proj.clear(); |
652 | } |
653 | } |
654 | } |
655 | } |
656 | |
657 | #endif |
658 | |
659 | CmpNode *CmpNode::make(Node *in1, Node *in2, BasicType bt, bool unsigned_comp) { |
660 | switch (bt) { |
661 | case T_INT: |
662 | if (unsigned_comp) { |
663 | return new CmpUNode(in1, in2); |
664 | } |
665 | return new CmpINode(in1, in2); |
666 | case T_LONG: |
667 | if (unsigned_comp) { |
668 | return new CmpULNode(in1, in2); |
669 | } |
670 | return new CmpLNode(in1, in2); |
671 | default: |
672 | fatal("Not implemented for %s", type2name(bt))do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 672, "Not implemented for %s", type2name(bt)); ::breakpoint (); } while (0); |
673 | } |
674 | return NULL__null; |
675 | } |
676 | |
677 | //============================================================================= |
678 | //------------------------------cmp-------------------------------------------- |
679 | // Simplify a CmpI (compare 2 integers) node, based on local information. |
680 | // If both inputs are constants, compare them. |
681 | const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const { |
682 | const TypeInt *r0 = t1->is_int(); // Handy access |
683 | const TypeInt *r1 = t2->is_int(); |
684 | |
685 | if( r0->_hi < r1->_lo ) // Range is always low? |
686 | return TypeInt::CC_LT; |
687 | else if( r0->_lo > r1->_hi ) // Range is always high? |
688 | return TypeInt::CC_GT; |
689 | |
690 | else if( r0->is_con() && r1->is_con() ) { // comparing constants? |
691 | assert(r0->get_con() == r1->get_con(), "must be equal")do { if (!(r0->get_con() == r1->get_con())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 691, "assert(" "r0->get_con() == r1->get_con()" ") failed" , "must be equal"); ::breakpoint(); } } while (0); |
692 | return TypeInt::CC_EQ; // Equal results. |
693 | } else if( r0->_hi == r1->_lo ) // Range is never high? |
694 | return TypeInt::CC_LE; |
695 | else if( r0->_lo == r1->_hi ) // Range is never low? |
696 | return TypeInt::CC_GE; |
697 | return TypeInt::CC; // else use worst case results |
698 | } |
699 | |
700 | // Simplify a CmpU (compare 2 integers) node, based on local information. |
701 | // If both inputs are constants, compare them. |
702 | const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { |
703 | assert(!t1->isa_ptr(), "obsolete usage of CmpU")do { if (!(!t1->isa_ptr())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 703, "assert(" "!t1->isa_ptr()" ") failed", "obsolete usage of CmpU" ); ::breakpoint(); } } while (0); |
704 | |
705 | // comparing two unsigned ints |
706 | const TypeInt *r0 = t1->is_int(); // Handy access |
707 | const TypeInt *r1 = t2->is_int(); |
708 | |
709 | // Current installed version |
710 | // Compare ranges for non-overlap |
711 | juint lo0 = r0->_lo; |
712 | juint hi0 = r0->_hi; |
713 | juint lo1 = r1->_lo; |
714 | juint hi1 = r1->_hi; |
715 | |
716 | // If either one has both negative and positive values, |
717 | // it therefore contains both 0 and -1, and since [0..-1] is the |
718 | // full unsigned range, the type must act as an unsigned bottom. |
719 | bool bot0 = ((jint)(lo0 ^ hi0) < 0); |
720 | bool bot1 = ((jint)(lo1 ^ hi1) < 0); |
721 | |
722 | if (bot0 || bot1) { |
723 | // All unsigned values are LE -1 and GE 0. |
724 | if (lo0 == 0 && hi0 == 0) { |
725 | return TypeInt::CC_LE; // 0 <= bot |
726 | } else if ((jint)lo0 == -1 && (jint)hi0 == -1) { |
727 | return TypeInt::CC_GE; // -1 >= bot |
728 | } else if (lo1 == 0 && hi1 == 0) { |
729 | return TypeInt::CC_GE; // bot >= 0 |
730 | } else if ((jint)lo1 == -1 && (jint)hi1 == -1) { |
731 | return TypeInt::CC_LE; // bot <= -1 |
732 | } |
733 | } else { |
734 | // We can use ranges of the form [lo..hi] if signs are the same. |
735 | assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid")do { if (!(lo0 <= hi0 && lo1 <= hi1)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 735, "assert(" "lo0 <= hi0 && lo1 <= hi1" ") failed" , "unsigned ranges are valid"); ::breakpoint(); } } while (0); |
736 | // results are reversed, '-' > '+' for unsigned compare |
737 | if (hi0 < lo1) { |
738 | return TypeInt::CC_LT; // smaller |
739 | } else if (lo0 > hi1) { |
740 | return TypeInt::CC_GT; // greater |
741 | } else if (hi0 == lo1 && lo0 == hi1) { |
742 | return TypeInt::CC_EQ; // Equal results |
743 | } else if (lo0 >= hi1) { |
744 | return TypeInt::CC_GE; |
745 | } else if (hi0 <= lo1) { |
746 | // Check for special case in Hashtable::get. (See below.) |
747 | if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) |
748 | return TypeInt::CC_LT; |
749 | return TypeInt::CC_LE; |
750 | } |
751 | } |
752 | // Check for special case in Hashtable::get - the hash index is |
753 | // mod'ed to the table size so the following range check is useless. |
754 | // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have |
755 | // to be positive. |
756 | // (This is a gross hack, since the sub method never |
757 | // looks at the structure of the node in any other case.) |
758 | if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) |
759 | return TypeInt::CC_LT; |
760 | return TypeInt::CC; // else use worst case results |
761 | } |
762 | |
763 | const Type* CmpUNode::Value(PhaseGVN* phase) const { |
764 | const Type* t = SubNode::Value_common(phase); |
765 | if (t != NULL__null) { |
766 | return t; |
767 | } |
768 | const Node* in1 = in(1); |
769 | const Node* in2 = in(2); |
770 | const Type* t1 = phase->type(in1); |
771 | const Type* t2 = phase->type(in2); |
772 | assert(t1->isa_int(), "CmpU has only Int type inputs")do { if (!(t1->isa_int())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 772, "assert(" "t1->isa_int()" ") failed", "CmpU has only Int type inputs" ); ::breakpoint(); } } while (0); |
773 | if (t2 == TypeInt::INT) { // Compare to bottom? |
774 | return bottom_type(); |
775 | } |
776 | uint in1_op = in1->Opcode(); |
777 | if (in1_op == Op_AddI || in1_op == Op_SubI) { |
778 | // The problem rise when result of AddI(SubI) may overflow |
779 | // signed integer value. Let say the input type is |
780 | // [256, maxint] then +128 will create 2 ranges due to |
781 | // overflow: [minint, minint+127] and [384, maxint]. |
782 | // But C2 type system keep only 1 type range and as result |
783 | // it use general [minint, maxint] for this case which we |
784 | // can't optimize. |
785 | // |
786 | // Make 2 separate type ranges based on types of AddI(SubI) inputs |
787 | // and compare results of their compare. If results are the same |
788 | // CmpU node can be optimized. |
789 | const Node* in11 = in1->in(1); |
790 | const Node* in12 = in1->in(2); |
791 | const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11); |
792 | const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12); |
793 | // Skip cases when input types are top or bottom. |
794 | if ((t11 != Type::TOP) && (t11 != TypeInt::INT) && |
795 | (t12 != Type::TOP) && (t12 != TypeInt::INT)) { |
796 | const TypeInt *r0 = t11->is_int(); |
797 | const TypeInt *r1 = t12->is_int(); |
798 | jlong lo_r0 = r0->_lo; |
799 | jlong hi_r0 = r0->_hi; |
800 | jlong lo_r1 = r1->_lo; |
801 | jlong hi_r1 = r1->_hi; |
802 | if (in1_op == Op_SubI) { |
803 | jlong tmp = hi_r1; |
804 | hi_r1 = -lo_r1; |
805 | lo_r1 = -tmp; |
806 | // Note, for substructing [minint,x] type range |
807 | // long arithmetic provides correct overflow answer. |
808 | // The confusion come from the fact that in 32-bit |
809 | // -minint == minint but in 64-bit -minint == maxint+1. |
810 | } |
811 | jlong lo_long = lo_r0 + lo_r1; |
812 | jlong hi_long = hi_r0 + hi_r1; |
813 | int lo_tr1 = min_jint; |
814 | int hi_tr1 = (int)hi_long; |
815 | int lo_tr2 = (int)lo_long; |
816 | int hi_tr2 = max_jint; |
817 | bool underflow = lo_long != (jlong)lo_tr2; |
818 | bool overflow = hi_long != (jlong)hi_tr1; |
819 | // Use sub(t1, t2) when there is no overflow (one type range) |
820 | // or when both overflow and underflow (too complex). |
821 | if ((underflow != overflow) && (hi_tr1 < lo_tr2)) { |
822 | // Overflow only on one boundary, compare 2 separate type ranges. |
823 | int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here |
824 | const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w); |
825 | const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w); |
826 | const Type* cmp1 = sub(tr1, t2); |
827 | const Type* cmp2 = sub(tr2, t2); |
828 | if (cmp1 == cmp2) { |
829 | return cmp1; // Hit! |
830 | } |
831 | } |
832 | } |
833 | } |
834 | |
835 | return sub(t1, t2); // Local flavor of type subtraction |
836 | } |
837 | |
838 | bool CmpUNode::is_index_range_check() const { |
839 | // Check for the "(X ModI Y) CmpU Y" shape |
840 | return (in(1)->Opcode() == Op_ModI && |
841 | in(1)->in(2)->eqv_uncast(in(2))); |
842 | } |
843 | |
844 | //------------------------------Idealize--------------------------------------- |
845 | Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) { |
846 | if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) { |
847 | switch (in(1)->Opcode()) { |
848 | case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL |
849 | return new CmpLNode(in(1)->in(1),in(1)->in(2)); |
850 | case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF |
851 | return new CmpFNode(in(1)->in(1),in(1)->in(2)); |
852 | case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD |
853 | return new CmpDNode(in(1)->in(1),in(1)->in(2)); |
854 | //case Op_SubI: |
855 | // If (x - y) cannot overflow, then ((x - y) <?> 0) |
856 | // can be turned into (x <?> y). |
857 | // This is handled (with more general cases) by Ideal_sub_algebra. |
858 | } |
859 | } |
860 | return NULL__null; // No change |
861 | } |
862 | |
863 | Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) { |
864 | const TypeLong *t2 = phase->type(in(2))->isa_long(); |
865 | if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) { |
866 | const jlong con = t2->get_con(); |
867 | if (con >= min_jint && con <= max_jint) { |
868 | return new CmpINode(in(1)->in(1), phase->intcon((jint)con)); |
869 | } |
870 | } |
871 | return NULL__null; |
872 | } |
873 | |
874 | //============================================================================= |
875 | // Simplify a CmpL (compare 2 longs ) node, based on local information. |
876 | // If both inputs are constants, compare them. |
877 | const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { |
878 | const TypeLong *r0 = t1->is_long(); // Handy access |
879 | const TypeLong *r1 = t2->is_long(); |
880 | |
881 | if( r0->_hi < r1->_lo ) // Range is always low? |
882 | return TypeInt::CC_LT; |
883 | else if( r0->_lo > r1->_hi ) // Range is always high? |
884 | return TypeInt::CC_GT; |
885 | |
886 | else if( r0->is_con() && r1->is_con() ) { // comparing constants? |
887 | assert(r0->get_con() == r1->get_con(), "must be equal")do { if (!(r0->get_con() == r1->get_con())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 887, "assert(" "r0->get_con() == r1->get_con()" ") failed" , "must be equal"); ::breakpoint(); } } while (0); |
888 | return TypeInt::CC_EQ; // Equal results. |
889 | } else if( r0->_hi == r1->_lo ) // Range is never high? |
890 | return TypeInt::CC_LE; |
891 | else if( r0->_lo == r1->_hi ) // Range is never low? |
892 | return TypeInt::CC_GE; |
893 | return TypeInt::CC; // else use worst case results |
894 | } |
895 | |
896 | |
897 | // Simplify a CmpUL (compare 2 unsigned longs) node, based on local information. |
898 | // If both inputs are constants, compare them. |
899 | const Type* CmpULNode::sub(const Type* t1, const Type* t2) const { |
900 | assert(!t1->isa_ptr(), "obsolete usage of CmpUL")do { if (!(!t1->isa_ptr())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 900, "assert(" "!t1->isa_ptr()" ") failed", "obsolete usage of CmpUL" ); ::breakpoint(); } } while (0); |
901 | |
902 | // comparing two unsigned longs |
903 | const TypeLong* r0 = t1->is_long(); // Handy access |
904 | const TypeLong* r1 = t2->is_long(); |
905 | |
906 | // Current installed version |
907 | // Compare ranges for non-overlap |
908 | julong lo0 = r0->_lo; |
909 | julong hi0 = r0->_hi; |
910 | julong lo1 = r1->_lo; |
911 | julong hi1 = r1->_hi; |
912 | |
913 | // If either one has both negative and positive values, |
914 | // it therefore contains both 0 and -1, and since [0..-1] is the |
915 | // full unsigned range, the type must act as an unsigned bottom. |
916 | bool bot0 = ((jlong)(lo0 ^ hi0) < 0); |
917 | bool bot1 = ((jlong)(lo1 ^ hi1) < 0); |
918 | |
919 | if (bot0 || bot1) { |
920 | // All unsigned values are LE -1 and GE 0. |
921 | if (lo0 == 0 && hi0 == 0) { |
922 | return TypeInt::CC_LE; // 0 <= bot |
923 | } else if ((jlong)lo0 == -1 && (jlong)hi0 == -1) { |
924 | return TypeInt::CC_GE; // -1 >= bot |
925 | } else if (lo1 == 0 && hi1 == 0) { |
926 | return TypeInt::CC_GE; // bot >= 0 |
927 | } else if ((jlong)lo1 == -1 && (jlong)hi1 == -1) { |
928 | return TypeInt::CC_LE; // bot <= -1 |
929 | } |
930 | } else { |
931 | // We can use ranges of the form [lo..hi] if signs are the same. |
932 | assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid")do { if (!(lo0 <= hi0 && lo1 <= hi1)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 932, "assert(" "lo0 <= hi0 && lo1 <= hi1" ") failed" , "unsigned ranges are valid"); ::breakpoint(); } } while (0); |
933 | // results are reversed, '-' > '+' for unsigned compare |
934 | if (hi0 < lo1) { |
935 | return TypeInt::CC_LT; // smaller |
936 | } else if (lo0 > hi1) { |
937 | return TypeInt::CC_GT; // greater |
938 | } else if (hi0 == lo1 && lo0 == hi1) { |
939 | return TypeInt::CC_EQ; // Equal results |
940 | } else if (lo0 >= hi1) { |
941 | return TypeInt::CC_GE; |
942 | } else if (hi0 <= lo1) { |
943 | return TypeInt::CC_LE; |
944 | } |
945 | } |
946 | |
947 | return TypeInt::CC; // else use worst case results |
948 | } |
949 | |
950 | //============================================================================= |
951 | //------------------------------sub-------------------------------------------- |
952 | // Simplify an CmpP (compare 2 pointers) node, based on local information. |
953 | // If both inputs are constants, compare them. |
954 | const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { |
955 | const TypePtr *r0 = t1->is_ptr(); // Handy access |
956 | const TypePtr *r1 = t2->is_ptr(); |
957 | |
958 | // Undefined inputs makes for an undefined result |
959 | if( TypePtr::above_centerline(r0->_ptr) || |
960 | TypePtr::above_centerline(r1->_ptr) ) |
961 | return Type::TOP; |
962 | |
963 | if (r0 == r1 && r0->singleton()) { |
964 | // Equal pointer constants (klasses, nulls, etc.) |
965 | return TypeInt::CC_EQ; |
966 | } |
967 | |
968 | // See if it is 2 unrelated classes. |
969 | const TypeOopPtr* oop_p0 = r0->isa_oopptr(); |
970 | const TypeOopPtr* oop_p1 = r1->isa_oopptr(); |
971 | bool both_oop_ptr = oop_p0 && oop_p1; |
972 | |
973 | if (both_oop_ptr) { |
974 | Node* in1 = in(1)->uncast(); |
975 | Node* in2 = in(2)->uncast(); |
976 | AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL__null); |
977 | AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL__null); |
978 | if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL__null)) { |
979 | return TypeInt::CC_GT; // different pointers |
980 | } |
981 | } |
982 | |
983 | const TypeKlassPtr* klass_p0 = r0->isa_klassptr(); |
984 | const TypeKlassPtr* klass_p1 = r1->isa_klassptr(); |
985 | |
986 | if (both_oop_ptr || (klass_p0 && klass_p1)) { // both or neither are klass pointers |
987 | ciKlass* klass0 = NULL__null; |
988 | bool xklass0 = false; |
989 | ciKlass* klass1 = NULL__null; |
990 | bool xklass1 = false; |
991 | |
992 | if (oop_p0) { |
993 | klass0 = oop_p0->klass(); |
994 | xklass0 = oop_p0->klass_is_exact(); |
995 | } else { |
996 | assert(klass_p0, "must be non-null if oop_p0 is null")do { if (!(klass_p0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 996, "assert(" "klass_p0" ") failed", "must be non-null if oop_p0 is null" ); ::breakpoint(); } } while (0); |
997 | klass0 = klass_p0->klass(); |
998 | xklass0 = klass_p0->klass_is_exact(); |
999 | } |
1000 | |
1001 | if (oop_p1) { |
1002 | klass1 = oop_p1->klass(); |
1003 | xklass1 = oop_p1->klass_is_exact(); |
1004 | } else { |
1005 | assert(klass_p1, "must be non-null if oop_p1 is null")do { if (!(klass_p1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 1005, "assert(" "klass_p1" ") failed", "must be non-null if oop_p1 is null" ); ::breakpoint(); } } while (0); |
1006 | klass1 = klass_p1->klass(); |
1007 | xklass1 = klass_p1->klass_is_exact(); |
1008 | } |
1009 | |
1010 | if (klass0 && klass1 && |
1011 | klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces |
1012 | klass1->is_loaded() && !klass1->is_interface() && |
1013 | (!klass0->is_obj_array_klass() || |
1014 | !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) && |
1015 | (!klass1->is_obj_array_klass() || |
1016 | !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) { |
1017 | bool unrelated_classes = false; |
1018 | // See if neither subclasses the other, or if the class on top |
1019 | // is precise. In either of these cases, the compare is known |
1020 | // to fail if at least one of the pointers is provably not null. |
1021 | if (klass0->equals(klass1)) { // if types are unequal but klasses are equal |
1022 | // Do nothing; we know nothing for imprecise types |
1023 | } else if (klass0->is_subtype_of(klass1)) { |
1024 | // If klass1's type is PRECISE, then classes are unrelated. |
1025 | unrelated_classes = xklass1; |
1026 | } else if (klass1->is_subtype_of(klass0)) { |
1027 | // If klass0's type is PRECISE, then classes are unrelated. |
1028 | unrelated_classes = xklass0; |
1029 | } else { // Neither subtypes the other |
1030 | unrelated_classes = true; |
1031 | } |
1032 | if (unrelated_classes) { |
1033 | // The oops classes are known to be unrelated. If the joined PTRs of |
1034 | // two oops is not Null and not Bottom, then we are sure that one |
1035 | // of the two oops is non-null, and the comparison will always fail. |
1036 | TypePtr::PTR jp = r0->join_ptr(r1->_ptr); |
1037 | if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { |
1038 | return TypeInt::CC_GT; |
1039 | } |
1040 | } |
1041 | } |
1042 | } |
1043 | |
1044 | // Known constants can be compared exactly |
1045 | // Null can be distinguished from any NotNull pointers |
1046 | // Unknown inputs makes an unknown result |
1047 | if( r0->singleton() ) { |
1048 | intptr_t bits0 = r0->get_con(); |
1049 | if( r1->singleton() ) |
1050 | return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; |
1051 | return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; |
1052 | } else if( r1->singleton() ) { |
1053 | intptr_t bits1 = r1->get_con(); |
1054 | return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; |
1055 | } else |
1056 | return TypeInt::CC; |
1057 | } |
1058 | |
1059 | static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) { |
1060 | // Return the klass node for (indirect load from OopHandle) |
1061 | // LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror)))) |
1062 | // or NULL if not matching. |
1063 | BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); |
1064 | n = bs->step_over_gc_barrier(n); |
1065 | |
1066 | if (n->Opcode() != Op_LoadP) return NULL__null; |
1067 | |
1068 | const TypeInstPtr* tp = phase->type(n)->isa_instptr(); |
1069 | if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL__null; |
1070 | |
1071 | Node* adr = n->in(MemNode::Address); |
1072 | // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier. |
1073 | if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL__null; |
1074 | adr = adr->in(MemNode::Address); |
1075 | |
1076 | intptr_t off = 0; |
1077 | Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off); |
1078 | if (k == NULL__null) return NULL__null; |
1079 | const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr(); |
1080 | if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL__null; |
1081 | |
1082 | // We've found the klass node of a Java mirror load. |
1083 | return k; |
1084 | } |
1085 | |
1086 | static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) { |
1087 | // for ConP(Foo.class) return ConP(Foo.klass) |
1088 | // otherwise return NULL |
1089 | if (!n->is_Con()) return NULL__null; |
1090 | |
1091 | const TypeInstPtr* tp = phase->type(n)->isa_instptr(); |
1092 | if (!tp) return NULL__null; |
1093 | |
1094 | ciType* mirror_type = tp->java_mirror_type(); |
1095 | // TypeInstPtr::java_mirror_type() returns non-NULL for compile- |
1096 | // time Class constants only. |
1097 | if (!mirror_type) return NULL__null; |
1098 | |
1099 | // x.getClass() == int.class can never be true (for all primitive types) |
1100 | // Return a ConP(NULL) node for this case. |
1101 | if (mirror_type->is_classless()) { |
1102 | return phase->makecon(TypePtr::NULL_PTR); |
1103 | } |
1104 | |
1105 | // return the ConP(Foo.klass) |
1106 | assert(mirror_type->is_klass(), "mirror_type should represent a Klass*")do { if (!(mirror_type->is_klass())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 1106, "assert(" "mirror_type->is_klass()" ") failed", "mirror_type should represent a Klass*" ); ::breakpoint(); } } while (0); |
1107 | return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass())); |
1108 | } |
1109 | |
1110 | //------------------------------Ideal------------------------------------------ |
1111 | // Normalize comparisons between Java mirror loads to compare the klass instead. |
1112 | // |
1113 | // Also check for the case of comparing an unknown klass loaded from the primary |
1114 | // super-type array vs a known klass with no subtypes. This amounts to |
1115 | // checking to see an unknown klass subtypes a known klass with no subtypes; |
1116 | // this only happens on an exact match. We can shorten this test by 1 load. |
1117 | Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) { |
1118 | // Normalize comparisons between Java mirrors into comparisons of the low- |
1119 | // level klass, where a dependent load could be shortened. |
1120 | // |
1121 | // The new pattern has a nice effect of matching the same pattern used in the |
1122 | // fast path of instanceof/checkcast/Class.isInstance(), which allows |
1123 | // redundant exact type check be optimized away by GVN. |
1124 | // For example, in |
1125 | // if (x.getClass() == Foo.class) { |
1126 | // Foo foo = (Foo) x; |
1127 | // // ... use a ... |
1128 | // } |
1129 | // a CmpPNode could be shared between if_acmpne and checkcast |
1130 | { |
1131 | Node* k1 = isa_java_mirror_load(phase, in(1)); |
1132 | Node* k2 = isa_java_mirror_load(phase, in(2)); |
1133 | Node* conk2 = isa_const_java_mirror(phase, in(2)); |
1134 | |
1135 | if (k1 && (k2 || conk2)) { |
1136 | Node* lhs = k1; |
1137 | Node* rhs = (k2 != NULL__null) ? k2 : conk2; |
1138 | set_req_X(1, lhs, phase); |
1139 | set_req_X(2, rhs, phase); |
1140 | return this; |
1141 | } |
1142 | } |
1143 | |
1144 | // Constant pointer on right? |
1145 | const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr(); |
1146 | if (t2 == NULL__null || !t2->klass_is_exact()) |
1147 | return NULL__null; |
1148 | // Get the constant klass we are comparing to. |
1149 | ciKlass* superklass = t2->klass(); |
1150 | |
1151 | // Now check for LoadKlass on left. |
1152 | Node* ldk1 = in(1); |
1153 | if (ldk1->is_DecodeNKlass()) { |
1154 | ldk1 = ldk1->in(1); |
1155 | if (ldk1->Opcode() != Op_LoadNKlass ) |
1156 | return NULL__null; |
1157 | } else if (ldk1->Opcode() != Op_LoadKlass ) |
1158 | return NULL__null; |
1159 | // Take apart the address of the LoadKlass: |
1160 | Node* adr1 = ldk1->in(MemNode::Address); |
1161 | intptr_t con2 = 0; |
1162 | Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2); |
1163 | if (ldk2 == NULL__null) |
1164 | return NULL__null; |
1165 | if (con2 == oopDesc::klass_offset_in_bytes()) { |
1166 | // We are inspecting an object's concrete class. |
1167 | // Short-circuit the check if the query is abstract. |
1168 | if (superklass->is_interface() || |
1169 | superklass->is_abstract()) { |
1170 | // Make it come out always false: |
1171 | this->set_req(2, phase->makecon(TypePtr::NULL_PTR)); |
1172 | return this; |
1173 | } |
1174 | } |
1175 | |
1176 | // Check for a LoadKlass from primary supertype array. |
1177 | // Any nested loadklass from loadklass+con must be from the p.s. array. |
1178 | if (ldk2->is_DecodeNKlass()) { |
1179 | // Keep ldk2 as DecodeN since it could be used in CmpP below. |
1180 | if (ldk2->in(1)->Opcode() != Op_LoadNKlass ) |
1181 | return NULL__null; |
1182 | } else if (ldk2->Opcode() != Op_LoadKlass) |
1183 | return NULL__null; |
1184 | |
1185 | // Verify that we understand the situation |
1186 | if (con2 != (intptr_t) superklass->super_check_offset()) |
1187 | return NULL__null; // Might be element-klass loading from array klass |
1188 | |
1189 | // If 'superklass' has no subklasses and is not an interface, then we are |
1190 | // assured that the only input which will pass the type check is |
1191 | // 'superklass' itself. |
1192 | // |
1193 | // We could be more liberal here, and allow the optimization on interfaces |
1194 | // which have a single implementor. This would require us to increase the |
1195 | // expressiveness of the add_dependency() mechanism. |
1196 | // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. |
1197 | |
1198 | // Object arrays must have their base element have no subtypes |
1199 | while (superklass->is_obj_array_klass()) { |
1200 | ciType* elem = superklass->as_obj_array_klass()->element_type(); |
1201 | superklass = elem->as_klass(); |
1202 | } |
1203 | if (superklass->is_instance_klass()) { |
1204 | ciInstanceKlass* ik = superklass->as_instance_klass(); |
1205 | if (ik->has_subklass() || ik->is_interface()) return NULL__null; |
1206 | // Add a dependency if there is a chance that a subclass will be added later. |
1207 | if (!ik->is_final()) { |
1208 | phase->C->dependencies()->assert_leaf_type(ik); |
1209 | } |
1210 | } |
1211 | |
1212 | // Bypass the dependent load, and compare directly |
1213 | this->set_req(1,ldk2); |
1214 | |
1215 | return this; |
1216 | } |
1217 | |
1218 | //============================================================================= |
1219 | //------------------------------sub-------------------------------------------- |
1220 | // Simplify an CmpN (compare 2 pointers) node, based on local information. |
1221 | // If both inputs are constants, compare them. |
1222 | const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { |
1223 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 1223); ::breakpoint(); } while (0); |
1224 | return bottom_type(); |
1225 | } |
1226 | |
1227 | //------------------------------Ideal------------------------------------------ |
1228 | Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) { |
1229 | return NULL__null; |
1230 | } |
1231 | |
1232 | //============================================================================= |
1233 | //------------------------------Value------------------------------------------ |
1234 | // Simplify an CmpF (compare 2 floats ) node, based on local information. |
1235 | // If both inputs are constants, compare them. |
1236 | const Type* CmpFNode::Value(PhaseGVN* phase) const { |
1237 | const Node* in1 = in(1); |
1238 | const Node* in2 = in(2); |
1239 | // Either input is TOP ==> the result is TOP |
1240 | const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); |
1241 | if( t1 == Type::TOP ) return Type::TOP; |
1242 | const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); |
1243 | if( t2 == Type::TOP ) return Type::TOP; |
1244 | |
1245 | // Not constants? Don't know squat - even if they are the same |
1246 | // value! If they are NaN's they compare to LT instead of EQ. |
1247 | const TypeF *tf1 = t1->isa_float_constant(); |
1248 | const TypeF *tf2 = t2->isa_float_constant(); |
1249 | if( !tf1 || !tf2 ) return TypeInt::CC; |
1250 | |
1251 | // This implements the Java bytecode fcmpl, so unordered returns -1. |
1252 | if( tf1->is_nan() || tf2->is_nan() ) |
1253 | return TypeInt::CC_LT; |
1254 | |
1255 | if( tf1->_f < tf2->_f ) return TypeInt::CC_LT; |
1256 | if( tf1->_f > tf2->_f ) return TypeInt::CC_GT; |
1257 | assert( tf1->_f == tf2->_f, "do not understand FP behavior" )do { if (!(tf1->_f == tf2->_f)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 1257, "assert(" "tf1->_f == tf2->_f" ") failed", "do not understand FP behavior" ); ::breakpoint(); } } while (0); |
1258 | return TypeInt::CC_EQ; |
1259 | } |
1260 | |
1261 | |
1262 | //============================================================================= |
1263 | //------------------------------Value------------------------------------------ |
1264 | // Simplify an CmpD (compare 2 doubles ) node, based on local information. |
1265 | // If both inputs are constants, compare them. |
1266 | const Type* CmpDNode::Value(PhaseGVN* phase) const { |
1267 | const Node* in1 = in(1); |
1268 | const Node* in2 = in(2); |
1269 | // Either input is TOP ==> the result is TOP |
1270 | const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); |
1271 | if( t1 == Type::TOP ) return Type::TOP; |
1272 | const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); |
1273 | if( t2 == Type::TOP ) return Type::TOP; |
1274 | |
1275 | // Not constants? Don't know squat - even if they are the same |
1276 | // value! If they are NaN's they compare to LT instead of EQ. |
1277 | const TypeD *td1 = t1->isa_double_constant(); |
1278 | const TypeD *td2 = t2->isa_double_constant(); |
1279 | if( !td1 || !td2 ) return TypeInt::CC; |
1280 | |
1281 | // This implements the Java bytecode dcmpl, so unordered returns -1. |
1282 | if( td1->is_nan() || td2->is_nan() ) |
1283 | return TypeInt::CC_LT; |
1284 | |
1285 | if( td1->_d < td2->_d ) return TypeInt::CC_LT; |
1286 | if( td1->_d > td2->_d ) return TypeInt::CC_GT; |
1287 | assert( td1->_d == td2->_d, "do not understand FP behavior" )do { if (!(td1->_d == td2->_d)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/subnode.cpp" , 1287, "assert(" "td1->_d == td2->_d" ") failed", "do not understand FP behavior" ); ::breakpoint(); } } while (0); |
1288 | return TypeInt::CC_EQ; |
1289 | } |
1290 | |
1291 | //------------------------------Ideal------------------------------------------ |
1292 | Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){ |
1293 | // Check if we can change this to a CmpF and remove a ConvD2F operation. |
1294 | // Change (CMPD (F2D (float)) (ConD value)) |
1295 | // To (CMPF (float) (ConF value)) |
1296 | // Valid when 'value' does not lose precision as a float. |
1297 | // Benefits: eliminates conversion, does not require 24-bit mode |
1298 | |
1299 | // NaNs prevent commuting operands. This transform works regardless of the |
1300 | // order of ConD and ConvF2D inputs by preserving the original order. |
1301 | int idx_f2d = 1; // ConvF2D on left side? |
1302 | if( in(idx_f2d)->Opcode() != Op_ConvF2D ) |
1303 | idx_f2d = 2; // No, swap to check for reversed args |
1304 | int idx_con = 3-idx_f2d; // Check for the constant on other input |
1305 | |
1306 | if( ConvertCmpD2CmpF && |
1307 | in(idx_f2d)->Opcode() == Op_ConvF2D && |
1308 | in(idx_con)->Opcode() == Op_ConD ) { |
1309 | const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant(); |
1310 | double t2_value_as_double = t2->_d; |
1311 | float t2_value_as_float = (float)t2_value_as_double; |
1312 | if( t2_value_as_double == (double)t2_value_as_float ) { |
1313 | // Test value can be represented as a float |
1314 | // Eliminate the conversion to double and create new comparison |
1315 | Node *new_in1 = in(idx_f2d)->in(1); |
1316 | Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) ); |
1317 | if( idx_f2d != 1 ) { // Must flip args to match original order |
1318 | Node *tmp = new_in1; |
1319 | new_in1 = new_in2; |
1320 | new_in2 = tmp; |
1321 | } |
1322 | CmpFNode *new_cmp = (Opcode() == Op_CmpD3) |
1323 | ? new CmpF3Node( new_in1, new_in2 ) |
1324 | : new CmpFNode ( new_in1, new_in2 ) ; |
1325 | return new_cmp; // Changed to CmpFNode |
1326 | } |
1327 | // Testing value required the precision of a double |
1328 | } |
1329 | return NULL__null; // No change |
1330 | } |
1331 | |
1332 | |
1333 | //============================================================================= |
1334 | //------------------------------cc2logical------------------------------------- |
1335 | // Convert a condition code type to a logical type |
1336 | const Type *BoolTest::cc2logical( const Type *CC ) const { |
1337 | if( CC == Type::TOP ) return Type::TOP; |
1338 | if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse |
1339 | const TypeInt *ti = CC->is_int(); |
1340 | if( ti->is_con() ) { // Only 1 kind of condition codes set? |
1341 | // Match low order 2 bits |
1342 | int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0; |
1343 | if( _test & 4 ) tmp = 1-tmp; // Optionally complement result |
1344 | return TypeInt::make(tmp); // Boolean result |
1345 | } |
1346 | |
1347 | if( CC == TypeInt::CC_GE ) { |
1348 | if( _test == ge ) return TypeInt::ONE; |
1349 | if( _test == lt ) return TypeInt::ZERO; |
1350 | } |
1351 | if( CC == TypeInt::CC_LE ) { |
1352 | if( _test == le ) return TypeInt::ONE; |
1353 | if( _test == gt ) return TypeInt::ZERO; |
1354 | } |
1355 | |
1356 | return TypeInt::BOOL; |
1357 | } |
1358 | |
1359 | //------------------------------dump_spec------------------------------------- |
1360 | // Print special per-node info |
1361 | void BoolTest::dump_on(outputStream *st) const { |
1362 | const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"}; |
1363 | st->print("%s", msg[_test]); |
1364 | } |
1365 | |
1366 | // Returns the logical AND of two tests (or 'never' if both tests can never be true). |
1367 | // For example, a test for 'le' followed by a test for 'lt' is equivalent with 'lt'. |
1368 | BoolTest::mask BoolTest::merge(BoolTest other) const { |
1369 | const mask res[illegal+1][illegal+1] = { |
1370 | // eq, gt, of, lt, ne, le, nof, ge, never, illegal |
1371 | {eq, never, illegal, never, never, eq, illegal, eq, never, illegal}, // eq |
1372 | {never, gt, illegal, never, gt, never, illegal, gt, never, illegal}, // gt |
1373 | {illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, never, illegal}, // of |
1374 | {never, never, illegal, lt, lt, lt, illegal, never, never, illegal}, // lt |
1375 | {never, gt, illegal, lt, ne, lt, illegal, gt, never, illegal}, // ne |
1376 | {eq, never, illegal, lt, lt, le, illegal, eq, never, illegal}, // le |
1377 | {illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, never, illegal}, // nof |
1378 | {eq, gt, illegal, never, gt, eq, illegal, ge, never, illegal}, // ge |
1379 | {never, never, never, never, never, never, never, never, never, illegal}, // never |
1380 | {illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal}}; // illegal |
1381 | return res[_test][other._test]; |
1382 | } |
1383 | |
1384 | //============================================================================= |
1385 | uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); } |
1386 | uint BoolNode::size_of() const { return sizeof(BoolNode); } |
1387 | |
1388 | //------------------------------operator==------------------------------------- |
1389 | bool BoolNode::cmp( const Node &n ) const { |
1390 | const BoolNode *b = (const BoolNode *)&n; // Cast up |
1391 | return (_test._test == b->_test._test); |
1392 | } |
1393 | |
1394 | //-------------------------------make_predicate-------------------------------- |
1395 | Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) { |
1396 | if (test_value->is_Con()) return test_value; |
1397 | if (test_value->is_Bool()) return test_value; |
1398 | if (test_value->is_CMove() && |
1399 | test_value->in(CMoveNode::Condition)->is_Bool()) { |
1400 | BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool(); |
1401 | const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse)); |
1402 | const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue)); |
1403 | if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) { |
1404 | return bol; |
1405 | } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) { |
1406 | return phase->transform( bol->negate(phase) ); |
1407 | } |
1408 | // Else fall through. The CMove gets in the way of the test. |
1409 | // It should be the case that make_predicate(bol->as_int_value()) == bol. |
1410 | } |
1411 | Node* cmp = new CmpINode(test_value, phase->intcon(0)); |
1412 | cmp = phase->transform(cmp); |
1413 | Node* bol = new BoolNode(cmp, BoolTest::ne); |
1414 | return phase->transform(bol); |
1415 | } |
1416 | |
1417 | //--------------------------------as_int_value--------------------------------- |
1418 | Node* BoolNode::as_int_value(PhaseGVN* phase) { |
1419 | // Inverse to make_predicate. The CMove probably boils down to a Conv2B. |
1420 | Node* cmov = CMoveNode::make(NULL__null, this, |
1421 | phase->intcon(0), phase->intcon(1), |
1422 | TypeInt::BOOL); |
1423 | return phase->transform(cmov); |
1424 | } |
1425 | |
1426 | //----------------------------------negate------------------------------------- |
1427 | BoolNode* BoolNode::negate(PhaseGVN* phase) { |
1428 | return new BoolNode(in(1), _test.negate()); |
1429 | } |
1430 | |
1431 | // Change "bool eq/ne (cmp (add/sub A B) C)" into false/true if add/sub |
1432 | // overflows and we can prove that C is not in the two resulting ranges. |
1433 | // This optimization is similar to the one performed by CmpUNode::Value(). |
1434 | Node* BoolNode::fold_cmpI(PhaseGVN* phase, SubNode* cmp, Node* cmp1, int cmp_op, |
1435 | int cmp1_op, const TypeInt* cmp2_type) { |
1436 | // Only optimize eq/ne integer comparison of add/sub |
1437 | if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && |
1438 | (cmp_op == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) { |
1439 | // Skip cases were inputs of add/sub are not integers or of bottom type |
1440 | const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int(); |
1441 | const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int(); |
1442 | if ((r0 != NULL__null) && (r0 != TypeInt::INT) && |
1443 | (r1 != NULL__null) && (r1 != TypeInt::INT) && |
1444 | (cmp2_type != TypeInt::INT)) { |
1445 | // Compute exact (long) type range of add/sub result |
1446 | jlong lo_long = r0->_lo; |
1447 | jlong hi_long = r0->_hi; |
1448 | if (cmp1_op == Op_AddI) { |
1449 | lo_long += r1->_lo; |
1450 | hi_long += r1->_hi; |
1451 | } else { |
1452 | lo_long -= r1->_hi; |
1453 | hi_long -= r1->_lo; |
1454 | } |
1455 | // Check for over-/underflow by casting to integer |
1456 | int lo_int = (int)lo_long; |
1457 | int hi_int = (int)hi_long; |
1458 | bool underflow = lo_long != (jlong)lo_int; |
1459 | bool overflow = hi_long != (jlong)hi_int; |
1460 | if ((underflow != overflow) && (hi_int < lo_int)) { |
1461 | // Overflow on one boundary, compute resulting type ranges: |
1462 | // tr1 [MIN_INT, hi_int] and tr2 [lo_int, MAX_INT] |
1463 | int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here |
1464 | const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w); |
1465 | const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w); |
1466 | // Compare second input of cmp to both type ranges |
1467 | const Type* sub_tr1 = cmp->sub(tr1, cmp2_type); |
1468 | const Type* sub_tr2 = cmp->sub(tr2, cmp2_type); |
1469 | if (sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) { |
1470 | // The result of the add/sub will never equal cmp2. Replace BoolNode |
1471 | // by false (0) if it tests for equality and by true (1) otherwise. |
1472 | return ConINode::make((_test._test == BoolTest::eq) ? 0 : 1); |
1473 | } |
1474 | } |
1475 | } |
1476 | } |
1477 | return NULL__null; |
1478 | } |
1479 | |
1480 | static bool is_counted_loop_cmp(Node *cmp) { |
1481 | Node *n = cmp->in(1)->in(1); |
1482 | return n != NULL__null && |
1483 | n->is_Phi() && |
1484 | n->in(0) != NULL__null && |
1485 | n->in(0)->is_CountedLoop() && |
1486 | n->in(0)->as_CountedLoop()->phi() == n; |
1487 | } |
1488 | |
1489 | //------------------------------Ideal------------------------------------------ |
1490 | Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
1491 | // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)". |
1492 | // This moves the constant to the right. Helps value-numbering. |
1493 | Node *cmp = in(1); |
1494 | if( !cmp->is_Sub() ) return NULL__null; |
1495 | int cop = cmp->Opcode(); |
1496 | if( cop == Op_FastLock || cop == Op_FastUnlock || cmp->is_SubTypeCheck()) return NULL__null; |
1497 | Node *cmp1 = cmp->in(1); |
1498 | Node *cmp2 = cmp->in(2); |
1499 | if( !cmp1 ) return NULL__null; |
1500 | |
1501 | if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) { |
1502 | return NULL__null; |
1503 | } |
1504 | |
1505 | const int cmp1_op = cmp1->Opcode(); |
1506 | const int cmp2_op = cmp2->Opcode(); |
1507 | |
1508 | // Constant on left? |
1509 | Node *con = cmp1; |
1510 | // Move constants to the right of compare's to canonicalize. |
1511 | // Do not muck with Opaque1 nodes, as this indicates a loop |
1512 | // guard that cannot change shape. |
1513 | if( con->is_Con() && !cmp2->is_Con() && cmp2_op != Op_Opaque1 && |
1514 | // Because of NaN's, CmpD and CmpF are not commutative |
1515 | cop != Op_CmpD && cop != Op_CmpF && |
1516 | // Protect against swapping inputs to a compare when it is used by a |
1517 | // counted loop exit, which requires maintaining the loop-limit as in(2) |
1518 | !is_counted_loop_exit_test() ) { |
1519 | // Ok, commute the constant to the right of the cmp node. |
1520 | // Clone the Node, getting a new Node of the same class |
1521 | cmp = cmp->clone(); |
1522 | // Swap inputs to the clone |
1523 | cmp->swap_edges(1, 2); |
1524 | cmp = phase->transform( cmp ); |
1525 | return new BoolNode( cmp, _test.commute() ); |
1526 | } |
1527 | |
1528 | // Change "bool eq/ne (cmp (and X 16) 16)" into "bool ne/eq (cmp (and X 16) 0)". |
1529 | if (cop == Op_CmpI && |
1530 | (_test._test == BoolTest::eq || _test._test == BoolTest::ne) && |
1531 | cmp1_op == Op_AndI && cmp2_op == Op_ConI && |
1532 | cmp1->in(2)->Opcode() == Op_ConI) { |
1533 | const TypeInt *t12 = phase->type(cmp2)->isa_int(); |
1534 | const TypeInt *t112 = phase->type(cmp1->in(2))->isa_int(); |
1535 | if (t12 && t12->is_con() && t112 && t112->is_con() && |
1536 | t12->get_con() == t112->get_con() && is_power_of_2(t12->get_con())) { |
1537 | Node *ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0))); |
1538 | return new BoolNode(ncmp, _test.negate()); |
1539 | } |
1540 | } |
1541 | |
1542 | // Same for long type: change "bool eq/ne (cmp (and X 16) 16)" into "bool ne/eq (cmp (and X 16) 0)". |
1543 | if (cop == Op_CmpL && |
1544 | (_test._test == BoolTest::eq || _test._test == BoolTest::ne) && |
1545 | cmp1_op == Op_AndL && cmp2_op == Op_ConL && |
1546 | cmp1->in(2)->Opcode() == Op_ConL) { |
1547 | const TypeLong *t12 = phase->type(cmp2)->isa_long(); |
1548 | const TypeLong *t112 = phase->type(cmp1->in(2))->isa_long(); |
1549 | if (t12 && t12->is_con() && t112 && t112->is_con() && |
1550 | t12->get_con() == t112->get_con() && is_power_of_2(t12->get_con())) { |
1551 | Node *ncmp = phase->transform(new CmpLNode(cmp1, phase->longcon(0))); |
1552 | return new BoolNode(ncmp, _test.negate()); |
1553 | } |
1554 | } |
1555 | |
1556 | // Change "cmp (add X min_jint) (add Y min_jint)" into "cmpu X Y" |
1557 | // and "cmp (add X min_jint) c" into "cmpu X (c + min_jint)" |
1558 | if (cop == Op_CmpI && |
1559 | cmp1_op == Op_AddI && |
1560 | phase->type(cmp1->in(2)) == TypeInt::MIN) { |
1561 | if (cmp2_op == Op_ConI) { |
1562 | Node* ncmp2 = phase->intcon(java_add(cmp2->get_int(), min_jint)); |
1563 | Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), ncmp2)); |
1564 | return new BoolNode(ncmp, _test._test); |
1565 | } else if (cmp2_op == Op_AddI && |
1566 | phase->type(cmp2->in(2)) == TypeInt::MIN) { |
1567 | Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), cmp2->in(1))); |
1568 | return new BoolNode(ncmp, _test._test); |
1569 | } |
1570 | } |
1571 | |
1572 | // Change "cmp (add X min_jlong) (add Y min_jlong)" into "cmpu X Y" |
1573 | // and "cmp (add X min_jlong) c" into "cmpu X (c + min_jlong)" |
1574 | if (cop == Op_CmpL && |
1575 | cmp1_op == Op_AddL && |
1576 | phase->type(cmp1->in(2)) == TypeLong::MIN) { |
1577 | if (cmp2_op == Op_ConL) { |
1578 | Node* ncmp2 = phase->longcon(java_add(cmp2->get_long(), min_jlong)); |
1579 | Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), ncmp2)); |
1580 | return new BoolNode(ncmp, _test._test); |
1581 | } else if (cmp2_op == Op_AddL && |
1582 | phase->type(cmp2->in(2)) == TypeLong::MIN) { |
1583 | Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), cmp2->in(1))); |
1584 | return new BoolNode(ncmp, _test._test); |
1585 | } |
1586 | } |
1587 | |
1588 | // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)". |
1589 | // The XOR-1 is an idiom used to flip the sense of a bool. We flip the |
1590 | // test instead. |
1591 | const TypeInt* cmp2_type = phase->type(cmp2)->isa_int(); |
1592 | if (cmp2_type == NULL__null) return NULL__null; |
1593 | Node* j_xor = cmp1; |
1594 | if( cmp2_type == TypeInt::ZERO && |
1595 | cmp1_op == Op_XorI && |
1596 | j_xor->in(1) != j_xor && // An xor of itself is dead |
1597 | phase->type( j_xor->in(1) ) == TypeInt::BOOL && |
1598 | phase->type( j_xor->in(2) ) == TypeInt::ONE && |
1599 | (_test._test == BoolTest::eq || |
1600 | _test._test == BoolTest::ne) ) { |
1601 | Node *ncmp = phase->transform(new CmpINode(j_xor->in(1),cmp2)); |
1602 | return new BoolNode( ncmp, _test.negate() ); |
1603 | } |
1604 | |
1605 | // Change ((x & m) u<= m) or ((m & x) u<= m) to always true |
1606 | // Same with ((x & m) u< m+1) and ((m & x) u< m+1) |
1607 | if (cop == Op_CmpU && |
1608 | cmp1_op == Op_AndI) { |
1609 | Node* bound = NULL__null; |
1610 | if (_test._test == BoolTest::le) { |
1611 | bound = cmp2; |
1612 | } else if (_test._test == BoolTest::lt && |
1613 | cmp2->Opcode() == Op_AddI && |
1614 | cmp2->in(2)->find_int_con(0) == 1) { |
1615 | bound = cmp2->in(1); |
1616 | } |
1617 | if (cmp1->in(2) == bound || cmp1->in(1) == bound) { |
1618 | return ConINode::make(1); |
1619 | } |
1620 | } |
1621 | |
1622 | // Change ((x & (m - 1)) u< m) into (m > 0) |
1623 | // This is the off-by-one variant of the above |
1624 | if (cop == Op_CmpU && |
1625 | _test._test == BoolTest::lt && |
1626 | cmp1_op == Op_AndI) { |
1627 | Node* l = cmp1->in(1); |
1628 | Node* r = cmp1->in(2); |
1629 | for (int repeat = 0; repeat < 2; repeat++) { |
1630 | bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 && |
1631 | r->in(1) == cmp2; |
1632 | if (match) { |
1633 | // arraylength known to be non-negative, so a (arraylength != 0) is sufficient, |
1634 | // but to be compatible with the array range check pattern, use (arraylength u> 0) |
1635 | Node* ncmp = cmp2->Opcode() == Op_LoadRange |
1636 | ? phase->transform(new CmpUNode(cmp2, phase->intcon(0))) |
1637 | : phase->transform(new CmpINode(cmp2, phase->intcon(0))); |
1638 | return new BoolNode(ncmp, BoolTest::gt); |
1639 | } else { |
1640 | // commute and try again |
1641 | l = cmp1->in(2); |
Value stored to 'l' is never read | |
1642 | r = cmp1->in(1); |
1643 | } |
1644 | } |
1645 | } |
1646 | |
1647 | // Change x u< 1 or x u<= 0 to x == 0 |
1648 | if (cop == Op_CmpU && |
1649 | cmp1_op != Op_LoadRange && |
1650 | ((_test._test == BoolTest::lt && |
1651 | cmp2->find_int_con(-1) == 1) || |
1652 | (_test._test == BoolTest::le && |
1653 | cmp2->find_int_con(-1) == 0))) { |
1654 | Node* ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0))); |
1655 | return new BoolNode(ncmp, BoolTest::eq); |
1656 | } |
1657 | |
1658 | // Change (arraylength <= 0) or (arraylength == 0) |
1659 | // into (arraylength u<= 0) |
1660 | // Also change (arraylength != 0) into (arraylength u> 0) |
1661 | // The latter version matches the code pattern generated for |
1662 | // array range checks, which will more likely be optimized later. |
1663 | if (cop == Op_CmpI && |
1664 | cmp1_op == Op_LoadRange && |
1665 | cmp2->find_int_con(-1) == 0) { |
1666 | if (_test._test == BoolTest::le || _test._test == BoolTest::eq) { |
1667 | Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2)); |
1668 | return new BoolNode(ncmp, BoolTest::le); |
1669 | } else if (_test._test == BoolTest::ne) { |
1670 | Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2)); |
1671 | return new BoolNode(ncmp, BoolTest::gt); |
1672 | } |
1673 | } |
1674 | |
1675 | // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)". |
1676 | // This is a standard idiom for branching on a boolean value. |
1677 | Node *c2b = cmp1; |
1678 | if( cmp2_type == TypeInt::ZERO && |
1679 | cmp1_op == Op_Conv2B && |
1680 | (_test._test == BoolTest::eq || |
1681 | _test._test == BoolTest::ne) ) { |
1682 | Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int() |
1683 | ? (Node*)new CmpINode(c2b->in(1),cmp2) |
1684 | : (Node*)new CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR)) |
1685 | ); |
1686 | return new BoolNode( ncmp, _test._test ); |
1687 | } |
1688 | |
1689 | // Comparing a SubI against a zero is equal to comparing the SubI |
1690 | // arguments directly. This only works for eq and ne comparisons |
1691 | // due to possible integer overflow. |
1692 | if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && |
1693 | (cop == Op_CmpI) && |
1694 | (cmp1_op == Op_SubI) && |
1695 | ( cmp2_type == TypeInt::ZERO ) ) { |
1696 | Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2))); |
1697 | return new BoolNode( ncmp, _test._test ); |
1698 | } |
1699 | |
1700 | // Same as above but with and AddI of a constant |
1701 | if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && |
1702 | cop == Op_CmpI && |
1703 | cmp1_op == Op_AddI && |
1704 | cmp1->in(2) != NULL__null && |
1705 | phase->type(cmp1->in(2))->isa_int() && |
1706 | phase->type(cmp1->in(2))->is_int()->is_con() && |
1707 | cmp2_type == TypeInt::ZERO && |
1708 | !is_counted_loop_cmp(cmp) // modifying the exit test of a counted loop messes the counted loop shape |
1709 | ) { |
1710 | const TypeInt* cmp1_in2 = phase->type(cmp1->in(2))->is_int(); |
1711 | Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),phase->intcon(-cmp1_in2->_hi))); |
1712 | return new BoolNode( ncmp, _test._test ); |
1713 | } |
1714 | |
1715 | // Change "bool eq/ne (cmp (phi (X -X) 0))" into "bool eq/ne (cmp X 0)" |
1716 | // since zero check of conditional negation of an integer is equal to |
1717 | // zero check of the integer directly. |
1718 | if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && |
1719 | (cop == Op_CmpI) && |
1720 | (cmp2_type == TypeInt::ZERO) && |
1721 | (cmp1_op == Op_Phi)) { |
1722 | // There should be a diamond phi with true path at index 1 or 2 |
1723 | PhiNode *phi = cmp1->as_Phi(); |
1724 | int idx_true = phi->is_diamond_phi(); |
1725 | if (idx_true != 0) { |
1726 | // True input is in(idx_true) while false input is in(3 - idx_true) |
1727 | Node *tin = phi->in(idx_true); |
1728 | Node *fin = phi->in(3 - idx_true); |
1729 | if ((tin->Opcode() == Op_SubI) && |
1730 | (phase->type(tin->in(1)) == TypeInt::ZERO) && |
1731 | (tin->in(2) == fin)) { |
1732 | // Found conditional negation at true path, create a new CmpINode without that |
1733 | Node *ncmp = phase->transform(new CmpINode(fin, cmp2)); |
1734 | return new BoolNode(ncmp, _test._test); |
1735 | } |
1736 | if ((fin->Opcode() == Op_SubI) && |
1737 | (phase->type(fin->in(1)) == TypeInt::ZERO) && |
1738 | (fin->in(2) == tin)) { |
1739 | // Found conditional negation at false path, create a new CmpINode without that |
1740 | Node *ncmp = phase->transform(new CmpINode(tin, cmp2)); |
1741 | return new BoolNode(ncmp, _test._test); |
1742 | } |
1743 | } |
1744 | } |
1745 | |
1746 | // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the |
1747 | // most general case because negating 0x80000000 does nothing. Needed for |
1748 | // the CmpF3/SubI/CmpI idiom. |
1749 | if( cop == Op_CmpI && |
1750 | cmp1_op == Op_SubI && |
1751 | cmp2_type == TypeInt::ZERO && |
1752 | phase->type( cmp1->in(1) ) == TypeInt::ZERO && |
1753 | phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) { |
1754 | Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2)); |
1755 | return new BoolNode( ncmp, _test.commute() ); |
1756 | } |
1757 | |
1758 | // Try to optimize signed integer comparison |
1759 | return fold_cmpI(phase, cmp->as_Sub(), cmp1, cop, cmp1_op, cmp2_type); |
1760 | |
1761 | // The transformation below is not valid for either signed or unsigned |
1762 | // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE. |
1763 | // This transformation can be resurrected when we are able to |
1764 | // make inferences about the range of values being subtracted from |
1765 | // (or added to) relative to the wraparound point. |
1766 | // |
1767 | // // Remove +/-1's if possible. |
1768 | // // "X <= Y-1" becomes "X < Y" |
1769 | // // "X+1 <= Y" becomes "X < Y" |
1770 | // // "X < Y+1" becomes "X <= Y" |
1771 | // // "X-1 < Y" becomes "X <= Y" |
1772 | // // Do not this to compares off of the counted-loop-end. These guys are |
1773 | // // checking the trip counter and they want to use the post-incremented |
1774 | // // counter. If they use the PRE-incremented counter, then the counter has |
1775 | // // to be incremented in a private block on a loop backedge. |
1776 | // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd ) |
1777 | // return NULL; |
1778 | // #ifndef PRODUCT |
1779 | // // Do not do this in a wash GVN pass during verification. |
1780 | // // Gets triggered by too many simple optimizations to be bothered with |
1781 | // // re-trying it again and again. |
1782 | // if( !phase->allow_progress() ) return NULL; |
1783 | // #endif |
1784 | // // Not valid for unsigned compare because of corner cases in involving zero. |
1785 | // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an |
1786 | // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but |
1787 | // // "0 <=u Y" is always true). |
1788 | // if( cmp->Opcode() == Op_CmpU ) return NULL; |
1789 | // int cmp2_op = cmp2->Opcode(); |
1790 | // if( _test._test == BoolTest::le ) { |
1791 | // if( cmp1_op == Op_AddI && |
1792 | // phase->type( cmp1->in(2) ) == TypeInt::ONE ) |
1793 | // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt ); |
1794 | // else if( cmp2_op == Op_AddI && |
1795 | // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 ) |
1796 | // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt ); |
1797 | // } else if( _test._test == BoolTest::lt ) { |
1798 | // if( cmp1_op == Op_AddI && |
1799 | // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 ) |
1800 | // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le ); |
1801 | // else if( cmp2_op == Op_AddI && |
1802 | // phase->type( cmp2->in(2) ) == TypeInt::ONE ) |
1803 | // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le ); |
1804 | // } |
1805 | } |
1806 | |
1807 | //------------------------------Value------------------------------------------ |
1808 | // Simplify a Bool (convert condition codes to boolean (1 or 0)) node, |
1809 | // based on local information. If the input is constant, do it. |
1810 | const Type* BoolNode::Value(PhaseGVN* phase) const { |
1811 | return _test.cc2logical( phase->type( in(1) ) ); |
1812 | } |
1813 | |
1814 | #ifndef PRODUCT |
1815 | //------------------------------dump_spec-------------------------------------- |
1816 | // Dump special per-node info |
1817 | void BoolNode::dump_spec(outputStream *st) const { |
1818 | st->print("["); |
1819 | _test.dump_on(st); |
1820 | st->print("]"); |
1821 | } |
1822 | |
1823 | //-------------------------------related--------------------------------------- |
1824 | // A BoolNode's related nodes are all of its data inputs, and all of its |
1825 | // outputs until control nodes are hit, which are included. In compact |
1826 | // representation, inputs till level 3 and immediate outputs are included. |
1827 | void BoolNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const { |
1828 | if (compact) { |
1829 | this->collect_nodes(in_rel, 3, false, true); |
1830 | this->collect_nodes(out_rel, -1, false, false); |
1831 | } else { |
1832 | this->collect_nodes_in_all_data(in_rel, false); |
1833 | this->collect_nodes_out_all_ctrl_boundary(out_rel); |
1834 | } |
1835 | } |
1836 | #endif |
1837 | |
1838 | //----------------------is_counted_loop_exit_test------------------------------ |
1839 | // Returns true if node is used by a counted loop node. |
1840 | bool BoolNode::is_counted_loop_exit_test() { |
1841 | for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { |
1842 | Node* use = fast_out(i); |
1843 | if (use->is_CountedLoopEnd()) { |
1844 | return true; |
1845 | } |
1846 | } |
1847 | return false; |
1848 | } |
1849 | |
1850 | //============================================================================= |
1851 | //------------------------------Value------------------------------------------ |
1852 | // Compute sqrt |
1853 | const Type* SqrtDNode::Value(PhaseGVN* phase) const { |
1854 | const Type *t1 = phase->type( in(1) ); |
1855 | if( t1 == Type::TOP ) return Type::TOP; |
1856 | if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; |
1857 | double d = t1->getd(); |
1858 | if( d < 0.0 ) return Type::DOUBLE; |
1859 | return TypeD::make( sqrt( d ) ); |
1860 | } |
1861 | |
1862 | const Type* SqrtFNode::Value(PhaseGVN* phase) const { |
1863 | const Type *t1 = phase->type( in(1) ); |
1864 | if( t1 == Type::TOP ) return Type::TOP; |
1865 | if( t1->base() != Type::FloatCon ) return Type::FLOAT; |
1866 | float f = t1->getf(); |
1867 | if( f < 0.0f ) return Type::FLOAT; |
1868 | return TypeF::make( (float)sqrt( (double)f ) ); |
1869 | } |