author | xdono |
Mon, 15 Dec 2008 16:55:11 -0800 | |
changeset 1623 | a0dd9009e992 |
parent 1432 | 44f076e3d2a4 |
child 2254 | f13dda645a4b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
670 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. 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 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
// Portions of code courtesy of Clifford Click |
|
26 |
||
27 |
#include "incls/_precompiled.incl" |
|
28 |
#include "incls/_addnode.cpp.incl" |
|
29 |
||
30 |
#define MAXFLOAT ((float)3.40282346638528860e+38) |
|
31 |
||
32 |
// Classic Add functionality. This covers all the usual 'add' behaviors for |
|
33 |
// an algebraic ring. Add-integer, add-float, add-double, and binary-or are |
|
34 |
// all inherited from this class. The various identity values are supplied |
|
35 |
// by virtual functions. |
|
36 |
||
37 |
||
38 |
//============================================================================= |
|
39 |
//------------------------------hash------------------------------------------- |
|
40 |
// Hash function over AddNodes. Needs to be commutative; i.e., I swap |
|
41 |
// (commute) inputs to AddNodes willy-nilly so the hash function must return |
|
42 |
// the same value in the presence of edge swapping. |
|
43 |
uint AddNode::hash() const { |
|
44 |
return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode(); |
|
45 |
} |
|
46 |
||
47 |
//------------------------------Identity--------------------------------------- |
|
48 |
// If either input is a constant 0, return the other input. |
|
49 |
Node *AddNode::Identity( PhaseTransform *phase ) { |
|
50 |
const Type *zero = add_id(); // The additive identity |
|
51 |
if( phase->type( in(1) )->higher_equal( zero ) ) return in(2); |
|
52 |
if( phase->type( in(2) )->higher_equal( zero ) ) return in(1); |
|
53 |
return this; |
|
54 |
} |
|
55 |
||
56 |
//------------------------------commute---------------------------------------- |
|
57 |
// Commute operands to move loads and constants to the right. |
|
58 |
static bool commute( Node *add, int con_left, int con_right ) { |
|
59 |
Node *in1 = add->in(1); |
|
60 |
Node *in2 = add->in(2); |
|
61 |
||
62 |
// Convert "1+x" into "x+1". |
|
63 |
// Right is a constant; leave it |
|
64 |
if( con_right ) return false; |
|
65 |
// Left is a constant; move it right. |
|
66 |
if( con_left ) { |
|
67 |
add->swap_edges(1, 2); |
|
68 |
return true; |
|
69 |
} |
|
70 |
||
71 |
// Convert "Load+x" into "x+Load". |
|
72 |
// Now check for loads |
|
346
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
73 |
if (in2->is_Load()) { |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
74 |
if (!in1->is_Load()) { |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
75 |
// already x+Load to return |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
76 |
return false; |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
77 |
} |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
78 |
// both are loads, so fall through to sort inputs by idx |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
79 |
} else if( in1->is_Load() ) { |
e13ccc474a28
6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents:
205
diff
changeset
|
80 |
// Left is a Load and Right is not; move it right. |
1 | 81 |
add->swap_edges(1, 2); |
82 |
return true; |
|
83 |
} |
|
84 |
||
85 |
PhiNode *phi; |
|
86 |
// Check for tight loop increments: Loop-phi of Add of loop-phi |
|
87 |
if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add) |
|
88 |
return false; |
|
89 |
if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){ |
|
90 |
add->swap_edges(1, 2); |
|
91 |
return true; |
|
92 |
} |
|
93 |
||
94 |
// Otherwise, sort inputs (commutativity) to help value numbering. |
|
95 |
if( in1->_idx > in2->_idx ) { |
|
96 |
add->swap_edges(1, 2); |
|
97 |
return true; |
|
98 |
} |
|
99 |
return false; |
|
100 |
} |
|
101 |
||
102 |
//------------------------------Idealize--------------------------------------- |
|
103 |
// If we get here, we assume we are associative! |
|
104 |
Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
105 |
const Type *t1 = phase->type( in(1) ); |
|
106 |
const Type *t2 = phase->type( in(2) ); |
|
107 |
int con_left = t1->singleton(); |
|
108 |
int con_right = t2->singleton(); |
|
109 |
||
110 |
// Check for commutative operation desired |
|
111 |
if( commute(this,con_left,con_right) ) return this; |
|
112 |
||
113 |
AddNode *progress = NULL; // Progress flag |
|
114 |
||
115 |
// Convert "(x+1)+2" into "x+(1+2)". If the right input is a |
|
116 |
// constant, and the left input is an add of a constant, flatten the |
|
117 |
// expression tree. |
|
118 |
Node *add1 = in(1); |
|
119 |
Node *add2 = in(2); |
|
120 |
int add1_op = add1->Opcode(); |
|
121 |
int this_op = Opcode(); |
|
122 |
if( con_right && t2 != Type::TOP && // Right input is a constant? |
|
123 |
add1_op == this_op ) { // Left input is an Add? |
|
124 |
||
125 |
// Type of left _in right input |
|
126 |
const Type *t12 = phase->type( add1->in(2) ); |
|
127 |
if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant? |
|
128 |
// Check for rare case of closed data cycle which can happen inside |
|
129 |
// unreachable loops. In these cases the computation is undefined. |
|
130 |
#ifdef ASSERT |
|
131 |
Node *add11 = add1->in(1); |
|
132 |
int add11_op = add11->Opcode(); |
|
133 |
if( (add1 == add1->in(1)) |
|
134 |
|| (add11_op == this_op && add11->in(1) == add1) ) { |
|
135 |
assert(false, "dead loop in AddNode::Ideal"); |
|
136 |
} |
|
137 |
#endif |
|
138 |
// The Add of the flattened expression |
|
139 |
Node *x1 = add1->in(1); |
|
140 |
Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 )); |
|
141 |
PhaseIterGVN *igvn = phase->is_IterGVN(); |
|
142 |
if( igvn ) { |
|
143 |
set_req_X(2,x2,igvn); |
|
144 |
set_req_X(1,x1,igvn); |
|
145 |
} else { |
|
146 |
set_req(2,x2); |
|
147 |
set_req(1,x1); |
|
148 |
} |
|
149 |
progress = this; // Made progress |
|
150 |
add1 = in(1); |
|
151 |
add1_op = add1->Opcode(); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
// Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree. |
|
156 |
if( add1_op == this_op && !con_right ) { |
|
157 |
Node *a12 = add1->in(2); |
|
158 |
const Type *t12 = phase->type( a12 ); |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
159 |
if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) && |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
160 |
!(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) { |
1124
4de0b4f7eae3
6676462: JVM sometimes would suddenly consume significant amount of memory
kvn
parents:
1068
diff
changeset
|
161 |
assert(add1->in(1) != this, "dead loop in AddNode::Ideal"); |
1 | 162 |
add2 = add1->clone(); |
163 |
add2->set_req(2, in(2)); |
|
164 |
add2 = phase->transform(add2); |
|
165 |
set_req(1, add2); |
|
166 |
set_req(2, a12); |
|
167 |
progress = this; |
|
168 |
add2 = a12; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
// Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree. |
|
173 |
int add2_op = add2->Opcode(); |
|
174 |
if( add2_op == this_op && !con_left ) { |
|
175 |
Node *a22 = add2->in(2); |
|
176 |
const Type *t22 = phase->type( a22 ); |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
177 |
if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) && |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
178 |
!(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) { |
1124
4de0b4f7eae3
6676462: JVM sometimes would suddenly consume significant amount of memory
kvn
parents:
1068
diff
changeset
|
179 |
assert(add2->in(1) != this, "dead loop in AddNode::Ideal"); |
1 | 180 |
Node *addx = add2->clone(); |
181 |
addx->set_req(1, in(1)); |
|
182 |
addx->set_req(2, add2->in(1)); |
|
183 |
addx = phase->transform(addx); |
|
184 |
set_req(1, addx); |
|
185 |
set_req(2, a22); |
|
186 |
progress = this; |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
return progress; |
|
191 |
} |
|
192 |
||
193 |
//------------------------------Value----------------------------------------- |
|
194 |
// An add node sums it's two _in. If one input is an RSD, we must mixin |
|
195 |
// the other input's symbols. |
|
196 |
const Type *AddNode::Value( PhaseTransform *phase ) const { |
|
197 |
// Either input is TOP ==> the result is TOP |
|
198 |
const Type *t1 = phase->type( in(1) ); |
|
199 |
const Type *t2 = phase->type( in(2) ); |
|
200 |
if( t1 == Type::TOP ) return Type::TOP; |
|
201 |
if( t2 == Type::TOP ) return Type::TOP; |
|
202 |
||
203 |
// Either input is BOTTOM ==> the result is the local BOTTOM |
|
204 |
const Type *bot = bottom_type(); |
|
205 |
if( (t1 == bot) || (t2 == bot) || |
|
206 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
|
207 |
return bot; |
|
208 |
||
209 |
// Check for an addition involving the additive identity |
|
210 |
const Type *tadd = add_of_identity( t1, t2 ); |
|
211 |
if( tadd ) return tadd; |
|
212 |
||
213 |
return add_ring(t1,t2); // Local flavor of type addition |
|
214 |
} |
|
215 |
||
216 |
//------------------------------add_identity----------------------------------- |
|
217 |
// Check for addition of the identity |
|
218 |
const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const { |
|
219 |
const Type *zero = add_id(); // The additive identity |
|
220 |
if( t1->higher_equal( zero ) ) return t2; |
|
221 |
if( t2->higher_equal( zero ) ) return t1; |
|
222 |
||
223 |
return NULL; |
|
224 |
} |
|
225 |
||
226 |
||
227 |
//============================================================================= |
|
228 |
//------------------------------Idealize--------------------------------------- |
|
229 |
Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
230 |
Node* in1 = in(1); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
231 |
Node* in2 = in(2); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
232 |
int op1 = in1->Opcode(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
233 |
int op2 = in2->Opcode(); |
1 | 234 |
// Fold (con1-x)+con2 into (con1+con2)-x |
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
235 |
if ( op1 == Op_AddI && op2 == Op_SubI ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
236 |
// Swap edges to try optimizations below |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
237 |
in1 = in2; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
238 |
in2 = in(1); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
239 |
op1 = op2; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
240 |
op2 = in2->Opcode(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
241 |
} |
1 | 242 |
if( op1 == Op_SubI ) { |
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
243 |
const Type *t_sub1 = phase->type( in1->in(1) ); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
244 |
const Type *t_2 = phase->type( in2 ); |
1 | 245 |
if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) |
246 |
return new (phase->C, 3) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
247 |
in1->in(2) ); |
1 | 248 |
// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" |
249 |
if( op2 == Op_SubI ) { |
|
250 |
// Check for dead cycle: d = (a-b)+(c-d) |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
251 |
assert( in1->in(2) != this && in2->in(2) != this, |
1 | 252 |
"dead loop in AddINode::Ideal" ); |
253 |
Node *sub = new (phase->C, 3) SubINode(NULL, NULL); |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
254 |
sub->init_req(1, phase->transform(new (phase->C, 3) AddINode(in1->in(1), in2->in(1) ) )); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
255 |
sub->init_req(2, phase->transform(new (phase->C, 3) AddINode(in1->in(2), in2->in(2) ) )); |
1 | 256 |
return sub; |
257 |
} |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
258 |
// Convert "(a-b)+(b+c)" into "(a+c)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
259 |
if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
260 |
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
261 |
return new (phase->C, 3) AddINode(in1->in(1), in2->in(2)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
262 |
} |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
263 |
// Convert "(a-b)+(c+b)" into "(a+c)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
264 |
if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
265 |
assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
266 |
return new (phase->C, 3) AddINode(in1->in(1), in2->in(1)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
267 |
} |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
268 |
// Convert "(a-b)+(b-c)" into "(a-c)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
269 |
if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
270 |
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
271 |
return new (phase->C, 3) SubINode(in1->in(1), in2->in(2)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
272 |
} |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
273 |
// Convert "(a-b)+(c-a)" into "(c-b)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
274 |
if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
275 |
assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
276 |
return new (phase->C, 3) SubINode(in2->in(1), in1->in(2)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
277 |
} |
1 | 278 |
} |
279 |
||
280 |
// Convert "x+(0-y)" into "(x-y)" |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
281 |
if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO ) |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
282 |
return new (phase->C, 3) SubINode(in1, in2->in(2) ); |
1 | 283 |
|
284 |
// Convert "(0-y)+x" into "(x-y)" |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
285 |
if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO ) |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
286 |
return new (phase->C, 3) SubINode( in2, in1->in(2) ); |
1 | 287 |
|
288 |
// Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y. |
|
289 |
// Helps with array allocation math constant folding |
|
290 |
// See 4790063: |
|
291 |
// Unrestricted transformation is unsafe for some runtime values of 'x' |
|
292 |
// ( x == 0, z == 1, y == -1 ) fails |
|
293 |
// ( x == -5, z == 1, y == 1 ) fails |
|
294 |
// Transform works for small z and small negative y when the addition |
|
295 |
// (x + (y << z)) does not cross zero. |
|
296 |
// Implement support for negative y and (x >= -(y << z)) |
|
297 |
// Have not observed cases where type information exists to support |
|
298 |
// positive y and (x <= -(y << z)) |
|
299 |
if( op1 == Op_URShiftI && op2 == Op_ConI && |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
300 |
in1->in(2)->Opcode() == Op_ConI ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
301 |
jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
302 |
jint y = phase->type( in2 )->is_int()->get_con(); |
1 | 303 |
|
304 |
if( z < 5 && -5 < y && y < 0 ) { |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
305 |
const Type *t_in11 = phase->type(in1->in(1)); |
1 | 306 |
if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) { |
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
307 |
Node *a = phase->transform( new (phase->C, 3) AddINode( in1->in(1), phase->intcon(y<<z) ) ); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
308 |
return new (phase->C, 3) URShiftINode( a, in1->in(2) ); |
1 | 309 |
} |
310 |
} |
|
311 |
} |
|
312 |
||
313 |
return AddNode::Ideal(phase, can_reshape); |
|
314 |
} |
|
315 |
||
316 |
||
317 |
//------------------------------Identity--------------------------------------- |
|
318 |
// Fold (x-y)+y OR y+(x-y) into x |
|
319 |
Node *AddINode::Identity( PhaseTransform *phase ) { |
|
320 |
if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) { |
|
321 |
return in(1)->in(1); |
|
322 |
} |
|
323 |
else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) { |
|
324 |
return in(2)->in(1); |
|
325 |
} |
|
326 |
return AddNode::Identity(phase); |
|
327 |
} |
|
328 |
||
329 |
||
330 |
//------------------------------add_ring--------------------------------------- |
|
331 |
// Supplied function returns the sum of the inputs. Guaranteed never |
|
332 |
// to be passed a TOP or BOTTOM type, these are filtered out by |
|
333 |
// pre-check. |
|
334 |
const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const { |
|
335 |
const TypeInt *r0 = t0->is_int(); // Handy access |
|
336 |
const TypeInt *r1 = t1->is_int(); |
|
337 |
int lo = r0->_lo + r1->_lo; |
|
338 |
int hi = r0->_hi + r1->_hi; |
|
339 |
if( !(r0->is_con() && r1->is_con()) ) { |
|
340 |
// Not both constants, compute approximate result |
|
341 |
if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) { |
|
342 |
lo = min_jint; hi = max_jint; // Underflow on the low side |
|
343 |
} |
|
344 |
if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) { |
|
345 |
lo = min_jint; hi = max_jint; // Overflow on the high side |
|
346 |
} |
|
347 |
if( lo > hi ) { // Handle overflow |
|
348 |
lo = min_jint; hi = max_jint; |
|
349 |
} |
|
350 |
} else { |
|
351 |
// both constants, compute precise result using 'lo' and 'hi' |
|
352 |
// Semantics define overflow and underflow for integer addition |
|
353 |
// as expected. In particular: 0x80000000 + 0x80000000 --> 0x0 |
|
354 |
} |
|
355 |
return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) ); |
|
356 |
} |
|
357 |
||
358 |
||
359 |
//============================================================================= |
|
360 |
//------------------------------Idealize--------------------------------------- |
|
361 |
Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
362 |
Node* in1 = in(1); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
363 |
Node* in2 = in(2); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
364 |
int op1 = in1->Opcode(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
365 |
int op2 = in2->Opcode(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
366 |
// Fold (con1-x)+con2 into (con1+con2)-x |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
367 |
if ( op1 == Op_AddL && op2 == Op_SubL ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
368 |
// Swap edges to try optimizations below |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
369 |
in1 = in2; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
370 |
in2 = in(1); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
371 |
op1 = op2; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
372 |
op2 = in2->Opcode(); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
373 |
} |
1 | 374 |
// Fold (con1-x)+con2 into (con1+con2)-x |
375 |
if( op1 == Op_SubL ) { |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
376 |
const Type *t_sub1 = phase->type( in1->in(1) ); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
377 |
const Type *t_2 = phase->type( in2 ); |
1 | 378 |
if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) |
379 |
return new (phase->C, 3) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
380 |
in1->in(2) ); |
1 | 381 |
// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" |
382 |
if( op2 == Op_SubL ) { |
|
383 |
// Check for dead cycle: d = (a-b)+(c-d) |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
384 |
assert( in1->in(2) != this && in2->in(2) != this, |
1 | 385 |
"dead loop in AddLNode::Ideal" ); |
386 |
Node *sub = new (phase->C, 3) SubLNode(NULL, NULL); |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
387 |
sub->init_req(1, phase->transform(new (phase->C, 3) AddLNode(in1->in(1), in2->in(1) ) )); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
388 |
sub->init_req(2, phase->transform(new (phase->C, 3) AddLNode(in1->in(2), in2->in(2) ) )); |
1 | 389 |
return sub; |
390 |
} |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
391 |
// Convert "(a-b)+(b+c)" into "(a+c)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
392 |
if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
393 |
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
394 |
return new (phase->C, 3) AddLNode(in1->in(1), in2->in(2)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
395 |
} |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
396 |
// Convert "(a-b)+(c+b)" into "(a+c)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
397 |
if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
398 |
assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
399 |
return new (phase->C, 3) AddLNode(in1->in(1), in2->in(1)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
400 |
} |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
401 |
// Convert "(a-b)+(b-c)" into "(a-c)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
402 |
if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
403 |
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
404 |
return new (phase->C, 3) SubLNode(in1->in(1), in2->in(2)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
405 |
} |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
406 |
// Convert "(a-b)+(c-a)" into "(c-b)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
407 |
if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) { |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
408 |
assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal"); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
409 |
return new (phase->C, 3) SubLNode(in2->in(1), in1->in(2)); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
410 |
} |
1 | 411 |
} |
412 |
||
413 |
// Convert "x+(0-y)" into "(x-y)" |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
414 |
if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO ) |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
415 |
return new (phase->C, 3) SubLNode( in1, in2->in(2) ); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
416 |
|
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
417 |
// Convert "(0-y)+x" into "(x-y)" |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
418 |
if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO ) |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
419 |
return new (phase->C, 3) SubLNode( in2, in1->in(2) ); |
1 | 420 |
|
421 |
// Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)" |
|
422 |
// into "(X<<1)+Y" and let shift-folding happen. |
|
423 |
if( op2 == Op_AddL && |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
424 |
in2->in(1) == in1 && |
1 | 425 |
op1 != Op_ConL && |
426 |
0 ) { |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
427 |
Node *shift = phase->transform(new (phase->C, 3) LShiftLNode(in1,phase->intcon(1))); |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1124
diff
changeset
|
428 |
return new (phase->C, 3) AddLNode(shift,in2->in(2)); |
1 | 429 |
} |
430 |
||
431 |
return AddNode::Ideal(phase, can_reshape); |
|
432 |
} |
|
433 |
||
434 |
||
435 |
//------------------------------Identity--------------------------------------- |
|
436 |
// Fold (x-y)+y OR y+(x-y) into x |
|
437 |
Node *AddLNode::Identity( PhaseTransform *phase ) { |
|
438 |
if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) { |
|
439 |
return in(1)->in(1); |
|
440 |
} |
|
441 |
else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) { |
|
442 |
return in(2)->in(1); |
|
443 |
} |
|
444 |
return AddNode::Identity(phase); |
|
445 |
} |
|
446 |
||
447 |
||
448 |
//------------------------------add_ring--------------------------------------- |
|
449 |
// Supplied function returns the sum of the inputs. Guaranteed never |
|
450 |
// to be passed a TOP or BOTTOM type, these are filtered out by |
|
451 |
// pre-check. |
|
452 |
const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const { |
|
453 |
const TypeLong *r0 = t0->is_long(); // Handy access |
|
454 |
const TypeLong *r1 = t1->is_long(); |
|
455 |
jlong lo = r0->_lo + r1->_lo; |
|
456 |
jlong hi = r0->_hi + r1->_hi; |
|
457 |
if( !(r0->is_con() && r1->is_con()) ) { |
|
458 |
// Not both constants, compute approximate result |
|
459 |
if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) { |
|
460 |
lo =min_jlong; hi = max_jlong; // Underflow on the low side |
|
461 |
} |
|
462 |
if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) { |
|
463 |
lo = min_jlong; hi = max_jlong; // Overflow on the high side |
|
464 |
} |
|
465 |
if( lo > hi ) { // Handle overflow |
|
466 |
lo = min_jlong; hi = max_jlong; |
|
467 |
} |
|
468 |
} else { |
|
469 |
// both constants, compute precise result using 'lo' and 'hi' |
|
470 |
// Semantics define overflow and underflow for integer addition |
|
471 |
// as expected. In particular: 0x80000000 + 0x80000000 --> 0x0 |
|
472 |
} |
|
473 |
return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) ); |
|
474 |
} |
|
475 |
||
476 |
||
477 |
//============================================================================= |
|
478 |
//------------------------------add_of_identity-------------------------------- |
|
479 |
// Check for addition of the identity |
|
480 |
const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const { |
|
481 |
// x ADD 0 should return x unless 'x' is a -zero |
|
482 |
// |
|
483 |
// const Type *zero = add_id(); // The additive identity |
|
484 |
// jfloat f1 = t1->getf(); |
|
485 |
// jfloat f2 = t2->getf(); |
|
486 |
// |
|
487 |
// if( t1->higher_equal( zero ) ) return t2; |
|
488 |
// if( t2->higher_equal( zero ) ) return t1; |
|
489 |
||
490 |
return NULL; |
|
491 |
} |
|
492 |
||
493 |
//------------------------------add_ring--------------------------------------- |
|
494 |
// Supplied function returns the sum of the inputs. |
|
495 |
// This also type-checks the inputs for sanity. Guaranteed never to |
|
496 |
// be passed a TOP or BOTTOM type, these are filtered out by pre-check. |
|
497 |
const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const { |
|
498 |
// We must be adding 2 float constants. |
|
499 |
return TypeF::make( t0->getf() + t1->getf() ); |
|
500 |
} |
|
501 |
||
502 |
//------------------------------Ideal------------------------------------------ |
|
503 |
Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
504 |
if( IdealizedNumerics && !phase->C->method()->is_strict() ) { |
|
505 |
return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms |
|
506 |
} |
|
507 |
||
508 |
// Floating point additions are not associative because of boundary conditions (infinity) |
|
509 |
return commute(this, |
|
510 |
phase->type( in(1) )->singleton(), |
|
511 |
phase->type( in(2) )->singleton() ) ? this : NULL; |
|
512 |
} |
|
513 |
||
514 |
||
515 |
//============================================================================= |
|
516 |
//------------------------------add_of_identity-------------------------------- |
|
517 |
// Check for addition of the identity |
|
518 |
const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const { |
|
519 |
// x ADD 0 should return x unless 'x' is a -zero |
|
520 |
// |
|
521 |
// const Type *zero = add_id(); // The additive identity |
|
522 |
// jfloat f1 = t1->getf(); |
|
523 |
// jfloat f2 = t2->getf(); |
|
524 |
// |
|
525 |
// if( t1->higher_equal( zero ) ) return t2; |
|
526 |
// if( t2->higher_equal( zero ) ) return t1; |
|
527 |
||
528 |
return NULL; |
|
529 |
} |
|
530 |
//------------------------------add_ring--------------------------------------- |
|
531 |
// Supplied function returns the sum of the inputs. |
|
532 |
// This also type-checks the inputs for sanity. Guaranteed never to |
|
533 |
// be passed a TOP or BOTTOM type, these are filtered out by pre-check. |
|
534 |
const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const { |
|
535 |
// We must be adding 2 double constants. |
|
536 |
return TypeD::make( t0->getd() + t1->getd() ); |
|
537 |
} |
|
538 |
||
539 |
//------------------------------Ideal------------------------------------------ |
|
540 |
Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
541 |
if( IdealizedNumerics && !phase->C->method()->is_strict() ) { |
|
542 |
return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms |
|
543 |
} |
|
544 |
||
545 |
// Floating point additions are not associative because of boundary conditions (infinity) |
|
546 |
return commute(this, |
|
547 |
phase->type( in(1) )->singleton(), |
|
548 |
phase->type( in(2) )->singleton() ) ? this : NULL; |
|
549 |
} |
|
550 |
||
551 |
||
552 |
//============================================================================= |
|
553 |
//------------------------------Identity--------------------------------------- |
|
554 |
// If one input is a constant 0, return the other input. |
|
555 |
Node *AddPNode::Identity( PhaseTransform *phase ) { |
|
556 |
return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this; |
|
557 |
} |
|
558 |
||
559 |
//------------------------------Idealize--------------------------------------- |
|
560 |
Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
561 |
// Bail out if dead inputs |
|
562 |
if( phase->type( in(Address) ) == Type::TOP ) return NULL; |
|
563 |
||
564 |
// If the left input is an add of a constant, flatten the expression tree. |
|
565 |
const Node *n = in(Address); |
|
566 |
if (n->is_AddP() && n->in(Base) == in(Base)) { |
|
567 |
const AddPNode *addp = n->as_AddP(); // Left input is an AddP |
|
568 |
assert( !addp->in(Address)->is_AddP() || |
|
569 |
addp->in(Address)->as_AddP() != addp, |
|
570 |
"dead loop in AddPNode::Ideal" ); |
|
571 |
// Type of left input's right input |
|
572 |
const Type *t = phase->type( addp->in(Offset) ); |
|
573 |
if( t == Type::TOP ) return NULL; |
|
574 |
const TypeX *t12 = t->is_intptr_t(); |
|
575 |
if( t12->is_con() ) { // Left input is an add of a constant? |
|
576 |
// If the right input is a constant, combine constants |
|
577 |
const Type *temp_t2 = phase->type( in(Offset) ); |
|
578 |
if( temp_t2 == Type::TOP ) return NULL; |
|
579 |
const TypeX *t2 = temp_t2->is_intptr_t(); |
|
205
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
580 |
Node* address; |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
581 |
Node* offset; |
1 | 582 |
if( t2->is_con() ) { |
583 |
// The Add of the flattened expression |
|
205
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
584 |
address = addp->in(Address); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
585 |
offset = phase->MakeConX(t2->get_con() + t12->get_con()); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
586 |
} else { |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
587 |
// Else move the constant to the right. ((A+con)+B) into ((A+B)+con) |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
588 |
address = phase->transform(new (phase->C, 4) AddPNode(in(Base),addp->in(Address),in(Offset))); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
589 |
offset = addp->in(Offset); |
1 | 590 |
} |
205
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
591 |
PhaseIterGVN *igvn = phase->is_IterGVN(); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
592 |
if( igvn ) { |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
593 |
set_req_X(Address,address,igvn); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
594 |
set_req_X(Offset,offset,igvn); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
595 |
} else { |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
596 |
set_req(Address,address); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
597 |
set_req(Offset,offset); |
4069fc169258
6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents:
190
diff
changeset
|
598 |
} |
1 | 599 |
return this; |
600 |
} |
|
601 |
} |
|
602 |
||
603 |
// Raw pointers? |
|
604 |
if( in(Base)->bottom_type() == Type::TOP ) { |
|
605 |
// If this is a NULL+long form (from unsafe accesses), switch to a rawptr. |
|
606 |
if (phase->type(in(Address)) == TypePtr::NULL_PTR) { |
|
607 |
Node* offset = in(Offset); |
|
608 |
return new (phase->C, 2) CastX2PNode(offset); |
|
609 |
} |
|
610 |
} |
|
611 |
||
612 |
// If the right is an add of a constant, push the offset down. |
|
613 |
// Convert: (ptr + (offset+con)) into (ptr+offset)+con. |
|
614 |
// The idea is to merge array_base+scaled_index groups together, |
|
615 |
// and only have different constant offsets from the same base. |
|
616 |
const Node *add = in(Offset); |
|
617 |
if( add->Opcode() == Op_AddX && add->in(1) != add ) { |
|
618 |
const Type *t22 = phase->type( add->in(2) ); |
|
619 |
if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant? |
|
620 |
set_req(Address, phase->transform(new (phase->C, 4) AddPNode(in(Base),in(Address),add->in(1)))); |
|
621 |
set_req(Offset, add->in(2)); |
|
622 |
return this; // Made progress |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
return NULL; // No progress |
|
627 |
} |
|
628 |
||
629 |
//------------------------------bottom_type------------------------------------ |
|
630 |
// Bottom-type is the pointer-type with unknown offset. |
|
631 |
const Type *AddPNode::bottom_type() const { |
|
632 |
if (in(Address) == NULL) return TypePtr::BOTTOM; |
|
633 |
const TypePtr *tp = in(Address)->bottom_type()->isa_ptr(); |
|
634 |
if( !tp ) return Type::TOP; // TOP input means TOP output |
|
635 |
assert( in(Offset)->Opcode() != Op_ConP, "" ); |
|
636 |
const Type *t = in(Offset)->bottom_type(); |
|
637 |
if( t == Type::TOP ) |
|
638 |
return tp->add_offset(Type::OffsetTop); |
|
639 |
const TypeX *tx = t->is_intptr_t(); |
|
640 |
intptr_t txoffset = Type::OffsetBot; |
|
641 |
if (tx->is_con()) { // Left input is an add of a constant? |
|
642 |
txoffset = tx->get_con(); |
|
643 |
} |
|
644 |
return tp->add_offset(txoffset); |
|
645 |
} |
|
646 |
||
647 |
//------------------------------Value------------------------------------------ |
|
648 |
const Type *AddPNode::Value( PhaseTransform *phase ) const { |
|
649 |
// Either input is TOP ==> the result is TOP |
|
650 |
const Type *t1 = phase->type( in(Address) ); |
|
651 |
const Type *t2 = phase->type( in(Offset) ); |
|
652 |
if( t1 == Type::TOP ) return Type::TOP; |
|
653 |
if( t2 == Type::TOP ) return Type::TOP; |
|
654 |
||
655 |
// Left input is a pointer |
|
656 |
const TypePtr *p1 = t1->isa_ptr(); |
|
657 |
// Right input is an int |
|
658 |
const TypeX *p2 = t2->is_intptr_t(); |
|
659 |
// Add 'em |
|
660 |
intptr_t p2offset = Type::OffsetBot; |
|
661 |
if (p2->is_con()) { // Left input is an add of a constant? |
|
662 |
p2offset = p2->get_con(); |
|
663 |
} |
|
664 |
return p1->add_offset(p2offset); |
|
665 |
} |
|
666 |
||
667 |
//------------------------Ideal_base_and_offset-------------------------------- |
|
668 |
// Split an oop pointer into a base and offset. |
|
669 |
// (The offset might be Type::OffsetBot in the case of an array.) |
|
670 |
// Return the base, or NULL if failure. |
|
671 |
Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase, |
|
672 |
// second return value: |
|
673 |
intptr_t& offset) { |
|
674 |
if (ptr->is_AddP()) { |
|
675 |
Node* base = ptr->in(AddPNode::Base); |
|
676 |
Node* addr = ptr->in(AddPNode::Address); |
|
677 |
Node* offs = ptr->in(AddPNode::Offset); |
|
678 |
if (base == addr || base->is_top()) { |
|
679 |
offset = phase->find_intptr_t_con(offs, Type::OffsetBot); |
|
680 |
if (offset != Type::OffsetBot) { |
|
681 |
return addr; |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
offset = Type::OffsetBot; |
|
686 |
return NULL; |
|
687 |
} |
|
688 |
||
190
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
689 |
//------------------------------unpack_offsets---------------------------------- |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
690 |
// Collect the AddP offset values into the elements array, giving up |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
691 |
// if there are more than length. |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
692 |
int AddPNode::unpack_offsets(Node* elements[], int length) { |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
693 |
int count = 0; |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
694 |
Node* addr = this; |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
695 |
Node* base = addr->in(AddPNode::Base); |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
696 |
while (addr->is_AddP()) { |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
697 |
if (addr->in(AddPNode::Base) != base) { |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
698 |
// give up |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
699 |
return -1; |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
700 |
} |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
701 |
elements[count++] = addr->in(AddPNode::Offset); |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
702 |
if (count == length) { |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
703 |
// give up |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
704 |
return -1; |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
705 |
} |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
706 |
addr = addr->in(AddPNode::Address); |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
707 |
} |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
708 |
return count; |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
709 |
} |
e9a0a9dcd4f6
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
1
diff
changeset
|
710 |
|
1 | 711 |
//------------------------------match_edge------------------------------------- |
712 |
// Do we Match on this edge index or not? Do not match base pointer edge |
|
713 |
uint AddPNode::match_edge(uint idx) const { |
|
714 |
return idx > Base; |
|
715 |
} |
|
716 |
||
717 |
//---------------------------mach_bottom_type---------------------------------- |
|
718 |
// Utility function for use by ADLC. Implements bottom_type for matched AddP. |
|
719 |
const Type *AddPNode::mach_bottom_type( const MachNode* n) { |
|
720 |
Node* base = n->in(Base); |
|
721 |
const Type *t = base->bottom_type(); |
|
722 |
if ( t == Type::TOP ) { |
|
723 |
// an untyped pointer |
|
724 |
return TypeRawPtr::BOTTOM; |
|
725 |
} |
|
726 |
const TypePtr* tp = t->isa_oopptr(); |
|
727 |
if ( tp == NULL ) return t; |
|
728 |
if ( tp->_offset == TypePtr::OffsetBot ) return tp; |
|
729 |
||
730 |
// We must carefully add up the various offsets... |
|
731 |
intptr_t offset = 0; |
|
732 |
const TypePtr* tptr = NULL; |
|
733 |
||
734 |
uint numopnds = n->num_opnds(); |
|
735 |
uint index = n->oper_input_base(); |
|
736 |
for ( uint i = 1; i < numopnds; i++ ) { |
|
737 |
MachOper *opnd = n->_opnds[i]; |
|
738 |
// Check for any interesting operand info. |
|
739 |
// In particular, check for both memory and non-memory operands. |
|
740 |
// %%%%% Clean this up: use xadd_offset |
|
1068
720698d9c89b
6741738: TypePtr::add_offset() set incorrect offset when the add overflows
kvn
parents:
1055
diff
changeset
|
741 |
intptr_t con = opnd->constant(); |
1 | 742 |
if ( con == TypePtr::OffsetBot ) goto bottom_out; |
743 |
offset += con; |
|
744 |
con = opnd->constant_disp(); |
|
745 |
if ( con == TypePtr::OffsetBot ) goto bottom_out; |
|
746 |
offset += con; |
|
747 |
if( opnd->scale() != 0 ) goto bottom_out; |
|
748 |
||
749 |
// Check each operand input edge. Find the 1 allowed pointer |
|
750 |
// edge. Other edges must be index edges; track exact constant |
|
751 |
// inputs and otherwise assume the worst. |
|
752 |
for ( uint j = opnd->num_edges(); j > 0; j-- ) { |
|
753 |
Node* edge = n->in(index++); |
|
754 |
const Type* et = edge->bottom_type(); |
|
755 |
const TypeX* eti = et->isa_intptr_t(); |
|
756 |
if ( eti == NULL ) { |
|
757 |
// there must be one pointer among the operands |
|
758 |
guarantee(tptr == NULL, "must be only one pointer operand"); |
|
759 |
tptr = et->isa_oopptr(); |
|
760 |
guarantee(tptr != NULL, "non-int operand must be pointer"); |
|
1055
f4fb9fb08038
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
670
diff
changeset
|
761 |
if (tptr->higher_equal(tp->add_offset(tptr->offset()))) |
f4fb9fb08038
6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents:
670
diff
changeset
|
762 |
tp = tptr; // Set more precise type for bailout |
1 | 763 |
continue; |
764 |
} |
|
765 |
if ( eti->_hi != eti->_lo ) goto bottom_out; |
|
766 |
offset += eti->_lo; |
|
767 |
} |
|
768 |
} |
|
769 |
guarantee(tptr != NULL, "must be exactly one pointer operand"); |
|
770 |
return tptr->add_offset(offset); |
|
771 |
||
772 |
bottom_out: |
|
773 |
return tp->add_offset(TypePtr::OffsetBot); |
|
774 |
} |
|
775 |
||
776 |
//============================================================================= |
|
777 |
//------------------------------Identity--------------------------------------- |
|
778 |
Node *OrINode::Identity( PhaseTransform *phase ) { |
|
779 |
// x | x => x |
|
780 |
if (phase->eqv(in(1), in(2))) { |
|
781 |
return in(1); |
|
782 |
} |
|
783 |
||
784 |
return AddNode::Identity(phase); |
|
785 |
} |
|
786 |
||
787 |
//------------------------------add_ring--------------------------------------- |
|
788 |
// Supplied function returns the sum of the inputs IN THE CURRENT RING. For |
|
789 |
// the logical operations the ring's ADD is really a logical OR function. |
|
790 |
// This also type-checks the inputs for sanity. Guaranteed never to |
|
791 |
// be passed a TOP or BOTTOM type, these are filtered out by pre-check. |
|
792 |
const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const { |
|
793 |
const TypeInt *r0 = t0->is_int(); // Handy access |
|
794 |
const TypeInt *r1 = t1->is_int(); |
|
795 |
||
796 |
// If both args are bool, can figure out better types |
|
797 |
if ( r0 == TypeInt::BOOL ) { |
|
798 |
if ( r1 == TypeInt::ONE) { |
|
799 |
return TypeInt::ONE; |
|
800 |
} else if ( r1 == TypeInt::BOOL ) { |
|
801 |
return TypeInt::BOOL; |
|
802 |
} |
|
803 |
} else if ( r0 == TypeInt::ONE ) { |
|
804 |
if ( r1 == TypeInt::BOOL ) { |
|
805 |
return TypeInt::ONE; |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
// If either input is not a constant, just return all integers. |
|
810 |
if( !r0->is_con() || !r1->is_con() ) |
|
811 |
return TypeInt::INT; // Any integer, but still no symbols. |
|
812 |
||
813 |
// Otherwise just OR them bits. |
|
814 |
return TypeInt::make( r0->get_con() | r1->get_con() ); |
|
815 |
} |
|
816 |
||
817 |
//============================================================================= |
|
818 |
//------------------------------Identity--------------------------------------- |
|
819 |
Node *OrLNode::Identity( PhaseTransform *phase ) { |
|
820 |
// x | x => x |
|
821 |
if (phase->eqv(in(1), in(2))) { |
|
822 |
return in(1); |
|
823 |
} |
|
824 |
||
825 |
return AddNode::Identity(phase); |
|
826 |
} |
|
827 |
||
828 |
//------------------------------add_ring--------------------------------------- |
|
829 |
const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const { |
|
830 |
const TypeLong *r0 = t0->is_long(); // Handy access |
|
831 |
const TypeLong *r1 = t1->is_long(); |
|
832 |
||
833 |
// If either input is not a constant, just return all integers. |
|
834 |
if( !r0->is_con() || !r1->is_con() ) |
|
835 |
return TypeLong::LONG; // Any integer, but still no symbols. |
|
836 |
||
837 |
// Otherwise just OR them bits. |
|
838 |
return TypeLong::make( r0->get_con() | r1->get_con() ); |
|
839 |
} |
|
840 |
||
841 |
//============================================================================= |
|
842 |
//------------------------------add_ring--------------------------------------- |
|
843 |
// Supplied function returns the sum of the inputs IN THE CURRENT RING. For |
|
844 |
// the logical operations the ring's ADD is really a logical OR function. |
|
845 |
// This also type-checks the inputs for sanity. Guaranteed never to |
|
846 |
// be passed a TOP or BOTTOM type, these are filtered out by pre-check. |
|
847 |
const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const { |
|
848 |
const TypeInt *r0 = t0->is_int(); // Handy access |
|
849 |
const TypeInt *r1 = t1->is_int(); |
|
850 |
||
851 |
// Complementing a boolean? |
|
852 |
if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE |
|
853 |
|| r1 == TypeInt::BOOL)) |
|
854 |
return TypeInt::BOOL; |
|
855 |
||
856 |
if( !r0->is_con() || !r1->is_con() ) // Not constants |
|
857 |
return TypeInt::INT; // Any integer, but still no symbols. |
|
858 |
||
859 |
// Otherwise just XOR them bits. |
|
860 |
return TypeInt::make( r0->get_con() ^ r1->get_con() ); |
|
861 |
} |
|
862 |
||
863 |
//============================================================================= |
|
864 |
//------------------------------add_ring--------------------------------------- |
|
865 |
const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const { |
|
866 |
const TypeLong *r0 = t0->is_long(); // Handy access |
|
867 |
const TypeLong *r1 = t1->is_long(); |
|
868 |
||
869 |
// If either input is not a constant, just return all integers. |
|
870 |
if( !r0->is_con() || !r1->is_con() ) |
|
871 |
return TypeLong::LONG; // Any integer, but still no symbols. |
|
872 |
||
873 |
// Otherwise just OR them bits. |
|
874 |
return TypeLong::make( r0->get_con() ^ r1->get_con() ); |
|
875 |
} |
|
876 |
||
877 |
//============================================================================= |
|
878 |
//------------------------------add_ring--------------------------------------- |
|
879 |
// Supplied function returns the sum of the inputs. |
|
880 |
const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const { |
|
881 |
const TypeInt *r0 = t0->is_int(); // Handy access |
|
882 |
const TypeInt *r1 = t1->is_int(); |
|
883 |
||
884 |
// Otherwise just MAX them bits. |
|
885 |
return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) ); |
|
886 |
} |
|
887 |
||
888 |
//============================================================================= |
|
889 |
//------------------------------Idealize--------------------------------------- |
|
890 |
// MINs show up in range-check loop limit calculations. Look for |
|
891 |
// "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)" |
|
892 |
Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
893 |
Node *progress = NULL; |
|
894 |
// Force a right-spline graph |
|
895 |
Node *l = in(1); |
|
896 |
Node *r = in(2); |
|
897 |
// Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) ) |
|
898 |
// to force a right-spline graph for the rest of MinINode::Ideal(). |
|
899 |
if( l->Opcode() == Op_MinI ) { |
|
900 |
assert( l != l->in(1), "dead loop in MinINode::Ideal" ); |
|
901 |
r = phase->transform(new (phase->C, 3) MinINode(l->in(2),r)); |
|
902 |
l = l->in(1); |
|
903 |
set_req(1, l); |
|
904 |
set_req(2, r); |
|
905 |
return this; |
|
906 |
} |
|
907 |
||
908 |
// Get left input & constant |
|
909 |
Node *x = l; |
|
910 |
int x_off = 0; |
|
911 |
if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant |
|
912 |
x->in(2)->is_Con() ) { |
|
913 |
const Type *t = x->in(2)->bottom_type(); |
|
914 |
if( t == Type::TOP ) return NULL; // No progress |
|
915 |
x_off = t->is_int()->get_con(); |
|
916 |
x = x->in(1); |
|
917 |
} |
|
918 |
||
919 |
// Scan a right-spline-tree for MINs |
|
920 |
Node *y = r; |
|
921 |
int y_off = 0; |
|
922 |
// Check final part of MIN tree |
|
923 |
if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant |
|
924 |
y->in(2)->is_Con() ) { |
|
925 |
const Type *t = y->in(2)->bottom_type(); |
|
926 |
if( t == Type::TOP ) return NULL; // No progress |
|
927 |
y_off = t->is_int()->get_con(); |
|
928 |
y = y->in(1); |
|
929 |
} |
|
930 |
if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) { |
|
931 |
swap_edges(1, 2); |
|
932 |
return this; |
|
933 |
} |
|
934 |
||
935 |
||
936 |
if( r->Opcode() == Op_MinI ) { |
|
937 |
assert( r != r->in(2), "dead loop in MinINode::Ideal" ); |
|
938 |
y = r->in(1); |
|
939 |
// Check final part of MIN tree |
|
940 |
if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant |
|
941 |
y->in(2)->is_Con() ) { |
|
942 |
const Type *t = y->in(2)->bottom_type(); |
|
943 |
if( t == Type::TOP ) return NULL; // No progress |
|
944 |
y_off = t->is_int()->get_con(); |
|
945 |
y = y->in(1); |
|
946 |
} |
|
947 |
||
948 |
if( x->_idx > y->_idx ) |
|
949 |
return new (phase->C, 3) MinINode(r->in(1),phase->transform(new (phase->C, 3) MinINode(l,r->in(2)))); |
|
950 |
||
951 |
// See if covers: MIN2(x+c0,MIN2(y+c1,z)) |
|
952 |
if( !phase->eqv(x,y) ) return NULL; |
|
953 |
// If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into |
|
954 |
// MIN2(x+c0 or x+c1 which less, z). |
|
955 |
return new (phase->C, 3) MinINode(phase->transform(new (phase->C, 3) AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2)); |
|
956 |
} else { |
|
957 |
// See if covers: MIN2(x+c0,y+c1) |
|
958 |
if( !phase->eqv(x,y) ) return NULL; |
|
959 |
// If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less. |
|
960 |
return new (phase->C, 3) AddINode(x,phase->intcon(MIN2(x_off,y_off))); |
|
961 |
} |
|
962 |
||
963 |
} |
|
964 |
||
965 |
//------------------------------add_ring--------------------------------------- |
|
966 |
// Supplied function returns the sum of the inputs. |
|
967 |
const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const { |
|
968 |
const TypeInt *r0 = t0->is_int(); // Handy access |
|
969 |
const TypeInt *r1 = t1->is_int(); |
|
970 |
||
971 |
// Otherwise just MIN them bits. |
|
972 |
return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) ); |
|
973 |
} |