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