Bug 825599 - Specialize type of switch's conditions. r=h4writer
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Thu, 03 Jan 2013 09:57:41 -0800
changeset 126803 e6e5fca3acb346d8982b0b53d19abb324a8ca1e4
parent 126802 9a315f39e03a9e92e8a39e3776ae1adf6bec8efd
child 126804 1c9ec9784927933897686f8f75e17f6567ad5c39
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersh4writer
bugs825599
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 825599 - Specialize type of switch's conditions. r=h4writer
js/src/ion/IonBuilder.cpp
js/src/ion/IonSpewer.cpp
js/src/jit-test/tests/ion/bug825599.js
--- a/js/src/ion/IonBuilder.cpp
+++ b/js/src/ion/IonBuilder.cpp
@@ -2371,16 +2371,18 @@ IonBuilder::processCondSwitchCase(CFGSta
         return ControlStatus_Error;
 
     // Terminate the last case condition block by emitting the code
     // corresponding to JSOP_CASE bytecode.
     if (bodyBlock != caseBlock) {
         MDefinition *caseOperand = current->pop();
         MDefinition *switchOperand = current->peek(-1);
         MCompare *cmpResult = MCompare::New(switchOperand, caseOperand, JSOP_STRICTEQ);
+        TypeOracle::BinaryTypes b = oracle->binaryTypes(script(), pc);
+        cmpResult->infer(b, cx);
         JS_ASSERT(!cmpResult->isEffectful());
         current->add(cmpResult);
         current->end(MTest::New(cmpResult, bodyBlock, caseBlock));
 
         // Add last case as predecessor of the body if the body is aliasing
         // the previous case body.
         if (!bodyIsNew && !bodyBlock->addPredecessorPopN(current, 1))
             return ControlStatus_Error;
--- a/js/src/ion/IonSpewer.cpp
+++ b/js/src/ion/IonSpewer.cpp
@@ -128,17 +128,17 @@ IonSpewer::isSpewingFunction() const
 
 void
 IonSpewer::beginFunction(MIRGraph *graph, HandleScript function)
 {
     if (!inited_)
         return;
 
     if (!FilterContainsLocation(function->filename, function->lineno)) {
-        JS_ASSERT(!this->function);
+        JS_ASSERT(!this->graph);
         // filter out logs during the compilation.
         filteredOutCompilations++;
         return;
     }
 
     this->graph = graph;
     this->function = function;
 
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/ion/bug825599.js
@@ -0,0 +1,27 @@
+var typedSwitch0 = function (a) {
+    switch (a) {
+        case null:
+        return 0;
+        case 1.1:
+        return 1;
+        case "2":
+        return 2;
+        case 3:
+        return 3;
+    }
+    return 4;
+};
+
+// reuse the same function for testing with different inputs & type.
+var typedSwitch1 = eval(typedSwitch0.toSource());
+var typedSwitch2 = eval(typedSwitch0.toSource());
+var typedSwitch3 = eval(typedSwitch0.toSource());
+var typedSwitch4 = eval(typedSwitch0.toSource());
+
+for (var i = 0; i < 100; i++) {
+    assertEq(typedSwitch0(null), 0);
+    assertEq(typedSwitch1(1.1), 1);
+    assertEq(typedSwitch2("2"), 2);
+    assertEq(typedSwitch3(3), 3);
+    assertEq(typedSwitch4(undefined), 4);
+}