haikuwebkit/JSTests/stress/spread-non-varargs.js

36 lines
644 B
JavaScript
Raw Permalink Normal View History

[JSC] Use JSFixedArray directly when using call_varargs https://bugs.webkit.org/show_bug.cgi?id=171057 Reviewed by Saam Barati. JSTests: * stress/spread-capture-rest.js: Added. (shouldBe): (capture): (a): (b): * stress/spread-multi-layers.js: Added. (shouldBe): (a): (b): (c): (d): * stress/spread-non-varargs.js: Added. (shouldBe): (a): (b): Source/JavaScriptCore: Previously we always emit new_array_with_spread when calling call(...args). But this array is unnecessary if varargs operation can handle Spread directly. This patch implements a peep-hole optimization in the bytecode compiler layer to omit new_array_with_spread. This is very simple and effective because this peep-hole optimization is quite common when using (...args) style calls and this optimization works all the tiers. While we can implement the phase to omit this NewArrayWithSpread in argument elimination phase, it only works for FTL. While such an optimization can work with complex data flow, this peep-hole optimization can optimize a common case easily. For now, Spread and PhantomSpread can be directly drained by CallVarargs and LoadVarargs related operations. We modify DFG and FTL to handle this correctly. This shows six-speed improvement. spread.es6 89.4300+-2.0236 ^ 69.6015+-1.7278 ^ definitely 1.2849x faster spread-generator.es6 344.7879+-5.9147 ^ 331.2712+-6.8610 ^ definitely 1.0408x faster * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitCall): (JSC::BytecodeGenerator::emitConstruct): * dfg/DFGArgumentsEliminationPhase.cpp: * dfg/DFGPreciseLocalClobberize.h: (JSC::DFG::PreciseLocalClobberizeAdaptor::readTop): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs): (JSC::FTL::DFG::LowerDFGToB3::compileForwardVarargs): (JSC::FTL::DFG::LowerDFGToB3::compileForwardVarargsWithSpread): * interpreter/Interpreter.cpp: (JSC::sizeOfVarargs): (JSC::loadVarargs): * parser/Nodes.h: (JSC::ArrayNode::elements): * runtime/JSFixedArray.cpp: (JSC::JSFixedArray::copyToArguments): * runtime/JSFixedArray.h: Canonical link: https://commits.webkit.org/188124@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-25 05:09:10 +00:00
(function () {
"use strict";
function shouldBe(actual, expected)
{
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
noInline(shouldBe);
var flag = false;
function a(...args)
{
if (flag) {
OSRExit();
return args[0];
}
return b(...args);
}
function b(...args)
{
return Math.max(...args);
}
for (var i = 0; i < 1e6; ++i) {
flag = i > (1e6 - 100);
var ret = a(0, 1, 2, 3, 4);
if (!flag)
shouldBe(ret, 4);
else
shouldBe(ret, 0);
}
}());