[DFG][FTL] Add vectorLengthHint for NewArray
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2018 07:58:22 +0000 (07:58 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2018 07:58:22 +0000 (07:58 +0000)
commitaf83599b27c0ec0b50c24e5771f4005f0dc81ba6
tree074a829cf92aca4e80e126a289d966d58ff45bce
parent2b832813e82abc416be834346cc5ce4413ab9700
[DFG][FTL] Add vectorLengthHint for NewArray
https://bugs.webkit.org/show_bug.cgi?id=183694

Reviewed by Saam Barati.

JSTests:

* stress/vector-length-hint-array-constructor.js: Added.
(shouldBe):
(test):
* stress/vector-length-hint-new-array.js: Added.
(shouldBe):
(test):

Source/JavaScriptCore:

While the following code is a common, it is not so efficient.

var array = [];
for (...) {
    ...
    array.push(...);
}

The array is always allocated with 0 vector length. And it is eventually grown.

We have ArrayAllocationProfile, and it tells us that the vector length hint for
the allocated arrays. This hint is already used for NewArrayBuffer. This patch
extends this support for NewArray DFG node.

This patch improves Kraken/stanford-crypto-aes 4%.

                              baseline                  patched

stanford-crypto-aes        64.069+-1.352             61.589+-1.274           might be 1.0403x faster

NewArray can be optimized.

                                               baseline                  patched

vector-length-hint-new-array               21.8157+-0.0882     ^     13.1764+-0.0942        ^ definitely 1.6557x faster
vector-length-hint-array-constructor       21.9076+-0.0987     ?     22.1168+-0.4814        ?

* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleConstantInternalFunction):
(JSC::DFG::ByteCodeParser::parseBlock):
* dfg/DFGNode.h:
(JSC::DFG::Node::hasVectorLengthHint):
(JSC::DFG::Node::vectorLengthHint):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileNewArray):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229743 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSTests/ChangeLog
JSTests/microbenchmarks/vector-length-hint-array-constructor.js [new file with mode: 0644]
JSTests/microbenchmarks/vector-length-hint-new-array.js [new file with mode: 0644]
JSTests/stress/vector-length-hint-array-constructor.js [new file with mode: 0644]
JSTests/stress/vector-length-hint-new-array.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Source/JavaScriptCore/dfg/DFGNode.h
Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp
Source/JavaScriptCore/dfg/DFGValidate.cpp
Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp