880 // Dump special per-node info
881 #ifndef PRODUCT
882 void CountedLoopNode::dump_spec(outputStream *st) const {
883 LoopNode::dump_spec(st);
884 if (stride_is_con()) {
885 st->print("stride: %d ",stride_con());
886 }
887 if (is_pre_loop ()) st->print("pre of N%d" , _main_idx);
888 if (is_main_loop()) st->print("main of N%d", _idx);
889 if (is_post_loop()) st->print("post of N%d", _main_idx);
890 }
891 #endif
892
893 //=============================================================================
894 int CountedLoopEndNode::stride_con() const {
895 return stride()->bottom_type()->is_int()->get_con();
896 }
897
898 //=============================================================================
899 //------------------------------Value-----------------------------------------
900 const Type *LoopLimitNode::Value( PhaseTransform *phase ) const {
901 const Type* init_t = phase->type(in(Init));
902 const Type* limit_t = phase->type(in(Limit));
903 const Type* stride_t = phase->type(in(Stride));
904 // Either input is TOP ==> the result is TOP
905 if (init_t == Type::TOP) return Type::TOP;
906 if (limit_t == Type::TOP) return Type::TOP;
907 if (stride_t == Type::TOP) return Type::TOP;
908
909 int stride_con = stride_t->is_int()->get_con();
910 if (stride_con == 1)
911 return NULL; // Identity
912
913 if (init_t->is_int()->is_con() && limit_t->is_int()->is_con()) {
914 // Use jlongs to avoid integer overflow.
915 jlong init_con = init_t->is_int()->get_con();
916 jlong limit_con = limit_t->is_int()->get_con();
917 int stride_m = stride_con - (stride_con > 0 ? 1 : -1);
918 jlong trip_count = (limit_con - init_con + stride_m)/stride_con;
919 jlong final_con = init_con + stride_con*trip_count;
920 int final_int = (int)final_con;
994 // we can get situation when init > limit. Note, for the empty loop
995 // optimization zero trip guard is generated explicitly which leaves
996 // only RCE predicate where exact limit is used and the predicate
997 // will simply fail forcing recompilation.
998 Node* neg_stride = phase->longcon(-stride_con);
999 span = phase->transform(new AndLNode(bias, neg_stride));
1000 } else {
1001 Node *trip = phase->transform(new DivLNode(0, bias, stride));
1002 span = phase->transform(new MulLNode(trip, stride));
1003 }
1004 // Convert back to int
1005 Node *span_int = phase->transform(new ConvL2INode(span));
1006 return new AddINode(span_int, in(Init)); // exact limit
1007 }
1008
1009 return NULL; // No progress
1010 }
1011
1012 //------------------------------Identity---------------------------------------
1013 // If stride == 1 return limit node.
1014 Node *LoopLimitNode::Identity( PhaseTransform *phase ) {
1015 int stride_con = phase->type(in(Stride))->is_int()->get_con();
1016 if (stride_con == 1 || stride_con == -1)
1017 return in(Limit);
1018 return this;
1019 }
1020
1021 //=============================================================================
1022 //----------------------match_incr_with_optional_truncation--------------------
1023 // Match increment with optional truncation:
1024 // CHAR: (i+1)&0x7fff, BYTE: ((i+1)<<8)>>8, or SHORT: ((i+1)<<16)>>16
1025 // Return NULL for failure. Success returns the increment node.
1026 Node* CountedLoopNode::match_incr_with_optional_truncation(
1027 Node* expr, Node** trunc1, Node** trunc2, const TypeInt** trunc_type) {
1028 // Quick cutouts:
1029 if (expr == NULL || expr->req() != 3) return NULL;
1030
1031 Node *t1 = NULL;
1032 Node *t2 = NULL;
1033 const TypeInt* trunc_t = TypeInt::INT;
1034 Node* n1 = expr;
|
880 // Dump special per-node info
881 #ifndef PRODUCT
882 void CountedLoopNode::dump_spec(outputStream *st) const {
883 LoopNode::dump_spec(st);
884 if (stride_is_con()) {
885 st->print("stride: %d ",stride_con());
886 }
887 if (is_pre_loop ()) st->print("pre of N%d" , _main_idx);
888 if (is_main_loop()) st->print("main of N%d", _idx);
889 if (is_post_loop()) st->print("post of N%d", _main_idx);
890 }
891 #endif
892
893 //=============================================================================
894 int CountedLoopEndNode::stride_con() const {
895 return stride()->bottom_type()->is_int()->get_con();
896 }
897
898 //=============================================================================
899 //------------------------------Value-----------------------------------------
900 const Type* LoopLimitNode::Value(PhaseGVN* phase) const {
901 const Type* init_t = phase->type(in(Init));
902 const Type* limit_t = phase->type(in(Limit));
903 const Type* stride_t = phase->type(in(Stride));
904 // Either input is TOP ==> the result is TOP
905 if (init_t == Type::TOP) return Type::TOP;
906 if (limit_t == Type::TOP) return Type::TOP;
907 if (stride_t == Type::TOP) return Type::TOP;
908
909 int stride_con = stride_t->is_int()->get_con();
910 if (stride_con == 1)
911 return NULL; // Identity
912
913 if (init_t->is_int()->is_con() && limit_t->is_int()->is_con()) {
914 // Use jlongs to avoid integer overflow.
915 jlong init_con = init_t->is_int()->get_con();
916 jlong limit_con = limit_t->is_int()->get_con();
917 int stride_m = stride_con - (stride_con > 0 ? 1 : -1);
918 jlong trip_count = (limit_con - init_con + stride_m)/stride_con;
919 jlong final_con = init_con + stride_con*trip_count;
920 int final_int = (int)final_con;
994 // we can get situation when init > limit. Note, for the empty loop
995 // optimization zero trip guard is generated explicitly which leaves
996 // only RCE predicate where exact limit is used and the predicate
997 // will simply fail forcing recompilation.
998 Node* neg_stride = phase->longcon(-stride_con);
999 span = phase->transform(new AndLNode(bias, neg_stride));
1000 } else {
1001 Node *trip = phase->transform(new DivLNode(0, bias, stride));
1002 span = phase->transform(new MulLNode(trip, stride));
1003 }
1004 // Convert back to int
1005 Node *span_int = phase->transform(new ConvL2INode(span));
1006 return new AddINode(span_int, in(Init)); // exact limit
1007 }
1008
1009 return NULL; // No progress
1010 }
1011
1012 //------------------------------Identity---------------------------------------
1013 // If stride == 1 return limit node.
1014 Node* LoopLimitNode::Identity(PhaseGVN* phase) {
1015 int stride_con = phase->type(in(Stride))->is_int()->get_con();
1016 if (stride_con == 1 || stride_con == -1)
1017 return in(Limit);
1018 return this;
1019 }
1020
1021 //=============================================================================
1022 //----------------------match_incr_with_optional_truncation--------------------
1023 // Match increment with optional truncation:
1024 // CHAR: (i+1)&0x7fff, BYTE: ((i+1)<<8)>>8, or SHORT: ((i+1)<<16)>>16
1025 // Return NULL for failure. Success returns the increment node.
1026 Node* CountedLoopNode::match_incr_with_optional_truncation(
1027 Node* expr, Node** trunc1, Node** trunc2, const TypeInt** trunc_type) {
1028 // Quick cutouts:
1029 if (expr == NULL || expr->req() != 3) return NULL;
1030
1031 Node *t1 = NULL;
1032 Node *t2 = NULL;
1033 const TypeInt* trunc_t = TypeInt::INT;
1034 Node* n1 = expr;
|