Revision: 8234
Author:   [email protected]
Date:     Thu Jun  9 04:42:22 2011
Log:      Merge r8230 from bleeding edge to 3.2 branch.

BUG=85177
Review URL: http://codereview.chromium.org/7129039
http://code.google.com/p/v8/source/detail?r=8234

Added:
 /branches/3.2/test/mjsunit/regress/regress-85177.js
Modified:
 /branches/3.2/src/hydrogen-instructions.cc
 /branches/3.2/src/hydrogen-instructions.h
 /branches/3.2/src/hydrogen.cc
 /branches/3.2/src/hydrogen.h
 /branches/3.2/src/version.cc

=======================================
--- /dev/null
+++ /branches/3.2/test/mjsunit/regress/regress-85177.js Thu Jun 9 04:42:22 2011
@@ -0,0 +1,65 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax
+
+gW=gH=175;
+g=[];
+
+for(var n=0; n<gW; n++){
+ var l=[];
+ for(var p=0; p<gH; p++){
+   l.push(1)
+ }
+ g.push(l)
+}
+
+function k(a,b){
+ if(a<0||b<0||a>=gW||b>=gH)
+   return 0;
+ return g[a][b];
+}
+
+function f(){
+ for(var a=[],f=0; f<gW; f++){
+   var b=[];
+   for(var h=0; h<gH; h++){
+     var e=0;
+     for(var i=-1; i<=1; i++)
+       for(var j=-1; j<=1; j++)
+          e+=k(f+i,h+j);
+     e=k(f,h)==1?1:0;
+     b.push(e)
+   }
+   a.push(b)
+ }
+}
+
+f();
+%OptimizeFunctionOnNextCall(f);
+f();
+
=======================================
--- /branches/3.2/src/hydrogen-instructions.cc  Mon Apr 11 05:33:05 2011
+++ /branches/3.2/src/hydrogen-instructions.cc  Thu Jun  9 04:42:22 2011
@@ -1612,7 +1612,6 @@

 void HBoundsCheck::Verify() {
   HInstruction::Verify();
-  ASSERT(HasNoUses());
 }


=======================================
--- /branches/3.2/src/hydrogen-instructions.h   Wed Apr 13 01:46:07 2011
+++ /branches/3.2/src/hydrogen-instructions.h   Thu Jun  9 04:42:22 2011
@@ -2133,6 +2133,7 @@
  public:
   HBoundsCheck(HValue* index, HValue* length)
       : HBinaryOperation(index, length) {
+    set_representation(Representation::Integer32());
     SetFlag(kUseGVN);
   }

=======================================
--- /branches/3.2/src/hydrogen.cc       Wed May 18 05:48:35 2011
+++ /branches/3.2/src/hydrogen.cc       Thu Jun  9 04:42:22 2011
@@ -2247,9 +2247,31 @@
     HGlobalValueNumberer gvn(graph(), info());
     gvn.Analyze();
   }
+
+ // Replace the results of check instructions with the original value, if the + // result is used. This is safe now, since we don't do code motion after this + // point. It enables better register allocation since the value produced by
+  // check instructions is really a copy of the original value.
+  graph()->ReplaceCheckedValues();

   return graph();
 }
+
+
+void HGraph::ReplaceCheckedValues() {
+  HPhase phase("Replace checked values", this);
+  for (int i = 0; i < blocks()->length(); ++i) {
+    HInstruction* instr = blocks()->at(i)->first();
+    while (instr != NULL) {
+      if (instr->IsBoundsCheck()) {
+        // Replace all uses of the checked value with the original input.
+        ASSERT(instr->uses()->length() > 0);
+        instr->ReplaceValue(HBoundsCheck::cast(instr)->index());
+      }
+      instr = instr->next();
+    }
+  }
+}


 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) {
@@ -3580,16 +3602,17 @@
   bool is_array = (map->instance_type() == JS_ARRAY_TYPE);
   HLoadElements* elements = new(zone()) HLoadElements(object);
   HInstruction* length = NULL;
+  HInstruction* checked_key = NULL;
   if (is_array) {
     length = AddInstruction(new(zone()) HJSArrayLength(object));
-    AddInstruction(new(zone()) HBoundsCheck(key, length));
+    checked_key = AddInstruction(new(zone()) HBoundsCheck(key, length));
     AddInstruction(elements);
   } else {
     AddInstruction(elements);
     length = AddInstruction(new(zone()) HFixedArrayLength(elements));
-    AddInstruction(new(zone()) HBoundsCheck(key, length));
-  }
-  return new(zone()) HLoadKeyedFastElement(elements, key);
+    checked_key = AddInstruction(new(zone()) HBoundsCheck(key, length));
+  }
+  return new(zone()) HLoadKeyedFastElement(elements, checked_key);
 }


