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