1 /*
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "opto/addnode.hpp"
27 #include "opto/castnode.hpp"
28 #include "opto/convertnode.hpp"
29 #include "opto/matcher.hpp"
30 #include "opto/phaseX.hpp"
31 #include "opto/subnode.hpp"
32 #include "runtime/sharedRuntime.hpp"
33
34 //=============================================================================
35 //------------------------------Identity---------------------------------------
36 Node* Conv2BNode::Identity(PhaseGVN* phase) {
37 const Type *t = phase->type( in(1) );
38 if( t == Type::TOP ) return in(1);
39 if( t == TypeInt::ZERO ) return in(1);
40 if( t == TypeInt::ONE ) return in(1);
41 if( t == TypeInt::BOOL ) return in(1);
42 return this;
43 }
44
45 //------------------------------Value------------------------------------------
46 const Type* Conv2BNode::Value(PhaseGVN* phase) const {
47 const Type *t = phase->type( in(1) );
48 if( t == Type::TOP ) return Type::TOP;
49 if( t == TypeInt::ZERO ) return TypeInt::ZERO;
50 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
51 const TypePtr *tp = t->isa_ptr();
52 if( tp != NULL ) {
53 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
54 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
55 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;
56 return TypeInt::BOOL;
57 }
58 if (t->base() != Type::Int) return TypeInt::BOOL;
59 const TypeInt *ti = t->is_int();
60 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
61 return TypeInt::BOOL;
62 }
63
64
65 // The conversions operations are all Alpha sorted. Please keep it that way!
66 //=============================================================================
67 //------------------------------Value------------------------------------------
68 const Type* ConvD2FNode::Value(PhaseGVN* phase) const {
69 const Type *t = phase->type( in(1) );
70 if( t == Type::TOP ) return Type::TOP;
71 if( t == Type::DOUBLE ) return Type::FLOAT;
72 const TypeD *td = t->is_double_constant();
73 return TypeF::make( (float)td->getd() );
74 }
75
76 //------------------------------Ideal------------------------------------------
77 // If we see pattern ConvF2D SomeDoubleOp ConvD2F, do operation as float.
78 Node *ConvD2FNode::Ideal(PhaseGVN *phase, bool can_reshape) {
79 if ( in(1)->Opcode() == Op_SqrtD ) {
80 Node* sqrtd = in(1);
81 if ( sqrtd->in(1)->Opcode() == Op_ConvF2D ) {
82 if ( Matcher::match_rule_supported(Op_SqrtF) ) {
83 Node* convf2d = sqrtd->in(1);
84 return new SqrtFNode(phase->C, sqrtd->in(0), convf2d->in(1));
85 }
86 }
87 }
88 return NULL;
89 }
90
91 //------------------------------Identity---------------------------------------
92 // Float's can be converted to doubles with no loss of bits. Hence
93 // converting a float to a double and back to a float is a NOP.
94 Node* ConvD2FNode::Identity(PhaseGVN* phase) {
95 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
96 }
97
98 //=============================================================================
99 //------------------------------Value------------------------------------------
100 const Type* ConvD2INode::Value(PhaseGVN* phase) const {
101 const Type *t = phase->type( in(1) );
102 if( t == Type::TOP ) return Type::TOP;
103 if( t == Type::DOUBLE ) return TypeInt::INT;
104 const TypeD *td = t->is_double_constant();
105 return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
106 }
107
108 //------------------------------Ideal------------------------------------------
109 // If converting to an int type, skip any rounding nodes
110 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
111 if (in(1)->Opcode() == Op_RoundDouble) {
112 set_req(1, in(1)->in(1));
113 return this;
114 }
115 return NULL;
116 }
117
118 //------------------------------Identity---------------------------------------
119 // Int's can be converted to doubles with no loss of bits. Hence
120 // converting an integer to a double and back to an integer is a NOP.
121 Node* ConvD2INode::Identity(PhaseGVN* phase) {
122 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
123 }
124
125 //=============================================================================
126 //------------------------------Value------------------------------------------
127 const Type* ConvD2LNode::Value(PhaseGVN* phase) const {
128 const Type *t = phase->type( in(1) );
129 if( t == Type::TOP ) return Type::TOP;
130 if( t == Type::DOUBLE ) return TypeLong::LONG;
131 const TypeD *td = t->is_double_constant();
132 return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
133 }
134
135 //------------------------------Identity---------------------------------------
136 Node* ConvD2LNode::Identity(PhaseGVN* phase) {
137 // Remove ConvD2L->ConvL2D->ConvD2L sequences.
138 if( in(1) ->Opcode() == Op_ConvL2D &&
139 in(1)->in(1)->Opcode() == Op_ConvD2L )
140 return in(1)->in(1);
141 return this;
142 }
143
144 //------------------------------Ideal------------------------------------------
145 // If converting to an int type, skip any rounding nodes
146 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
147 if (in(1)->Opcode() == Op_RoundDouble) {
148 set_req(1, in(1)->in(1));
149 return this;
150 }
151 return NULL;
152 }
153
154 //=============================================================================
155 //------------------------------Value------------------------------------------
156 const Type* ConvF2DNode::Value(PhaseGVN* phase) const {
157 const Type *t = phase->type( in(1) );
158 if( t == Type::TOP ) return Type::TOP;
159 if( t == Type::FLOAT ) return Type::DOUBLE;
160 const TypeF *tf = t->is_float_constant();
161 return TypeD::make( (double)tf->getf() );
162 }
163
164 //=============================================================================
165 //------------------------------Value------------------------------------------
166 const Type* ConvF2INode::Value(PhaseGVN* phase) const {
167 const Type *t = phase->type( in(1) );
168 if( t == Type::TOP ) return Type::TOP;
169 if( t == Type::FLOAT ) return TypeInt::INT;
170 const TypeF *tf = t->is_float_constant();
171 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
172 }
173
174 //------------------------------Identity---------------------------------------
175 Node* ConvF2INode::Identity(PhaseGVN* phase) {
176 // Remove ConvF2I->ConvI2F->ConvF2I sequences.
177 if( in(1) ->Opcode() == Op_ConvI2F &&
178 in(1)->in(1)->Opcode() == Op_ConvF2I )
179 return in(1)->in(1);
180 return this;
181 }
182
183 //------------------------------Ideal------------------------------------------
184 // If converting to an int type, skip any rounding nodes
185 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
186 if (in(1)->Opcode() == Op_RoundFloat) {
187 set_req(1, in(1)->in(1));
188 return this;
189 }
190 return NULL;
191 }
192
193 //=============================================================================
194 //------------------------------Value------------------------------------------
195 const Type* ConvF2LNode::Value(PhaseGVN* phase) const {
196 const Type *t = phase->type( in(1) );
197 if( t == Type::TOP ) return Type::TOP;
198 if( t == Type::FLOAT ) return TypeLong::LONG;
199 const TypeF *tf = t->is_float_constant();
200 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
201 }
202
203 //------------------------------Identity---------------------------------------
204 Node* ConvF2LNode::Identity(PhaseGVN* phase) {
205 // Remove ConvF2L->ConvL2F->ConvF2L sequences.
206 if( in(1) ->Opcode() == Op_ConvL2F &&
207 in(1)->in(1)->Opcode() == Op_ConvF2L )
208 return in(1)->in(1);
209 return this;
210 }
211
212 //------------------------------Ideal------------------------------------------
213 // If converting to an int type, skip any rounding nodes
214 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
215 if (in(1)->Opcode() == Op_RoundFloat) {
216 set_req(1, in(1)->in(1));
217 return this;
218 }
219 return NULL;
220 }
221
222 //=============================================================================
223 //------------------------------Value------------------------------------------
224 const Type* ConvI2DNode::Value(PhaseGVN* phase) const {
225 const Type *t = phase->type( in(1) );
226 if( t == Type::TOP ) return Type::TOP;
227 const TypeInt *ti = t->is_int();
228 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
229 return bottom_type();
230 }
231
232 //=============================================================================
233 //------------------------------Value------------------------------------------
234 const Type* ConvI2FNode::Value(PhaseGVN* phase) const {
235 const Type *t = phase->type( in(1) );
236 if( t == Type::TOP ) return Type::TOP;
237 const TypeInt *ti = t->is_int();
238 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
239 return bottom_type();
240 }
241
242 //------------------------------Identity---------------------------------------
243 Node* ConvI2FNode::Identity(PhaseGVN* phase) {
244 // Remove ConvI2F->ConvF2I->ConvI2F sequences.
245 if( in(1) ->Opcode() == Op_ConvF2I &&
246 in(1)->in(1)->Opcode() == Op_ConvI2F )
247 return in(1)->in(1);
248 return this;
249 }
250
251 //=============================================================================
252 //------------------------------Value------------------------------------------
253 const Type* ConvI2LNode::Value(PhaseGVN* phase) const {
254 const Type *t = phase->type( in(1) );
255 if (t == Type::TOP) {
256 return Type::TOP;
257 }
258 const TypeInt *ti = t->is_int();
259 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
260 // Join my declared type against my incoming type.
261 tl = tl->filter(_type);
262 if (!tl->isa_long()) {
263 return tl;
264 }
265 const TypeLong* this_type = tl->is_long();
266 // Do NOT remove this node's type assertion until no more loop ops can happen.
267 if (phase->C->post_loop_opts_phase()) {
268 const TypeInt* in_type = phase->type(in(1))->isa_int();
269 if (in_type != NULL &&
270 (in_type->_lo != this_type->_lo ||
271 in_type->_hi != this_type->_hi)) {
272 // Although this WORSENS the type, it increases GVN opportunities,
273 // because I2L nodes with the same input will common up, regardless
274 // of slightly differing type assertions. Such slight differences
275 // arise routinely as a result of loop unrolling, so this is a
276 // post-unrolling graph cleanup. Choose a type which depends only
277 // on my input. (Exception: Keep a range assertion of >=0 or <0.)
278 jlong lo1 = this_type->_lo;
279 jlong hi1 = this_type->_hi;
280 int w1 = this_type->_widen;
281 if (lo1 >= 0) {
282 // Keep a range assertion of >=0.
283 lo1 = 0; hi1 = max_jint;
284 } else if (hi1 < 0) {
285 // Keep a range assertion of <0.
286 lo1 = min_jint; hi1 = -1;
287 } else {
288 lo1 = min_jint; hi1 = max_jint;
289 }
290 return TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
291 MIN2((jlong)in_type->_hi, hi1),
292 MAX2((int)in_type->_widen, w1));
293 }
294 }
295 return this_type;
296 }
297
298 static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
299 jlong lo2, jlong hi2) {
300 // Two ranges overlap iff one range's low point falls in the other range.
301 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
302 }
303
304 #ifdef _LP64
305 // If there is an existing ConvI2L node with the given parent and type, return
306 // it. Otherwise, create and return a new one. Both reusing existing ConvI2L
307 // nodes and postponing the idealization of new ones are needed to avoid an
308 // explosion of recursive Ideal() calls when compiling long AddI chains.
309 static Node* find_or_make_convI2L(PhaseIterGVN* igvn, Node* parent,
310 const TypeLong* type) {
311 Node* n = new ConvI2LNode(parent, type);
312 Node* existing = igvn->hash_find_insert(n);
313 if (existing != NULL) {
314 n->destruct(igvn);
315 return existing;
316 }
317 return igvn->register_new_node_with_optimizer(n);
318 }
319 #endif
320
321 bool Compile::push_thru_add(PhaseGVN* phase, Node* z, const TypeInteger* tz, const TypeInteger*& rx, const TypeInteger*& ry,
322 BasicType bt) {
323 int op = z->Opcode();
324 if (op == Op_AddI || op == Op_SubI) {
325 Node* x = z->in(1);
326 Node* y = z->in(2);
327 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
328 if (phase->type(x) == Type::TOP) {
329 return false;
330 }
331 if (phase->type(y) == Type::TOP) {
332 return false;
333 }
334 const TypeInt* tx = phase->type(x)->is_int();
335 const TypeInt* ty = phase->type(y)->is_int();
336
337 jlong xlo = tx->is_int()->_lo;
338 jlong xhi = tx->is_int()->_hi;
339 jlong ylo = ty->is_int()->_lo;
340 jlong yhi = ty->is_int()->_hi;
341 jlong zlo = tz->lo_as_long();
342 jlong zhi = tz->hi_as_long();
343 jlong vbit = CONST64(1) << BitsPerInt;
344 int widen = MAX2(tx->_widen, ty->_widen);
345 if (op == Op_SubI) {
346 jlong ylo0 = ylo;
347 ylo = -yhi;
348 yhi = -ylo0;
349 }
350 // See if x+y can cause positive overflow into z+2**32
351 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
352 return false;
353 }
354 // See if x+y can cause negative overflow into z-2**32
355 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
356 return false;
357 }
358 // Now it's always safe to assume x+y does not overflow.
359 // This is true even if some pairs x,y might cause overflow, as long
360 // as that overflow value cannot fall into [zlo,zhi].
361
362 // Confident that the arithmetic is "as if infinite precision",
363 // we can now use z's range to put constraints on those of x and y.
364 // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
365 // more "restricted" range by intersecting [xlo,xhi] with the
366 // range obtained by subtracting y's range from the asserted range
367 // of the I2L conversion. Here's the interval arithmetic algebra:
368 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
369 // => x in [zlo-yhi, zhi-ylo]
370 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
371 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
372 jlong rxlo = MAX2(xlo, zlo - yhi);
373 jlong rxhi = MIN2(xhi, zhi - ylo);
374 // And similarly, x changing place with y:
375 jlong rylo = MAX2(ylo, zlo - xhi);
376 jlong ryhi = MIN2(yhi, zhi - xlo);
377 if (rxlo > rxhi || rylo > ryhi) {
378 return false; // x or y is dying; don't mess w/ it
379 }
380 if (op == Op_SubI) {
381 jlong rylo0 = rylo;
382 rylo = -ryhi;
383 ryhi = -rylo0;
384 }
385 assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");
386 assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");
387 rx = TypeInteger::make(rxlo, rxhi, widen, bt);
388 ry = TypeInteger::make(rylo, ryhi, widen, bt);
389 return true;
390 }
391 return false;
392 }
393
394
395 //------------------------------Ideal------------------------------------------
396 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
397 const TypeLong* this_type = this->type()->is_long();
398 if (can_reshape && !phase->C->post_loop_opts_phase()) {
399 // makes sure we run ::Value to potentially remove type assertion after loop opts
400 phase->C->record_for_post_loop_opts_igvn(this);
401 }
402 #ifdef _LP64
403 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y))
404 // but only if x and y have subranges that cannot cause 32-bit overflow,
405 // under the assumption that x+y is in my own subrange this->type().
406
407 // This assumption is based on a constraint (i.e., type assertion)
408 // established in Parse::array_addressing or perhaps elsewhere.
409 // This constraint has been adjoined to the "natural" type of
410 // the incoming argument in(0). We know (because of runtime
411 // checks) - that the result value I2L(x+y) is in the joined range.
412 // Hence we can restrict the incoming terms (x, y) to values such
413 // that their sum also lands in that range.
414
415 // This optimization is useful only on 64-bit systems, where we hope
416 // the addition will end up subsumed in an addressing mode.
417 // It is necessary to do this when optimizing an unrolled array
418 // copy loop such as x[i++] = y[i++].
419
420 // On 32-bit systems, it's better to perform as much 32-bit math as
421 // possible before the I2L conversion, because 32-bit math is cheaper.
422 // There's no common reason to "leak" a constant offset through the I2L.
423 // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
424 PhaseIterGVN* igvn = phase->is_IterGVN();
425 Node* z = in(1);
426 const TypeInteger* rx = NULL;
427 const TypeInteger* ry = NULL;
428 if (Compile::push_thru_add(phase, z, this_type, rx, ry, T_LONG)) {
429 if (igvn == NULL) {
430 // Postpone this optimization to iterative GVN, where we can handle deep
431 // AddI chains without an exponential number of recursive Ideal() calls.
432 phase->record_for_igvn(this);
433 return NULL;
434 }
435 int op = z->Opcode();
436 Node* x = z->in(1);
437 Node* y = z->in(2);
438
439 Node* cx = find_or_make_convI2L(igvn, x, rx->is_long());
440 Node* cy = find_or_make_convI2L(igvn, y, ry->is_long());
441 switch (op) {
442 case Op_AddI: return new AddLNode(cx, cy);
443 case Op_SubI: return new SubLNode(cx, cy);
444 default: ShouldNotReachHere();
445 }
446 }
447 #endif //_LP64
448
449 return NULL;
450 }
451
452 //=============================================================================
453 //------------------------------Value------------------------------------------
454 const Type* ConvL2DNode::Value(PhaseGVN* phase) const {
455 const Type *t = phase->type( in(1) );
456 if( t == Type::TOP ) return Type::TOP;
457 const TypeLong *tl = t->is_long();
458 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
459 return bottom_type();
460 }
461
462 //=============================================================================
463 //------------------------------Value------------------------------------------
464 const Type* ConvL2FNode::Value(PhaseGVN* phase) const {
465 const Type *t = phase->type( in(1) );
466 if( t == Type::TOP ) return Type::TOP;
467 const TypeLong *tl = t->is_long();
468 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
469 return bottom_type();
470 }
471
472 //=============================================================================
473 //----------------------------Identity-----------------------------------------
474 Node* ConvL2INode::Identity(PhaseGVN* phase) {
475 // Convert L2I(I2L(x)) => x
476 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);
477 return this;
478 }
479
480 //------------------------------Value------------------------------------------
481 const Type* ConvL2INode::Value(PhaseGVN* phase) const {
482 const Type *t = phase->type( in(1) );
483 if( t == Type::TOP ) return Type::TOP;
484 const TypeLong *tl = t->is_long();
485 const TypeInt* ti = TypeInt::INT;
486 if (tl->is_con()) {
487 // Easy case.
488 ti = TypeInt::make((jint)tl->get_con());
489 } else if (tl->_lo >= min_jint && tl->_hi <= max_jint) {
490 ti = TypeInt::make((jint)tl->_lo, (jint)tl->_hi, tl->_widen);
491 }
492 return ti->filter(_type);
493 }
494
495 //------------------------------Ideal------------------------------------------
496 // Return a node which is more "ideal" than the current node.
497 // Blow off prior masking to int
498 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
499 Node *andl = in(1);
500 uint andl_op = andl->Opcode();
501 if( andl_op == Op_AndL ) {
502 // Blow off prior masking to int
503 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
504 set_req_X(1,andl->in(1), phase);
505 return this;
506 }
507 }
508
509 // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
510 // This replaces an 'AddL' with an 'AddI'.
511 if( andl_op == Op_AddL ) {
512 // Don't do this for nodes which have more than one user since
513 // we'll end up computing the long add anyway.
514 if (andl->outcnt() > 1) return NULL;
515
516 Node* x = andl->in(1);
517 Node* y = andl->in(2);
518 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
519 if (phase->type(x) == Type::TOP) return NULL;
520 if (phase->type(y) == Type::TOP) return NULL;
521 Node *add1 = phase->transform(new ConvL2INode(x));
522 Node *add2 = phase->transform(new ConvL2INode(y));
523 return new AddINode(add1,add2);
524 }
525
526 // Disable optimization: LoadL->ConvL2I ==> LoadI.
527 // It causes problems (sizes of Load and Store nodes do not match)
528 // in objects initialization code and Escape Analysis.
529 return NULL;
530 }
531
532
533
534 //=============================================================================
535 //------------------------------Identity---------------------------------------
536 // Remove redundant roundings
537 Node* RoundFloatNode::Identity(PhaseGVN* phase) {
538 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
539 // Do not round constants
540 if (phase->type(in(1))->base() == Type::FloatCon) return in(1);
541 int op = in(1)->Opcode();
542 // Redundant rounding
543 if( op == Op_RoundFloat ) return in(1);
544 // Already rounded
545 if( op == Op_Parm ) return in(1);
546 if( op == Op_LoadF ) return in(1);
547 return this;
548 }
549
550 //------------------------------Value------------------------------------------
551 const Type* RoundFloatNode::Value(PhaseGVN* phase) const {
552 return phase->type( in(1) );
553 }
554
555 //=============================================================================
556 //------------------------------Identity---------------------------------------
557 // Remove redundant roundings. Incoming arguments are already rounded.
558 Node* RoundDoubleNode::Identity(PhaseGVN* phase) {
559 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
560 // Do not round constants
561 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);
562 int op = in(1)->Opcode();
563 // Redundant rounding
564 if( op == Op_RoundDouble ) return in(1);
565 // Already rounded
566 if( op == Op_Parm ) return in(1);
567 if( op == Op_LoadD ) return in(1);
568 if( op == Op_ConvF2D ) return in(1);
569 if( op == Op_ConvI2D ) return in(1);
570 return this;
571 }
572
573 //------------------------------Value------------------------------------------
574 const Type* RoundDoubleNode::Value(PhaseGVN* phase) const {
575 return phase->type( in(1) );
576 }
577
578 //=============================================================================
579 RoundDoubleModeNode* RoundDoubleModeNode::make(PhaseGVN& gvn, Node* arg, RoundDoubleModeNode::RoundingMode rmode) {
580 ConINode* rm = gvn.intcon(rmode);
581 return new RoundDoubleModeNode(arg, (Node *)rm);
582 }
583
584 //------------------------------Identity---------------------------------------
585 // Remove redundant roundings.
586 Node* RoundDoubleModeNode::Identity(PhaseGVN* phase) {
587 int op = in(1)->Opcode();
588 // Redundant rounding e.g. floor(ceil(n)) -> ceil(n)
589 if(op == Op_RoundDoubleMode) return in(1);
590 return this;
591 }
592 const Type* RoundDoubleModeNode::Value(PhaseGVN* phase) const {
593 return Type::DOUBLE;
594 }
595 //=============================================================================
--- EOF ---