Mercurial > hg > truffle
annotate src/share/vm/opto/subnode.cpp @ 21282:93215cb4a2f9
include duringCall and rethrowException for BytecodeFrames in disassembly comments
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 11 May 2015 12:22:49 +0200 |
parents | 7848fc12602b |
children |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14495
diff
changeset
|
2 * Copyright (c) 1997, 2014, 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:
1174
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1174
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:
1174
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileLog.hpp" | |
27 #include "memory/allocation.inline.hpp" | |
28 #include "opto/addnode.hpp" | |
29 #include "opto/callnode.hpp" | |
30 #include "opto/cfgnode.hpp" | |
31 #include "opto/connode.hpp" | |
32 #include "opto/loopnode.hpp" | |
33 #include "opto/matcher.hpp" | |
34 #include "opto/mulnode.hpp" | |
35 #include "opto/opcodes.hpp" | |
36 #include "opto/phaseX.hpp" | |
37 #include "opto/subnode.hpp" | |
38 #include "runtime/sharedRuntime.hpp" | |
39 | |
0 | 40 // Portions of code courtesy of Clifford Click |
41 | |
42 // Optimization - Graph Style | |
43 | |
44 #include "math.h" | |
45 | |
46 //============================================================================= | |
47 //------------------------------Identity--------------------------------------- | |
48 // If right input is a constant 0, return the left input. | |
49 Node *SubNode::Identity( PhaseTransform *phase ) { | |
50 assert(in(1) != this, "Must already have called Value"); | |
51 assert(in(2) != this, "Must already have called Value"); | |
52 | |
53 // Remove double negation | |
54 const Type *zero = add_id(); | |
55 if( phase->type( in(1) )->higher_equal( zero ) && | |
56 in(2)->Opcode() == Opcode() && | |
57 phase->type( in(2)->in(1) )->higher_equal( zero ) ) { | |
58 return in(2)->in(2); | |
59 } | |
60 | |
212 | 61 // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y |
0 | 62 if( in(1)->Opcode() == Op_AddI ) { |
63 if( phase->eqv(in(1)->in(2),in(2)) ) | |
64 return in(1)->in(1); | |
212 | 65 if (phase->eqv(in(1)->in(1),in(2))) |
66 return in(1)->in(2); | |
67 | |
0 | 68 // Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying |
69 // trip counter and X is likely to be loop-invariant (that's how O2 Nodes | |
70 // are originally used, although the optimizer sometimes jiggers things). | |
71 // This folding through an O2 removes a loop-exit use of a loop-varying | |
72 // value and generally lowers register pressure in and around the loop. | |
73 if( in(1)->in(2)->Opcode() == Op_Opaque2 && | |
74 phase->eqv(in(1)->in(2)->in(1),in(2)) ) | |
75 return in(1)->in(1); | |
76 } | |
77 | |
78 return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this; | |
79 } | |
80 | |
81 //------------------------------Value------------------------------------------ | |
82 // A subtract node differences it's two inputs. | |
17936 | 83 const Type* SubNode::Value_common(PhaseTransform *phase) const { |
0 | 84 const Node* in1 = in(1); |
85 const Node* in2 = in(2); | |
86 // Either input is TOP ==> the result is TOP | |
87 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); | |
88 if( t1 == Type::TOP ) return Type::TOP; | |
89 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); | |
90 if( t2 == Type::TOP ) return Type::TOP; | |
91 | |
92 // Not correct for SubFnode and AddFNode (must check for infinity) | |
93 // Equal? Subtract is zero | |
4778 | 94 if (in1->eqv_uncast(in2)) return add_id(); |
0 | 95 |
96 // Either input is BOTTOM ==> the result is the local BOTTOM | |
97 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM ) | |
98 return bottom_type(); | |
99 | |
17936 | 100 return NULL; |
101 } | |
102 | |
103 const Type* SubNode::Value(PhaseTransform *phase) const { | |
104 const Type* t = Value_common(phase); | |
105 if (t != NULL) { | |
106 return t; | |
107 } | |
108 const Type* t1 = phase->type(in(1)); | |
109 const Type* t2 = phase->type(in(2)); | |
0 | 110 return sub(t1,t2); // Local flavor of type subtraction |
111 | |
112 } | |
113 | |
114 //============================================================================= | |
115 | |
116 //------------------------------Helper function-------------------------------- | |
117 static bool ok_to_convert(Node* inc, Node* iv) { | |
118 // Do not collapse (x+c0)-y if "+" is a loop increment, because the | |
119 // "-" is loop invariant and collapsing extends the live-range of "x" | |
120 // to overlap with the "+", forcing another register to be used in | |
121 // the loop. | |
122 // This test will be clearer with '&&' (apply DeMorgan's rule) | |
123 // but I like the early cutouts that happen here. | |
124 const PhiNode *phi; | |
125 if( ( !inc->in(1)->is_Phi() || | |
126 !(phi=inc->in(1)->as_Phi()) || | |
127 phi->is_copy() || | |
128 !phi->region()->is_CountedLoop() || | |
129 inc != phi->region()->as_CountedLoop()->incr() ) | |
130 && | |
131 // Do not collapse (x+c0)-iv if "iv" is a loop induction variable, | |
132 // because "x" maybe invariant. | |
133 ( !iv->is_loop_iv() ) | |
134 ) { | |
135 return true; | |
136 } else { | |
137 return false; | |
138 } | |
139 } | |
140 //------------------------------Ideal------------------------------------------ | |
141 Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
142 Node *in1 = in(1); | |
143 Node *in2 = in(2); | |
144 uint op1 = in1->Opcode(); | |
145 uint op2 = in2->Opcode(); | |
146 | |
147 #ifdef ASSERT | |
148 // Check for dead loop | |
149 if( phase->eqv( in1, this ) || phase->eqv( in2, this ) || | |
150 ( op1 == Op_AddI || op1 == Op_SubI ) && | |
151 ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) || | |
152 phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) ) | |
153 assert(false, "dead loop in SubINode::Ideal"); | |
154 #endif | |
155 | |
156 const Type *t2 = phase->type( in2 ); | |
157 if( t2 == Type::TOP ) return NULL; | |
158 // Convert "x-c0" into "x+ -c0". | |
159 if( t2->base() == Type::Int ){ // Might be bottom or top... | |
160 const TypeInt *i = t2->is_int(); | |
161 if( i->is_con() ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
162 return new (phase->C) AddINode(in1, phase->intcon(-i->get_con())); |
0 | 163 } |
164 | |
165 // Convert "(x+c0) - y" into (x-y) + c0" | |
166 // Do not collapse (x+c0)-y if "+" is a loop increment or | |
167 // if "y" is a loop induction variable. | |
168 if( op1 == Op_AddI && ok_to_convert(in1, in2) ) { | |
169 const Type *tadd = phase->type( in1->in(2) ); | |
170 if( tadd->singleton() && tadd != Type::TOP ) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
171 Node *sub2 = phase->transform( new (phase->C) SubINode( in1->in(1), in2 )); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
172 return new (phase->C) AddINode( sub2, in1->in(2) ); |
0 | 173 } |
174 } | |
175 | |
176 | |
177 // Convert "x - (y+c0)" into "(x-y) - c0" | |
178 // Need the same check as in above optimization but reversed. | |
179 if (op2 == Op_AddI && ok_to_convert(in2, in1)) { | |
180 Node* in21 = in2->in(1); | |
181 Node* in22 = in2->in(2); | |
182 const TypeInt* tcon = phase->type(in22)->isa_int(); | |
183 if (tcon != NULL && tcon->is_con()) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
184 Node* sub2 = phase->transform( new (phase->C) SubINode(in1, in21) ); |
0 | 185 Node* neg_c0 = phase->intcon(- tcon->get_con()); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
186 return new (phase->C) AddINode(sub2, neg_c0); |
0 | 187 } |
188 } | |
189 | |
190 const Type *t1 = phase->type( in1 ); | |
191 if( t1 == Type::TOP ) return NULL; | |
192 | |
193 #ifdef ASSERT | |
194 // Check for dead loop | |
195 if( ( op2 == Op_AddI || op2 == Op_SubI ) && | |
196 ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) || | |
197 phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) ) | |
198 assert(false, "dead loop in SubINode::Ideal"); | |
199 #endif | |
200 | |
201 // Convert "x - (x+y)" into "-y" | |
202 if( op2 == Op_AddI && | |
203 phase->eqv( in1, in2->in(1) ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
204 return new (phase->C) SubINode( phase->intcon(0),in2->in(2)); |
0 | 205 // Convert "(x-y) - x" into "-y" |
206 if( op1 == Op_SubI && | |
207 phase->eqv( in1->in(1), in2 ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
208 return new (phase->C) SubINode( phase->intcon(0),in1->in(2)); |
0 | 209 // Convert "x - (y+x)" into "-y" |
210 if( op2 == Op_AddI && | |
211 phase->eqv( in1, in2->in(2) ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
212 return new (phase->C) SubINode( phase->intcon(0),in2->in(1)); |
0 | 213 |
214 // Convert "0 - (x-y)" into "y-x" | |
215 if( t1 == TypeInt::ZERO && op2 == Op_SubI ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
216 return new (phase->C) SubINode( in2->in(2), in2->in(1) ); |
0 | 217 |
218 // Convert "0 - (x+con)" into "-con-x" | |
219 jint con; | |
220 if( t1 == TypeInt::ZERO && op2 == Op_AddI && | |
221 (con = in2->in(2)->find_int_con(0)) != 0 ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
222 return new (phase->C) SubINode( phase->intcon(-con), in2->in(1) ); |
0 | 223 |
224 // Convert "(X+A) - (X+B)" into "A - B" | |
225 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
226 return new (phase->C) SubINode( in1->in(2), in2->in(2) ); |
0 | 227 |
228 // Convert "(A+X) - (B+X)" into "A - B" | |
229 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
230 return new (phase->C) SubINode( in1->in(1), in2->in(1) ); |
0 | 231 |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
296
diff
changeset
|
232 // Convert "(A+X) - (X+B)" into "A - B" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
296
diff
changeset
|
233 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) ) |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
234 return new (phase->C) SubINode( in1->in(1), in2->in(2) ); |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
296
diff
changeset
|
235 |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
296
diff
changeset
|
236 // Convert "(X+A) - (B+X)" into "A - B" |
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
296
diff
changeset
|
237 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
238 return new (phase->C) SubINode( in1->in(2), in2->in(1) ); |
400
cc80376deb0c
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
296
diff
changeset
|
239 |
0 | 240 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally |
241 // nicer to optimize than subtract. | |
242 if( op2 == Op_SubI && in2->outcnt() == 1) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
243 Node *add1 = phase->transform( new (phase->C) AddINode( in1, in2->in(2) ) ); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
244 return new (phase->C) SubINode( add1, in2->in(1) ); |
0 | 245 } |
246 | |
247 return NULL; | |
248 } | |
249 | |
250 //------------------------------sub-------------------------------------------- | |
251 // A subtract node differences it's two inputs. | |
252 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { | |
253 const TypeInt *r0 = t1->is_int(); // Handy access | |
254 const TypeInt *r1 = t2->is_int(); | |
255 int32 lo = r0->_lo - r1->_hi; | |
256 int32 hi = r0->_hi - r1->_lo; | |
257 | |
258 // We next check for 32-bit overflow. | |
259 // If that happens, we just assume all integers are possible. | |
260 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR | |
261 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND | |
262 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR | |
263 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs | |
264 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); | |
265 else // Overflow; assume all integers | |
266 return TypeInt::INT; | |
267 } | |
268 | |
269 //============================================================================= | |
270 //------------------------------Ideal------------------------------------------ | |
271 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
272 Node *in1 = in(1); | |
273 Node *in2 = in(2); | |
274 uint op1 = in1->Opcode(); | |
275 uint op2 = in2->Opcode(); | |
276 | |
277 #ifdef ASSERT | |
278 // Check for dead loop | |
279 if( phase->eqv( in1, this ) || phase->eqv( in2, this ) || | |
280 ( op1 == Op_AddL || op1 == Op_SubL ) && | |
281 ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) || | |
282 phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) ) | |
283 assert(false, "dead loop in SubLNode::Ideal"); | |
284 #endif | |
285 | |
286 if( phase->type( in2 ) == Type::TOP ) return NULL; | |
287 const TypeLong *i = phase->type( in2 )->isa_long(); | |
288 // Convert "x-c0" into "x+ -c0". | |
289 if( i && // Might be bottom or top... | |
290 i->is_con() ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
291 return new (phase->C) AddLNode(in1, phase->longcon(-i->get_con())); |
0 | 292 |
293 // Convert "(x+c0) - y" into (x-y) + c0" | |
294 // Do not collapse (x+c0)-y if "+" is a loop increment or | |
295 // if "y" is a loop induction variable. | |
296 if( op1 == Op_AddL && ok_to_convert(in1, in2) ) { | |
297 Node *in11 = in1->in(1); | |
298 const Type *tadd = phase->type( in1->in(2) ); | |
299 if( tadd->singleton() && tadd != Type::TOP ) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
300 Node *sub2 = phase->transform( new (phase->C) SubLNode( in11, in2 )); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
301 return new (phase->C) AddLNode( sub2, in1->in(2) ); |
0 | 302 } |
303 } | |
304 | |
305 // Convert "x - (y+c0)" into "(x-y) - c0" | |
306 // Need the same check as in above optimization but reversed. | |
307 if (op2 == Op_AddL && ok_to_convert(in2, in1)) { | |
308 Node* in21 = in2->in(1); | |
309 Node* in22 = in2->in(2); | |
310 const TypeLong* tcon = phase->type(in22)->isa_long(); | |
311 if (tcon != NULL && tcon->is_con()) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
312 Node* sub2 = phase->transform( new (phase->C) SubLNode(in1, in21) ); |
0 | 313 Node* neg_c0 = phase->longcon(- tcon->get_con()); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
314 return new (phase->C) AddLNode(sub2, neg_c0); |
0 | 315 } |
316 } | |
317 | |
318 const Type *t1 = phase->type( in1 ); | |
319 if( t1 == Type::TOP ) return NULL; | |
320 | |
321 #ifdef ASSERT | |
322 // Check for dead loop | |
323 if( ( op2 == Op_AddL || op2 == Op_SubL ) && | |
324 ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) || | |
325 phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) ) | |
326 assert(false, "dead loop in SubLNode::Ideal"); | |
327 #endif | |
328 | |
329 // Convert "x - (x+y)" into "-y" | |
330 if( op2 == Op_AddL && | |
331 phase->eqv( in1, in2->in(1) ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
332 return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2)); |
0 | 333 // Convert "x - (y+x)" into "-y" |
334 if( op2 == Op_AddL && | |
335 phase->eqv( in1, in2->in(2) ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
336 return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1)); |
0 | 337 |
338 // Convert "0 - (x-y)" into "y-x" | |
339 if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
340 return new (phase->C) SubLNode( in2->in(2), in2->in(1) ); |
0 | 341 |
342 // Convert "(X+A) - (X+B)" into "A - B" | |
343 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
344 return new (phase->C) SubLNode( in1->in(2), in2->in(2) ); |
0 | 345 |
346 // Convert "(A+X) - (B+X)" into "A - B" | |
347 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
348 return new (phase->C) SubLNode( in1->in(1), in2->in(1) ); |
0 | 349 |
350 // Convert "A-(B-C)" into (A+C)-B" | |
351 if( op2 == Op_SubL && in2->outcnt() == 1) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
352 Node *add1 = phase->transform( new (phase->C) AddLNode( in1, in2->in(2) ) ); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
353 return new (phase->C) SubLNode( add1, in2->in(1) ); |
0 | 354 } |
355 | |
356 return NULL; | |
357 } | |
358 | |
359 //------------------------------sub-------------------------------------------- | |
360 // A subtract node differences it's two inputs. | |
361 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const { | |
362 const TypeLong *r0 = t1->is_long(); // Handy access | |
363 const TypeLong *r1 = t2->is_long(); | |
364 jlong lo = r0->_lo - r1->_hi; | |
365 jlong hi = r0->_hi - r1->_lo; | |
366 | |
367 // We next check for 32-bit overflow. | |
368 // If that happens, we just assume all integers are possible. | |
369 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR | |
370 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND | |
371 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR | |
372 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs | |
373 return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen)); | |
374 else // Overflow; assume all integers | |
375 return TypeLong::LONG; | |
376 } | |
377 | |
378 //============================================================================= | |
379 //------------------------------Value------------------------------------------ | |
380 // A subtract node differences its two inputs. | |
381 const Type *SubFPNode::Value( PhaseTransform *phase ) const { | |
382 const Node* in1 = in(1); | |
383 const Node* in2 = in(2); | |
384 // Either input is TOP ==> the result is TOP | |
385 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); | |
386 if( t1 == Type::TOP ) return Type::TOP; | |
387 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); | |
388 if( t2 == Type::TOP ) return Type::TOP; | |
389 | |
390 // if both operands are infinity of same sign, the result is NaN; do | |
391 // not replace with zero | |
392 if( (t1->is_finite() && t2->is_finite()) ) { | |
393 if( phase->eqv(in1, in2) ) return add_id(); | |
394 } | |
395 | |
396 // Either input is BOTTOM ==> the result is the local BOTTOM | |
397 const Type *bot = bottom_type(); | |
398 if( (t1 == bot) || (t2 == bot) || | |
399 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) | |
400 return bot; | |
401 | |
402 return sub(t1,t2); // Local flavor of type subtraction | |
403 } | |
404 | |
405 | |
406 //============================================================================= | |
407 //------------------------------Ideal------------------------------------------ | |
408 Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
409 const Type *t2 = phase->type( in(2) ); | |
410 // Convert "x-c0" into "x+ -c0". | |
411 if( t2->base() == Type::FloatCon ) { // Might be bottom or top... | |
412 // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) ); | |
413 } | |
414 | |
415 // Not associative because of boundary conditions (infinity) | |
416 if( IdealizedNumerics && !phase->C->method()->is_strict() ) { | |
417 // Convert "x - (x+y)" into "-y" | |
418 if( in(2)->is_Add() && | |
419 phase->eqv(in(1),in(2)->in(1) ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
420 return new (phase->C) SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2)); |
0 | 421 } |
422 | |
423 // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes | |
424 // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0. | |
425 //if( phase->type(in(1)) == TypeF::ZERO ) | |
426 //return new (phase->C, 2) NegFNode(in(2)); | |
427 | |
428 return NULL; | |
429 } | |
430 | |
431 //------------------------------sub-------------------------------------------- | |
432 // A subtract node differences its two inputs. | |
433 const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const { | |
434 // no folding if one of operands is infinity or NaN, do not do constant folding | |
435 if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) { | |
436 return TypeF::make( t1->getf() - t2->getf() ); | |
437 } | |
438 else if( g_isnan(t1->getf()) ) { | |
439 return t1; | |
440 } | |
441 else if( g_isnan(t2->getf()) ) { | |
442 return t2; | |
443 } | |
444 else { | |
445 return Type::FLOAT; | |
446 } | |
447 } | |
448 | |
449 //============================================================================= | |
450 //------------------------------Ideal------------------------------------------ | |
451 Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
452 const Type *t2 = phase->type( in(2) ); | |
453 // Convert "x-c0" into "x+ -c0". | |
454 if( t2->base() == Type::DoubleCon ) { // Might be bottom or top... | |
455 // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) ); | |
456 } | |
457 | |
458 // Not associative because of boundary conditions (infinity) | |
459 if( IdealizedNumerics && !phase->C->method()->is_strict() ) { | |
460 // Convert "x - (x+y)" into "-y" | |
461 if( in(2)->is_Add() && | |
462 phase->eqv(in(1),in(2)->in(1) ) ) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
463 return new (phase->C) SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2)); |
0 | 464 } |
465 | |
466 // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes | |
467 // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0. | |
468 //if( phase->type(in(1)) == TypeD::ZERO ) | |
469 //return new (phase->C, 2) NegDNode(in(2)); | |
470 | |
471 return NULL; | |
472 } | |
473 | |
474 //------------------------------sub-------------------------------------------- | |
475 // A subtract node differences its two inputs. | |
476 const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const { | |
477 // no folding if one of operands is infinity or NaN, do not do constant folding | |
478 if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) { | |
479 return TypeD::make( t1->getd() - t2->getd() ); | |
480 } | |
481 else if( g_isnan(t1->getd()) ) { | |
482 return t1; | |
483 } | |
484 else if( g_isnan(t2->getd()) ) { | |
485 return t2; | |
486 } | |
487 else { | |
488 return Type::DOUBLE; | |
489 } | |
490 } | |
491 | |
492 //============================================================================= | |
493 //------------------------------Idealize--------------------------------------- | |
494 // Unlike SubNodes, compare must still flatten return value to the | |
495 // range -1, 0, 1. | |
496 // And optimizations like those for (X + Y) - X fail if overflow happens. | |
497 Node *CmpNode::Identity( PhaseTransform *phase ) { | |
498 return this; | |
499 } | |
500 | |
501 //============================================================================= | |
502 //------------------------------cmp-------------------------------------------- | |
503 // Simplify a CmpI (compare 2 integers) node, based on local information. | |
504 // If both inputs are constants, compare them. | |
505 const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const { | |
506 const TypeInt *r0 = t1->is_int(); // Handy access | |
507 const TypeInt *r1 = t2->is_int(); | |
508 | |
509 if( r0->_hi < r1->_lo ) // Range is always low? | |
510 return TypeInt::CC_LT; | |
511 else if( r0->_lo > r1->_hi ) // Range is always high? | |
512 return TypeInt::CC_GT; | |
513 | |
514 else if( r0->is_con() && r1->is_con() ) { // comparing constants? | |
515 assert(r0->get_con() == r1->get_con(), "must be equal"); | |
516 return TypeInt::CC_EQ; // Equal results. | |
517 } else if( r0->_hi == r1->_lo ) // Range is never high? | |
518 return TypeInt::CC_LE; | |
519 else if( r0->_lo == r1->_hi ) // Range is never low? | |
520 return TypeInt::CC_GE; | |
521 return TypeInt::CC; // else use worst case results | |
522 } | |
523 | |
524 // Simplify a CmpU (compare 2 integers) node, based on local information. | |
525 // If both inputs are constants, compare them. | |
526 const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { | |
527 assert(!t1->isa_ptr(), "obsolete usage of CmpU"); | |
528 | |
529 // comparing two unsigned ints | |
530 const TypeInt *r0 = t1->is_int(); // Handy access | |
531 const TypeInt *r1 = t2->is_int(); | |
532 | |
533 // Current installed version | |
534 // Compare ranges for non-overlap | |
535 juint lo0 = r0->_lo; | |
536 juint hi0 = r0->_hi; | |
537 juint lo1 = r1->_lo; | |
538 juint hi1 = r1->_hi; | |
539 | |
540 // If either one has both negative and positive values, | |
541 // it therefore contains both 0 and -1, and since [0..-1] is the | |
542 // full unsigned range, the type must act as an unsigned bottom. | |
543 bool bot0 = ((jint)(lo0 ^ hi0) < 0); | |
544 bool bot1 = ((jint)(lo1 ^ hi1) < 0); | |
545 | |
546 if (bot0 || bot1) { | |
547 // All unsigned values are LE -1 and GE 0. | |
548 if (lo0 == 0 && hi0 == 0) { | |
549 return TypeInt::CC_LE; // 0 <= bot | |
550 } else if (lo1 == 0 && hi1 == 0) { | |
551 return TypeInt::CC_GE; // bot >= 0 | |
552 } | |
553 } else { | |
554 // We can use ranges of the form [lo..hi] if signs are the same. | |
555 assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); | |
556 // results are reversed, '-' > '+' for unsigned compare | |
557 if (hi0 < lo1) { | |
558 return TypeInt::CC_LT; // smaller | |
559 } else if (lo0 > hi1) { | |
560 return TypeInt::CC_GT; // greater | |
561 } else if (hi0 == lo1 && lo0 == hi1) { | |
562 return TypeInt::CC_EQ; // Equal results | |
563 } else if (lo0 >= hi1) { | |
564 return TypeInt::CC_GE; | |
565 } else if (hi0 <= lo1) { | |
566 // Check for special case in Hashtable::get. (See below.) | |
6207
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
567 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) |
0 | 568 return TypeInt::CC_LT; |
569 return TypeInt::CC_LE; | |
570 } | |
571 } | |
572 // Check for special case in Hashtable::get - the hash index is | |
573 // mod'ed to the table size so the following range check is useless. | |
574 // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have | |
575 // to be positive. | |
576 // (This is a gross hack, since the sub method never | |
577 // looks at the structure of the node in any other case.) | |
6207
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
578 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) |
0 | 579 return TypeInt::CC_LT; |
580 return TypeInt::CC; // else use worst case results | |
581 } | |
582 | |
17936 | 583 const Type* CmpUNode::Value(PhaseTransform *phase) const { |
584 const Type* t = SubNode::Value_common(phase); | |
585 if (t != NULL) { | |
586 return t; | |
587 } | |
588 const Node* in1 = in(1); | |
589 const Node* in2 = in(2); | |
590 const Type* t1 = phase->type(in1); | |
591 const Type* t2 = phase->type(in2); | |
592 assert(t1->isa_int(), "CmpU has only Int type inputs"); | |
593 if (t2 == TypeInt::INT) { // Compare to bottom? | |
594 return bottom_type(); | |
595 } | |
596 uint in1_op = in1->Opcode(); | |
597 if (in1_op == Op_AddI || in1_op == Op_SubI) { | |
598 // The problem rise when result of AddI(SubI) may overflow | |
599 // signed integer value. Let say the input type is | |
600 // [256, maxint] then +128 will create 2 ranges due to | |
601 // overflow: [minint, minint+127] and [384, maxint]. | |
602 // But C2 type system keep only 1 type range and as result | |
603 // it use general [minint, maxint] for this case which we | |
604 // can't optimize. | |
605 // | |
606 // Make 2 separate type ranges based on types of AddI(SubI) inputs | |
607 // and compare results of their compare. If results are the same | |
608 // CmpU node can be optimized. | |
609 const Node* in11 = in1->in(1); | |
610 const Node* in12 = in1->in(2); | |
611 const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11); | |
612 const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12); | |
613 // Skip cases when input types are top or bottom. | |
614 if ((t11 != Type::TOP) && (t11 != TypeInt::INT) && | |
615 (t12 != Type::TOP) && (t12 != TypeInt::INT)) { | |
616 const TypeInt *r0 = t11->is_int(); | |
617 const TypeInt *r1 = t12->is_int(); | |
618 jlong lo_r0 = r0->_lo; | |
619 jlong hi_r0 = r0->_hi; | |
620 jlong lo_r1 = r1->_lo; | |
621 jlong hi_r1 = r1->_hi; | |
622 if (in1_op == Op_SubI) { | |
623 jlong tmp = hi_r1; | |
624 hi_r1 = -lo_r1; | |
625 lo_r1 = -tmp; | |
626 // Note, for substructing [minint,x] type range | |
627 // long arithmetic provides correct overflow answer. | |
628 // The confusion come from the fact that in 32-bit | |
629 // -minint == minint but in 64-bit -minint == maxint+1. | |
630 } | |
631 jlong lo_long = lo_r0 + lo_r1; | |
632 jlong hi_long = hi_r0 + hi_r1; | |
633 int lo_tr1 = min_jint; | |
634 int hi_tr1 = (int)hi_long; | |
635 int lo_tr2 = (int)lo_long; | |
636 int hi_tr2 = max_jint; | |
637 bool underflow = lo_long != (jlong)lo_tr2; | |
638 bool overflow = hi_long != (jlong)hi_tr1; | |
639 // Use sub(t1, t2) when there is no overflow (one type range) | |
640 // or when both overflow and underflow (too complex). | |
641 if ((underflow != overflow) && (hi_tr1 < lo_tr2)) { | |
642 // Overflow only on one boundary, compare 2 separate type ranges. | |
643 int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here | |
644 const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w); | |
645 const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w); | |
646 const Type* cmp1 = sub(tr1, t2); | |
647 const Type* cmp2 = sub(tr2, t2); | |
648 if (cmp1 == cmp2) { | |
649 return cmp1; // Hit! | |
650 } | |
651 } | |
652 } | |
653 } | |
654 | |
655 return sub(t1, t2); // Local flavor of type subtraction | |
656 } | |
657 | |
6207
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
658 bool CmpUNode::is_index_range_check() const { |
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
659 // Check for the "(X ModI Y) CmpU Y" shape |
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
660 return (in(1)->Opcode() == Op_ModI && |
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
661 in(1)->in(2)->eqv_uncast(in(2))); |
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
662 } |
ae9241bbce4a
7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents:
6131
diff
changeset
|
663 |
0 | 664 //------------------------------Idealize--------------------------------------- |
665 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) { | |
666 if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) { | |
667 switch (in(1)->Opcode()) { | |
668 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
669 return new (phase->C) CmpLNode(in(1)->in(1),in(1)->in(2)); |
0 | 670 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
671 return new (phase->C) CmpFNode(in(1)->in(1),in(1)->in(2)); |
0 | 672 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
673 return new (phase->C) CmpDNode(in(1)->in(1),in(1)->in(2)); |
0 | 674 //case Op_SubI: |
675 // If (x - y) cannot overflow, then ((x - y) <?> 0) | |
676 // can be turned into (x <?> y). | |
677 // This is handled (with more general cases) by Ideal_sub_algebra. | |
678 } | |
679 } | |
680 return NULL; // No change | |
681 } | |
682 | |
683 | |
684 //============================================================================= | |
685 // Simplify a CmpL (compare 2 longs ) node, based on local information. | |
686 // If both inputs are constants, compare them. | |
687 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { | |
688 const TypeLong *r0 = t1->is_long(); // Handy access | |
689 const TypeLong *r1 = t2->is_long(); | |
690 | |
691 if( r0->_hi < r1->_lo ) // Range is always low? | |
692 return TypeInt::CC_LT; | |
693 else if( r0->_lo > r1->_hi ) // Range is always high? | |
694 return TypeInt::CC_GT; | |
695 | |
696 else if( r0->is_con() && r1->is_con() ) { // comparing constants? | |
697 assert(r0->get_con() == r1->get_con(), "must be equal"); | |
698 return TypeInt::CC_EQ; // Equal results. | |
699 } else if( r0->_hi == r1->_lo ) // Range is never high? | |
700 return TypeInt::CC_LE; | |
701 else if( r0->_lo == r1->_hi ) // Range is never low? | |
702 return TypeInt::CC_GE; | |
703 return TypeInt::CC; // else use worst case results | |
704 } | |
705 | |
706 //============================================================================= | |
707 //------------------------------sub-------------------------------------------- | |
708 // Simplify an CmpP (compare 2 pointers) node, based on local information. | |
709 // If both inputs are constants, compare them. | |
710 const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { | |
711 const TypePtr *r0 = t1->is_ptr(); // Handy access | |
712 const TypePtr *r1 = t2->is_ptr(); | |
713 | |
714 // Undefined inputs makes for an undefined result | |
715 if( TypePtr::above_centerline(r0->_ptr) || | |
716 TypePtr::above_centerline(r1->_ptr) ) | |
717 return Type::TOP; | |
718 | |
719 if (r0 == r1 && r0->singleton()) { | |
720 // Equal pointer constants (klasses, nulls, etc.) | |
721 return TypeInt::CC_EQ; | |
722 } | |
723 | |
724 // See if it is 2 unrelated classes. | |
725 const TypeOopPtr* p0 = r0->isa_oopptr(); | |
726 const TypeOopPtr* p1 = r1->isa_oopptr(); | |
727 if (p0 && p1) { | |
33 | 728 Node* in1 = in(1)->uncast(); |
729 Node* in2 = in(2)->uncast(); | |
730 AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL); | |
731 AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL); | |
732 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) { | |
733 return TypeInt::CC_GT; // different pointers | |
734 } | |
0 | 735 ciKlass* klass0 = p0->klass(); |
736 bool xklass0 = p0->klass_is_exact(); | |
737 ciKlass* klass1 = p1->klass(); | |
738 bool xklass1 = p1->klass_is_exact(); | |
739 int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0); | |
740 if (klass0 && klass1 && | |
741 kps != 1 && // both or neither are klass pointers | |
668
90a66aa50514
6820510: assertion failure with unloaded class in subnode.cpp
never
parents:
400
diff
changeset
|
742 klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces |
783
a9e116455022
6832293: JIT compiler got wrong result in type checking with -server
kvn
parents:
668
diff
changeset
|
743 klass1->is_loaded() && !klass1->is_interface() && |
a9e116455022
6832293: JIT compiler got wrong result in type checking with -server
kvn
parents:
668
diff
changeset
|
744 (!klass0->is_obj_array_klass() || |
a9e116455022
6832293: JIT compiler got wrong result in type checking with -server
kvn
parents:
668
diff
changeset
|
745 !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) && |
a9e116455022
6832293: JIT compiler got wrong result in type checking with -server
kvn
parents:
668
diff
changeset
|
746 (!klass1->is_obj_array_klass() || |
a9e116455022
6832293: JIT compiler got wrong result in type checking with -server
kvn
parents:
668
diff
changeset
|
747 !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) { |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
748 bool unrelated_classes = false; |
0 | 749 // See if neither subclasses the other, or if the class on top |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
750 // is precise. In either of these cases, the compare is known |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
751 // to fail if at least one of the pointers is provably not null. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6207
diff
changeset
|
752 if (klass0->equals(klass1)) { // if types are unequal but klasses are equal |
0 | 753 // Do nothing; we know nothing for imprecise types |
754 } else if (klass0->is_subtype_of(klass1)) { | |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
755 // If klass1's type is PRECISE, then classes are unrelated. |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
756 unrelated_classes = xklass1; |
0 | 757 } else if (klass1->is_subtype_of(klass0)) { |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
758 // If klass0's type is PRECISE, then classes are unrelated. |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
759 unrelated_classes = xklass0; |
0 | 760 } else { // Neither subtypes the other |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
761 unrelated_classes = true; |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
762 } |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
763 if (unrelated_classes) { |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
764 // The oops classes are known to be unrelated. If the joined PTRs of |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
765 // two oops is not Null and not Bottom, then we are sure that one |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
766 // of the two oops is non-null, and the comparison will always fail. |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
767 TypePtr::PTR jp = r0->join_ptr(r1->_ptr); |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
768 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
769 return TypeInt::CC_GT; |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
770 } |
0 | 771 } |
772 } | |
773 } | |
774 | |
775 // Known constants can be compared exactly | |
776 // Null can be distinguished from any NotNull pointers | |
777 // Unknown inputs makes an unknown result | |
778 if( r0->singleton() ) { | |
779 intptr_t bits0 = r0->get_con(); | |
780 if( r1->singleton() ) | |
781 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; | |
782 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; | |
783 } else if( r1->singleton() ) { | |
784 intptr_t bits1 = r1->get_con(); | |
785 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; | |
786 } else | |
787 return TypeInt::CC; | |
788 } | |
789 | |
6131
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
790 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) { |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
791 // Return the klass node for |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
792 // LoadP(AddP(foo:Klass, #java_mirror)) |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
793 // or NULL if not matching. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
794 if (n->Opcode() != Op_LoadP) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
795 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
796 const TypeInstPtr* tp = phase->type(n)->isa_instptr(); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
797 if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
798 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
799 Node* adr = n->in(MemNode::Address); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
800 intptr_t off = 0; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
801 Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
802 if (k == NULL) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
803 const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr(); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
804 if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
805 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
806 // We've found the klass node of a Java mirror load. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
807 return k; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
808 } |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
809 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
810 static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) { |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
811 // for ConP(Foo.class) return ConP(Foo.klass) |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
812 // otherwise return NULL |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
813 if (!n->is_Con()) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
814 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
815 const TypeInstPtr* tp = phase->type(n)->isa_instptr(); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
816 if (!tp) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
817 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
818 ciType* mirror_type = tp->java_mirror_type(); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
819 // TypeInstPtr::java_mirror_type() returns non-NULL for compile- |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
820 // time Class constants only. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
821 if (!mirror_type) return NULL; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
822 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
823 // x.getClass() == int.class can never be true (for all primitive types) |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
824 // Return a ConP(NULL) node for this case. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
825 if (mirror_type->is_classless()) { |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
826 return phase->makecon(TypePtr::NULL_PTR); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
827 } |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
828 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
829 // return the ConP(Foo.klass) |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6207
diff
changeset
|
830 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*"); |
6131
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
831 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass())); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
832 } |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
833 |
0 | 834 //------------------------------Ideal------------------------------------------ |
6131
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
835 // Normalize comparisons between Java mirror loads to compare the klass instead. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
836 // |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
837 // Also check for the case of comparing an unknown klass loaded from the primary |
0 | 838 // super-type array vs a known klass with no subtypes. This amounts to |
839 // checking to see an unknown klass subtypes a known klass with no subtypes; | |
840 // this only happens on an exact match. We can shorten this test by 1 load. | |
841 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) { | |
6131
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
842 // Normalize comparisons between Java mirrors into comparisons of the low- |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
843 // level klass, where a dependent load could be shortened. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
844 // |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
845 // The new pattern has a nice effect of matching the same pattern used in the |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
846 // fast path of instanceof/checkcast/Class.isInstance(), which allows |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
847 // redundant exact type check be optimized away by GVN. |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
848 // For example, in |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
849 // if (x.getClass() == Foo.class) { |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
850 // Foo foo = (Foo) x; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
851 // // ... use a ... |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
852 // } |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
853 // a CmpPNode could be shared between if_acmpne and checkcast |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
854 { |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
855 Node* k1 = isa_java_mirror_load(phase, in(1)); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
856 Node* k2 = isa_java_mirror_load(phase, in(2)); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
857 Node* conk2 = isa_const_java_mirror(phase, in(2)); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
858 |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
859 if (k1 && (k2 || conk2)) { |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
860 Node* lhs = k1; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
861 Node* rhs = (k2 != NULL) ? k2 : conk2; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
862 this->set_req(1, lhs); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
863 this->set_req(2, rhs); |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
864 return this; |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
865 } |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
866 } |
8f6ce6f1049b
7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents:
6084
diff
changeset
|
867 |
0 | 868 // Constant pointer on right? |
869 const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr(); | |
870 if (t2 == NULL || !t2->klass_is_exact()) | |
871 return NULL; | |
872 // Get the constant klass we are comparing to. | |
873 ciKlass* superklass = t2->klass(); | |
874 | |
875 // Now check for LoadKlass on left. | |
876 Node* ldk1 = in(1); | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6804
diff
changeset
|
877 if (ldk1->is_DecodeNKlass()) { |
293
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
878 ldk1 = ldk1->in(1); |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
879 if (ldk1->Opcode() != Op_LoadNKlass ) |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
880 return NULL; |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
881 } else if (ldk1->Opcode() != Op_LoadKlass ) |
0 | 882 return NULL; |
883 // Take apart the address of the LoadKlass: | |
884 Node* adr1 = ldk1->in(MemNode::Address); | |
885 intptr_t con2 = 0; | |
886 Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2); | |
887 if (ldk2 == NULL) | |
888 return NULL; | |
889 if (con2 == oopDesc::klass_offset_in_bytes()) { | |
890 // We are inspecting an object's concrete class. | |
891 // Short-circuit the check if the query is abstract. | |
892 if (superklass->is_interface() || | |
893 superklass->is_abstract()) { | |
894 // Make it come out always false: | |
895 this->set_req(2, phase->makecon(TypePtr::NULL_PTR)); | |
896 return this; | |
897 } | |
898 } | |
899 | |
900 // Check for a LoadKlass from primary supertype array. | |
901 // Any nested loadklass from loadklass+con must be from the p.s. array. | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6804
diff
changeset
|
902 if (ldk2->is_DecodeNKlass()) { |
293
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
903 // Keep ldk2 as DecodeN since it could be used in CmpP below. |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
904 if (ldk2->in(1)->Opcode() != Op_LoadNKlass ) |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
905 return NULL; |
c3e045194476
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
235
diff
changeset
|
906 } else if (ldk2->Opcode() != Op_LoadKlass) |
0 | 907 return NULL; |
908 | |
909 // Verify that we understand the situation | |
910 if (con2 != (intptr_t) superklass->super_check_offset()) | |
911 return NULL; // Might be element-klass loading from array klass | |
912 | |
913 // If 'superklass' has no subklasses and is not an interface, then we are | |
914 // assured that the only input which will pass the type check is | |
915 // 'superklass' itself. | |
916 // | |
917 // We could be more liberal here, and allow the optimization on interfaces | |
918 // which have a single implementor. This would require us to increase the | |
919 // expressiveness of the add_dependency() mechanism. | |
920 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. | |
921 | |
922 // Object arrays must have their base element have no subtypes | |
923 while (superklass->is_obj_array_klass()) { | |
924 ciType* elem = superklass->as_obj_array_klass()->element_type(); | |
925 superklass = elem->as_klass(); | |
926 } | |
927 if (superklass->is_instance_klass()) { | |
928 ciInstanceKlass* ik = superklass->as_instance_klass(); | |
929 if (ik->has_subklass() || ik->is_interface()) return NULL; | |
930 // Add a dependency if there is a chance that a subclass will be added later. | |
931 if (!ik->is_final()) { | |
932 phase->C->dependencies()->assert_leaf_type(ik); | |
933 } | |
934 } | |
935 | |
936 // Bypass the dependent load, and compare directly | |
937 this->set_req(1,ldk2); | |
938 | |
939 return this; | |
940 } | |
941 | |
942 //============================================================================= | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
943 //------------------------------sub-------------------------------------------- |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
944 // Simplify an CmpN (compare 2 pointers) node, based on local information. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
945 // If both inputs are constants, compare them. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
946 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
212
diff
changeset
|
947 const TypePtr *r0 = t1->make_ptr(); // Handy access |
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
212
diff
changeset
|
948 const TypePtr *r1 = t2->make_ptr(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
949 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
950 // Undefined inputs makes for an undefined result |
10279
70120f47d403
8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents:
9060
diff
changeset
|
951 if ((r0 == NULL) || (r1 == NULL) || |
70120f47d403
8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents:
9060
diff
changeset
|
952 TypePtr::above_centerline(r0->_ptr) || |
70120f47d403
8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents:
9060
diff
changeset
|
953 TypePtr::above_centerline(r1->_ptr)) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
954 return Type::TOP; |
10279
70120f47d403
8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents:
9060
diff
changeset
|
955 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
956 if (r0 == r1 && r0->singleton()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
957 // Equal pointer constants (klasses, nulls, etc.) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
958 return TypeInt::CC_EQ; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
959 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
960 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
961 // See if it is 2 unrelated classes. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
962 const TypeOopPtr* p0 = r0->isa_oopptr(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
963 const TypeOopPtr* p1 = r1->isa_oopptr(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
964 if (p0 && p1) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
965 ciKlass* klass0 = p0->klass(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
966 bool xklass0 = p0->klass_is_exact(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
967 ciKlass* klass1 = p1->klass(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
968 bool xklass1 = p1->klass_is_exact(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
969 int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
970 if (klass0 && klass1 && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
971 kps != 1 && // both or neither are klass pointers |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
972 !klass0->is_interface() && // do not trust interfaces |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
973 !klass1->is_interface()) { |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
974 bool unrelated_classes = false; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
975 // See if neither subclasses the other, or if the class on top |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
976 // is precise. In either of these cases, the compare is known |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
977 // to fail if at least one of the pointers is provably not null. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6207
diff
changeset
|
978 if (klass0->equals(klass1)) { // if types are unequal but klasses are equal |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
979 // Do nothing; we know nothing for imprecise types |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
980 } else if (klass0->is_subtype_of(klass1)) { |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
981 // If klass1's type is PRECISE, then classes are unrelated. |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
982 unrelated_classes = xklass1; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
983 } else if (klass1->is_subtype_of(klass0)) { |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
984 // If klass0's type is PRECISE, then classes are unrelated. |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
985 unrelated_classes = xklass0; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
986 } else { // Neither subtypes the other |
296
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
987 unrelated_classes = true; |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
988 } |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
989 if (unrelated_classes) { |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
990 // The oops classes are known to be unrelated. If the joined PTRs of |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
991 // two oops is not Null and not Bottom, then we are sure that one |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
992 // of the two oops is non-null, and the comparison will always fail. |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
993 TypePtr::PTR jp = r0->join_ptr(r1->_ptr); |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
994 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) { |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
995 return TypeInt::CC_GT; |
ce93a51457ae
6730716: nulls from two unrelated classes compare not equal
rasbold
parents:
293
diff
changeset
|
996 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
997 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
998 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
999 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1000 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1001 // Known constants can be compared exactly |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1002 // Null can be distinguished from any NotNull pointers |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1003 // Unknown inputs makes an unknown result |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1004 if( r0->singleton() ) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1005 intptr_t bits0 = r0->get_con(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1006 if( r1->singleton() ) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1007 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1008 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1009 } else if( r1->singleton() ) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1010 intptr_t bits1 = r1->get_con(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1011 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1012 } else |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1013 return TypeInt::CC; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1014 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1015 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1016 //------------------------------Ideal------------------------------------------ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1017 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1018 return NULL; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1019 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1020 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
33
diff
changeset
|
1021 //============================================================================= |
0 | 1022 //------------------------------Value------------------------------------------ |
1023 // Simplify an CmpF (compare 2 floats ) node, based on local information. | |
1024 // If both inputs are constants, compare them. | |
1025 const Type *CmpFNode::Value( PhaseTransform *phase ) const { | |
1026 const Node* in1 = in(1); | |
1027 const Node* in2 = in(2); | |
1028 // Either input is TOP ==> the result is TOP | |
1029 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); | |
1030 if( t1 == Type::TOP ) return Type::TOP; | |
1031 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); | |
1032 if( t2 == Type::TOP ) return Type::TOP; | |
1033 | |
1034 // Not constants? Don't know squat - even if they are the same | |
1035 // value! If they are NaN's they compare to LT instead of EQ. | |
1036 const TypeF *tf1 = t1->isa_float_constant(); | |
1037 const TypeF *tf2 = t2->isa_float_constant(); | |
1038 if( !tf1 || !tf2 ) return TypeInt::CC; | |
1039 | |
1040 // This implements the Java bytecode fcmpl, so unordered returns -1. | |
1041 if( tf1->is_nan() || tf2->is_nan() ) | |
1042 return TypeInt::CC_LT; | |
1043 | |
1044 if( tf1->_f < tf2->_f ) return TypeInt::CC_LT; | |
1045 if( tf1->_f > tf2->_f ) return TypeInt::CC_GT; | |
1046 assert( tf1->_f == tf2->_f, "do not understand FP behavior" ); | |
1047 return TypeInt::CC_EQ; | |
1048 } | |
1049 | |
1050 | |
1051 //============================================================================= | |
1052 //------------------------------Value------------------------------------------ | |
1053 // Simplify an CmpD (compare 2 doubles ) node, based on local information. | |
1054 // If both inputs are constants, compare them. | |
1055 const Type *CmpDNode::Value( PhaseTransform *phase ) const { | |
1056 const Node* in1 = in(1); | |
1057 const Node* in2 = in(2); | |
1058 // Either input is TOP ==> the result is TOP | |
1059 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1); | |
1060 if( t1 == Type::TOP ) return Type::TOP; | |
1061 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2); | |
1062 if( t2 == Type::TOP ) return Type::TOP; | |
1063 | |
1064 // Not constants? Don't know squat - even if they are the same | |
1065 // value! If they are NaN's they compare to LT instead of EQ. | |
1066 const TypeD *td1 = t1->isa_double_constant(); | |
1067 const TypeD *td2 = t2->isa_double_constant(); | |
1068 if( !td1 || !td2 ) return TypeInt::CC; | |
1069 | |
1070 // This implements the Java bytecode dcmpl, so unordered returns -1. | |
1071 if( td1->is_nan() || td2->is_nan() ) | |
1072 return TypeInt::CC_LT; | |
1073 | |
1074 if( td1->_d < td2->_d ) return TypeInt::CC_LT; | |
1075 if( td1->_d > td2->_d ) return TypeInt::CC_GT; | |
1076 assert( td1->_d == td2->_d, "do not understand FP behavior" ); | |
1077 return TypeInt::CC_EQ; | |
1078 } | |
1079 | |
1080 //------------------------------Ideal------------------------------------------ | |
1081 Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
1082 // Check if we can change this to a CmpF and remove a ConvD2F operation. | |
1083 // Change (CMPD (F2D (float)) (ConD value)) | |
1084 // To (CMPF (float) (ConF value)) | |
1085 // Valid when 'value' does not lose precision as a float. | |
1086 // Benefits: eliminates conversion, does not require 24-bit mode | |
1087 | |
1088 // NaNs prevent commuting operands. This transform works regardless of the | |
1089 // order of ConD and ConvF2D inputs by preserving the original order. | |
1090 int idx_f2d = 1; // ConvF2D on left side? | |
1091 if( in(idx_f2d)->Opcode() != Op_ConvF2D ) | |
1092 idx_f2d = 2; // No, swap to check for reversed args | |
1093 int idx_con = 3-idx_f2d; // Check for the constant on other input | |
1094 | |
1095 if( ConvertCmpD2CmpF && | |
1096 in(idx_f2d)->Opcode() == Op_ConvF2D && | |
1097 in(idx_con)->Opcode() == Op_ConD ) { | |
1098 const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant(); | |
1099 double t2_value_as_double = t2->_d; | |
1100 float t2_value_as_float = (float)t2_value_as_double; | |
1101 if( t2_value_as_double == (double)t2_value_as_float ) { | |
1102 // Test value can be represented as a float | |
1103 // Eliminate the conversion to double and create new comparison | |
1104 Node *new_in1 = in(idx_f2d)->in(1); | |
1105 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) ); | |
1106 if( idx_f2d != 1 ) { // Must flip args to match original order | |
1107 Node *tmp = new_in1; | |
1108 new_in1 = new_in2; | |
1109 new_in2 = tmp; | |
1110 } | |
1111 CmpFNode *new_cmp = (Opcode() == Op_CmpD3) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1112 ? new (phase->C) CmpF3Node( new_in1, new_in2 ) |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1113 : new (phase->C) CmpFNode ( new_in1, new_in2 ) ; |
0 | 1114 return new_cmp; // Changed to CmpFNode |
1115 } | |
1116 // Testing value required the precision of a double | |
1117 } | |
1118 return NULL; // No change | |
1119 } | |
1120 | |
1121 | |
1122 //============================================================================= | |
1123 //------------------------------cc2logical------------------------------------- | |
1124 // Convert a condition code type to a logical type | |
1125 const Type *BoolTest::cc2logical( const Type *CC ) const { | |
1126 if( CC == Type::TOP ) return Type::TOP; | |
1127 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse | |
1128 const TypeInt *ti = CC->is_int(); | |
1129 if( ti->is_con() ) { // Only 1 kind of condition codes set? | |
1130 // Match low order 2 bits | |
1131 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0; | |
1132 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result | |
1133 return TypeInt::make(tmp); // Boolean result | |
1134 } | |
1135 | |
1136 if( CC == TypeInt::CC_GE ) { | |
1137 if( _test == ge ) return TypeInt::ONE; | |
1138 if( _test == lt ) return TypeInt::ZERO; | |
1139 } | |
1140 if( CC == TypeInt::CC_LE ) { | |
1141 if( _test == le ) return TypeInt::ONE; | |
1142 if( _test == gt ) return TypeInt::ZERO; | |
1143 } | |
1144 | |
1145 return TypeInt::BOOL; | |
1146 } | |
1147 | |
1148 //------------------------------dump_spec------------------------------------- | |
1149 // Print special per-node info | |
1150 void BoolTest::dump_on(outputStream *st) const { | |
12323 | 1151 const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"}; |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14495
diff
changeset
|
1152 st->print("%s", msg[_test]); |
0 | 1153 } |
1154 | |
1155 //============================================================================= | |
1156 uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); } | |
1157 uint BoolNode::size_of() const { return sizeof(BoolNode); } | |
1158 | |
1159 //------------------------------operator==------------------------------------- | |
1160 uint BoolNode::cmp( const Node &n ) const { | |
1161 const BoolNode *b = (const BoolNode *)&n; // Cast up | |
1162 return (_test._test == b->_test._test); | |
1163 } | |
1164 | |
1165 //-------------------------------make_predicate-------------------------------- | |
1166 Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) { | |
1167 if (test_value->is_Con()) return test_value; | |
1168 if (test_value->is_Bool()) return test_value; | |
1169 Compile* C = phase->C; | |
1170 if (test_value->is_CMove() && | |
1171 test_value->in(CMoveNode::Condition)->is_Bool()) { | |
1172 BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool(); | |
1173 const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse)); | |
1174 const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue)); | |
1175 if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) { | |
1176 return bol; | |
1177 } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) { | |
1178 return phase->transform( bol->negate(phase) ); | |
1179 } | |
1180 // Else fall through. The CMove gets in the way of the test. | |
1181 // It should be the case that make_predicate(bol->as_int_value()) == bol. | |
1182 } | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1183 Node* cmp = new (C) CmpINode(test_value, phase->intcon(0)); |
0 | 1184 cmp = phase->transform(cmp); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1185 Node* bol = new (C) BoolNode(cmp, BoolTest::ne); |
0 | 1186 return phase->transform(bol); |
1187 } | |
1188 | |
1189 //--------------------------------as_int_value--------------------------------- | |
1190 Node* BoolNode::as_int_value(PhaseGVN* phase) { | |
1191 // Inverse to make_predicate. The CMove probably boils down to a Conv2B. | |
1192 Node* cmov = CMoveNode::make(phase->C, NULL, this, | |
1193 phase->intcon(0), phase->intcon(1), | |
1194 TypeInt::BOOL); | |
1195 return phase->transform(cmov); | |
1196 } | |
1197 | |
1198 //----------------------------------negate------------------------------------- | |
1199 BoolNode* BoolNode::negate(PhaseGVN* phase) { | |
1200 Compile* C = phase->C; | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1201 return new (C) BoolNode(in(1), _test.negate()); |
0 | 1202 } |
1203 | |
1204 | |
1205 //------------------------------Ideal------------------------------------------ | |
1206 Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
1207 // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)". | |
1208 // This moves the constant to the right. Helps value-numbering. | |
1209 Node *cmp = in(1); | |
1210 if( !cmp->is_Sub() ) return NULL; | |
1211 int cop = cmp->Opcode(); | |
14495
cd5d10655495
8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents:
14223
diff
changeset
|
1212 if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL; |
0 | 1213 Node *cmp1 = cmp->in(1); |
1214 Node *cmp2 = cmp->in(2); | |
1215 if( !cmp1 ) return NULL; | |
1216 | |
14495
cd5d10655495
8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents:
14223
diff
changeset
|
1217 if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) { |
cd5d10655495
8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents:
14223
diff
changeset
|
1218 return NULL; |
cd5d10655495
8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents:
14223
diff
changeset
|
1219 } |
cd5d10655495
8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents:
14223
diff
changeset
|
1220 |
0 | 1221 // Constant on left? |
1222 Node *con = cmp1; | |
1223 uint op2 = cmp2->Opcode(); | |
1224 // Move constants to the right of compare's to canonicalize. | |
1225 // Do not muck with Opaque1 nodes, as this indicates a loop | |
1226 // guard that cannot change shape. | |
1227 if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 && | |
1228 // Because of NaN's, CmpD and CmpF are not commutative | |
1229 cop != Op_CmpD && cop != Op_CmpF && | |
1230 // Protect against swapping inputs to a compare when it is used by a | |
1231 // counted loop exit, which requires maintaining the loop-limit as in(2) | |
1232 !is_counted_loop_exit_test() ) { | |
1233 // Ok, commute the constant to the right of the cmp node. | |
1234 // Clone the Node, getting a new Node of the same class | |
1235 cmp = cmp->clone(); | |
1236 // Swap inputs to the clone | |
1237 cmp->swap_edges(1, 2); | |
1238 cmp = phase->transform( cmp ); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1239 return new (phase->C) BoolNode( cmp, _test.commute() ); |
0 | 1240 } |
1241 | |
1242 // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)". | |
1243 // The XOR-1 is an idiom used to flip the sense of a bool. We flip the | |
1244 // test instead. | |
1245 int cmp1_op = cmp1->Opcode(); | |
1246 const TypeInt* cmp2_type = phase->type(cmp2)->isa_int(); | |
1247 if (cmp2_type == NULL) return NULL; | |
1248 Node* j_xor = cmp1; | |
1249 if( cmp2_type == TypeInt::ZERO && | |
1250 cmp1_op == Op_XorI && | |
1251 j_xor->in(1) != j_xor && // An xor of itself is dead | |
3416 | 1252 phase->type( j_xor->in(1) ) == TypeInt::BOOL && |
0 | 1253 phase->type( j_xor->in(2) ) == TypeInt::ONE && |
1254 (_test._test == BoolTest::eq || | |
1255 _test._test == BoolTest::ne) ) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1256 Node *ncmp = phase->transform(new (phase->C) CmpINode(j_xor->in(1),cmp2)); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1257 return new (phase->C) BoolNode( ncmp, _test.negate() ); |
0 | 1258 } |
1259 | |
1260 // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)". | |
1261 // This is a standard idiom for branching on a boolean value. | |
1262 Node *c2b = cmp1; | |
1263 if( cmp2_type == TypeInt::ZERO && | |
1264 cmp1_op == Op_Conv2B && | |
1265 (_test._test == BoolTest::eq || | |
1266 _test._test == BoolTest::ne) ) { | |
1267 Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int() | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1268 ? (Node*)new (phase->C) CmpINode(c2b->in(1),cmp2) |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1269 : (Node*)new (phase->C) CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR)) |
0 | 1270 ); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1271 return new (phase->C) BoolNode( ncmp, _test._test ); |
0 | 1272 } |
1273 | |
1274 // Comparing a SubI against a zero is equal to comparing the SubI | |
1275 // arguments directly. This only works for eq and ne comparisons | |
1276 // due to possible integer overflow. | |
1277 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) && | |
1278 (cop == Op_CmpI) && | |
1279 (cmp1->Opcode() == Op_SubI) && | |
1280 ( cmp2_type == TypeInt::ZERO ) ) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1281 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(1),cmp1->in(2))); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1282 return new (phase->C) BoolNode( ncmp, _test._test ); |
0 | 1283 } |
1284 | |
1285 // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the | |
1286 // most general case because negating 0x80000000 does nothing. Needed for | |
1287 // the CmpF3/SubI/CmpI idiom. | |
1288 if( cop == Op_CmpI && | |
1289 cmp1->Opcode() == Op_SubI && | |
1290 cmp2_type == TypeInt::ZERO && | |
1291 phase->type( cmp1->in(1) ) == TypeInt::ZERO && | |
1292 phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1293 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(2),cmp2)); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1294 return new (phase->C) BoolNode( ncmp, _test.commute() ); |
0 | 1295 } |
1296 | |
1297 // The transformation below is not valid for either signed or unsigned | |
1298 // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE. | |
1299 // This transformation can be resurrected when we are able to | |
1300 // make inferences about the range of values being subtracted from | |
1301 // (or added to) relative to the wraparound point. | |
1302 // | |
1303 // // Remove +/-1's if possible. | |
1304 // // "X <= Y-1" becomes "X < Y" | |
1305 // // "X+1 <= Y" becomes "X < Y" | |
1306 // // "X < Y+1" becomes "X <= Y" | |
1307 // // "X-1 < Y" becomes "X <= Y" | |
1308 // // Do not this to compares off of the counted-loop-end. These guys are | |
1309 // // checking the trip counter and they want to use the post-incremented | |
1310 // // counter. If they use the PRE-incremented counter, then the counter has | |
1311 // // to be incremented in a private block on a loop backedge. | |
1312 // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd ) | |
1313 // return NULL; | |
1314 // #ifndef PRODUCT | |
1315 // // Do not do this in a wash GVN pass during verification. | |
1316 // // Gets triggered by too many simple optimizations to be bothered with | |
1317 // // re-trying it again and again. | |
1318 // if( !phase->allow_progress() ) return NULL; | |
1319 // #endif | |
1320 // // Not valid for unsigned compare because of corner cases in involving zero. | |
1321 // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an | |
1322 // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but | |
1323 // // "0 <=u Y" is always true). | |
1324 // if( cmp->Opcode() == Op_CmpU ) return NULL; | |
1325 // int cmp2_op = cmp2->Opcode(); | |
1326 // if( _test._test == BoolTest::le ) { | |
1327 // if( cmp1_op == Op_AddI && | |
1328 // phase->type( cmp1->in(2) ) == TypeInt::ONE ) | |
1329 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt ); | |
1330 // else if( cmp2_op == Op_AddI && | |
1331 // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 ) | |
1332 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt ); | |
1333 // } else if( _test._test == BoolTest::lt ) { | |
1334 // if( cmp1_op == Op_AddI && | |
1335 // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 ) | |
1336 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le ); | |
1337 // else if( cmp2_op == Op_AddI && | |
1338 // phase->type( cmp2->in(2) ) == TypeInt::ONE ) | |
1339 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le ); | |
1340 // } | |
1341 | |
1342 return NULL; | |
1343 } | |
1344 | |
1345 //------------------------------Value------------------------------------------ | |
1346 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node, | |
1347 // based on local information. If the input is constant, do it. | |
1348 const Type *BoolNode::Value( PhaseTransform *phase ) const { | |
1349 return _test.cc2logical( phase->type( in(1) ) ); | |
1350 } | |
1351 | |
1352 //------------------------------dump_spec-------------------------------------- | |
1353 // Dump special per-node info | |
1354 #ifndef PRODUCT | |
1355 void BoolNode::dump_spec(outputStream *st) const { | |
1356 st->print("["); | |
1357 _test.dump_on(st); | |
1358 st->print("]"); | |
1359 } | |
1360 #endif | |
1361 | |
1362 //------------------------------is_counted_loop_exit_test-------------------------------------- | |
1363 // Returns true if node is used by a counted loop node. | |
1364 bool BoolNode::is_counted_loop_exit_test() { | |
1365 for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { | |
1366 Node* use = fast_out(i); | |
1367 if (use->is_CountedLoopEnd()) { | |
1368 return true; | |
1369 } | |
1370 } | |
1371 return false; | |
1372 } | |
1373 | |
1374 //============================================================================= | |
1375 //------------------------------Value------------------------------------------ | |
1376 // Compute sqrt | |
1377 const Type *SqrtDNode::Value( PhaseTransform *phase ) const { | |
1378 const Type *t1 = phase->type( in(1) ); | |
1379 if( t1 == Type::TOP ) return Type::TOP; | |
1380 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1381 double d = t1->getd(); | |
1382 if( d < 0.0 ) return Type::DOUBLE; | |
1383 return TypeD::make( sqrt( d ) ); | |
1384 } | |
1385 | |
1386 //============================================================================= | |
1387 //------------------------------Value------------------------------------------ | |
1388 // Compute cos | |
1389 const Type *CosDNode::Value( PhaseTransform *phase ) const { | |
1390 const Type *t1 = phase->type( in(1) ); | |
1391 if( t1 == Type::TOP ) return Type::TOP; | |
1392 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1393 double d = t1->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1394 return TypeD::make( StubRoutines::intrinsic_cos( d ) ); |
0 | 1395 } |
1396 | |
1397 //============================================================================= | |
1398 //------------------------------Value------------------------------------------ | |
1399 // Compute sin | |
1400 const Type *SinDNode::Value( PhaseTransform *phase ) const { | |
1401 const Type *t1 = phase->type( in(1) ); | |
1402 if( t1 == Type::TOP ) return Type::TOP; | |
1403 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1404 double d = t1->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1405 return TypeD::make( StubRoutines::intrinsic_sin( d ) ); |
0 | 1406 } |
1407 | |
1408 //============================================================================= | |
1409 //------------------------------Value------------------------------------------ | |
1410 // Compute tan | |
1411 const Type *TanDNode::Value( PhaseTransform *phase ) const { | |
1412 const Type *t1 = phase->type( in(1) ); | |
1413 if( t1 == Type::TOP ) return Type::TOP; | |
1414 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1415 double d = t1->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1416 return TypeD::make( StubRoutines::intrinsic_tan( d ) ); |
0 | 1417 } |
1418 | |
1419 //============================================================================= | |
1420 //------------------------------Value------------------------------------------ | |
1421 // Compute log | |
1422 const Type *LogDNode::Value( PhaseTransform *phase ) const { | |
1423 const Type *t1 = phase->type( in(1) ); | |
1424 if( t1 == Type::TOP ) return Type::TOP; | |
1425 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1426 double d = t1->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1427 return TypeD::make( StubRoutines::intrinsic_log( d ) ); |
0 | 1428 } |
1429 | |
1430 //============================================================================= | |
1431 //------------------------------Value------------------------------------------ | |
1432 // Compute log10 | |
1433 const Type *Log10DNode::Value( PhaseTransform *phase ) const { | |
1434 const Type *t1 = phase->type( in(1) ); | |
1435 if( t1 == Type::TOP ) return Type::TOP; | |
1436 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1437 double d = t1->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1438 return TypeD::make( StubRoutines::intrinsic_log10( d ) ); |
0 | 1439 } |
1440 | |
1441 //============================================================================= | |
1442 //------------------------------Value------------------------------------------ | |
1443 // Compute exp | |
1444 const Type *ExpDNode::Value( PhaseTransform *phase ) const { | |
1445 const Type *t1 = phase->type( in(1) ); | |
1446 if( t1 == Type::TOP ) return Type::TOP; | |
1447 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1448 double d = t1->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1449 return TypeD::make( StubRoutines::intrinsic_exp( d ) ); |
0 | 1450 } |
1451 | |
1452 | |
1453 //============================================================================= | |
1454 //------------------------------Value------------------------------------------ | |
1455 // Compute pow | |
1456 const Type *PowDNode::Value( PhaseTransform *phase ) const { | |
1457 const Type *t1 = phase->type( in(1) ); | |
1458 if( t1 == Type::TOP ) return Type::TOP; | |
1459 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1460 const Type *t2 = phase->type( in(2) ); | |
1461 if( t2 == Type::TOP ) return Type::TOP; | |
1462 if( t2->base() != Type::DoubleCon ) return Type::DOUBLE; | |
1463 double d1 = t1->getd(); | |
1464 double d2 = t2->getd(); | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
844
diff
changeset
|
1465 return TypeD::make( StubRoutines::intrinsic_pow( d1, d2 ) ); |
0 | 1466 } |