1.1 --- a/src/share/vm/opto/loopTransform.cpp Wed Mar 30 07:47:19 2011 -0700 1.2 +++ b/src/share/vm/opto/loopTransform.cpp Wed Mar 30 12:08:49 2011 -0700 1.3 @@ -396,16 +396,16 @@ 1.4 // Return exact loop trip count, or 0 if not maximally unrolling 1.5 bool IdealLoopTree::policy_maximally_unroll( PhaseIdealLoop *phase ) const { 1.6 CountedLoopNode *cl = _head->as_CountedLoop(); 1.7 - assert( cl->is_normal_loop(), "" ); 1.8 + assert(cl->is_normal_loop(), ""); 1.9 1.10 Node *init_n = cl->init_trip(); 1.11 Node *limit_n = cl->limit(); 1.12 1.13 // Non-constant bounds 1.14 - if( init_n == NULL || !init_n->is_Con() || 1.15 + if (init_n == NULL || !init_n->is_Con() || 1.16 limit_n == NULL || !limit_n->is_Con() || 1.17 // protect against stride not being a constant 1.18 - !cl->stride_is_con() ) { 1.19 + !cl->stride_is_con()) { 1.20 return false; 1.21 } 1.22 int init = init_n->get_int(); 1.23 @@ -428,7 +428,25 @@ 1.24 uint unroll_limit = (uint)LoopUnrollLimit * 4; 1.25 assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits"); 1.26 cl->set_trip_count(trip_count); 1.27 - if( trip_count <= unroll_limit && body_size <= unroll_limit ) { 1.28 + if (trip_count > unroll_limit || body_size > unroll_limit) { 1.29 + return false; 1.30 + } 1.31 + 1.32 + // Do not unroll a loop with String intrinsics code. 1.33 + // String intrinsics are large and have loops. 1.34 + for (uint k = 0; k < _body.size(); k++) { 1.35 + Node* n = _body.at(k); 1.36 + switch (n->Opcode()) { 1.37 + case Op_StrComp: 1.38 + case Op_StrEquals: 1.39 + case Op_StrIndexOf: 1.40 + case Op_AryEq: { 1.41 + return false; 1.42 + } 1.43 + } // switch 1.44 + } 1.45 + 1.46 + if (body_size <= unroll_limit) { 1.47 uint new_body_size = body_size * trip_count; 1.48 if (new_body_size <= unroll_limit && 1.49 body_size == new_body_size / trip_count && 1.50 @@ -448,13 +466,13 @@ 1.51 bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const { 1.52 1.53 CountedLoopNode *cl = _head->as_CountedLoop(); 1.54 - assert( cl->is_normal_loop() || cl->is_main_loop(), "" ); 1.55 + assert(cl->is_normal_loop() || cl->is_main_loop(), ""); 1.56 1.57 // protect against stride not being a constant 1.58 - if( !cl->stride_is_con() ) return false; 1.59 + if (!cl->stride_is_con()) return false; 1.60 1.61 // protect against over-unrolling 1.62 - if( cl->trip_count() <= 1 ) return false; 1.63 + if (cl->trip_count() <= 1) return false; 1.64 1.65 int future_unroll_ct = cl->unrolled_count() * 2; 1.66 1.67 @@ -485,21 +503,21 @@ 1.68 // Non-constant bounds. 1.69 // Protect against over-unrolling when init or/and limit are not constant 1.70 // (so that trip_count's init value is maxint) but iv range is known. 1.71 - if( init_n == NULL || !init_n->is_Con() || 1.72 - limit_n == NULL || !limit_n->is_Con() ) { 1.73 + if (init_n == NULL || !init_n->is_Con() || 1.74 + limit_n == NULL || !limit_n->is_Con()) { 1.75 Node* phi = cl->phi(); 1.76 - if( phi != NULL ) { 1.77 + if (phi != NULL) { 1.78 assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi."); 1.79 const TypeInt* iv_type = phase->_igvn.type(phi)->is_int(); 1.80 int next_stride = cl->stride_con() * 2; // stride after this unroll 1.81 - if( next_stride > 0 ) { 1.82 - if( iv_type->_lo + next_stride <= iv_type->_lo || // overflow 1.83 - iv_type->_lo + next_stride > iv_type->_hi ) { 1.84 + if (next_stride > 0) { 1.85 + if (iv_type->_lo + next_stride <= iv_type->_lo || // overflow 1.86 + iv_type->_lo + next_stride > iv_type->_hi) { 1.87 return false; // over-unrolling 1.88 } 1.89 - } else if( next_stride < 0 ) { 1.90 - if( iv_type->_hi + next_stride >= iv_type->_hi || // overflow 1.91 - iv_type->_hi + next_stride < iv_type->_lo ) { 1.92 + } else if (next_stride < 0) { 1.93 + if (iv_type->_hi + next_stride >= iv_type->_hi || // overflow 1.94 + iv_type->_hi + next_stride < iv_type->_lo) { 1.95 return false; // over-unrolling 1.96 } 1.97 } 1.98 @@ -511,24 +529,33 @@ 1.99 // Key test to unroll CaffeineMark's Logic test 1.100 int xors_in_loop = 0; 1.101 // Also count ModL, DivL and MulL which expand mightly 1.102 - for( uint k = 0; k < _body.size(); k++ ) { 1.103 - switch( _body.at(k)->Opcode() ) { 1.104 - case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test 1.105 - case Op_ModL: body_size += 30; break; 1.106 - case Op_DivL: body_size += 30; break; 1.107 - case Op_MulL: body_size += 10; break; 1.108 - } 1.109 + for (uint k = 0; k < _body.size(); k++) { 1.110 + Node* n = _body.at(k); 1.111 + switch (n->Opcode()) { 1.112 + case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test 1.113 + case Op_ModL: body_size += 30; break; 1.114 + case Op_DivL: body_size += 30; break; 1.115 + case Op_MulL: body_size += 10; break; 1.116 + case Op_StrComp: 1.117 + case Op_StrEquals: 1.118 + case Op_StrIndexOf: 1.119 + case Op_AryEq: { 1.120 + // Do not unroll a loop with String intrinsics code. 1.121 + // String intrinsics are large and have loops. 1.122 + return false; 1.123 + } 1.124 + } // switch 1.125 } 1.126 1.127 // Check for being too big 1.128 - if( body_size > (uint)LoopUnrollLimit ) { 1.129 - if( xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true; 1.130 + if (body_size > (uint)LoopUnrollLimit) { 1.131 + if (xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true; 1.132 // Normal case: loop too big 1.133 return false; 1.134 } 1.135 1.136 // Check for stride being a small enough constant 1.137 - if( abs(cl->stride_con()) > (1<<3) ) return false; 1.138 + if (abs(cl->stride_con()) > (1<<3)) return false; 1.139 1.140 // Unroll once! (Each trip will soon do double iterations) 1.141 return true;