Closed Bug 1655465 Opened 5 years ago Closed 5 years ago

Optimise String.prototype.replace and String.prototype.split in CacheIR and Warp

Categories

(Core :: JavaScript Engine: JIT, task, P1)

task

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox80 --- wontfix
firefox81 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(9 files, 2 obsolete files)

47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review

Support StringReplaceString, StringSplitString, and ObjectHasPrototype in CacheIR and Warp. Plus transpile any remaining CacheIR ops used within String.prototype.replace and String.prototype.split (i.e. LoadValueTag and GuardTagNotEqual).

To ensure the generated code looks sensible (*), also apply additional optimisations to MCompare and replace the GetBuiltinPrototype() and GetBuiltinConstructor() intrinsics with a new JSOp.


(*) The generated code will look almost sensible, except that it's still cluttered with MBail instructions in unreachable code. This is probably caused by https://searchfox.org/mozilla-central/rev/cf561cece0ca9aeaf0202e68699836d957d0c670/js/src/jit/WarpBuilder.cpp#3094-3095.

LoadValueTag is used when comparing strictly different types. This happens in
the string built-ins when the this-value is a primitive string and it is
compared against null or undefined.

Value tags are represented as MIRType::Int32 and folding is supported to be
able to optimise away the checks after inlining.

Swapping bi's operands should depend on bi itself being commutative.

Drive-by change: Use std::swap to swap the operands.

Depends on D84976

This is part two to support comparing strictly different types in Warp.

The operation doesn't have any result, so when folding it, MNop is used to
optimise it away when the value tags are already different at compile time.

Depends on D84978

The next part will add a different tryFoldTypeOf() method, so rename the
existing one to avoid any confusion.

Drive-by change: Correct the access specifiers.

Depends on D84980

String built-ins use typeof thing === "string" to check for string values.
These were compiled to LTypeOfV followed by a string comparison. Using
MLoadValueTag from part 1 can make this more efficient.

Depends on D84982

Inling ObjectHasPrototype() using the GuardProto CacheIR op for the normal
case when the prototype chain wasn't modified.

Also change intrinsic_ObjectHasPrototype() to expect that both objects are
NativeObject, because then we don't need to handle proxies in CacheIR.

Drive-by change:

  • Use staticPrototype() in ObjectOperations-inl.h instead of effectively inlining it.

Depends on D84983

Drive-by change:

  • Remove a bogus resumeAfter(), MStringReplace is never effectful.

Depends on D84984

Warp can't currently fold away MToString, as a workaround handle the already
string case in WarpBuilder.

Depends on D84987

Drive-by change:

  • Make intrinsic_StringSplitString a static function.

Depends on D84988

Callers to GetBuiltinPrototype() rely on inlining the function itself plus
optimising the object access, so that the property value is directly seen as a
constant in the compiler. By changing GetBuiltinPrototype() and
GetBuiltinConstructor() to be directly translated into a JSOp, we can avoid
heavily relying on the compiler to optimise these two functions.

The new opcode replaces the existing JSOp::FunctionProto opcode. It doesn't
use JSProtoKey directly in order to help jsparagus (bug 1622530), but instead
uses its own set of mapping from enum values to built-in prototypes and
constructors.

This change also resolves bug 1377264.

Depends on D84989

That GetBuiltinPrototype change is great! I ran into that a few weeks ago when optimizing the RegExp intrinsics, and the old code was surprising.