@@ -3607,13 +3630,14 @@
   AddInstruction(elements);
   HInstruction* length = new(zone()) HExternalArrayLength(elements);
   AddInstruction(length);
-  AddInstruction(new(zone()) HBoundsCheck(key, length));
+  HInstruction* checked_key =
+      AddInstruction(new(zone()) HBoundsCheck(key, length));
   HLoadExternalArrayPointer* external_elements =
       new(zone()) HLoadExternalArrayPointer(elements);
   AddInstruction(external_elements);
   HLoadKeyedSpecializedArrayElement* pixel_array_value =
       new(zone()) HLoadKeyedSpecializedArrayElement(
-          external_elements, key, expr->external_array_type());
+          external_elements, checked_key, expr->external_array_type());
   return pixel_array_value;
 }

@@ -3669,8 +3693,9 @@
   } else {
     length = AddInstruction(new(zone()) HFixedArrayLength(elements));
   }
-  AddInstruction(new(zone()) HBoundsCheck(key, length));
-  return new(zone()) HStoreKeyedFastElement(elements, key, val);
+  HInstruction* checked_key =
+      AddInstruction(new(zone()) HBoundsCheck(key, length));
+  return new(zone()) HStoreKeyedFastElement(elements, checked_key, val);
 }


@@ -3689,13 +3714,14 @@
   AddInstruction(elements);
   HInstruction* length = AddInstruction(
       new(zone()) HExternalArrayLength(elements));
-  AddInstruction(new(zone()) HBoundsCheck(key, length));
+  HInstruction* checked_key =
+      AddInstruction(new(zone()) HBoundsCheck(key, length));
   HLoadExternalArrayPointer* external_elements =
       new(zone()) HLoadExternalArrayPointer(elements);
   AddInstruction(external_elements);
   return new(zone()) HStoreKeyedSpecializedArrayElement(
       external_elements,
-      key,
+      checked_key,
       val,
       expr->external_array_type());
 }
@@ -3746,8 +3772,9 @@
HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements);
     HInstruction* length = AddInstruction(
         new(zone()) HArgumentsLength(elements));
-    AddInstruction(new(zone()) HBoundsCheck(key, length));
-    result = new(zone()) HAccessArgumentsAt(elements, length, key);
+    HInstruction* checked_key =
+        AddInstruction(new(zone()) HBoundsCheck(key, length));
+    result = new(zone()) HAccessArgumentsAt(elements, length, checked_key);
   }
   ast_context()->ReturnInstruction(result, expr->id());
   return true;
@@ -4778,8 +4805,9 @@
       string, FIRST_STRING_TYPE, LAST_STRING_TYPE));
   HStringLength* length = new(zone()) HStringLength(string);
   AddInstruction(length);
-  AddInstruction(new(zone()) HBoundsCheck(index, length));
-  return new(zone()) HStringCharCodeAt(string, index);
+  HInstruction* checked_index =
+      AddInstruction(new(zone()) HBoundsCheck(index, length));
+  return new(zone()) HStringCharCodeAt(string, checked_index);
 }


=======================================
--- /branches/3.2/src/hydrogen.h        Mon Apr 11 05:33:05 2011
+++ /branches/3.2/src/hydrogen.h        Thu Jun  9 04:42:22 2011
@@ -221,6 +221,7 @@
   void Canonicalize();
   void OrderBlocks();
   void AssignDominators();
+  void ReplaceCheckedValues();

   // Returns false if there are phi-uses of the arguments-object
   // which are not supported by the optimizing compiler.
=======================================
--- /branches/3.2/src/version.cc        Tue Jun  7 05:08:41 2011
+++ /branches/3.2/src/version.cc        Thu Jun  9 04:42:22 2011
@@ -35,7 +35,7 @@
 #define MAJOR_VERSION     3
 #define MINOR_VERSION     2
 #define BUILD_NUMBER      10
-#define PATCH_LEVEL       16
+#define PATCH_LEVEL       17
 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
 #define IS_CANDIDATE_VERSION 0

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to