1
|
1 |
/*
|
|
2 |
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
// Optimization - Graph Style
|
|
26 |
|
|
27 |
#include "incls/_precompiled.incl"
|
|
28 |
#include "incls/_connode.cpp.incl"
|
|
29 |
|
|
30 |
//=============================================================================
|
|
31 |
//------------------------------hash-------------------------------------------
|
|
32 |
uint ConNode::hash() const {
|
|
33 |
return (uintptr_t)in(TypeFunc::Control) + _type->hash();
|
|
34 |
}
|
|
35 |
|
|
36 |
//------------------------------make-------------------------------------------
|
|
37 |
ConNode *ConNode::make( Compile* C, const Type *t ) {
|
|
38 |
switch( t->basic_type() ) {
|
|
39 |
case T_INT: return new (C, 1) ConINode( t->is_int() );
|
|
40 |
case T_ARRAY: return new (C, 1) ConPNode( t->is_aryptr() );
|
|
41 |
case T_LONG: return new (C, 1) ConLNode( t->is_long() );
|
|
42 |
case T_FLOAT: return new (C, 1) ConFNode( t->is_float_constant() );
|
|
43 |
case T_DOUBLE: return new (C, 1) ConDNode( t->is_double_constant() );
|
|
44 |
case T_VOID: return new (C, 1) ConNode ( Type::TOP );
|
|
45 |
case T_OBJECT: return new (C, 1) ConPNode( t->is_oopptr() );
|
|
46 |
case T_ADDRESS: return new (C, 1) ConPNode( t->is_ptr() );
|
|
47 |
// Expected cases: TypePtr::NULL_PTR, any is_rawptr()
|
|
48 |
// Also seen: AnyPtr(TopPTR *+top); from command line:
|
|
49 |
// r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660
|
|
50 |
// %%%% Stop using TypePtr::NULL_PTR to represent nulls: use either TypeRawPtr::NULL_PTR
|
|
51 |
// or else TypeOopPtr::NULL_PTR. Then set Type::_basic_type[AnyPtr] = T_ILLEGAL
|
|
52 |
}
|
|
53 |
ShouldNotReachHere();
|
|
54 |
return NULL;
|
|
55 |
}
|
|
56 |
|
|
57 |
//=============================================================================
|
|
58 |
/*
|
|
59 |
The major change is for CMoveP and StrComp. They have related but slightly
|
|
60 |
different problems. They both take in TWO oops which are both null-checked
|
|
61 |
independently before the using Node. After CCP removes the CastPP's they need
|
|
62 |
to pick up the guarding test edge - in this case TWO control edges. I tried
|
|
63 |
various solutions, all have problems:
|
|
64 |
|
|
65 |
(1) Do nothing. This leads to a bug where we hoist a Load from a CMoveP or a
|
|
66 |
StrComp above a guarding null check. I've seen both cases in normal -Xcomp
|
|
67 |
testing.
|
|
68 |
|
|
69 |
(2) Plug the control edge from 1 of the 2 oops in. Apparent problem here is
|
|
70 |
to figure out which test post-dominates. The real problem is that it doesn't
|
|
71 |
matter which one you pick. After you pick up, the dominating-test elider in
|
|
72 |
IGVN can remove the test and allow you to hoist up to the dominating test on
|
|
73 |
the choosen oop bypassing the test on the not-choosen oop. Seen in testing.
|
|
74 |
Oops.
|
|
75 |
|
|
76 |
(3) Leave the CastPP's in. This makes the graph more accurate in some sense;
|
|
77 |
we get to keep around the knowledge that an oop is not-null after some test.
|
|
78 |
Alas, the CastPP's interfere with GVN (some values are the regular oop, some
|
|
79 |
are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
|
|
80 |
This cost us 10% on SpecJVM, even when I removed some of the more trivial
|
|
81 |
cases in the optimizer. Removing more useless Phi's started allowing Loads to
|
|
82 |
illegally float above null checks. I gave up on this approach.
|
|
83 |
|
|
84 |
(4) Add BOTH control edges to both tests. Alas, too much code knows that
|
|
85 |
control edges are in slot-zero ONLY. Many quick asserts fail; no way to do
|
|
86 |
this one. Note that I really want to allow the CMoveP to float and add both
|
|
87 |
control edges to the dependent Load op - meaning I can select early but I
|
|
88 |
cannot Load until I pass both tests.
|
|
89 |
|
|
90 |
(5) Do not hoist CMoveP and StrComp. To this end I added the v-call
|
|
91 |
depends_only_on_test(). No obvious performance loss on Spec, but we are
|
|
92 |
clearly conservative on CMoveP (also so on StrComp but that's unlikely to
|
|
93 |
matter ever).
|
|
94 |
|
|
95 |
*/
|
|
96 |
|
|
97 |
|
|
98 |
//------------------------------Ideal------------------------------------------
|
|
99 |
// Return a node which is more "ideal" than the current node.
|
|
100 |
// Move constants to the right.
|
|
101 |
Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
102 |
if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
|
|
103 |
assert( !phase->eqv(in(Condition), this) &&
|
|
104 |
!phase->eqv(in(IfFalse), this) &&
|
|
105 |
!phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
|
|
106 |
if( phase->type(in(Condition)) == Type::TOP )
|
|
107 |
return NULL; // return NULL when Condition is dead
|
|
108 |
|
|
109 |
if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
|
|
110 |
if( in(Condition)->is_Bool() ) {
|
|
111 |
BoolNode* b = in(Condition)->as_Bool();
|
|
112 |
BoolNode* b2 = b->negate(phase);
|
|
113 |
return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
|
|
114 |
}
|
|
115 |
}
|
|
116 |
return NULL;
|
|
117 |
}
|
|
118 |
|
|
119 |
//------------------------------is_cmove_id------------------------------------
|
|
120 |
// Helper function to check for CMOVE identity. Shared with PhiNode::Identity
|
|
121 |
Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
|
|
122 |
// Check for Cmp'ing and CMove'ing same values
|
|
123 |
if( (phase->eqv(cmp->in(1),f) &&
|
|
124 |
phase->eqv(cmp->in(2),t)) ||
|
|
125 |
// Swapped Cmp is OK
|
|
126 |
(phase->eqv(cmp->in(2),f) &&
|
|
127 |
phase->eqv(cmp->in(1),t)) ) {
|
|
128 |
// Check for "(t==f)?t:f;" and replace with "f"
|
|
129 |
if( b->_test._test == BoolTest::eq )
|
|
130 |
return f;
|
|
131 |
// Allow the inverted case as well
|
|
132 |
// Check for "(t!=f)?t:f;" and replace with "t"
|
|
133 |
if( b->_test._test == BoolTest::ne )
|
|
134 |
return t;
|
|
135 |
}
|
|
136 |
return NULL;
|
|
137 |
}
|
|
138 |
|
|
139 |
//------------------------------Identity---------------------------------------
|
|
140 |
// Conditional-move is an identity if both inputs are the same, or the test
|
|
141 |
// true or false.
|
|
142 |
Node *CMoveNode::Identity( PhaseTransform *phase ) {
|
|
143 |
if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
|
|
144 |
return in(IfFalse); // Then it doesn't matter
|
|
145 |
if( phase->type(in(Condition)) == TypeInt::ZERO )
|
|
146 |
return in(IfFalse); // Always pick left(false) input
|
|
147 |
if( phase->type(in(Condition)) == TypeInt::ONE )
|
|
148 |
return in(IfTrue); // Always pick right(true) input
|
|
149 |
|
|
150 |
// Check for CMove'ing a constant after comparing against the constant.
|
|
151 |
// Happens all the time now, since if we compare equality vs a constant in
|
|
152 |
// the parser, we "know" the variable is constant on one path and we force
|
|
153 |
// it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
|
|
154 |
// conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more
|
|
155 |
// general in that we don't need constants.
|
|
156 |
if( in(Condition)->is_Bool() ) {
|
|
157 |
BoolNode *b = in(Condition)->as_Bool();
|
|
158 |
Node *cmp = b->in(1);
|
|
159 |
if( cmp->is_Cmp() ) {
|
|
160 |
Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
|
|
161 |
if( id ) return id;
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
return this;
|
|
166 |
}
|
|
167 |
|
|
168 |
//------------------------------Value------------------------------------------
|
|
169 |
// Result is the meet of inputs
|
|
170 |
const Type *CMoveNode::Value( PhaseTransform *phase ) const {
|
|
171 |
if( phase->type(in(Condition)) == Type::TOP )
|
|
172 |
return Type::TOP;
|
|
173 |
return phase->type(in(IfFalse))->meet(phase->type(in(IfTrue)));
|
|
174 |
}
|
|
175 |
|
|
176 |
//------------------------------make-------------------------------------------
|
|
177 |
// Make a correctly-flavored CMove. Since _type is directly determined
|
|
178 |
// from the inputs we do not need to specify it here.
|
|
179 |
CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {
|
|
180 |
switch( t->basic_type() ) {
|
|
181 |
case T_INT: return new (C, 4) CMoveINode( bol, left, right, t->is_int() );
|
|
182 |
case T_FLOAT: return new (C, 4) CMoveFNode( bol, left, right, t );
|
|
183 |
case T_DOUBLE: return new (C, 4) CMoveDNode( bol, left, right, t );
|
|
184 |
case T_LONG: return new (C, 4) CMoveLNode( bol, left, right, t->is_long() );
|
|
185 |
case T_OBJECT: return new (C, 4) CMovePNode( c, bol, left, right, t->is_oopptr() );
|
|
186 |
case T_ADDRESS: return new (C, 4) CMovePNode( c, bol, left, right, t->is_ptr() );
|
|
187 |
default:
|
|
188 |
ShouldNotReachHere();
|
|
189 |
return NULL;
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
//=============================================================================
|
|
194 |
//------------------------------Ideal------------------------------------------
|
|
195 |
// Return a node which is more "ideal" than the current node.
|
|
196 |
// Check for conversions to boolean
|
|
197 |
Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
198 |
// Try generic ideal's first
|
|
199 |
Node *x = CMoveNode::Ideal(phase, can_reshape);
|
|
200 |
if( x ) return x;
|
|
201 |
|
|
202 |
// If zero is on the left (false-case, no-move-case) it must mean another
|
|
203 |
// constant is on the right (otherwise the shared CMove::Ideal code would
|
|
204 |
// have moved the constant to the right). This situation is bad for Intel
|
|
205 |
// and a don't-care for Sparc. It's bad for Intel because the zero has to
|
|
206 |
// be manifested in a register with a XOR which kills flags, which are live
|
|
207 |
// on input to the CMoveI, leading to a situation which causes excessive
|
|
208 |
// spilling on Intel. For Sparc, if the zero in on the left the Sparc will
|
|
209 |
// zero a register via G0 and conditionally-move the other constant. If the
|
|
210 |
// zero is on the right, the Sparc will load the first constant with a
|
|
211 |
// 13-bit set-lo and conditionally move G0. See bug 4677505.
|
|
212 |
if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
|
|
213 |
if( in(Condition)->is_Bool() ) {
|
|
214 |
BoolNode* b = in(Condition)->as_Bool();
|
|
215 |
BoolNode* b2 = b->negate(phase);
|
|
216 |
return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
// Now check for booleans
|
|
221 |
int flip = 0;
|
|
222 |
|
|
223 |
// Check for picking from zero/one
|
|
224 |
if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
|
|
225 |
flip = 1 - flip;
|
|
226 |
} else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
|
|
227 |
} else return NULL;
|
|
228 |
|
|
229 |
// Check for eq/ne test
|
|
230 |
if( !in(1)->is_Bool() ) return NULL;
|
|
231 |
BoolNode *bol = in(1)->as_Bool();
|
|
232 |
if( bol->_test._test == BoolTest::eq ) {
|
|
233 |
} else if( bol->_test._test == BoolTest::ne ) {
|
|
234 |
flip = 1-flip;
|
|
235 |
} else return NULL;
|
|
236 |
|
|
237 |
// Check for vs 0 or 1
|
|
238 |
if( !bol->in(1)->is_Cmp() ) return NULL;
|
|
239 |
const CmpNode *cmp = bol->in(1)->as_Cmp();
|
|
240 |
if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
|
|
241 |
} else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
|
|
242 |
// Allow cmp-vs-1 if the other input is bounded by 0-1
|
|
243 |
if( phase->type(cmp->in(1)) != TypeInt::BOOL )
|
|
244 |
return NULL;
|
|
245 |
flip = 1 - flip;
|
|
246 |
} else return NULL;
|
|
247 |
|
|
248 |
// Convert to a bool (flipped)
|
|
249 |
// Build int->bool conversion
|
|
250 |
#ifndef PRODUCT
|
|
251 |
if( PrintOpto ) tty->print_cr("CMOV to I2B");
|
|
252 |
#endif
|
|
253 |
Node *n = new (phase->C, 2) Conv2BNode( cmp->in(1) );
|
|
254 |
if( flip )
|
|
255 |
n = new (phase->C, 3) XorINode( phase->transform(n), phase->intcon(1) );
|
|
256 |
|
|
257 |
return n;
|
|
258 |
}
|
|
259 |
|
|
260 |
//=============================================================================
|
|
261 |
//------------------------------Ideal------------------------------------------
|
|
262 |
// Return a node which is more "ideal" than the current node.
|
|
263 |
// Check for absolute value
|
|
264 |
Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
265 |
// Try generic ideal's first
|
|
266 |
Node *x = CMoveNode::Ideal(phase, can_reshape);
|
|
267 |
if( x ) return x;
|
|
268 |
|
|
269 |
int cmp_zero_idx = 0; // Index of compare input where to look for zero
|
|
270 |
int phi_x_idx = 0; // Index of phi input where to find naked x
|
|
271 |
|
|
272 |
// Find the Bool
|
|
273 |
if( !in(1)->is_Bool() ) return NULL;
|
|
274 |
BoolNode *bol = in(1)->as_Bool();
|
|
275 |
// Check bool sense
|
|
276 |
switch( bol->_test._test ) {
|
|
277 |
case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;
|
|
278 |
case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
|
|
279 |
case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;
|
|
280 |
case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
|
|
281 |
default: return NULL; break;
|
|
282 |
}
|
|
283 |
|
|
284 |
// Find zero input of CmpF; the other input is being abs'd
|
|
285 |
Node *cmpf = bol->in(1);
|
|
286 |
if( cmpf->Opcode() != Op_CmpF ) return NULL;
|
|
287 |
Node *X = NULL;
|
|
288 |
bool flip = false;
|
|
289 |
if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
|
|
290 |
X = cmpf->in(3 - cmp_zero_idx);
|
|
291 |
} else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
|
|
292 |
// The test is inverted, we should invert the result...
|
|
293 |
X = cmpf->in(cmp_zero_idx);
|
|
294 |
flip = true;
|
|
295 |
} else {
|
|
296 |
return NULL;
|
|
297 |
}
|
|
298 |
|
|
299 |
// If X is found on the appropriate phi input, find the subtract on the other
|
|
300 |
if( X != in(phi_x_idx) ) return NULL;
|
|
301 |
int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
|
|
302 |
Node *sub = in(phi_sub_idx);
|
|
303 |
|
|
304 |
// Allow only SubF(0,X) and fail out for all others; NegF is not OK
|
|
305 |
if( sub->Opcode() != Op_SubF ||
|
|
306 |
sub->in(2) != X ||
|
|
307 |
phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
|
|
308 |
|
|
309 |
Node *abs = new (phase->C, 2) AbsFNode( X );
|
|
310 |
if( flip )
|
|
311 |
abs = new (phase->C, 3) SubFNode(sub->in(1), phase->transform(abs));
|
|
312 |
|
|
313 |
return abs;
|
|
314 |
}
|
|
315 |
|
|
316 |
//=============================================================================
|
|
317 |
//------------------------------Ideal------------------------------------------
|
|
318 |
// Return a node which is more "ideal" than the current node.
|
|
319 |
// Check for absolute value
|
|
320 |
Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
321 |
// Try generic ideal's first
|
|
322 |
Node *x = CMoveNode::Ideal(phase, can_reshape);
|
|
323 |
if( x ) return x;
|
|
324 |
|
|
325 |
int cmp_zero_idx = 0; // Index of compare input where to look for zero
|
|
326 |
int phi_x_idx = 0; // Index of phi input where to find naked x
|
|
327 |
|
|
328 |
// Find the Bool
|
|
329 |
if( !in(1)->is_Bool() ) return NULL;
|
|
330 |
BoolNode *bol = in(1)->as_Bool();
|
|
331 |
// Check bool sense
|
|
332 |
switch( bol->_test._test ) {
|
|
333 |
case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;
|
|
334 |
case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
|
|
335 |
case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;
|
|
336 |
case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
|
|
337 |
default: return NULL; break;
|
|
338 |
}
|
|
339 |
|
|
340 |
// Find zero input of CmpD; the other input is being abs'd
|
|
341 |
Node *cmpd = bol->in(1);
|
|
342 |
if( cmpd->Opcode() != Op_CmpD ) return NULL;
|
|
343 |
Node *X = NULL;
|
|
344 |
bool flip = false;
|
|
345 |
if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
|
|
346 |
X = cmpd->in(3 - cmp_zero_idx);
|
|
347 |
} else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
|
|
348 |
// The test is inverted, we should invert the result...
|
|
349 |
X = cmpd->in(cmp_zero_idx);
|
|
350 |
flip = true;
|
|
351 |
} else {
|
|
352 |
return NULL;
|
|
353 |
}
|
|
354 |
|
|
355 |
// If X is found on the appropriate phi input, find the subtract on the other
|
|
356 |
if( X != in(phi_x_idx) ) return NULL;
|
|
357 |
int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
|
|
358 |
Node *sub = in(phi_sub_idx);
|
|
359 |
|
|
360 |
// Allow only SubD(0,X) and fail out for all others; NegD is not OK
|
|
361 |
if( sub->Opcode() != Op_SubD ||
|
|
362 |
sub->in(2) != X ||
|
|
363 |
phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
|
|
364 |
|
|
365 |
Node *abs = new (phase->C, 2) AbsDNode( X );
|
|
366 |
if( flip )
|
|
367 |
abs = new (phase->C, 3) SubDNode(sub->in(1), phase->transform(abs));
|
|
368 |
|
|
369 |
return abs;
|
|
370 |
}
|
|
371 |
|
|
372 |
|
|
373 |
//=============================================================================
|
|
374 |
// If input is already higher or equal to cast type, then this is an identity.
|
|
375 |
Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {
|
|
376 |
return phase->type(in(1))->higher_equal(_type) ? in(1) : this;
|
|
377 |
}
|
|
378 |
|
|
379 |
//------------------------------Value------------------------------------------
|
|
380 |
// Take 'join' of input and cast-up type
|
|
381 |
const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
|
|
382 |
if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
|
|
383 |
const Type* ft = phase->type(in(1))->filter(_type);
|
|
384 |
|
|
385 |
#ifdef ASSERT
|
|
386 |
// Previous versions of this function had some special case logic,
|
|
387 |
// which is no longer necessary. Make sure of the required effects.
|
|
388 |
switch (Opcode()) {
|
|
389 |
case Op_CastII:
|
|
390 |
{
|
|
391 |
const Type* t1 = phase->type(in(1));
|
|
392 |
if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1");
|
|
393 |
const Type* rt = t1->join(_type);
|
|
394 |
if (rt->empty()) assert(ft == Type::TOP, "special case #2");
|
|
395 |
break;
|
|
396 |
}
|
|
397 |
case Op_CastPP:
|
|
398 |
if (phase->type(in(1)) == TypePtr::NULL_PTR &&
|
|
399 |
_type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
|
|
400 |
assert(ft == Type::TOP, "special case #3");
|
|
401 |
break;
|
|
402 |
}
|
|
403 |
#endif //ASSERT
|
|
404 |
|
|
405 |
return ft;
|
|
406 |
}
|
|
407 |
|
|
408 |
//------------------------------Ideal------------------------------------------
|
|
409 |
// Return a node which is more "ideal" than the current node. Strip out
|
|
410 |
// control copies
|
|
411 |
Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
|
|
412 |
return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
|
|
413 |
}
|
|
414 |
|
|
415 |
//------------------------------Ideal_DU_postCCP-------------------------------
|
|
416 |
// Throw away cast after constant propagation
|
|
417 |
Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
|
|
418 |
const Type *t = ccp->type(in(1));
|
|
419 |
ccp->hash_delete(this);
|
|
420 |
set_type(t); // Turn into ID function
|
|
421 |
ccp->hash_insert(this);
|
|
422 |
return this;
|
|
423 |
}
|
|
424 |
|
|
425 |
|
|
426 |
//=============================================================================
|
|
427 |
|
|
428 |
//------------------------------Ideal_DU_postCCP-------------------------------
|
|
429 |
// If not converting int->oop, throw away cast after constant propagation
|
|
430 |
Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
|
|
431 |
const Type *t = ccp->type(in(1));
|
|
432 |
if (!t->isa_oop_ptr()) {
|
|
433 |
return NULL; // do not transform raw pointers
|
|
434 |
}
|
|
435 |
return ConstraintCastNode::Ideal_DU_postCCP(ccp);
|
|
436 |
}
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
//=============================================================================
|
|
441 |
//------------------------------Identity---------------------------------------
|
|
442 |
// If input is already higher or equal to cast type, then this is an identity.
|
|
443 |
Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
|
|
444 |
// Toned down to rescue meeting at a Phi 3 different oops all implementing
|
|
445 |
// the same interface. CompileTheWorld starting at 502, kd12rc1.zip.
|
|
446 |
return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
|
|
447 |
}
|
|
448 |
|
|
449 |
// Determine whether "n" is a node which can cause an alias of one of its inputs. Node types
|
|
450 |
// which can create aliases are: CheckCastPP, Phi, and any store (if there is also a load from
|
|
451 |
// the location.)
|
|
452 |
// Note: this checks for aliases created in this compilation, not ones which may
|
|
453 |
// be potentially created at call sites.
|
|
454 |
static bool can_cause_alias(Node *n, PhaseTransform *phase) {
|
|
455 |
bool possible_alias = false;
|
|
456 |
|
|
457 |
if (n->is_Store()) {
|
|
458 |
possible_alias = !n->as_Store()->value_never_loaded(phase);
|
|
459 |
} else {
|
|
460 |
int opc = n->Opcode();
|
|
461 |
possible_alias = n->is_Phi() ||
|
|
462 |
opc == Op_CheckCastPP ||
|
|
463 |
opc == Op_StorePConditional ||
|
|
464 |
opc == Op_CompareAndSwapP;
|
|
465 |
}
|
|
466 |
return possible_alias;
|
|
467 |
}
|
|
468 |
|
|
469 |
//------------------------------Value------------------------------------------
|
|
470 |
// Take 'join' of input and cast-up type, unless working with an Interface
|
|
471 |
const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
|
|
472 |
if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
|
|
473 |
|
|
474 |
const Type *inn = phase->type(in(1));
|
|
475 |
if( inn == Type::TOP ) return Type::TOP; // No information yet
|
|
476 |
|
|
477 |
const TypePtr *in_type = inn->isa_ptr();
|
|
478 |
const TypePtr *my_type = _type->isa_ptr();
|
|
479 |
const Type *result = _type;
|
|
480 |
if( in_type != NULL && my_type != NULL ) {
|
|
481 |
TypePtr::PTR in_ptr = in_type->ptr();
|
|
482 |
if( in_ptr == TypePtr::Null ) {
|
|
483 |
result = in_type;
|
|
484 |
} else if( in_ptr == TypePtr::Constant ) {
|
|
485 |
// Casting a constant oop to an interface?
|
|
486 |
// (i.e., a String to a Comparable?)
|
|
487 |
// Then return the interface.
|
|
488 |
const TypeOopPtr *jptr = my_type->isa_oopptr();
|
|
489 |
assert( jptr, "" );
|
|
490 |
result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
|
|
491 |
? my_type->cast_to_ptr_type( TypePtr::NotNull )
|
|
492 |
: in_type;
|
|
493 |
} else {
|
|
494 |
result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
|
|
495 |
}
|
|
496 |
}
|
|
497 |
return result;
|
|
498 |
|
|
499 |
// JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
|
|
500 |
// FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
|
|
501 |
|
|
502 |
//
|
|
503 |
// Remove this code after overnight run indicates no performance
|
|
504 |
// loss from not performing JOIN at CheckCastPPNode
|
|
505 |
//
|
|
506 |
// const TypeInstPtr *in_oop = in->isa_instptr();
|
|
507 |
// const TypeInstPtr *my_oop = _type->isa_instptr();
|
|
508 |
// // If either input is an 'interface', return destination type
|
|
509 |
// assert (in_oop == NULL || in_oop->klass() != NULL, "");
|
|
510 |
// assert (my_oop == NULL || my_oop->klass() != NULL, "");
|
|
511 |
// if( (in_oop && in_oop->klass()->klass_part()->is_interface())
|
|
512 |
// ||(my_oop && my_oop->klass()->klass_part()->is_interface()) ) {
|
|
513 |
// TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
|
|
514 |
// // Preserve cast away nullness for interfaces
|
|
515 |
// if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
|
|
516 |
// return my_oop->cast_to_ptr_type(TypePtr::NotNull);
|
|
517 |
// }
|
|
518 |
// return _type;
|
|
519 |
// }
|
|
520 |
//
|
|
521 |
// // Neither the input nor the destination type is an interface,
|
|
522 |
//
|
|
523 |
// // history: JOIN used to cause weird corner case bugs
|
|
524 |
// // return (in == TypeOopPtr::NULL_PTR) ? in : _type;
|
|
525 |
// // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
|
|
526 |
// // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
|
|
527 |
// const Type *join = in->join(_type);
|
|
528 |
// // Check if join preserved NotNull'ness for pointers
|
|
529 |
// if( join->isa_ptr() && _type->isa_ptr() ) {
|
|
530 |
// TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
|
|
531 |
// TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
|
|
532 |
// // If there isn't any NotNull'ness to preserve
|
|
533 |
// // OR if join preserved NotNull'ness then return it
|
|
534 |
// if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null ||
|
|
535 |
// join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
|
|
536 |
// return join;
|
|
537 |
// }
|
|
538 |
// // ELSE return same old type as before
|
|
539 |
// return _type;
|
|
540 |
// }
|
|
541 |
// // Not joining two pointers
|
|
542 |
// return join;
|
|
543 |
}
|
|
544 |
|
|
545 |
//------------------------------Ideal------------------------------------------
|
|
546 |
// Return a node which is more "ideal" than the current node. Strip out
|
|
547 |
// control copies
|
|
548 |
Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
|
|
549 |
return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
|
|
550 |
}
|
|
551 |
|
|
552 |
//=============================================================================
|
|
553 |
//------------------------------Identity---------------------------------------
|
|
554 |
Node *Conv2BNode::Identity( PhaseTransform *phase ) {
|
|
555 |
const Type *t = phase->type( in(1) );
|
|
556 |
if( t == Type::TOP ) return in(1);
|
|
557 |
if( t == TypeInt::ZERO ) return in(1);
|
|
558 |
if( t == TypeInt::ONE ) return in(1);
|
|
559 |
if( t == TypeInt::BOOL ) return in(1);
|
|
560 |
return this;
|
|
561 |
}
|
|
562 |
|
|
563 |
//------------------------------Value------------------------------------------
|
|
564 |
const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
|
|
565 |
const Type *t = phase->type( in(1) );
|
|
566 |
if( t == Type::TOP ) return Type::TOP;
|
|
567 |
if( t == TypeInt::ZERO ) return TypeInt::ZERO;
|
|
568 |
if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
|
|
569 |
const TypePtr *tp = t->isa_ptr();
|
|
570 |
if( tp != NULL ) {
|
|
571 |
if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
|
|
572 |
if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
|
|
573 |
if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;
|
|
574 |
return TypeInt::BOOL;
|
|
575 |
}
|
|
576 |
if (t->base() != Type::Int) return TypeInt::BOOL;
|
|
577 |
const TypeInt *ti = t->is_int();
|
|
578 |
if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
|
|
579 |
return TypeInt::BOOL;
|
|
580 |
}
|
|
581 |
|
|
582 |
|
|
583 |
// The conversions operations are all Alpha sorted. Please keep it that way!
|
|
584 |
//=============================================================================
|
|
585 |
//------------------------------Value------------------------------------------
|
|
586 |
const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
|
|
587 |
const Type *t = phase->type( in(1) );
|
|
588 |
if( t == Type::TOP ) return Type::TOP;
|
|
589 |
if( t == Type::DOUBLE ) return Type::FLOAT;
|
|
590 |
const TypeD *td = t->is_double_constant();
|
|
591 |
return TypeF::make( (float)td->getd() );
|
|
592 |
}
|
|
593 |
|
|
594 |
//------------------------------Identity---------------------------------------
|
|
595 |
// Float's can be converted to doubles with no loss of bits. Hence
|
|
596 |
// converting a float to a double and back to a float is a NOP.
|
|
597 |
Node *ConvD2FNode::Identity(PhaseTransform *phase) {
|
|
598 |
return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
|
|
599 |
}
|
|
600 |
|
|
601 |
//=============================================================================
|
|
602 |
//------------------------------Value------------------------------------------
|
|
603 |
const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
|
|
604 |
const Type *t = phase->type( in(1) );
|
|
605 |
if( t == Type::TOP ) return Type::TOP;
|
|
606 |
if( t == Type::DOUBLE ) return TypeInt::INT;
|
|
607 |
const TypeD *td = t->is_double_constant();
|
|
608 |
return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
|
|
609 |
}
|
|
610 |
|
|
611 |
//------------------------------Ideal------------------------------------------
|
|
612 |
// If converting to an int type, skip any rounding nodes
|
|
613 |
Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
614 |
if( in(1)->Opcode() == Op_RoundDouble )
|
|
615 |
set_req(1,in(1)->in(1));
|
|
616 |
return NULL;
|
|
617 |
}
|
|
618 |
|
|
619 |
//------------------------------Identity---------------------------------------
|
|
620 |
// Int's can be converted to doubles with no loss of bits. Hence
|
|
621 |
// converting an integer to a double and back to an integer is a NOP.
|
|
622 |
Node *ConvD2INode::Identity(PhaseTransform *phase) {
|
|
623 |
return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
|
|
624 |
}
|
|
625 |
|
|
626 |
//=============================================================================
|
|
627 |
//------------------------------Value------------------------------------------
|
|
628 |
const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
|
|
629 |
const Type *t = phase->type( in(1) );
|
|
630 |
if( t == Type::TOP ) return Type::TOP;
|
|
631 |
if( t == Type::DOUBLE ) return TypeLong::LONG;
|
|
632 |
const TypeD *td = t->is_double_constant();
|
|
633 |
return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
|
|
634 |
}
|
|
635 |
|
|
636 |
//------------------------------Identity---------------------------------------
|
|
637 |
Node *ConvD2LNode::Identity(PhaseTransform *phase) {
|
|
638 |
// Remove ConvD2L->ConvL2D->ConvD2L sequences.
|
|
639 |
if( in(1) ->Opcode() == Op_ConvL2D &&
|
|
640 |
in(1)->in(1)->Opcode() == Op_ConvD2L )
|
|
641 |
return in(1)->in(1);
|
|
642 |
return this;
|
|
643 |
}
|
|
644 |
|
|
645 |
//------------------------------Ideal------------------------------------------
|
|
646 |
// If converting to an int type, skip any rounding nodes
|
|
647 |
Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
648 |
if( in(1)->Opcode() == Op_RoundDouble )
|
|
649 |
set_req(1,in(1)->in(1));
|
|
650 |
return NULL;
|
|
651 |
}
|
|
652 |
|
|
653 |
//=============================================================================
|
|
654 |
//------------------------------Value------------------------------------------
|
|
655 |
const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
|
|
656 |
const Type *t = phase->type( in(1) );
|
|
657 |
if( t == Type::TOP ) return Type::TOP;
|
|
658 |
if( t == Type::FLOAT ) return Type::DOUBLE;
|
|
659 |
const TypeF *tf = t->is_float_constant();
|
|
660 |
#ifndef IA64
|
|
661 |
return TypeD::make( (double)tf->getf() );
|
|
662 |
#else
|
|
663 |
float x = tf->getf();
|
|
664 |
return TypeD::make( (x == 0.0f) ? (double)x : (double)x + ia64_double_zero );
|
|
665 |
#endif
|
|
666 |
}
|
|
667 |
|
|
668 |
//=============================================================================
|
|
669 |
//------------------------------Value------------------------------------------
|
|
670 |
const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
|
|
671 |
const Type *t = phase->type( in(1) );
|
|
672 |
if( t == Type::TOP ) return Type::TOP;
|
|
673 |
if( t == Type::FLOAT ) return TypeInt::INT;
|
|
674 |
const TypeF *tf = t->is_float_constant();
|
|
675 |
return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
|
|
676 |
}
|
|
677 |
|
|
678 |
//------------------------------Identity---------------------------------------
|
|
679 |
Node *ConvF2INode::Identity(PhaseTransform *phase) {
|
|
680 |
// Remove ConvF2I->ConvI2F->ConvF2I sequences.
|
|
681 |
if( in(1) ->Opcode() == Op_ConvI2F &&
|
|
682 |
in(1)->in(1)->Opcode() == Op_ConvF2I )
|
|
683 |
return in(1)->in(1);
|
|
684 |
return this;
|
|
685 |
}
|
|
686 |
|
|
687 |
//------------------------------Ideal------------------------------------------
|
|
688 |
// If converting to an int type, skip any rounding nodes
|
|
689 |
Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
690 |
if( in(1)->Opcode() == Op_RoundFloat )
|
|
691 |
set_req(1,in(1)->in(1));
|
|
692 |
return NULL;
|
|
693 |
}
|
|
694 |
|
|
695 |
//=============================================================================
|
|
696 |
//------------------------------Value------------------------------------------
|
|
697 |
const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
|
|
698 |
const Type *t = phase->type( in(1) );
|
|
699 |
if( t == Type::TOP ) return Type::TOP;
|
|
700 |
if( t == Type::FLOAT ) return TypeLong::LONG;
|
|
701 |
const TypeF *tf = t->is_float_constant();
|
|
702 |
return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
|
|
703 |
}
|
|
704 |
|
|
705 |
//------------------------------Identity---------------------------------------
|
|
706 |
Node *ConvF2LNode::Identity(PhaseTransform *phase) {
|
|
707 |
// Remove ConvF2L->ConvL2F->ConvF2L sequences.
|
|
708 |
if( in(1) ->Opcode() == Op_ConvL2F &&
|
|
709 |
in(1)->in(1)->Opcode() == Op_ConvF2L )
|
|
710 |
return in(1)->in(1);
|
|
711 |
return this;
|
|
712 |
}
|
|
713 |
|
|
714 |
//------------------------------Ideal------------------------------------------
|
|
715 |
// If converting to an int type, skip any rounding nodes
|
|
716 |
Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
717 |
if( in(1)->Opcode() == Op_RoundFloat )
|
|
718 |
set_req(1,in(1)->in(1));
|
|
719 |
return NULL;
|
|
720 |
}
|
|
721 |
|
|
722 |
//=============================================================================
|
|
723 |
//------------------------------Value------------------------------------------
|
|
724 |
const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
|
|
725 |
const Type *t = phase->type( in(1) );
|
|
726 |
if( t == Type::TOP ) return Type::TOP;
|
|
727 |
const TypeInt *ti = t->is_int();
|
|
728 |
if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
|
|
729 |
return bottom_type();
|
|
730 |
}
|
|
731 |
|
|
732 |
//=============================================================================
|
|
733 |
//------------------------------Value------------------------------------------
|
|
734 |
const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
|
|
735 |
const Type *t = phase->type( in(1) );
|
|
736 |
if( t == Type::TOP ) return Type::TOP;
|
|
737 |
const TypeInt *ti = t->is_int();
|
|
738 |
if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
|
|
739 |
return bottom_type();
|
|
740 |
}
|
|
741 |
|
|
742 |
//------------------------------Identity---------------------------------------
|
|
743 |
Node *ConvI2FNode::Identity(PhaseTransform *phase) {
|
|
744 |
// Remove ConvI2F->ConvF2I->ConvI2F sequences.
|
|
745 |
if( in(1) ->Opcode() == Op_ConvF2I &&
|
|
746 |
in(1)->in(1)->Opcode() == Op_ConvI2F )
|
|
747 |
return in(1)->in(1);
|
|
748 |
return this;
|
|
749 |
}
|
|
750 |
|
|
751 |
//=============================================================================
|
|
752 |
//------------------------------Value------------------------------------------
|
|
753 |
const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
|
|
754 |
const Type *t = phase->type( in(1) );
|
|
755 |
if( t == Type::TOP ) return Type::TOP;
|
|
756 |
const TypeInt *ti = t->is_int();
|
|
757 |
const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
|
|
758 |
// Join my declared type against my incoming type.
|
|
759 |
tl = tl->filter(_type);
|
|
760 |
return tl;
|
|
761 |
}
|
|
762 |
|
|
763 |
#ifdef _LP64
|
|
764 |
static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
|
|
765 |
jlong lo2, jlong hi2) {
|
|
766 |
// Two ranges overlap iff one range's low point falls in the other range.
|
|
767 |
return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
|
|
768 |
}
|
|
769 |
#endif
|
|
770 |
|
|
771 |
//------------------------------Ideal------------------------------------------
|
|
772 |
Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
773 |
const TypeLong* this_type = this->type()->is_long();
|
|
774 |
Node* this_changed = NULL;
|
|
775 |
|
|
776 |
// If _major_progress, then more loop optimizations follow. Do NOT
|
|
777 |
// remove this node's type assertion until no more loop ops can happen.
|
|
778 |
// The progress bit is set in the major loop optimizations THEN comes the
|
|
779 |
// call to IterGVN and any chance of hitting this code. Cf. Opaque1Node.
|
|
780 |
if (can_reshape && !phase->C->major_progress()) {
|
|
781 |
const TypeInt* in_type = phase->type(in(1))->isa_int();
|
|
782 |
if (in_type != NULL && this_type != NULL &&
|
|
783 |
(in_type->_lo != this_type->_lo ||
|
|
784 |
in_type->_hi != this_type->_hi)) {
|
|
785 |
// Although this WORSENS the type, it increases GVN opportunities,
|
|
786 |
// because I2L nodes with the same input will common up, regardless
|
|
787 |
// of slightly differing type assertions. Such slight differences
|
|
788 |
// arise routinely as a result of loop unrolling, so this is a
|
|
789 |
// post-unrolling graph cleanup. Choose a type which depends only
|
|
790 |
// on my input. (Exception: Keep a range assertion of >=0 or <0.)
|
|
791 |
jlong lo1 = this_type->_lo;
|
|
792 |
jlong hi1 = this_type->_hi;
|
|
793 |
int w1 = this_type->_widen;
|
|
794 |
if (lo1 != (jint)lo1 ||
|
|
795 |
hi1 != (jint)hi1 ||
|
|
796 |
lo1 > hi1) {
|
|
797 |
// Overflow leads to wraparound, wraparound leads to range saturation.
|
|
798 |
lo1 = min_jint; hi1 = max_jint;
|
|
799 |
} else if (lo1 >= 0) {
|
|
800 |
// Keep a range assertion of >=0.
|
|
801 |
lo1 = 0; hi1 = max_jint;
|
|
802 |
} else if (hi1 < 0) {
|
|
803 |
// Keep a range assertion of <0.
|
|
804 |
lo1 = min_jint; hi1 = -1;
|
|
805 |
} else {
|
|
806 |
lo1 = min_jint; hi1 = max_jint;
|
|
807 |
}
|
|
808 |
const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
|
|
809 |
MIN2((jlong)in_type->_hi, hi1),
|
|
810 |
MAX2((int)in_type->_widen, w1));
|
|
811 |
if (wtype != type()) {
|
|
812 |
set_type(wtype);
|
|
813 |
// Note: this_type still has old type value, for the logic below.
|
|
814 |
this_changed = this;
|
|
815 |
}
|
|
816 |
}
|
|
817 |
}
|
|
818 |
|
|
819 |
#ifdef _LP64
|
|
820 |
// Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
|
|
821 |
// but only if x and y have subranges that cannot cause 32-bit overflow,
|
|
822 |
// under the assumption that x+y is in my own subrange this->type().
|
|
823 |
|
|
824 |
// This assumption is based on a constraint (i.e., type assertion)
|
|
825 |
// established in Parse::array_addressing or perhaps elsewhere.
|
|
826 |
// This constraint has been adjoined to the "natural" type of
|
|
827 |
// the incoming argument in(0). We know (because of runtime
|
|
828 |
// checks) - that the result value I2L(x+y) is in the joined range.
|
|
829 |
// Hence we can restrict the incoming terms (x, y) to values such
|
|
830 |
// that their sum also lands in that range.
|
|
831 |
|
|
832 |
// This optimization is useful only on 64-bit systems, where we hope
|
|
833 |
// the addition will end up subsumed in an addressing mode.
|
|
834 |
// It is necessary to do this when optimizing an unrolled array
|
|
835 |
// copy loop such as x[i++] = y[i++].
|
|
836 |
|
|
837 |
// On 32-bit systems, it's better to perform as much 32-bit math as
|
|
838 |
// possible before the I2L conversion, because 32-bit math is cheaper.
|
|
839 |
// There's no common reason to "leak" a constant offset through the I2L.
|
|
840 |
// Addressing arithmetic will not absorb it as part of a 64-bit AddL.
|
|
841 |
|
|
842 |
Node* z = in(1);
|
|
843 |
int op = z->Opcode();
|
|
844 |
if (op == Op_AddI || op == Op_SubI) {
|
|
845 |
Node* x = z->in(1);
|
|
846 |
Node* y = z->in(2);
|
|
847 |
assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
|
|
848 |
if (phase->type(x) == Type::TOP) return this_changed;
|
|
849 |
if (phase->type(y) == Type::TOP) return this_changed;
|
|
850 |
const TypeInt* tx = phase->type(x)->is_int();
|
|
851 |
const TypeInt* ty = phase->type(y)->is_int();
|
|
852 |
const TypeLong* tz = this_type;
|
|
853 |
jlong xlo = tx->_lo;
|
|
854 |
jlong xhi = tx->_hi;
|
|
855 |
jlong ylo = ty->_lo;
|
|
856 |
jlong yhi = ty->_hi;
|
|
857 |
jlong zlo = tz->_lo;
|
|
858 |
jlong zhi = tz->_hi;
|
|
859 |
jlong vbit = CONST64(1) << BitsPerInt;
|
|
860 |
int widen = MAX2(tx->_widen, ty->_widen);
|
|
861 |
if (op == Op_SubI) {
|
|
862 |
jlong ylo0 = ylo;
|
|
863 |
ylo = -yhi;
|
|
864 |
yhi = -ylo0;
|
|
865 |
}
|
|
866 |
// See if x+y can cause positive overflow into z+2**32
|
|
867 |
if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
|
|
868 |
return this_changed;
|
|
869 |
}
|
|
870 |
// See if x+y can cause negative overflow into z-2**32
|
|
871 |
if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
|
|
872 |
return this_changed;
|
|
873 |
}
|
|
874 |
// Now it's always safe to assume x+y does not overflow.
|
|
875 |
// This is true even if some pairs x,y might cause overflow, as long
|
|
876 |
// as that overflow value cannot fall into [zlo,zhi].
|
|
877 |
|
|
878 |
// Confident that the arithmetic is "as if infinite precision",
|
|
879 |
// we can now use z's range to put constraints on those of x and y.
|
|
880 |
// The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
|
|
881 |
// more "restricted" range by intersecting [xlo,xhi] with the
|
|
882 |
// range obtained by subtracting y's range from the asserted range
|
|
883 |
// of the I2L conversion. Here's the interval arithmetic algebra:
|
|
884 |
// x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
|
|
885 |
// => x in [zlo-yhi, zhi-ylo]
|
|
886 |
// => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
|
|
887 |
// => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
|
|
888 |
jlong rxlo = MAX2(xlo, zlo - yhi);
|
|
889 |
jlong rxhi = MIN2(xhi, zhi - ylo);
|
|
890 |
// And similarly, x changing place with y:
|
|
891 |
jlong rylo = MAX2(ylo, zlo - xhi);
|
|
892 |
jlong ryhi = MIN2(yhi, zhi - xlo);
|
|
893 |
if (rxlo > rxhi || rylo > ryhi) {
|
|
894 |
return this_changed; // x or y is dying; don't mess w/ it
|
|
895 |
}
|
|
896 |
if (op == Op_SubI) {
|
|
897 |
jlong rylo0 = rylo;
|
|
898 |
rylo = -ryhi;
|
|
899 |
ryhi = -rylo0;
|
|
900 |
}
|
|
901 |
|
|
902 |
Node* cx = phase->transform( new (phase->C, 2) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
|
|
903 |
Node* cy = phase->transform( new (phase->C, 2) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
|
|
904 |
switch (op) {
|
|
905 |
case Op_AddI: return new (phase->C, 3) AddLNode(cx, cy);
|
|
906 |
case Op_SubI: return new (phase->C, 3) SubLNode(cx, cy);
|
|
907 |
default: ShouldNotReachHere();
|
|
908 |
}
|
|
909 |
}
|
|
910 |
#endif //_LP64
|
|
911 |
|
|
912 |
return this_changed;
|
|
913 |
}
|
|
914 |
|
|
915 |
//=============================================================================
|
|
916 |
//------------------------------Value------------------------------------------
|
|
917 |
const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
|
|
918 |
const Type *t = phase->type( in(1) );
|
|
919 |
if( t == Type::TOP ) return Type::TOP;
|
|
920 |
const TypeLong *tl = t->is_long();
|
|
921 |
if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
|
|
922 |
return bottom_type();
|
|
923 |
}
|
|
924 |
|
|
925 |
//=============================================================================
|
|
926 |
//------------------------------Value------------------------------------------
|
|
927 |
const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
|
|
928 |
const Type *t = phase->type( in(1) );
|
|
929 |
if( t == Type::TOP ) return Type::TOP;
|
|
930 |
const TypeLong *tl = t->is_long();
|
|
931 |
if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
|
|
932 |
return bottom_type();
|
|
933 |
}
|
|
934 |
|
|
935 |
//=============================================================================
|
|
936 |
//----------------------------Identity-----------------------------------------
|
|
937 |
Node *ConvL2INode::Identity( PhaseTransform *phase ) {
|
|
938 |
// Convert L2I(I2L(x)) => x
|
|
939 |
if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);
|
|
940 |
return this;
|
|
941 |
}
|
|
942 |
|
|
943 |
//------------------------------Value------------------------------------------
|
|
944 |
const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
|
|
945 |
const Type *t = phase->type( in(1) );
|
|
946 |
if( t == Type::TOP ) return Type::TOP;
|
|
947 |
const TypeLong *tl = t->is_long();
|
|
948 |
if (tl->is_con())
|
|
949 |
// Easy case.
|
|
950 |
return TypeInt::make((jint)tl->get_con());
|
|
951 |
return bottom_type();
|
|
952 |
}
|
|
953 |
|
|
954 |
//------------------------------Ideal------------------------------------------
|
|
955 |
// Return a node which is more "ideal" than the current node.
|
|
956 |
// Blow off prior masking to int
|
|
957 |
Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
958 |
Node *andl = in(1);
|
|
959 |
uint andl_op = andl->Opcode();
|
|
960 |
if( andl_op == Op_AndL ) {
|
|
961 |
// Blow off prior masking to int
|
|
962 |
if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
|
|
963 |
set_req(1,andl->in(1));
|
|
964 |
return this;
|
|
965 |
}
|
|
966 |
}
|
|
967 |
|
|
968 |
// Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
|
|
969 |
// This replaces an 'AddL' with an 'AddI'.
|
|
970 |
if( andl_op == Op_AddL ) {
|
|
971 |
// Don't do this for nodes which have more than one user since
|
|
972 |
// we'll end up computing the long add anyway.
|
|
973 |
if (andl->outcnt() > 1) return NULL;
|
|
974 |
|
|
975 |
Node* x = andl->in(1);
|
|
976 |
Node* y = andl->in(2);
|
|
977 |
assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
|
|
978 |
if (phase->type(x) == Type::TOP) return NULL;
|
|
979 |
if (phase->type(y) == Type::TOP) return NULL;
|
|
980 |
Node *add1 = phase->transform(new (phase->C, 2) ConvL2INode(x));
|
|
981 |
Node *add2 = phase->transform(new (phase->C, 2) ConvL2INode(y));
|
|
982 |
return new (phase->C, 3) AddINode(add1,add2);
|
|
983 |
}
|
|
984 |
|
209
|
985 |
// Disable optimization: LoadL->ConvL2I ==> LoadI.
|
|
986 |
// It causes problems (sizes of Load and Store nodes do not match)
|
|
987 |
// in objects initialization code and Escape Analysis.
|
1
|
988 |
return NULL;
|
|
989 |
}
|
|
990 |
|
|
991 |
//=============================================================================
|
|
992 |
//------------------------------Value------------------------------------------
|
|
993 |
const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
|
|
994 |
const Type* t = phase->type(in(1));
|
|
995 |
if (t->base() == Type_X && t->singleton()) {
|
|
996 |
uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
|
|
997 |
if (bits == 0) return TypePtr::NULL_PTR;
|
|
998 |
return TypeRawPtr::make((address) bits);
|
|
999 |
}
|
|
1000 |
return CastX2PNode::bottom_type();
|
|
1001 |
}
|
|
1002 |
|
|
1003 |
//------------------------------Idealize---------------------------------------
|
|
1004 |
static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
|
|
1005 |
if (t == Type::TOP) return false;
|
|
1006 |
const TypeX* tl = t->is_intptr_t();
|
|
1007 |
jint lo = min_jint;
|
|
1008 |
jint hi = max_jint;
|
|
1009 |
if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow
|
|
1010 |
return (tl->_lo >= lo) && (tl->_hi <= hi);
|
|
1011 |
}
|
|
1012 |
|
|
1013 |
static inline Node* addP_of_X2P(PhaseGVN *phase,
|
|
1014 |
Node* base,
|
|
1015 |
Node* dispX,
|
|
1016 |
bool negate = false) {
|
|
1017 |
if (negate) {
|
|
1018 |
dispX = new (phase->C, 3) SubXNode(phase->MakeConX(0), phase->transform(dispX));
|
|
1019 |
}
|
|
1020 |
return new (phase->C, 4) AddPNode(phase->C->top(),
|
|
1021 |
phase->transform(new (phase->C, 2) CastX2PNode(base)),
|
|
1022 |
phase->transform(dispX));
|
|
1023 |
}
|
|
1024 |
|
|
1025 |
Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
1026 |
// convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
|
|
1027 |
int op = in(1)->Opcode();
|
|
1028 |
Node* x;
|
|
1029 |
Node* y;
|
|
1030 |
switch (op) {
|
|
1031 |
case Op_SubX:
|
|
1032 |
x = in(1)->in(1);
|
|
1033 |
y = in(1)->in(2);
|
|
1034 |
if (fits_in_int(phase->type(y), true)) {
|
|
1035 |
return addP_of_X2P(phase, x, y, true);
|
|
1036 |
}
|
|
1037 |
break;
|
|
1038 |
case Op_AddX:
|
|
1039 |
x = in(1)->in(1);
|
|
1040 |
y = in(1)->in(2);
|
|
1041 |
if (fits_in_int(phase->type(y))) {
|
|
1042 |
return addP_of_X2P(phase, x, y);
|
|
1043 |
}
|
|
1044 |
if (fits_in_int(phase->type(x))) {
|
|
1045 |
return addP_of_X2P(phase, y, x);
|
|
1046 |
}
|
|
1047 |
break;
|
|
1048 |
}
|
|
1049 |
return NULL;
|
|
1050 |
}
|
|
1051 |
|
|
1052 |
//------------------------------Identity---------------------------------------
|
|
1053 |
Node *CastX2PNode::Identity( PhaseTransform *phase ) {
|
|
1054 |
if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
|
|
1055 |
return this;
|
|
1056 |
}
|
|
1057 |
|
|
1058 |
//=============================================================================
|
|
1059 |
//------------------------------Value------------------------------------------
|
|
1060 |
const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
|
|
1061 |
const Type* t = phase->type(in(1));
|
|
1062 |
if (t->base() == Type::RawPtr && t->singleton()) {
|
|
1063 |
uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
|
|
1064 |
return TypeX::make(bits);
|
|
1065 |
}
|
|
1066 |
return CastP2XNode::bottom_type();
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
1070 |
return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
|
|
1071 |
}
|
|
1072 |
|
|
1073 |
//------------------------------Identity---------------------------------------
|
|
1074 |
Node *CastP2XNode::Identity( PhaseTransform *phase ) {
|
|
1075 |
if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
|
|
1076 |
return this;
|
|
1077 |
}
|
|
1078 |
|
|
1079 |
|
|
1080 |
//=============================================================================
|
|
1081 |
//------------------------------Identity---------------------------------------
|
|
1082 |
// Remove redundant roundings
|
|
1083 |
Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
|
|
1084 |
assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
|
|
1085 |
// Do not round constants
|
|
1086 |
if (phase->type(in(1))->base() == Type::FloatCon) return in(1);
|
|
1087 |
int op = in(1)->Opcode();
|
|
1088 |
// Redundant rounding
|
|
1089 |
if( op == Op_RoundFloat ) return in(1);
|
|
1090 |
// Already rounded
|
|
1091 |
if( op == Op_Parm ) return in(1);
|
|
1092 |
if( op == Op_LoadF ) return in(1);
|
|
1093 |
return this;
|
|
1094 |
}
|
|
1095 |
|
|
1096 |
//------------------------------Value------------------------------------------
|
|
1097 |
const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
|
|
1098 |
return phase->type( in(1) );
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
//=============================================================================
|
|
1102 |
//------------------------------Identity---------------------------------------
|
|
1103 |
// Remove redundant roundings. Incoming arguments are already rounded.
|
|
1104 |
Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
|
|
1105 |
assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
|
|
1106 |
// Do not round constants
|
|
1107 |
if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);
|
|
1108 |
int op = in(1)->Opcode();
|
|
1109 |
// Redundant rounding
|
|
1110 |
if( op == Op_RoundDouble ) return in(1);
|
|
1111 |
// Already rounded
|
|
1112 |
if( op == Op_Parm ) return in(1);
|
|
1113 |
if( op == Op_LoadD ) return in(1);
|
|
1114 |
if( op == Op_ConvF2D ) return in(1);
|
|
1115 |
if( op == Op_ConvI2D ) return in(1);
|
|
1116 |
return this;
|
|
1117 |
}
|
|
1118 |
|
|
1119 |
//------------------------------Value------------------------------------------
|
|
1120 |
const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
|
|
1121 |
return phase->type( in(1) );
|
|
1122 |
}
|
|
1123 |
|
|
1124 |
|
|
1125 |
//=============================================================================
|
|
1126 |
// Do not allow value-numbering
|
|
1127 |
uint Opaque1Node::hash() const { return NO_HASH; }
|
|
1128 |
uint Opaque1Node::cmp( const Node &n ) const {
|
|
1129 |
return (&n == this); // Always fail except on self
|
|
1130 |
}
|
|
1131 |
|
|
1132 |
//------------------------------Identity---------------------------------------
|
|
1133 |
// If _major_progress, then more loop optimizations follow. Do NOT remove
|
|
1134 |
// the opaque Node until no more loop ops can happen. Note the timing of
|
|
1135 |
// _major_progress; it's set in the major loop optimizations THEN comes the
|
|
1136 |
// call to IterGVN and any chance of hitting this code. Hence there's no
|
|
1137 |
// phase-ordering problem with stripping Opaque1 in IGVN followed by some
|
|
1138 |
// more loop optimizations that require it.
|
|
1139 |
Node *Opaque1Node::Identity( PhaseTransform *phase ) {
|
|
1140 |
return phase->C->major_progress() ? this : in(1);
|
|
1141 |
}
|
|
1142 |
|
|
1143 |
//=============================================================================
|
|
1144 |
// A node to prevent unwanted optimizations. Allows constant folding. Stops
|
|
1145 |
// value-numbering, most Ideal calls or Identity functions. This Node is
|
|
1146 |
// specifically designed to prevent the pre-increment value of a loop trip
|
|
1147 |
// counter from being live out of the bottom of the loop (hence causing the
|
|
1148 |
// pre- and post-increment values both being live and thus requiring an extra
|
|
1149 |
// temp register and an extra move). If we "accidentally" optimize through
|
|
1150 |
// this kind of a Node, we'll get slightly pessimal, but correct, code. Thus
|
|
1151 |
// it's OK to be slightly sloppy on optimizations here.
|
|
1152 |
|
|
1153 |
// Do not allow value-numbering
|
|
1154 |
uint Opaque2Node::hash() const { return NO_HASH; }
|
|
1155 |
uint Opaque2Node::cmp( const Node &n ) const {
|
|
1156 |
return (&n == this); // Always fail except on self
|
|
1157 |
}
|
|
1158 |
|
|
1159 |
|
|
1160 |
//------------------------------Value------------------------------------------
|
|
1161 |
const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
|
|
1162 |
const Type *t = phase->type( in(1) );
|
|
1163 |
if( t == Type::TOP ) return Type::TOP;
|
|
1164 |
const TypeLong *tl = t->is_long();
|
|
1165 |
if( !tl->is_con() ) return bottom_type();
|
|
1166 |
JavaValue v;
|
|
1167 |
v.set_jlong(tl->get_con());
|
|
1168 |
return TypeD::make( v.get_jdouble() );
|
|
1169 |
}
|
|
1170 |
|
|
1171 |
//------------------------------Value------------------------------------------
|
|
1172 |
const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
|
|
1173 |
const Type *t = phase->type( in(1) );
|
|
1174 |
if( t == Type::TOP ) return Type::TOP;
|
|
1175 |
const TypeInt *ti = t->is_int();
|
|
1176 |
if( !ti->is_con() ) return bottom_type();
|
|
1177 |
JavaValue v;
|
|
1178 |
v.set_jint(ti->get_con());
|
|
1179 |
return TypeF::make( v.get_jfloat() );
|
|
1180 |
}
|
|
1181 |
|
|
1182 |
//------------------------------Value------------------------------------------
|
|
1183 |
const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
|
|
1184 |
const Type *t = phase->type( in(1) );
|
|
1185 |
if( t == Type::TOP ) return Type::TOP;
|
|
1186 |
if( t == Type::FLOAT ) return TypeInt::INT;
|
|
1187 |
const TypeF *tf = t->is_float_constant();
|
|
1188 |
JavaValue v;
|
|
1189 |
v.set_jfloat(tf->getf());
|
|
1190 |
return TypeInt::make( v.get_jint() );
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
//------------------------------Value------------------------------------------
|
|
1194 |
const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
|
|
1195 |
const Type *t = phase->type( in(1) );
|
|
1196 |
if( t == Type::TOP ) return Type::TOP;
|
|
1197 |
if( t == Type::DOUBLE ) return TypeLong::LONG;
|
|
1198 |
const TypeD *td = t->is_double_constant();
|
|
1199 |
JavaValue v;
|
|
1200 |
v.set_jdouble(td->getd());
|
|
1201 |
return TypeLong::make( v.get_jlong() );
|
|
1202 |
}
|