hotspot/src/share/vm/opto/loopTransform.cpp
changeset 8879 e6ae9a7aa72a
parent 8870 119881dc9d0b
child 8884 9e2b81253ef9
--- a/hotspot/src/share/vm/opto/loopTransform.cpp	Wed Mar 30 07:47:19 2011 -0700
+++ b/hotspot/src/share/vm/opto/loopTransform.cpp	Wed Mar 30 12:08:49 2011 -0700
@@ -396,16 +396,16 @@
 // Return exact loop trip count, or 0 if not maximally unrolling
 bool IdealLoopTree::policy_maximally_unroll( PhaseIdealLoop *phase ) const {
   CountedLoopNode *cl = _head->as_CountedLoop();
-  assert( cl->is_normal_loop(), "" );
+  assert(cl->is_normal_loop(), "");
 
   Node *init_n = cl->init_trip();
   Node *limit_n = cl->limit();
 
   // Non-constant bounds
-  if( init_n   == NULL || !init_n->is_Con()  ||
+  if (init_n   == NULL || !init_n->is_Con()  ||
       limit_n  == NULL || !limit_n->is_Con() ||
       // protect against stride not being a constant
-      !cl->stride_is_con() ) {
+      !cl->stride_is_con()) {
     return false;
   }
   int init   = init_n->get_int();
@@ -428,7 +428,25 @@
   uint unroll_limit = (uint)LoopUnrollLimit * 4;
   assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits");
   cl->set_trip_count(trip_count);
-  if( trip_count <= unroll_limit && body_size <= unroll_limit ) {
+  if (trip_count > unroll_limit || body_size > unroll_limit) {
+    return false;
+  }
+
+  // Do not unroll a loop with String intrinsics code.
+  // String intrinsics are large and have loops.
+  for (uint k = 0; k < _body.size(); k++) {
+    Node* n = _body.at(k);
+    switch (n->Opcode()) {
+      case Op_StrComp:
+      case Op_StrEquals:
+      case Op_StrIndexOf:
+      case Op_AryEq: {
+        return false;
+      }
+    } // switch
+  }
+
+  if (body_size <= unroll_limit) {
     uint new_body_size = body_size * trip_count;
     if (new_body_size <= unroll_limit &&
         body_size == new_body_size / trip_count &&
@@ -448,13 +466,13 @@
 bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const {
 
   CountedLoopNode *cl = _head->as_CountedLoop();
-  assert( cl->is_normal_loop() || cl->is_main_loop(), "" );
+  assert(cl->is_normal_loop() || cl->is_main_loop(), "");
 
   // protect against stride not being a constant
-  if( !cl->stride_is_con() ) return false;
+  if (!cl->stride_is_con()) return false;
 
   // protect against over-unrolling
-  if( cl->trip_count() <= 1 ) return false;
+  if (cl->trip_count() <= 1) return false;
 
   int future_unroll_ct = cl->unrolled_count() * 2;
 
@@ -485,21 +503,21 @@
   // Non-constant bounds.
   // Protect against over-unrolling when init or/and limit are not constant
   // (so that trip_count's init value is maxint) but iv range is known.
-  if( init_n   == NULL || !init_n->is_Con()  ||
-      limit_n  == NULL || !limit_n->is_Con() ) {
+  if (init_n   == NULL || !init_n->is_Con()  ||
+      limit_n  == NULL || !limit_n->is_Con()) {
     Node* phi = cl->phi();
-    if( phi != NULL ) {
+    if (phi != NULL) {
       assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi.");
       const TypeInt* iv_type = phase->_igvn.type(phi)->is_int();
       int next_stride = cl->stride_con() * 2; // stride after this unroll
-      if( next_stride > 0 ) {
-        if( iv_type->_lo + next_stride <= iv_type->_lo || // overflow
-            iv_type->_lo + next_stride >  iv_type->_hi ) {
+      if (next_stride > 0) {
+        if (iv_type->_lo + next_stride <= iv_type->_lo || // overflow
+            iv_type->_lo + next_stride >  iv_type->_hi) {
           return false;  // over-unrolling
         }
-      } else if( next_stride < 0 ) {
-        if( iv_type->_hi + next_stride >= iv_type->_hi || // overflow
-            iv_type->_hi + next_stride <  iv_type->_lo ) {
+      } else if (next_stride < 0) {
+        if (iv_type->_hi + next_stride >= iv_type->_hi || // overflow
+            iv_type->_hi + next_stride <  iv_type->_lo) {
           return false;  // over-unrolling
         }
       }
@@ -511,24 +529,33 @@
   // Key test to unroll CaffeineMark's Logic test
   int xors_in_loop = 0;
   // Also count ModL, DivL and MulL which expand mightly
-  for( uint k = 0; k < _body.size(); k++ ) {
-    switch( _body.at(k)->Opcode() ) {
-    case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test
-    case Op_ModL: body_size += 30; break;
-    case Op_DivL: body_size += 30; break;
-    case Op_MulL: body_size += 10; break;
-    }
+  for (uint k = 0; k < _body.size(); k++) {
+    Node* n = _body.at(k);
+    switch (n->Opcode()) {
+      case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test
+      case Op_ModL: body_size += 30; break;
+      case Op_DivL: body_size += 30; break;
+      case Op_MulL: body_size += 10; break;
+      case Op_StrComp:
+      case Op_StrEquals:
+      case Op_StrIndexOf:
+      case Op_AryEq: {
+        // Do not unroll a loop with String intrinsics code.
+        // String intrinsics are large and have loops.
+        return false;
+      }
+    } // switch
   }
 
   // Check for being too big
-  if( body_size > (uint)LoopUnrollLimit ) {
-    if( xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true;
+  if (body_size > (uint)LoopUnrollLimit) {
+    if (xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true;
     // Normal case: loop too big
     return false;
   }
 
   // Check for stride being a small enough constant
-  if( abs(cl->stride_con()) > (1<<3) ) return false;
+  if (abs(cl->stride_con()) > (1<<3)) return false;
 
   // Unroll once!  (Each trip will soon do double iterations)
   return true;