Bug 898576 - Ignore cold phi inputs when specializing phi types. (r=jandem)
authorShu-yu Guo <shu@rfrn.org>
Fri, 02 Aug 2013 08:24:56 -0700
changeset 141142 471dcc138dfee3eecf7e4ef9c0d4e78f9bb20218
parent 141141 d6d7900215918382ff6e0d59605142e93ebf148d
child 141143 9b4314a6c8ee391b24366bf40774d8d6295ddc0d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjandem
bugs898576
milestone25.0a1
Bug 898576 - Ignore cold phi inputs when specializing phi types. (r=jandem)
js/src/ion/IonAnalysis.cpp
--- a/js/src/ion/IonAnalysis.cpp
+++ b/js/src/ion/IonAnalysis.cpp
@@ -411,16 +411,20 @@ GuessPhiType(MPhi *phi)
                 continue;
             }
         }
         if (type == MIRType_None) {
             type = in->type();
             continue;
         }
         if (type != in->type()) {
+            // Ignore operands which we've never observed.
+            if (in->resultTypeSet() && in->resultTypeSet()->empty())
+                continue;
+
             // Specialize phis with int32 and double operands as double.
             if (IsNumberType(type) && IsNumberType(in->type()))
                 type = MIRType_Double;
             else
                 return MIRType_Value;
         }
     }
     return type;
@@ -515,25 +519,47 @@ TypeAnalyzer::adjustPhiInputs(MPhi *phi)
         // Convert int32 operands to double.
         for (size_t i = 0, e = phi->numOperands(); i < e; i++) {
             MDefinition *in = phi->getOperand(i);
 
             if (in->type() == MIRType_Int32) {
                 MToDouble *toDouble = MToDouble::New(in);
                 in->block()->insertBefore(in->block()->lastIns(), toDouble);
                 phi->replaceOperand(i, toDouble);
+            } else if (in->type() == MIRType_Value) {
+                MUnbox *unbox = MUnbox::New(in, MIRType_Double, MUnbox::Fallible);
+                in->block()->insertBefore(in->block()->lastIns(), unbox);
+                phi->replaceOperand(i, unbox);
             } else {
                 JS_ASSERT(in->type() == MIRType_Double);
             }
         }
         return;
     }
 
-    if (phiType != MIRType_Value)
+    // If we specialized a type that's not Value, either every input is of
+    // that type or the input's typeset was unobserved (i.e. the opcode hasn't
+    // been executed yet.) Be optimistic and insert unboxes.
+    if (phiType != MIRType_Value) {
+        for (size_t i = 0, e = phi->numOperands(); i < e; i++) {
+            MDefinition *in = phi->getOperand(i);
+            if (in->type() == phiType)
+                continue;
+
+            if (in->isBox() && in->toBox()->input()->type() == phiType) {
+                phi->replaceOperand(i, in->toBox()->input());
+            } else {
+                MUnbox *unbox = MUnbox::New(in, phiType, MUnbox::Fallible);
+                in->block()->insertBefore(in->block()->lastIns(), unbox);
+                phi->replaceOperand(i, unbox);
+            }
+        }
+
         return;
+    }
 
     // Box every typed input.
     for (size_t i = 0, e = phi->numOperands(); i < e; i++) {
         MDefinition *in = phi->getOperand(i);
         if (in->type() == MIRType_Value)
             continue;
 
         if (in->isUnbox() && phi->typeIncludes(in->toUnbox()->input())) {