1
|
1 |
/*
|
|
2 |
* Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
// Portions of code courtesy of Clifford Click
|
|
26 |
|
|
27 |
// Optimization - Graph Style
|
|
28 |
|
|
29 |
#include "incls/_precompiled.incl"
|
|
30 |
#include "incls/_subnode.cpp.incl"
|
|
31 |
#include "math.h"
|
|
32 |
|
|
33 |
//=============================================================================
|
|
34 |
//------------------------------Identity---------------------------------------
|
|
35 |
// If right input is a constant 0, return the left input.
|
|
36 |
Node *SubNode::Identity( PhaseTransform *phase ) {
|
|
37 |
assert(in(1) != this, "Must already have called Value");
|
|
38 |
assert(in(2) != this, "Must already have called Value");
|
|
39 |
|
|
40 |
// Remove double negation
|
|
41 |
const Type *zero = add_id();
|
|
42 |
if( phase->type( in(1) )->higher_equal( zero ) &&
|
|
43 |
in(2)->Opcode() == Opcode() &&
|
|
44 |
phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
|
|
45 |
return in(2)->in(2);
|
|
46 |
}
|
|
47 |
|
|
48 |
// Convert "(X+Y) - Y" into X
|
|
49 |
if( in(1)->Opcode() == Op_AddI ) {
|
|
50 |
if( phase->eqv(in(1)->in(2),in(2)) )
|
|
51 |
return in(1)->in(1);
|
|
52 |
// Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying
|
|
53 |
// trip counter and X is likely to be loop-invariant (that's how O2 Nodes
|
|
54 |
// are originally used, although the optimizer sometimes jiggers things).
|
|
55 |
// This folding through an O2 removes a loop-exit use of a loop-varying
|
|
56 |
// value and generally lowers register pressure in and around the loop.
|
|
57 |
if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
|
|
58 |
phase->eqv(in(1)->in(2)->in(1),in(2)) )
|
|
59 |
return in(1)->in(1);
|
|
60 |
}
|
|
61 |
|
|
62 |
return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
|
|
63 |
}
|
|
64 |
|
|
65 |
//------------------------------Value------------------------------------------
|
|
66 |
// A subtract node differences it's two inputs.
|
|
67 |
const Type *SubNode::Value( PhaseTransform *phase ) const {
|
|
68 |
const Node* in1 = in(1);
|
|
69 |
const Node* in2 = in(2);
|
|
70 |
// Either input is TOP ==> the result is TOP
|
|
71 |
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
|
|
72 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
73 |
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
|
|
74 |
if( t2 == Type::TOP ) return Type::TOP;
|
|
75 |
|
|
76 |
// Not correct for SubFnode and AddFNode (must check for infinity)
|
|
77 |
// Equal? Subtract is zero
|
|
78 |
if (phase->eqv_uncast(in1, in2)) return add_id();
|
|
79 |
|
|
80 |
// Either input is BOTTOM ==> the result is the local BOTTOM
|
|
81 |
if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
|
|
82 |
return bottom_type();
|
|
83 |
|
|
84 |
return sub(t1,t2); // Local flavor of type subtraction
|
|
85 |
|
|
86 |
}
|
|
87 |
|
|
88 |
//=============================================================================
|
|
89 |
|
|
90 |
//------------------------------Helper function--------------------------------
|
|
91 |
static bool ok_to_convert(Node* inc, Node* iv) {
|
|
92 |
// Do not collapse (x+c0)-y if "+" is a loop increment, because the
|
|
93 |
// "-" is loop invariant and collapsing extends the live-range of "x"
|
|
94 |
// to overlap with the "+", forcing another register to be used in
|
|
95 |
// the loop.
|
|
96 |
// This test will be clearer with '&&' (apply DeMorgan's rule)
|
|
97 |
// but I like the early cutouts that happen here.
|
|
98 |
const PhiNode *phi;
|
|
99 |
if( ( !inc->in(1)->is_Phi() ||
|
|
100 |
!(phi=inc->in(1)->as_Phi()) ||
|
|
101 |
phi->is_copy() ||
|
|
102 |
!phi->region()->is_CountedLoop() ||
|
|
103 |
inc != phi->region()->as_CountedLoop()->incr() )
|
|
104 |
&&
|
|
105 |
// Do not collapse (x+c0)-iv if "iv" is a loop induction variable,
|
|
106 |
// because "x" maybe invariant.
|
|
107 |
( !iv->is_loop_iv() )
|
|
108 |
) {
|
|
109 |
return true;
|
|
110 |
} else {
|
|
111 |
return false;
|
|
112 |
}
|
|
113 |
}
|
|
114 |
//------------------------------Ideal------------------------------------------
|
|
115 |
Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
|
|
116 |
Node *in1 = in(1);
|
|
117 |
Node *in2 = in(2);
|
|
118 |
uint op1 = in1->Opcode();
|
|
119 |
uint op2 = in2->Opcode();
|
|
120 |
|
|
121 |
#ifdef ASSERT
|
|
122 |
// Check for dead loop
|
|
123 |
if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
|
|
124 |
( op1 == Op_AddI || op1 == Op_SubI ) &&
|
|
125 |
( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
|
|
126 |
phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) )
|
|
127 |
assert(false, "dead loop in SubINode::Ideal");
|
|
128 |
#endif
|
|
129 |
|
|
130 |
const Type *t2 = phase->type( in2 );
|
|
131 |
if( t2 == Type::TOP ) return NULL;
|
|
132 |
// Convert "x-c0" into "x+ -c0".
|
|
133 |
if( t2->base() == Type::Int ){ // Might be bottom or top...
|
|
134 |
const TypeInt *i = t2->is_int();
|
|
135 |
if( i->is_con() )
|
|
136 |
return new (phase->C, 3) AddINode(in1, phase->intcon(-i->get_con()));
|
|
137 |
}
|
|
138 |
|
|
139 |
// Convert "(x+c0) - y" into (x-y) + c0"
|
|
140 |
// Do not collapse (x+c0)-y if "+" is a loop increment or
|
|
141 |
// if "y" is a loop induction variable.
|
|
142 |
if( op1 == Op_AddI && ok_to_convert(in1, in2) ) {
|
|
143 |
const Type *tadd = phase->type( in1->in(2) );
|
|
144 |
if( tadd->singleton() && tadd != Type::TOP ) {
|
|
145 |
Node *sub2 = phase->transform( new (phase->C, 3) SubINode( in1->in(1), in2 ));
|
|
146 |
return new (phase->C, 3) AddINode( sub2, in1->in(2) );
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
// Convert "x - (y+c0)" into "(x-y) - c0"
|
|
152 |
// Need the same check as in above optimization but reversed.
|
|
153 |
if (op2 == Op_AddI && ok_to_convert(in2, in1)) {
|
|
154 |
Node* in21 = in2->in(1);
|
|
155 |
Node* in22 = in2->in(2);
|
|
156 |
const TypeInt* tcon = phase->type(in22)->isa_int();
|
|
157 |
if (tcon != NULL && tcon->is_con()) {
|
|
158 |
Node* sub2 = phase->transform( new (phase->C, 3) SubINode(in1, in21) );
|
|
159 |
Node* neg_c0 = phase->intcon(- tcon->get_con());
|
|
160 |
return new (phase->C, 3) AddINode(sub2, neg_c0);
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
const Type *t1 = phase->type( in1 );
|
|
165 |
if( t1 == Type::TOP ) return NULL;
|
|
166 |
|
|
167 |
#ifdef ASSERT
|
|
168 |
// Check for dead loop
|
|
169 |
if( ( op2 == Op_AddI || op2 == Op_SubI ) &&
|
|
170 |
( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
|
|
171 |
phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) )
|
|
172 |
assert(false, "dead loop in SubINode::Ideal");
|
|
173 |
#endif
|
|
174 |
|
|
175 |
// Convert "x - (x+y)" into "-y"
|
|
176 |
if( op2 == Op_AddI &&
|
|
177 |
phase->eqv( in1, in2->in(1) ) )
|
|
178 |
return new (phase->C, 3) SubINode( phase->intcon(0),in2->in(2));
|
|
179 |
// Convert "(x-y) - x" into "-y"
|
|
180 |
if( op1 == Op_SubI &&
|
|
181 |
phase->eqv( in1->in(1), in2 ) )
|
|
182 |
return new (phase->C, 3) SubINode( phase->intcon(0),in1->in(2));
|
|
183 |
// Convert "x - (y+x)" into "-y"
|
|
184 |
if( op2 == Op_AddI &&
|
|
185 |
phase->eqv( in1, in2->in(2) ) )
|
|
186 |
return new (phase->C, 3) SubINode( phase->intcon(0),in2->in(1));
|
|
187 |
|
|
188 |
// Convert "0 - (x-y)" into "y-x"
|
|
189 |
if( t1 == TypeInt::ZERO && op2 == Op_SubI )
|
|
190 |
return new (phase->C, 3) SubINode( in2->in(2), in2->in(1) );
|
|
191 |
|
|
192 |
// Convert "0 - (x+con)" into "-con-x"
|
|
193 |
jint con;
|
|
194 |
if( t1 == TypeInt::ZERO && op2 == Op_AddI &&
|
|
195 |
(con = in2->in(2)->find_int_con(0)) != 0 )
|
|
196 |
return new (phase->C, 3) SubINode( phase->intcon(-con), in2->in(1) );
|
|
197 |
|
|
198 |
// Convert "(X+A) - (X+B)" into "A - B"
|
|
199 |
if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) )
|
|
200 |
return new (phase->C, 3) SubINode( in1->in(2), in2->in(2) );
|
|
201 |
|
|
202 |
// Convert "(A+X) - (B+X)" into "A - B"
|
|
203 |
if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) )
|
|
204 |
return new (phase->C, 3) SubINode( in1->in(1), in2->in(1) );
|
|
205 |
|
|
206 |
// Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
|
|
207 |
// nicer to optimize than subtract.
|
|
208 |
if( op2 == Op_SubI && in2->outcnt() == 1) {
|
|
209 |
Node *add1 = phase->transform( new (phase->C, 3) AddINode( in1, in2->in(2) ) );
|
|
210 |
return new (phase->C, 3) SubINode( add1, in2->in(1) );
|
|
211 |
}
|
|
212 |
|
|
213 |
return NULL;
|
|
214 |
}
|
|
215 |
|
|
216 |
//------------------------------sub--------------------------------------------
|
|
217 |
// A subtract node differences it's two inputs.
|
|
218 |
const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
|
|
219 |
const TypeInt *r0 = t1->is_int(); // Handy access
|
|
220 |
const TypeInt *r1 = t2->is_int();
|
|
221 |
int32 lo = r0->_lo - r1->_hi;
|
|
222 |
int32 hi = r0->_hi - r1->_lo;
|
|
223 |
|
|
224 |
// We next check for 32-bit overflow.
|
|
225 |
// If that happens, we just assume all integers are possible.
|
|
226 |
if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
|
|
227 |
((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
|
|
228 |
(((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
|
|
229 |
((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
|
|
230 |
return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
|
|
231 |
else // Overflow; assume all integers
|
|
232 |
return TypeInt::INT;
|
|
233 |
}
|
|
234 |
|
|
235 |
//=============================================================================
|
|
236 |
//------------------------------Ideal------------------------------------------
|
|
237 |
Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
238 |
Node *in1 = in(1);
|
|
239 |
Node *in2 = in(2);
|
|
240 |
uint op1 = in1->Opcode();
|
|
241 |
uint op2 = in2->Opcode();
|
|
242 |
|
|
243 |
#ifdef ASSERT
|
|
244 |
// Check for dead loop
|
|
245 |
if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
|
|
246 |
( op1 == Op_AddL || op1 == Op_SubL ) &&
|
|
247 |
( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
|
|
248 |
phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) )
|
|
249 |
assert(false, "dead loop in SubLNode::Ideal");
|
|
250 |
#endif
|
|
251 |
|
|
252 |
if( phase->type( in2 ) == Type::TOP ) return NULL;
|
|
253 |
const TypeLong *i = phase->type( in2 )->isa_long();
|
|
254 |
// Convert "x-c0" into "x+ -c0".
|
|
255 |
if( i && // Might be bottom or top...
|
|
256 |
i->is_con() )
|
|
257 |
return new (phase->C, 3) AddLNode(in1, phase->longcon(-i->get_con()));
|
|
258 |
|
|
259 |
// Convert "(x+c0) - y" into (x-y) + c0"
|
|
260 |
// Do not collapse (x+c0)-y if "+" is a loop increment or
|
|
261 |
// if "y" is a loop induction variable.
|
|
262 |
if( op1 == Op_AddL && ok_to_convert(in1, in2) ) {
|
|
263 |
Node *in11 = in1->in(1);
|
|
264 |
const Type *tadd = phase->type( in1->in(2) );
|
|
265 |
if( tadd->singleton() && tadd != Type::TOP ) {
|
|
266 |
Node *sub2 = phase->transform( new (phase->C, 3) SubLNode( in11, in2 ));
|
|
267 |
return new (phase->C, 3) AddLNode( sub2, in1->in(2) );
|
|
268 |
}
|
|
269 |
}
|
|
270 |
|
|
271 |
// Convert "x - (y+c0)" into "(x-y) - c0"
|
|
272 |
// Need the same check as in above optimization but reversed.
|
|
273 |
if (op2 == Op_AddL && ok_to_convert(in2, in1)) {
|
|
274 |
Node* in21 = in2->in(1);
|
|
275 |
Node* in22 = in2->in(2);
|
|
276 |
const TypeLong* tcon = phase->type(in22)->isa_long();
|
|
277 |
if (tcon != NULL && tcon->is_con()) {
|
|
278 |
Node* sub2 = phase->transform( new (phase->C, 3) SubLNode(in1, in21) );
|
|
279 |
Node* neg_c0 = phase->longcon(- tcon->get_con());
|
|
280 |
return new (phase->C, 3) AddLNode(sub2, neg_c0);
|
|
281 |
}
|
|
282 |
}
|
|
283 |
|
|
284 |
const Type *t1 = phase->type( in1 );
|
|
285 |
if( t1 == Type::TOP ) return NULL;
|
|
286 |
|
|
287 |
#ifdef ASSERT
|
|
288 |
// Check for dead loop
|
|
289 |
if( ( op2 == Op_AddL || op2 == Op_SubL ) &&
|
|
290 |
( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
|
|
291 |
phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) )
|
|
292 |
assert(false, "dead loop in SubLNode::Ideal");
|
|
293 |
#endif
|
|
294 |
|
|
295 |
// Convert "x - (x+y)" into "-y"
|
|
296 |
if( op2 == Op_AddL &&
|
|
297 |
phase->eqv( in1, in2->in(1) ) )
|
|
298 |
return new (phase->C, 3) SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2));
|
|
299 |
// Convert "x - (y+x)" into "-y"
|
|
300 |
if( op2 == Op_AddL &&
|
|
301 |
phase->eqv( in1, in2->in(2) ) )
|
|
302 |
return new (phase->C, 3) SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1));
|
|
303 |
|
|
304 |
// Convert "0 - (x-y)" into "y-x"
|
|
305 |
if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL )
|
|
306 |
return new (phase->C, 3) SubLNode( in2->in(2), in2->in(1) );
|
|
307 |
|
|
308 |
// Convert "(X+A) - (X+B)" into "A - B"
|
|
309 |
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
|
|
310 |
return new (phase->C, 3) SubLNode( in1->in(2), in2->in(2) );
|
|
311 |
|
|
312 |
// Convert "(A+X) - (B+X)" into "A - B"
|
|
313 |
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
|
|
314 |
return new (phase->C, 3) SubLNode( in1->in(1), in2->in(1) );
|
|
315 |
|
|
316 |
// Convert "A-(B-C)" into (A+C)-B"
|
|
317 |
if( op2 == Op_SubL && in2->outcnt() == 1) {
|
|
318 |
Node *add1 = phase->transform( new (phase->C, 3) AddLNode( in1, in2->in(2) ) );
|
|
319 |
return new (phase->C, 3) SubLNode( add1, in2->in(1) );
|
|
320 |
}
|
|
321 |
|
|
322 |
return NULL;
|
|
323 |
}
|
|
324 |
|
|
325 |
//------------------------------sub--------------------------------------------
|
|
326 |
// A subtract node differences it's two inputs.
|
|
327 |
const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
|
|
328 |
const TypeLong *r0 = t1->is_long(); // Handy access
|
|
329 |
const TypeLong *r1 = t2->is_long();
|
|
330 |
jlong lo = r0->_lo - r1->_hi;
|
|
331 |
jlong hi = r0->_hi - r1->_lo;
|
|
332 |
|
|
333 |
// We next check for 32-bit overflow.
|
|
334 |
// If that happens, we just assume all integers are possible.
|
|
335 |
if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
|
|
336 |
((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
|
|
337 |
(((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
|
|
338 |
((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
|
|
339 |
return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
|
|
340 |
else // Overflow; assume all integers
|
|
341 |
return TypeLong::LONG;
|
|
342 |
}
|
|
343 |
|
|
344 |
//=============================================================================
|
|
345 |
//------------------------------Value------------------------------------------
|
|
346 |
// A subtract node differences its two inputs.
|
|
347 |
const Type *SubFPNode::Value( PhaseTransform *phase ) const {
|
|
348 |
const Node* in1 = in(1);
|
|
349 |
const Node* in2 = in(2);
|
|
350 |
// Either input is TOP ==> the result is TOP
|
|
351 |
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
|
|
352 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
353 |
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
|
|
354 |
if( t2 == Type::TOP ) return Type::TOP;
|
|
355 |
|
|
356 |
// if both operands are infinity of same sign, the result is NaN; do
|
|
357 |
// not replace with zero
|
|
358 |
if( (t1->is_finite() && t2->is_finite()) ) {
|
|
359 |
if( phase->eqv(in1, in2) ) return add_id();
|
|
360 |
}
|
|
361 |
|
|
362 |
// Either input is BOTTOM ==> the result is the local BOTTOM
|
|
363 |
const Type *bot = bottom_type();
|
|
364 |
if( (t1 == bot) || (t2 == bot) ||
|
|
365 |
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
|
|
366 |
return bot;
|
|
367 |
|
|
368 |
return sub(t1,t2); // Local flavor of type subtraction
|
|
369 |
}
|
|
370 |
|
|
371 |
|
|
372 |
//=============================================================================
|
|
373 |
//------------------------------Ideal------------------------------------------
|
|
374 |
Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
375 |
const Type *t2 = phase->type( in(2) );
|
|
376 |
// Convert "x-c0" into "x+ -c0".
|
|
377 |
if( t2->base() == Type::FloatCon ) { // Might be bottom or top...
|
|
378 |
// return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) );
|
|
379 |
}
|
|
380 |
|
|
381 |
// Not associative because of boundary conditions (infinity)
|
|
382 |
if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
|
|
383 |
// Convert "x - (x+y)" into "-y"
|
|
384 |
if( in(2)->is_Add() &&
|
|
385 |
phase->eqv(in(1),in(2)->in(1) ) )
|
|
386 |
return new (phase->C, 3) SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2));
|
|
387 |
}
|
|
388 |
|
|
389 |
// Cannot replace 0.0-X with -X because a 'fsub' bytecode computes
|
|
390 |
// 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0.
|
|
391 |
//if( phase->type(in(1)) == TypeF::ZERO )
|
|
392 |
//return new (phase->C, 2) NegFNode(in(2));
|
|
393 |
|
|
394 |
return NULL;
|
|
395 |
}
|
|
396 |
|
|
397 |
//------------------------------sub--------------------------------------------
|
|
398 |
// A subtract node differences its two inputs.
|
|
399 |
const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const {
|
|
400 |
// no folding if one of operands is infinity or NaN, do not do constant folding
|
|
401 |
if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) {
|
|
402 |
return TypeF::make( t1->getf() - t2->getf() );
|
|
403 |
}
|
|
404 |
else if( g_isnan(t1->getf()) ) {
|
|
405 |
return t1;
|
|
406 |
}
|
|
407 |
else if( g_isnan(t2->getf()) ) {
|
|
408 |
return t2;
|
|
409 |
}
|
|
410 |
else {
|
|
411 |
return Type::FLOAT;
|
|
412 |
}
|
|
413 |
}
|
|
414 |
|
|
415 |
//=============================================================================
|
|
416 |
//------------------------------Ideal------------------------------------------
|
|
417 |
Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){
|
|
418 |
const Type *t2 = phase->type( in(2) );
|
|
419 |
// Convert "x-c0" into "x+ -c0".
|
|
420 |
if( t2->base() == Type::DoubleCon ) { // Might be bottom or top...
|
|
421 |
// return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) );
|
|
422 |
}
|
|
423 |
|
|
424 |
// Not associative because of boundary conditions (infinity)
|
|
425 |
if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
|
|
426 |
// Convert "x - (x+y)" into "-y"
|
|
427 |
if( in(2)->is_Add() &&
|
|
428 |
phase->eqv(in(1),in(2)->in(1) ) )
|
|
429 |
return new (phase->C, 3) SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2));
|
|
430 |
}
|
|
431 |
|
|
432 |
// Cannot replace 0.0-X with -X because a 'dsub' bytecode computes
|
|
433 |
// 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0.
|
|
434 |
//if( phase->type(in(1)) == TypeD::ZERO )
|
|
435 |
//return new (phase->C, 2) NegDNode(in(2));
|
|
436 |
|
|
437 |
return NULL;
|
|
438 |
}
|
|
439 |
|
|
440 |
//------------------------------sub--------------------------------------------
|
|
441 |
// A subtract node differences its two inputs.
|
|
442 |
const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const {
|
|
443 |
// no folding if one of operands is infinity or NaN, do not do constant folding
|
|
444 |
if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
|
|
445 |
return TypeD::make( t1->getd() - t2->getd() );
|
|
446 |
}
|
|
447 |
else if( g_isnan(t1->getd()) ) {
|
|
448 |
return t1;
|
|
449 |
}
|
|
450 |
else if( g_isnan(t2->getd()) ) {
|
|
451 |
return t2;
|
|
452 |
}
|
|
453 |
else {
|
|
454 |
return Type::DOUBLE;
|
|
455 |
}
|
|
456 |
}
|
|
457 |
|
|
458 |
//=============================================================================
|
|
459 |
//------------------------------Idealize---------------------------------------
|
|
460 |
// Unlike SubNodes, compare must still flatten return value to the
|
|
461 |
// range -1, 0, 1.
|
|
462 |
// And optimizations like those for (X + Y) - X fail if overflow happens.
|
|
463 |
Node *CmpNode::Identity( PhaseTransform *phase ) {
|
|
464 |
return this;
|
|
465 |
}
|
|
466 |
|
|
467 |
//=============================================================================
|
|
468 |
//------------------------------cmp--------------------------------------------
|
|
469 |
// Simplify a CmpI (compare 2 integers) node, based on local information.
|
|
470 |
// If both inputs are constants, compare them.
|
|
471 |
const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
|
|
472 |
const TypeInt *r0 = t1->is_int(); // Handy access
|
|
473 |
const TypeInt *r1 = t2->is_int();
|
|
474 |
|
|
475 |
if( r0->_hi < r1->_lo ) // Range is always low?
|
|
476 |
return TypeInt::CC_LT;
|
|
477 |
else if( r0->_lo > r1->_hi ) // Range is always high?
|
|
478 |
return TypeInt::CC_GT;
|
|
479 |
|
|
480 |
else if( r0->is_con() && r1->is_con() ) { // comparing constants?
|
|
481 |
assert(r0->get_con() == r1->get_con(), "must be equal");
|
|
482 |
return TypeInt::CC_EQ; // Equal results.
|
|
483 |
} else if( r0->_hi == r1->_lo ) // Range is never high?
|
|
484 |
return TypeInt::CC_LE;
|
|
485 |
else if( r0->_lo == r1->_hi ) // Range is never low?
|
|
486 |
return TypeInt::CC_GE;
|
|
487 |
return TypeInt::CC; // else use worst case results
|
|
488 |
}
|
|
489 |
|
|
490 |
// Simplify a CmpU (compare 2 integers) node, based on local information.
|
|
491 |
// If both inputs are constants, compare them.
|
|
492 |
const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
|
|
493 |
assert(!t1->isa_ptr(), "obsolete usage of CmpU");
|
|
494 |
|
|
495 |
// comparing two unsigned ints
|
|
496 |
const TypeInt *r0 = t1->is_int(); // Handy access
|
|
497 |
const TypeInt *r1 = t2->is_int();
|
|
498 |
|
|
499 |
// Current installed version
|
|
500 |
// Compare ranges for non-overlap
|
|
501 |
juint lo0 = r0->_lo;
|
|
502 |
juint hi0 = r0->_hi;
|
|
503 |
juint lo1 = r1->_lo;
|
|
504 |
juint hi1 = r1->_hi;
|
|
505 |
|
|
506 |
// If either one has both negative and positive values,
|
|
507 |
// it therefore contains both 0 and -1, and since [0..-1] is the
|
|
508 |
// full unsigned range, the type must act as an unsigned bottom.
|
|
509 |
bool bot0 = ((jint)(lo0 ^ hi0) < 0);
|
|
510 |
bool bot1 = ((jint)(lo1 ^ hi1) < 0);
|
|
511 |
|
|
512 |
if (bot0 || bot1) {
|
|
513 |
// All unsigned values are LE -1 and GE 0.
|
|
514 |
if (lo0 == 0 && hi0 == 0) {
|
|
515 |
return TypeInt::CC_LE; // 0 <= bot
|
|
516 |
} else if (lo1 == 0 && hi1 == 0) {
|
|
517 |
return TypeInt::CC_GE; // bot >= 0
|
|
518 |
}
|
|
519 |
} else {
|
|
520 |
// We can use ranges of the form [lo..hi] if signs are the same.
|
|
521 |
assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
|
|
522 |
// results are reversed, '-' > '+' for unsigned compare
|
|
523 |
if (hi0 < lo1) {
|
|
524 |
return TypeInt::CC_LT; // smaller
|
|
525 |
} else if (lo0 > hi1) {
|
|
526 |
return TypeInt::CC_GT; // greater
|
|
527 |
} else if (hi0 == lo1 && lo0 == hi1) {
|
|
528 |
return TypeInt::CC_EQ; // Equal results
|
|
529 |
} else if (lo0 >= hi1) {
|
|
530 |
return TypeInt::CC_GE;
|
|
531 |
} else if (hi0 <= lo1) {
|
|
532 |
// Check for special case in Hashtable::get. (See below.)
|
|
533 |
if ((jint)lo0 >= 0 && (jint)lo1 >= 0 &&
|
|
534 |
in(1)->Opcode() == Op_ModI &&
|
|
535 |
in(1)->in(2) == in(2) )
|
|
536 |
return TypeInt::CC_LT;
|
|
537 |
return TypeInt::CC_LE;
|
|
538 |
}
|
|
539 |
}
|
|
540 |
// Check for special case in Hashtable::get - the hash index is
|
|
541 |
// mod'ed to the table size so the following range check is useless.
|
|
542 |
// Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
|
|
543 |
// to be positive.
|
|
544 |
// (This is a gross hack, since the sub method never
|
|
545 |
// looks at the structure of the node in any other case.)
|
|
546 |
if ((jint)lo0 >= 0 && (jint)lo1 >= 0 &&
|
|
547 |
in(1)->Opcode() == Op_ModI &&
|
|
548 |
in(1)->in(2)->uncast() == in(2)->uncast())
|
|
549 |
return TypeInt::CC_LT;
|
|
550 |
return TypeInt::CC; // else use worst case results
|
|
551 |
}
|
|
552 |
|
|
553 |
//------------------------------Idealize---------------------------------------
|
|
554 |
Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
|
|
555 |
if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
|
|
556 |
switch (in(1)->Opcode()) {
|
|
557 |
case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
|
|
558 |
return new (phase->C, 3) CmpLNode(in(1)->in(1),in(1)->in(2));
|
|
559 |
case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
|
|
560 |
return new (phase->C, 3) CmpFNode(in(1)->in(1),in(1)->in(2));
|
|
561 |
case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
|
|
562 |
return new (phase->C, 3) CmpDNode(in(1)->in(1),in(1)->in(2));
|
|
563 |
//case Op_SubI:
|
|
564 |
// If (x - y) cannot overflow, then ((x - y) <?> 0)
|
|
565 |
// can be turned into (x <?> y).
|
|
566 |
// This is handled (with more general cases) by Ideal_sub_algebra.
|
|
567 |
}
|
|
568 |
}
|
|
569 |
return NULL; // No change
|
|
570 |
}
|
|
571 |
|
|
572 |
|
|
573 |
//=============================================================================
|
|
574 |
// Simplify a CmpL (compare 2 longs ) node, based on local information.
|
|
575 |
// If both inputs are constants, compare them.
|
|
576 |
const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
|
|
577 |
const TypeLong *r0 = t1->is_long(); // Handy access
|
|
578 |
const TypeLong *r1 = t2->is_long();
|
|
579 |
|
|
580 |
if( r0->_hi < r1->_lo ) // Range is always low?
|
|
581 |
return TypeInt::CC_LT;
|
|
582 |
else if( r0->_lo > r1->_hi ) // Range is always high?
|
|
583 |
return TypeInt::CC_GT;
|
|
584 |
|
|
585 |
else if( r0->is_con() && r1->is_con() ) { // comparing constants?
|
|
586 |
assert(r0->get_con() == r1->get_con(), "must be equal");
|
|
587 |
return TypeInt::CC_EQ; // Equal results.
|
|
588 |
} else if( r0->_hi == r1->_lo ) // Range is never high?
|
|
589 |
return TypeInt::CC_LE;
|
|
590 |
else if( r0->_lo == r1->_hi ) // Range is never low?
|
|
591 |
return TypeInt::CC_GE;
|
|
592 |
return TypeInt::CC; // else use worst case results
|
|
593 |
}
|
|
594 |
|
|
595 |
//=============================================================================
|
|
596 |
//------------------------------sub--------------------------------------------
|
|
597 |
// Simplify an CmpP (compare 2 pointers) node, based on local information.
|
|
598 |
// If both inputs are constants, compare them.
|
|
599 |
const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
|
|
600 |
const TypePtr *r0 = t1->is_ptr(); // Handy access
|
|
601 |
const TypePtr *r1 = t2->is_ptr();
|
|
602 |
|
|
603 |
// Undefined inputs makes for an undefined result
|
|
604 |
if( TypePtr::above_centerline(r0->_ptr) ||
|
|
605 |
TypePtr::above_centerline(r1->_ptr) )
|
|
606 |
return Type::TOP;
|
|
607 |
|
|
608 |
if (r0 == r1 && r0->singleton()) {
|
|
609 |
// Equal pointer constants (klasses, nulls, etc.)
|
|
610 |
return TypeInt::CC_EQ;
|
|
611 |
}
|
|
612 |
|
|
613 |
// See if it is 2 unrelated classes.
|
|
614 |
const TypeOopPtr* p0 = r0->isa_oopptr();
|
|
615 |
const TypeOopPtr* p1 = r1->isa_oopptr();
|
|
616 |
if (p0 && p1) {
|
206
|
617 |
Node* in1 = in(1)->uncast();
|
|
618 |
Node* in2 = in(2)->uncast();
|
|
619 |
AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
|
|
620 |
AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
|
|
621 |
if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
|
|
622 |
return TypeInt::CC_GT; // different pointers
|
|
623 |
}
|
1
|
624 |
ciKlass* klass0 = p0->klass();
|
|
625 |
bool xklass0 = p0->klass_is_exact();
|
|
626 |
ciKlass* klass1 = p1->klass();
|
|
627 |
bool xklass1 = p1->klass_is_exact();
|
|
628 |
int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
|
|
629 |
if (klass0 && klass1 &&
|
|
630 |
kps != 1 && // both or neither are klass pointers
|
|
631 |
!klass0->is_interface() && // do not trust interfaces
|
|
632 |
!klass1->is_interface()) {
|
|
633 |
// See if neither subclasses the other, or if the class on top
|
|
634 |
// is precise. In either of these cases, the compare must fail.
|
|
635 |
if (klass0->equals(klass1) || // if types are unequal but klasses are
|
|
636 |
!klass0->is_java_klass() || // types not part of Java language?
|
|
637 |
!klass1->is_java_klass()) { // types not part of Java language?
|
|
638 |
// Do nothing; we know nothing for imprecise types
|
|
639 |
} else if (klass0->is_subtype_of(klass1)) {
|
|
640 |
// If klass1's type is PRECISE, then we can fail.
|
|
641 |
if (xklass1) return TypeInt::CC_GT;
|
|
642 |
} else if (klass1->is_subtype_of(klass0)) {
|
|
643 |
// If klass0's type is PRECISE, then we can fail.
|
|
644 |
if (xklass0) return TypeInt::CC_GT;
|
|
645 |
} else { // Neither subtypes the other
|
|
646 |
return TypeInt::CC_GT; // ...so always fail
|
|
647 |
}
|
|
648 |
}
|
|
649 |
}
|
|
650 |
|
|
651 |
// Known constants can be compared exactly
|
|
652 |
// Null can be distinguished from any NotNull pointers
|
|
653 |
// Unknown inputs makes an unknown result
|
|
654 |
if( r0->singleton() ) {
|
|
655 |
intptr_t bits0 = r0->get_con();
|
|
656 |
if( r1->singleton() )
|
|
657 |
return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
|
|
658 |
return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
|
|
659 |
} else if( r1->singleton() ) {
|
|
660 |
intptr_t bits1 = r1->get_con();
|
|
661 |
return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
|
|
662 |
} else
|
|
663 |
return TypeInt::CC;
|
|
664 |
}
|
|
665 |
|
|
666 |
//------------------------------Ideal------------------------------------------
|
|
667 |
// Check for the case of comparing an unknown klass loaded from the primary
|
|
668 |
// super-type array vs a known klass with no subtypes. This amounts to
|
|
669 |
// checking to see an unknown klass subtypes a known klass with no subtypes;
|
|
670 |
// this only happens on an exact match. We can shorten this test by 1 load.
|
|
671 |
Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
|
|
672 |
// Constant pointer on right?
|
|
673 |
const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
|
|
674 |
if (t2 == NULL || !t2->klass_is_exact())
|
|
675 |
return NULL;
|
|
676 |
// Get the constant klass we are comparing to.
|
|
677 |
ciKlass* superklass = t2->klass();
|
|
678 |
|
|
679 |
// Now check for LoadKlass on left.
|
|
680 |
Node* ldk1 = in(1);
|
|
681 |
if (ldk1->Opcode() != Op_LoadKlass)
|
|
682 |
return NULL;
|
|
683 |
// Take apart the address of the LoadKlass:
|
|
684 |
Node* adr1 = ldk1->in(MemNode::Address);
|
|
685 |
intptr_t con2 = 0;
|
|
686 |
Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2);
|
|
687 |
if (ldk2 == NULL)
|
|
688 |
return NULL;
|
|
689 |
if (con2 == oopDesc::klass_offset_in_bytes()) {
|
|
690 |
// We are inspecting an object's concrete class.
|
|
691 |
// Short-circuit the check if the query is abstract.
|
|
692 |
if (superklass->is_interface() ||
|
|
693 |
superklass->is_abstract()) {
|
|
694 |
// Make it come out always false:
|
|
695 |
this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
|
|
696 |
return this;
|
|
697 |
}
|
|
698 |
}
|
|
699 |
|
|
700 |
// Check for a LoadKlass from primary supertype array.
|
|
701 |
// Any nested loadklass from loadklass+con must be from the p.s. array.
|
|
702 |
if (ldk2->Opcode() != Op_LoadKlass)
|
|
703 |
return NULL;
|
|
704 |
|
|
705 |
// Verify that we understand the situation
|
|
706 |
if (con2 != (intptr_t) superklass->super_check_offset())
|
|
707 |
return NULL; // Might be element-klass loading from array klass
|
|
708 |
|
|
709 |
// If 'superklass' has no subklasses and is not an interface, then we are
|
|
710 |
// assured that the only input which will pass the type check is
|
|
711 |
// 'superklass' itself.
|
|
712 |
//
|
|
713 |
// We could be more liberal here, and allow the optimization on interfaces
|
|
714 |
// which have a single implementor. This would require us to increase the
|
|
715 |
// expressiveness of the add_dependency() mechanism.
|
|
716 |
// %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
|
|
717 |
|
|
718 |
// Object arrays must have their base element have no subtypes
|
|
719 |
while (superklass->is_obj_array_klass()) {
|
|
720 |
ciType* elem = superklass->as_obj_array_klass()->element_type();
|
|
721 |
superklass = elem->as_klass();
|
|
722 |
}
|
|
723 |
if (superklass->is_instance_klass()) {
|
|
724 |
ciInstanceKlass* ik = superklass->as_instance_klass();
|
|
725 |
if (ik->has_subklass() || ik->is_interface()) return NULL;
|
|
726 |
// Add a dependency if there is a chance that a subclass will be added later.
|
|
727 |
if (!ik->is_final()) {
|
|
728 |
phase->C->dependencies()->assert_leaf_type(ik);
|
|
729 |
}
|
|
730 |
}
|
|
731 |
|
|
732 |
// Bypass the dependent load, and compare directly
|
|
733 |
this->set_req(1,ldk2);
|
|
734 |
|
|
735 |
return this;
|
|
736 |
}
|
|
737 |
|
|
738 |
//=============================================================================
|
|
739 |
//------------------------------Value------------------------------------------
|
|
740 |
// Simplify an CmpF (compare 2 floats ) node, based on local information.
|
|
741 |
// If both inputs are constants, compare them.
|
|
742 |
const Type *CmpFNode::Value( PhaseTransform *phase ) const {
|
|
743 |
const Node* in1 = in(1);
|
|
744 |
const Node* in2 = in(2);
|
|
745 |
// Either input is TOP ==> the result is TOP
|
|
746 |
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
|
|
747 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
748 |
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
|
|
749 |
if( t2 == Type::TOP ) return Type::TOP;
|
|
750 |
|
|
751 |
// Not constants? Don't know squat - even if they are the same
|
|
752 |
// value! If they are NaN's they compare to LT instead of EQ.
|
|
753 |
const TypeF *tf1 = t1->isa_float_constant();
|
|
754 |
const TypeF *tf2 = t2->isa_float_constant();
|
|
755 |
if( !tf1 || !tf2 ) return TypeInt::CC;
|
|
756 |
|
|
757 |
// This implements the Java bytecode fcmpl, so unordered returns -1.
|
|
758 |
if( tf1->is_nan() || tf2->is_nan() )
|
|
759 |
return TypeInt::CC_LT;
|
|
760 |
|
|
761 |
if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
|
|
762 |
if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
|
|
763 |
assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
|
|
764 |
return TypeInt::CC_EQ;
|
|
765 |
}
|
|
766 |
|
|
767 |
|
|
768 |
//=============================================================================
|
|
769 |
//------------------------------Value------------------------------------------
|
|
770 |
// Simplify an CmpD (compare 2 doubles ) node, based on local information.
|
|
771 |
// If both inputs are constants, compare them.
|
|
772 |
const Type *CmpDNode::Value( PhaseTransform *phase ) const {
|
|
773 |
const Node* in1 = in(1);
|
|
774 |
const Node* in2 = in(2);
|
|
775 |
// Either input is TOP ==> the result is TOP
|
|
776 |
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
|
|
777 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
778 |
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
|
|
779 |
if( t2 == Type::TOP ) return Type::TOP;
|
|
780 |
|
|
781 |
// Not constants? Don't know squat - even if they are the same
|
|
782 |
// value! If they are NaN's they compare to LT instead of EQ.
|
|
783 |
const TypeD *td1 = t1->isa_double_constant();
|
|
784 |
const TypeD *td2 = t2->isa_double_constant();
|
|
785 |
if( !td1 || !td2 ) return TypeInt::CC;
|
|
786 |
|
|
787 |
// This implements the Java bytecode dcmpl, so unordered returns -1.
|
|
788 |
if( td1->is_nan() || td2->is_nan() )
|
|
789 |
return TypeInt::CC_LT;
|
|
790 |
|
|
791 |
if( td1->_d < td2->_d ) return TypeInt::CC_LT;
|
|
792 |
if( td1->_d > td2->_d ) return TypeInt::CC_GT;
|
|
793 |
assert( td1->_d == td2->_d, "do not understand FP behavior" );
|
|
794 |
return TypeInt::CC_EQ;
|
|
795 |
}
|
|
796 |
|
|
797 |
//------------------------------Ideal------------------------------------------
|
|
798 |
Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){
|
|
799 |
// Check if we can change this to a CmpF and remove a ConvD2F operation.
|
|
800 |
// Change (CMPD (F2D (float)) (ConD value))
|
|
801 |
// To (CMPF (float) (ConF value))
|
|
802 |
// Valid when 'value' does not lose precision as a float.
|
|
803 |
// Benefits: eliminates conversion, does not require 24-bit mode
|
|
804 |
|
|
805 |
// NaNs prevent commuting operands. This transform works regardless of the
|
|
806 |
// order of ConD and ConvF2D inputs by preserving the original order.
|
|
807 |
int idx_f2d = 1; // ConvF2D on left side?
|
|
808 |
if( in(idx_f2d)->Opcode() != Op_ConvF2D )
|
|
809 |
idx_f2d = 2; // No, swap to check for reversed args
|
|
810 |
int idx_con = 3-idx_f2d; // Check for the constant on other input
|
|
811 |
|
|
812 |
if( ConvertCmpD2CmpF &&
|
|
813 |
in(idx_f2d)->Opcode() == Op_ConvF2D &&
|
|
814 |
in(idx_con)->Opcode() == Op_ConD ) {
|
|
815 |
const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant();
|
|
816 |
double t2_value_as_double = t2->_d;
|
|
817 |
float t2_value_as_float = (float)t2_value_as_double;
|
|
818 |
if( t2_value_as_double == (double)t2_value_as_float ) {
|
|
819 |
// Test value can be represented as a float
|
|
820 |
// Eliminate the conversion to double and create new comparison
|
|
821 |
Node *new_in1 = in(idx_f2d)->in(1);
|
|
822 |
Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
|
|
823 |
if( idx_f2d != 1 ) { // Must flip args to match original order
|
|
824 |
Node *tmp = new_in1;
|
|
825 |
new_in1 = new_in2;
|
|
826 |
new_in2 = tmp;
|
|
827 |
}
|
|
828 |
CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
|
|
829 |
? new (phase->C, 3) CmpF3Node( new_in1, new_in2 )
|
|
830 |
: new (phase->C, 3) CmpFNode ( new_in1, new_in2 ) ;
|
|
831 |
return new_cmp; // Changed to CmpFNode
|
|
832 |
}
|
|
833 |
// Testing value required the precision of a double
|
|
834 |
}
|
|
835 |
return NULL; // No change
|
|
836 |
}
|
|
837 |
|
|
838 |
|
|
839 |
//=============================================================================
|
|
840 |
//------------------------------cc2logical-------------------------------------
|
|
841 |
// Convert a condition code type to a logical type
|
|
842 |
const Type *BoolTest::cc2logical( const Type *CC ) const {
|
|
843 |
if( CC == Type::TOP ) return Type::TOP;
|
|
844 |
if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
|
|
845 |
const TypeInt *ti = CC->is_int();
|
|
846 |
if( ti->is_con() ) { // Only 1 kind of condition codes set?
|
|
847 |
// Match low order 2 bits
|
|
848 |
int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
|
|
849 |
if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
|
|
850 |
return TypeInt::make(tmp); // Boolean result
|
|
851 |
}
|
|
852 |
|
|
853 |
if( CC == TypeInt::CC_GE ) {
|
|
854 |
if( _test == ge ) return TypeInt::ONE;
|
|
855 |
if( _test == lt ) return TypeInt::ZERO;
|
|
856 |
}
|
|
857 |
if( CC == TypeInt::CC_LE ) {
|
|
858 |
if( _test == le ) return TypeInt::ONE;
|
|
859 |
if( _test == gt ) return TypeInt::ZERO;
|
|
860 |
}
|
|
861 |
|
|
862 |
return TypeInt::BOOL;
|
|
863 |
}
|
|
864 |
|
|
865 |
//------------------------------dump_spec-------------------------------------
|
|
866 |
// Print special per-node info
|
|
867 |
#ifndef PRODUCT
|
|
868 |
void BoolTest::dump_on(outputStream *st) const {
|
|
869 |
const char *msg[] = {"eq","gt","??","lt","ne","le","??","ge"};
|
|
870 |
st->print(msg[_test]);
|
|
871 |
}
|
|
872 |
#endif
|
|
873 |
|
|
874 |
//=============================================================================
|
|
875 |
uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
|
|
876 |
uint BoolNode::size_of() const { return sizeof(BoolNode); }
|
|
877 |
|
|
878 |
//------------------------------operator==-------------------------------------
|
|
879 |
uint BoolNode::cmp( const Node &n ) const {
|
|
880 |
const BoolNode *b = (const BoolNode *)&n; // Cast up
|
|
881 |
return (_test._test == b->_test._test);
|
|
882 |
}
|
|
883 |
|
|
884 |
//------------------------------clone_cmp--------------------------------------
|
|
885 |
// Clone a compare/bool tree
|
|
886 |
static Node *clone_cmp( Node *cmp, Node *cmp1, Node *cmp2, PhaseGVN *gvn, BoolTest::mask test ) {
|
|
887 |
Node *ncmp = cmp->clone();
|
|
888 |
ncmp->set_req(1,cmp1);
|
|
889 |
ncmp->set_req(2,cmp2);
|
|
890 |
ncmp = gvn->transform( ncmp );
|
|
891 |
return new (gvn->C, 2) BoolNode( ncmp, test );
|
|
892 |
}
|
|
893 |
|
|
894 |
//-------------------------------make_predicate--------------------------------
|
|
895 |
Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
|
|
896 |
if (test_value->is_Con()) return test_value;
|
|
897 |
if (test_value->is_Bool()) return test_value;
|
|
898 |
Compile* C = phase->C;
|
|
899 |
if (test_value->is_CMove() &&
|
|
900 |
test_value->in(CMoveNode::Condition)->is_Bool()) {
|
|
901 |
BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool();
|
|
902 |
const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
|
|
903 |
const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
|
|
904 |
if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
|
|
905 |
return bol;
|
|
906 |
} else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
|
|
907 |
return phase->transform( bol->negate(phase) );
|
|
908 |
}
|
|
909 |
// Else fall through. The CMove gets in the way of the test.
|
|
910 |
// It should be the case that make_predicate(bol->as_int_value()) == bol.
|
|
911 |
}
|
|
912 |
Node* cmp = new (C, 3) CmpINode(test_value, phase->intcon(0));
|
|
913 |
cmp = phase->transform(cmp);
|
|
914 |
Node* bol = new (C, 2) BoolNode(cmp, BoolTest::ne);
|
|
915 |
return phase->transform(bol);
|
|
916 |
}
|
|
917 |
|
|
918 |
//--------------------------------as_int_value---------------------------------
|
|
919 |
Node* BoolNode::as_int_value(PhaseGVN* phase) {
|
|
920 |
// Inverse to make_predicate. The CMove probably boils down to a Conv2B.
|
|
921 |
Node* cmov = CMoveNode::make(phase->C, NULL, this,
|
|
922 |
phase->intcon(0), phase->intcon(1),
|
|
923 |
TypeInt::BOOL);
|
|
924 |
return phase->transform(cmov);
|
|
925 |
}
|
|
926 |
|
|
927 |
//----------------------------------negate-------------------------------------
|
|
928 |
BoolNode* BoolNode::negate(PhaseGVN* phase) {
|
|
929 |
Compile* C = phase->C;
|
|
930 |
return new (C, 2) BoolNode(in(1), _test.negate());
|
|
931 |
}
|
|
932 |
|
|
933 |
|
|
934 |
//------------------------------Ideal------------------------------------------
|
|
935 |
Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
936 |
// Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
|
|
937 |
// This moves the constant to the right. Helps value-numbering.
|
|
938 |
Node *cmp = in(1);
|
|
939 |
if( !cmp->is_Sub() ) return NULL;
|
|
940 |
int cop = cmp->Opcode();
|
|
941 |
if( cop == Op_FastLock || cop == Op_FastUnlock ) return NULL;
|
|
942 |
Node *cmp1 = cmp->in(1);
|
|
943 |
Node *cmp2 = cmp->in(2);
|
|
944 |
if( !cmp1 ) return NULL;
|
|
945 |
|
|
946 |
// Constant on left?
|
|
947 |
Node *con = cmp1;
|
|
948 |
uint op2 = cmp2->Opcode();
|
|
949 |
// Move constants to the right of compare's to canonicalize.
|
|
950 |
// Do not muck with Opaque1 nodes, as this indicates a loop
|
|
951 |
// guard that cannot change shape.
|
|
952 |
if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 &&
|
|
953 |
// Because of NaN's, CmpD and CmpF are not commutative
|
|
954 |
cop != Op_CmpD && cop != Op_CmpF &&
|
|
955 |
// Protect against swapping inputs to a compare when it is used by a
|
|
956 |
// counted loop exit, which requires maintaining the loop-limit as in(2)
|
|
957 |
!is_counted_loop_exit_test() ) {
|
|
958 |
// Ok, commute the constant to the right of the cmp node.
|
|
959 |
// Clone the Node, getting a new Node of the same class
|
|
960 |
cmp = cmp->clone();
|
|
961 |
// Swap inputs to the clone
|
|
962 |
cmp->swap_edges(1, 2);
|
|
963 |
cmp = phase->transform( cmp );
|
|
964 |
return new (phase->C, 2) BoolNode( cmp, _test.commute() );
|
|
965 |
}
|
|
966 |
|
|
967 |
// Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)".
|
|
968 |
// The XOR-1 is an idiom used to flip the sense of a bool. We flip the
|
|
969 |
// test instead.
|
|
970 |
int cmp1_op = cmp1->Opcode();
|
|
971 |
const TypeInt* cmp2_type = phase->type(cmp2)->isa_int();
|
|
972 |
if (cmp2_type == NULL) return NULL;
|
|
973 |
Node* j_xor = cmp1;
|
|
974 |
if( cmp2_type == TypeInt::ZERO &&
|
|
975 |
cmp1_op == Op_XorI &&
|
|
976 |
j_xor->in(1) != j_xor && // An xor of itself is dead
|
|
977 |
phase->type( j_xor->in(2) ) == TypeInt::ONE &&
|
|
978 |
(_test._test == BoolTest::eq ||
|
|
979 |
_test._test == BoolTest::ne) ) {
|
|
980 |
Node *ncmp = phase->transform(new (phase->C, 3) CmpINode(j_xor->in(1),cmp2));
|
|
981 |
return new (phase->C, 2) BoolNode( ncmp, _test.negate() );
|
|
982 |
}
|
|
983 |
|
|
984 |
// Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)".
|
|
985 |
// This is a standard idiom for branching on a boolean value.
|
|
986 |
Node *c2b = cmp1;
|
|
987 |
if( cmp2_type == TypeInt::ZERO &&
|
|
988 |
cmp1_op == Op_Conv2B &&
|
|
989 |
(_test._test == BoolTest::eq ||
|
|
990 |
_test._test == BoolTest::ne) ) {
|
|
991 |
Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int()
|
|
992 |
? (Node*)new (phase->C, 3) CmpINode(c2b->in(1),cmp2)
|
|
993 |
: (Node*)new (phase->C, 3) CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR))
|
|
994 |
);
|
|
995 |
return new (phase->C, 2) BoolNode( ncmp, _test._test );
|
|
996 |
}
|
|
997 |
|
|
998 |
// Comparing a SubI against a zero is equal to comparing the SubI
|
|
999 |
// arguments directly. This only works for eq and ne comparisons
|
|
1000 |
// due to possible integer overflow.
|
|
1001 |
if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
|
|
1002 |
(cop == Op_CmpI) &&
|
|
1003 |
(cmp1->Opcode() == Op_SubI) &&
|
|
1004 |
( cmp2_type == TypeInt::ZERO ) ) {
|
|
1005 |
Node *ncmp = phase->transform( new (phase->C, 3) CmpINode(cmp1->in(1),cmp1->in(2)));
|
|
1006 |
return new (phase->C, 2) BoolNode( ncmp, _test._test );
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
// Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the
|
|
1010 |
// most general case because negating 0x80000000 does nothing. Needed for
|
|
1011 |
// the CmpF3/SubI/CmpI idiom.
|
|
1012 |
if( cop == Op_CmpI &&
|
|
1013 |
cmp1->Opcode() == Op_SubI &&
|
|
1014 |
cmp2_type == TypeInt::ZERO &&
|
|
1015 |
phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
|
|
1016 |
phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
|
|
1017 |
Node *ncmp = phase->transform( new (phase->C, 3) CmpINode(cmp1->in(2),cmp2));
|
|
1018 |
return new (phase->C, 2) BoolNode( ncmp, _test.commute() );
|
|
1019 |
}
|
|
1020 |
|
|
1021 |
// The transformation below is not valid for either signed or unsigned
|
|
1022 |
// comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
|
|
1023 |
// This transformation can be resurrected when we are able to
|
|
1024 |
// make inferences about the range of values being subtracted from
|
|
1025 |
// (or added to) relative to the wraparound point.
|
|
1026 |
//
|
|
1027 |
// // Remove +/-1's if possible.
|
|
1028 |
// // "X <= Y-1" becomes "X < Y"
|
|
1029 |
// // "X+1 <= Y" becomes "X < Y"
|
|
1030 |
// // "X < Y+1" becomes "X <= Y"
|
|
1031 |
// // "X-1 < Y" becomes "X <= Y"
|
|
1032 |
// // Do not this to compares off of the counted-loop-end. These guys are
|
|
1033 |
// // checking the trip counter and they want to use the post-incremented
|
|
1034 |
// // counter. If they use the PRE-incremented counter, then the counter has
|
|
1035 |
// // to be incremented in a private block on a loop backedge.
|
|
1036 |
// if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
|
|
1037 |
// return NULL;
|
|
1038 |
// #ifndef PRODUCT
|
|
1039 |
// // Do not do this in a wash GVN pass during verification.
|
|
1040 |
// // Gets triggered by too many simple optimizations to be bothered with
|
|
1041 |
// // re-trying it again and again.
|
|
1042 |
// if( !phase->allow_progress() ) return NULL;
|
|
1043 |
// #endif
|
|
1044 |
// // Not valid for unsigned compare because of corner cases in involving zero.
|
|
1045 |
// // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
|
|
1046 |
// // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
|
|
1047 |
// // "0 <=u Y" is always true).
|
|
1048 |
// if( cmp->Opcode() == Op_CmpU ) return NULL;
|
|
1049 |
// int cmp2_op = cmp2->Opcode();
|
|
1050 |
// if( _test._test == BoolTest::le ) {
|
|
1051 |
// if( cmp1_op == Op_AddI &&
|
|
1052 |
// phase->type( cmp1->in(2) ) == TypeInt::ONE )
|
|
1053 |
// return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
|
|
1054 |
// else if( cmp2_op == Op_AddI &&
|
|
1055 |
// phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
|
|
1056 |
// return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
|
|
1057 |
// } else if( _test._test == BoolTest::lt ) {
|
|
1058 |
// if( cmp1_op == Op_AddI &&
|
|
1059 |
// phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
|
|
1060 |
// return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
|
|
1061 |
// else if( cmp2_op == Op_AddI &&
|
|
1062 |
// phase->type( cmp2->in(2) ) == TypeInt::ONE )
|
|
1063 |
// return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
|
|
1064 |
// }
|
|
1065 |
|
|
1066 |
return NULL;
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
//------------------------------Value------------------------------------------
|
|
1070 |
// Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
|
|
1071 |
// based on local information. If the input is constant, do it.
|
|
1072 |
const Type *BoolNode::Value( PhaseTransform *phase ) const {
|
|
1073 |
return _test.cc2logical( phase->type( in(1) ) );
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
//------------------------------dump_spec--------------------------------------
|
|
1077 |
// Dump special per-node info
|
|
1078 |
#ifndef PRODUCT
|
|
1079 |
void BoolNode::dump_spec(outputStream *st) const {
|
|
1080 |
st->print("[");
|
|
1081 |
_test.dump_on(st);
|
|
1082 |
st->print("]");
|
|
1083 |
}
|
|
1084 |
#endif
|
|
1085 |
|
|
1086 |
//------------------------------is_counted_loop_exit_test--------------------------------------
|
|
1087 |
// Returns true if node is used by a counted loop node.
|
|
1088 |
bool BoolNode::is_counted_loop_exit_test() {
|
|
1089 |
for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
|
|
1090 |
Node* use = fast_out(i);
|
|
1091 |
if (use->is_CountedLoopEnd()) {
|
|
1092 |
return true;
|
|
1093 |
}
|
|
1094 |
}
|
|
1095 |
return false;
|
|
1096 |
}
|
|
1097 |
|
|
1098 |
//=============================================================================
|
|
1099 |
//------------------------------NegNode----------------------------------------
|
|
1100 |
Node *NegFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
1101 |
if( in(1)->Opcode() == Op_SubF )
|
|
1102 |
return new (phase->C, 3) SubFNode( in(1)->in(2), in(1)->in(1) );
|
|
1103 |
return NULL;
|
|
1104 |
}
|
|
1105 |
|
|
1106 |
Node *NegDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
|
|
1107 |
if( in(1)->Opcode() == Op_SubD )
|
|
1108 |
return new (phase->C, 3) SubDNode( in(1)->in(2), in(1)->in(1) );
|
|
1109 |
return NULL;
|
|
1110 |
}
|
|
1111 |
|
|
1112 |
|
|
1113 |
//=============================================================================
|
|
1114 |
//------------------------------Value------------------------------------------
|
|
1115 |
// Compute sqrt
|
|
1116 |
const Type *SqrtDNode::Value( PhaseTransform *phase ) const {
|
|
1117 |
const Type *t1 = phase->type( in(1) );
|
|
1118 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1119 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1120 |
double d = t1->getd();
|
|
1121 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1122 |
return TypeD::make( sqrt( d ) );
|
|
1123 |
}
|
|
1124 |
|
|
1125 |
//=============================================================================
|
|
1126 |
//------------------------------Value------------------------------------------
|
|
1127 |
// Compute cos
|
|
1128 |
const Type *CosDNode::Value( PhaseTransform *phase ) const {
|
|
1129 |
const Type *t1 = phase->type( in(1) );
|
|
1130 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1131 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1132 |
double d = t1->getd();
|
|
1133 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1134 |
return TypeD::make( SharedRuntime::dcos( d ) );
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
//=============================================================================
|
|
1138 |
//------------------------------Value------------------------------------------
|
|
1139 |
// Compute sin
|
|
1140 |
const Type *SinDNode::Value( PhaseTransform *phase ) const {
|
|
1141 |
const Type *t1 = phase->type( in(1) );
|
|
1142 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1143 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1144 |
double d = t1->getd();
|
|
1145 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1146 |
return TypeD::make( SharedRuntime::dsin( d ) );
|
|
1147 |
}
|
|
1148 |
|
|
1149 |
//=============================================================================
|
|
1150 |
//------------------------------Value------------------------------------------
|
|
1151 |
// Compute tan
|
|
1152 |
const Type *TanDNode::Value( PhaseTransform *phase ) const {
|
|
1153 |
const Type *t1 = phase->type( in(1) );
|
|
1154 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1155 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1156 |
double d = t1->getd();
|
|
1157 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1158 |
return TypeD::make( SharedRuntime::dtan( d ) );
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
//=============================================================================
|
|
1162 |
//------------------------------Value------------------------------------------
|
|
1163 |
// Compute log
|
|
1164 |
const Type *LogDNode::Value( PhaseTransform *phase ) const {
|
|
1165 |
const Type *t1 = phase->type( in(1) );
|
|
1166 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1167 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1168 |
double d = t1->getd();
|
|
1169 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1170 |
return TypeD::make( SharedRuntime::dlog( d ) );
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
//=============================================================================
|
|
1174 |
//------------------------------Value------------------------------------------
|
|
1175 |
// Compute log10
|
|
1176 |
const Type *Log10DNode::Value( PhaseTransform *phase ) const {
|
|
1177 |
const Type *t1 = phase->type( in(1) );
|
|
1178 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1179 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1180 |
double d = t1->getd();
|
|
1181 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1182 |
return TypeD::make( SharedRuntime::dlog10( d ) );
|
|
1183 |
}
|
|
1184 |
|
|
1185 |
//=============================================================================
|
|
1186 |
//------------------------------Value------------------------------------------
|
|
1187 |
// Compute exp
|
|
1188 |
const Type *ExpDNode::Value( PhaseTransform *phase ) const {
|
|
1189 |
const Type *t1 = phase->type( in(1) );
|
|
1190 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1191 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1192 |
double d = t1->getd();
|
|
1193 |
if( d < 0.0 ) return Type::DOUBLE;
|
|
1194 |
return TypeD::make( SharedRuntime::dexp( d ) );
|
|
1195 |
}
|
|
1196 |
|
|
1197 |
|
|
1198 |
//=============================================================================
|
|
1199 |
//------------------------------Value------------------------------------------
|
|
1200 |
// Compute pow
|
|
1201 |
const Type *PowDNode::Value( PhaseTransform *phase ) const {
|
|
1202 |
const Type *t1 = phase->type( in(1) );
|
|
1203 |
if( t1 == Type::TOP ) return Type::TOP;
|
|
1204 |
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1205 |
const Type *t2 = phase->type( in(2) );
|
|
1206 |
if( t2 == Type::TOP ) return Type::TOP;
|
|
1207 |
if( t2->base() != Type::DoubleCon ) return Type::DOUBLE;
|
|
1208 |
double d1 = t1->getd();
|
|
1209 |
double d2 = t2->getd();
|
|
1210 |
if( d1 < 0.0 ) return Type::DOUBLE;
|
|
1211 |
if( d2 < 0.0 ) return Type::DOUBLE;
|
|
1212 |
return TypeD::make( SharedRuntime::dpow( d1, d2 ) );
|
|
1213 |
}
|