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