518 }
519 }
520 }
521 }
522 return res;
523 }
524
525 Node *CastIINode::Ideal_DU_postCCP(PhaseCCP *ccp) {
526 if (_carry_dependency) {
527 return NULL;
528 }
529 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
530 }
531
532 #ifndef PRODUCT
533 void CastIINode::dump_spec(outputStream *st) const {
534 TypeNode::dump_spec(st);
535 if (_carry_dependency) {
536 st->print(" carry dependency");
537 }
538 }
539 #endif
540
541 //=============================================================================
542
543 //------------------------------Ideal_DU_postCCP-------------------------------
544 // If not converting int->oop, throw away cast after constant propagation
545 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
546 const Type *t = ccp->type(in(1));
547 if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {
548 return NULL; // do not transform raw pointers or narrow oops
549 }
550 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
551 }
552
553
554
555 //=============================================================================
556 //------------------------------Identity---------------------------------------
557 // If input is already higher or equal to cast type, then this is an identity.
977 // Keep a range assertion of >=0.
978 lo1 = 0; hi1 = max_jint;
979 } else if (hi1 < 0) {
980 // Keep a range assertion of <0.
981 lo1 = min_jint; hi1 = -1;
982 } else {
983 lo1 = min_jint; hi1 = max_jint;
984 }
985 const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
986 MIN2((jlong)in_type->_hi, hi1),
987 MAX2((int)in_type->_widen, w1));
988 if (wtype != type()) {
989 set_type(wtype);
990 // Note: this_type still has old type value, for the logic below.
991 this_changed = this;
992 }
993 }
994 }
995
996 #ifdef _LP64
997 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
998 // but only if x and y have subranges that cannot cause 32-bit overflow,
999 // under the assumption that x+y is in my own subrange this->type().
1000
1001 // This assumption is based on a constraint (i.e., type assertion)
1002 // established in Parse::array_addressing or perhaps elsewhere.
1003 // This constraint has been adjoined to the "natural" type of
1004 // the incoming argument in(0). We know (because of runtime
1005 // checks) - that the result value I2L(x+y) is in the joined range.
1006 // Hence we can restrict the incoming terms (x, y) to values such
1007 // that their sum also lands in that range.
1008
1009 // This optimization is useful only on 64-bit systems, where we hope
1010 // the addition will end up subsumed in an addressing mode.
1011 // It is necessary to do this when optimizing an unrolled array
1012 // copy loop such as x[i++] = y[i++].
1013
1014 // On 32-bit systems, it's better to perform as much 32-bit math as
1015 // possible before the I2L conversion, because 32-bit math is cheaper.
1016 // There's no common reason to "leak" a constant offset through the I2L.
1017 // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
1018
1019 Node* z = in(1);
1020 int op = z->Opcode();
1021 if (op == Op_AddI || op == Op_SubI) {
1022 Node* x = z->in(1);
1023 Node* y = z->in(2);
1024 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
1025 if (phase->type(x) == Type::TOP) return this_changed;
1026 if (phase->type(y) == Type::TOP) return this_changed;
1027 const TypeInt* tx = phase->type(x)->is_int();
1028 const TypeInt* ty = phase->type(y)->is_int();
1029 const TypeLong* tz = this_type;
1030 jlong xlo = tx->_lo;
1031 jlong xhi = tx->_hi;
1032 jlong ylo = ty->_lo;
1033 jlong yhi = ty->_hi;
1034 jlong zlo = tz->_lo;
1035 jlong zhi = tz->_hi;
1036 jlong vbit = CONST64(1) << BitsPerInt;
1037 int widen = MAX2(tx->_widen, ty->_widen);
1038 if (op == Op_SubI) {
1039 jlong ylo0 = ylo;
1040 ylo = -yhi;
1058 // more "restricted" range by intersecting [xlo,xhi] with the
1059 // range obtained by subtracting y's range from the asserted range
1060 // of the I2L conversion. Here's the interval arithmetic algebra:
1061 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
1062 // => x in [zlo-yhi, zhi-ylo]
1063 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
1064 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
1065 jlong rxlo = MAX2(xlo, zlo - yhi);
1066 jlong rxhi = MIN2(xhi, zhi - ylo);
1067 // And similarly, x changing place with y:
1068 jlong rylo = MAX2(ylo, zlo - xhi);
1069 jlong ryhi = MIN2(yhi, zhi - xlo);
1070 if (rxlo > rxhi || rylo > ryhi) {
1071 return this_changed; // x or y is dying; don't mess w/ it
1072 }
1073 if (op == Op_SubI) {
1074 jlong rylo0 = rylo;
1075 rylo = -ryhi;
1076 ryhi = -rylo0;
1077 }
1078
1079 Node* cx = phase->transform( new (phase->C) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
1080 Node* cy = phase->transform( new (phase->C) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
1081 switch (op) {
1082 case Op_AddI: return new (phase->C) AddLNode(cx, cy);
1083 case Op_SubI: return new (phase->C) SubLNode(cx, cy);
1084 default: ShouldNotReachHere();
1085 }
1086 }
1087 #endif //_LP64
1088
1089 return this_changed;
1090 }
1091
1092 //=============================================================================
1093 //------------------------------Value------------------------------------------
1094 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
1095 const Type *t = phase->type( in(1) );
1096 if( t == Type::TOP ) return Type::TOP;
1097 const TypeLong *tl = t->is_long();
1098 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
1099 return bottom_type();
1100 }
|
518 }
519 }
520 }
521 }
522 return res;
523 }
524
525 Node *CastIINode::Ideal_DU_postCCP(PhaseCCP *ccp) {
526 if (_carry_dependency) {
527 return NULL;
528 }
529 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
530 }
531
532 #ifndef PRODUCT
533 void CastIINode::dump_spec(outputStream *st) const {
534 TypeNode::dump_spec(st);
535 if (_carry_dependency) {
536 st->print(" carry dependency");
537 }
538 if (_range_check_dependency) {
539 st->print(" range check dependency");
540 }
541 }
542 #endif
543
544 //=============================================================================
545
546 //------------------------------Ideal_DU_postCCP-------------------------------
547 // If not converting int->oop, throw away cast after constant propagation
548 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
549 const Type *t = ccp->type(in(1));
550 if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {
551 return NULL; // do not transform raw pointers or narrow oops
552 }
553 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
554 }
555
556
557
558 //=============================================================================
559 //------------------------------Identity---------------------------------------
560 // If input is already higher or equal to cast type, then this is an identity.
980 // Keep a range assertion of >=0.
981 lo1 = 0; hi1 = max_jint;
982 } else if (hi1 < 0) {
983 // Keep a range assertion of <0.
984 lo1 = min_jint; hi1 = -1;
985 } else {
986 lo1 = min_jint; hi1 = max_jint;
987 }
988 const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
989 MIN2((jlong)in_type->_hi, hi1),
990 MAX2((int)in_type->_widen, w1));
991 if (wtype != type()) {
992 set_type(wtype);
993 // Note: this_type still has old type value, for the logic below.
994 this_changed = this;
995 }
996 }
997 }
998
999 #ifdef _LP64
1000 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) or
1001 // ConvI2L(CastII(AddI(x, y))) to AddL(ConvI2L(CastII(x)), ConvI2L(CastII(y))),
1002 // but only if x and y have subranges that cannot cause 32-bit overflow,
1003 // under the assumption that x+y is in my own subrange this->type().
1004
1005 // This assumption is based on a constraint (i.e., type assertion)
1006 // established in Parse::array_addressing or perhaps elsewhere.
1007 // This constraint has been adjoined to the "natural" type of
1008 // the incoming argument in(0). We know (because of runtime
1009 // checks) - that the result value I2L(x+y) is in the joined range.
1010 // Hence we can restrict the incoming terms (x, y) to values such
1011 // that their sum also lands in that range.
1012
1013 // This optimization is useful only on 64-bit systems, where we hope
1014 // the addition will end up subsumed in an addressing mode.
1015 // It is necessary to do this when optimizing an unrolled array
1016 // copy loop such as x[i++] = y[i++].
1017
1018 // On 32-bit systems, it's better to perform as much 32-bit math as
1019 // possible before the I2L conversion, because 32-bit math is cheaper.
1020 // There's no common reason to "leak" a constant offset through the I2L.
1021 // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
1022
1023 Node* z = in(1);
1024 int op = z->Opcode();
1025 Node* ctrl = NULL;
1026 if (op == Op_CastII && z->as_CastII()->has_range_check()) {
1027 // Skip CastII node but save control dependency
1028 ctrl = z->in(0);
1029 z = z->in(1);
1030 op = z->Opcode();
1031 }
1032 if (op == Op_AddI || op == Op_SubI) {
1033 Node* x = z->in(1);
1034 Node* y = z->in(2);
1035 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
1036 if (phase->type(x) == Type::TOP) return this_changed;
1037 if (phase->type(y) == Type::TOP) return this_changed;
1038 const TypeInt* tx = phase->type(x)->is_int();
1039 const TypeInt* ty = phase->type(y)->is_int();
1040 const TypeLong* tz = this_type;
1041 jlong xlo = tx->_lo;
1042 jlong xhi = tx->_hi;
1043 jlong ylo = ty->_lo;
1044 jlong yhi = ty->_hi;
1045 jlong zlo = tz->_lo;
1046 jlong zhi = tz->_hi;
1047 jlong vbit = CONST64(1) << BitsPerInt;
1048 int widen = MAX2(tx->_widen, ty->_widen);
1049 if (op == Op_SubI) {
1050 jlong ylo0 = ylo;
1051 ylo = -yhi;
1069 // more "restricted" range by intersecting [xlo,xhi] with the
1070 // range obtained by subtracting y's range from the asserted range
1071 // of the I2L conversion. Here's the interval arithmetic algebra:
1072 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
1073 // => x in [zlo-yhi, zhi-ylo]
1074 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
1075 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
1076 jlong rxlo = MAX2(xlo, zlo - yhi);
1077 jlong rxhi = MIN2(xhi, zhi - ylo);
1078 // And similarly, x changing place with y:
1079 jlong rylo = MAX2(ylo, zlo - xhi);
1080 jlong ryhi = MIN2(yhi, zhi - xlo);
1081 if (rxlo > rxhi || rylo > ryhi) {
1082 return this_changed; // x or y is dying; don't mess w/ it
1083 }
1084 if (op == Op_SubI) {
1085 jlong rylo0 = rylo;
1086 rylo = -ryhi;
1087 ryhi = -rylo0;
1088 }
1089 assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");
1090 assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");
1091 Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), ctrl);
1092 Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), ctrl);
1093 switch (op) {
1094 case Op_AddI: return new (phase->C) AddLNode(cx, cy);
1095 case Op_SubI: return new (phase->C) SubLNode(cx, cy);
1096 default: ShouldNotReachHere();
1097 }
1098 }
1099 #endif //_LP64
1100
1101 return this_changed;
1102 }
1103
1104 //=============================================================================
1105 //------------------------------Value------------------------------------------
1106 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
1107 const Type *t = phase->type( in(1) );
1108 if( t == Type::TOP ) return Type::TOP;
1109 const TypeLong *tl = t->is_long();
1110 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
1111 return bottom_type();
1112 }
|