Fix MathFloorOfDiv canonicalization ASSERT failures
authorjkummerow@chromium.org <jkummerow@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 14 Jun 2013 16:27:52 +0000 (16:27 +0000)
committerjkummerow@chromium.org <jkummerow@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 14 Jun 2013 16:27:52 +0000 (16:27 +0000)
- remove outdated ASSERT about instruction type
- add inserted HChanges to the graph

R=danno@chromium.org

Review URL: https://codereview.chromium.org/17094005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15166 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/hydrogen-instructions.cc

index 5ec663c..f69fbc9 100644 (file)
@@ -1510,9 +1510,7 @@ void HChange::PrintDataTo(StringStream* stream) {
 }
 
 
-static HValue* SimplifiedDividendForMathFloorOfDiv(
-    HValue* dividend,
-    Representation observed_representation) {
+static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* dividend) {
   // A value with an integer representation does not need to be transformed.
   if (dividend->representation().IsInteger32()) {
     return dividend;
@@ -1522,11 +1520,6 @@ static HValue* SimplifiedDividendForMathFloorOfDiv(
       HChange::cast(dividend)->from().IsInteger32()) {
     return HChange::cast(dividend)->value();
   }
-  // If we've only seen integers so far, insert an appropriate change.
-  if (observed_representation.IsSmiOrInteger32()) {
-    return new(dividend->block()->zone())
-        HChange(dividend, Representation::Integer32(), false, false);
-  }
   return NULL;
 }
 
@@ -1547,14 +1540,20 @@ HValue* HUnaryMathOperation::Canonicalize() {
       HValue* left = hdiv->left();
       HValue* right = hdiv->right();
       // Try to simplify left and right values of the division.
-      HValue* new_left = SimplifiedDividendForMathFloorOfDiv(
-          left, hdiv->observed_input_representation(1));
+      HValue* new_left = SimplifiedDividendForMathFloorOfDiv(left);
+      if (new_left == NULL &&
+          hdiv->observed_input_representation(1).IsSmiOrInteger32()) {
+        new_left = new(block()->zone())
+            HChange(left, Representation::Integer32(), false, false);
+        HChange::cast(new_left)->InsertBefore(this);
+      }
       HValue* new_right =
           LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
       if (new_right == NULL &&
           hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
         new_right = new(block()->zone())
             HChange(right, Representation::Integer32(), false, false);
+        HChange::cast(new_right)->InsertBefore(this);
       }
 
       // Return if left or right are not optimizable.
@@ -1576,13 +1575,9 @@ HValue* HUnaryMathOperation::Canonicalize() {
       ReplaceAllUsesWith(instr);
       Kill();
       // We know the division had no other uses than this HMathFloor. Delete it.
-      // Also delete the arguments of the division if they are not used any
-      // more.
+      // Dead code elimination will deal with |left| and |right| if
+      // appropriate.
       hdiv->DeleteAndReplaceWith(NULL);
-      ASSERT(left->IsChange() || left->IsConstant());
-      ASSERT(right->IsChange() || right->IsConstant());
-      if (left->HasNoUses())  left->DeleteAndReplaceWith(NULL);
-      if (right->HasNoUses())  right->DeleteAndReplaceWith(NULL);
 
       // Return NULL to remove this instruction from the graph.
       return NULL;