Title: [200992] trunk/Source/_javascript_Core
Revision
200992
Author
[email protected]
Date
2016-05-16 20:36:45 -0700 (Mon, 16 May 2016)

Log Message

[JSC] "return this" in a constructor does not need a branch on isObject(this)
https://bugs.webkit.org/show_bug.cgi?id=157775

Patch by Benjamin Poulain <[email protected]> on 2016-05-16
Reviewed by Saam Barati and Ryosuke Niwa.

When returning "this" in a constructor, the bytecode generator was generating:
    is_object         locX, this
    jtrue             locX, 5(->second ret)
    ret               this
    ret               this

That code is eliminated in DFG but it is pretty costly lower tiers.

This patch changes bytecode generation to avoid the is_object test
when possible and not generate two ret if they encode the same thing.

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitReturn):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (200991 => 200992)


--- trunk/Source/_javascript_Core/ChangeLog	2016-05-17 03:31:12 UTC (rev 200991)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-05-17 03:36:45 UTC (rev 200992)
@@ -1,5 +1,26 @@
 2016-05-16  Benjamin Poulain  <[email protected]>
 
+        [JSC] "return this" in a constructor does not need a branch on isObject(this)
+        https://bugs.webkit.org/show_bug.cgi?id=157775
+
+        Reviewed by Saam Barati and Ryosuke Niwa.
+
+        When returning "this" in a constructor, the bytecode generator was generating:
+            is_object         locX, this
+            jtrue             locX, 5(->second ret)
+            ret               this
+            ret               this
+
+        That code is eliminated in DFG but it is pretty costly lower tiers.
+
+        This patch changes bytecode generation to avoid the is_object test
+        when possible and not generate two ret if they encode the same thing.
+
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::emitReturn):
+
+2016-05-16  Benjamin Poulain  <[email protected]>
+
         [JSC] Remove the index check from op_get_by_val/op_put_by_val when the index is constant
         https://bugs.webkit.org/show_bug.cgi?id=157766
 

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (200991 => 200992)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2016-05-17 03:31:12 UTC (rev 200991)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2016-05-17 03:36:45 UTC (rev 200992)
@@ -3219,24 +3219,26 @@
 {
     if (isConstructor()) {
         bool derived = constructorKind() == ConstructorKind::Derived;
-        if (derived && src->index() == m_thisRegister.index())
+        bool srcIsThis = src->index() == m_thisRegister.index();
+
+        if (derived && srcIsThis)
             emitTDZCheck(src);
 
-        RefPtr<Label> isObjectLabel = newLabel();
-        emitJumpIfTrue(emitIsObject(newTemporary(), src), isObjectLabel.get());
+        if (!srcIsThis) {
+            RefPtr<Label> isObjectLabel = newLabel();
+            emitJumpIfTrue(emitIsObject(newTemporary(), src), isObjectLabel.get());
 
-        if (derived) {
-            RefPtr<Label> isUndefinedLabel = newLabel();
-            emitJumpIfTrue(emitIsUndefined(newTemporary(), src), isUndefinedLabel.get());
-            emitThrowTypeError("Cannot return a non-object type in the constructor of a derived class.");
-            emitLabel(isUndefinedLabel.get());
-            if (constructorKind() == ConstructorKind::Derived)
+            if (derived) {
+                RefPtr<Label> isUndefinedLabel = newLabel();
+                emitJumpIfTrue(emitIsUndefined(newTemporary(), src), isUndefinedLabel.get());
+                emitThrowTypeError("Cannot return a non-object type in the constructor of a derived class.");
+                emitLabel(isUndefinedLabel.get());
                 emitTDZCheck(&m_thisRegister);
+            }
+
+            emitUnaryNoDstOp(op_ret, &m_thisRegister);
+            emitLabel(isObjectLabel.get());
         }
-
-        emitUnaryNoDstOp(op_ret, &m_thisRegister);
-
-        emitLabel(isObjectLabel.get());
     }
 
     return emitUnaryNoDstOp(op_ret, src);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to