Severity: -- → N/A
Priority: -- → P1
Pushed by dluca@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8fe934b1ec0a Part 1: Transpile LoadValueTag in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/b395e15e6453 Part 2: Test node is commutative before swapping the operands. r=jandem https://hg.mozilla.org/integration/autoland/rev/bad8617d0562 Part 3: Use BytecodeUtil.h helpers to test for equality operations. r=jandem https://hg.mozilla.org/integration/autoland/rev/1b65fe996077 Part 4: Transpile GuardTagNotEqual in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/7e65234359d8 Part 5: Rename `tryFoldTypeOf` to `tryFoldConstantTypeOf`. r=jandem https://hg.mozilla.org/integration/autoland/rev/d8a3835a65e7 Part 6: Fold MCompare with typeof to check the value tag. r=jandem https://hg.mozilla.org/integration/autoland/rev/453eb1a0a816 Part 7: Support ObjectHasPrototype in CacheIR. r=jandem https://hg.mozilla.org/integration/autoland/rev/cecabf647d61 Part 8: Support StringReplaceString in CacheIR and Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/6f5eafbf3525 Part 9: Avoid MToString on string-typed inputs in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/b57c53d012b4 Part 10: Support StringSplitString in CacheIR and Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/c47720118613 Part 11: Change JSOp::FunctionProto to JSOp::BuiltinObject. r=jandem
Flags: needinfo?(andrebargull)
Pushed by abutkovits@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4dbe80f41370 Part 1: Transpile LoadValueTag in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/737e3a6415de Part 2: Test node is commutative before swapping the operands. r=jandem https://hg.mozilla.org/integration/autoland/rev/66ff72ea169b Part 3: Use BytecodeUtil.h helpers to test for equality operations. r=jandem https://hg.mozilla.org/integration/autoland/rev/bc2378fcaf0f Part 4: Transpile GuardTagNotEqual in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/367207c1cece Part 5: Rename `tryFoldTypeOf` to `tryFoldConstantTypeOf`. r=jandem https://hg.mozilla.org/integration/autoland/rev/7527a8726d9c Part 6: Fold MCompare with typeof to check the value tag. r=jandem https://hg.mozilla.org/integration/autoland/rev/1682c7ee28f9 Part 7: Support ObjectHasPrototype in CacheIR. r=jandem https://hg.mozilla.org/integration/autoland/rev/8b030b7d13ab Part 8: Support StringReplaceString in CacheIR and Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/5ead4048955f Part 9: Avoid MToString on string-typed inputs in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/a5491d62d560 Part 10: Support StringSplitString in CacheIR and Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/6567d54b63c8 Part 11: Change JSOp::FunctionProto to JSOp::BuiltinObject. r=jandem

Support for GuardTagNotEqual would be great to have. This is also used by (obj = GuardToArrayIterator(this)) === null in ArrayIteratorNext.

Attachment #9166272 - Attachment is obsolete: true
Attachment #9166273 - Attachment is obsolete: true
Attachment #9166274 - Attachment description: Bug 1655465 - Part 7: Support ObjectHasPrototype in CacheIR. r=jandem! → Bug 1655465 - Part 5: Support ObjectHasPrototype in CacheIR. r=jandem!
Attachment #9166275 - Attachment description: Bug 1655465 - Part 8: Support StringReplaceString in CacheIR and Warp. r=jandem! → Bug 1655465 - Part 6: Support StringReplaceString in CacheIR and Warp. r=jandem!
Attachment #9166276 - Attachment description: Bug 1655465 - Part 9: Avoid MToString on string-typed inputs in Warp. r=jandem! → Bug 1655465 - Part 7: Avoid MToString on string-typed inputs in Warp. r=jandem!
Attachment #9166277 - Attachment description: Bug 1655465 - Part 10: Support StringSplitString in CacheIR and Warp. r=jandem! → Bug 1655465 - Part 8: Support StringSplitString in CacheIR and Warp. r=jandem!
Attachment #9166279 - Attachment description: Bug 1655465 - Part 11: Change JSOp::FunctionProto to JSOp::BuiltinObject. r=jandem! → Bug 1655465 - Part 9: Change JSOp::FunctionProto to JSOp::BuiltinObject. r=jandem!
Flags: needinfo?(andrebargull)
Pushed by btara@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b1062d8261fc Part 1: Transpile LoadValueTag in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/1dc74f4f2413 Part 2: Test node is commutative before swapping the operands. r=jandem https://hg.mozilla.org/integration/autoland/rev/c0d82360f73b Part 3: Use BytecodeUtil.h helpers to test for equality operations. r=jandem https://hg.mozilla.org/integration/autoland/rev/35399bebf4b6 Part 4: Transpile GuardTagNotEqual in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/5b74237b6a7e Part 5: Support ObjectHasPrototype in CacheIR. r=jandem https://hg.mozilla.org/integration/autoland/rev/2867f1a4afcb Part 6: Support StringReplaceString in CacheIR and Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/b958b136e2a8 Part 7: Avoid MToString on string-typed inputs in Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/02cbce29b638 Part 8: Support StringSplitString in CacheIR and Warp. r=jandem https://hg.mozilla.org/integration/autoland/rev/834447abbbf1 Part 9: Change JSOp::FunctionProto to JSOp::BuiltinObject. r=jandem
See Also: → 1828714
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: