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