Bug 193869 - [BigInt] Support constant fold of BigInts on DFG
Summary: [BigInt] Support constant fold of BigInts on DFG
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Caio Lima
URL:
Keywords:
Depends on:
Blocks: 186173
  Show dependency treegraph
 
Reported: 2019-01-26 10:14 PST by Caio Lima
Modified: 2019-01-31 00:04 PST (History)
1 user (show)

See Also:


Attachments
WIP - Patch (16.90 KB, patch)
2019-01-26 10:33 PST, Caio Lima
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caio Lima 2019-01-26 10:14:01 PST
...
Comment 1 Caio Lima 2019-01-26 10:28:14 PST
What I have in mind to make it possible is to follow what we do with Strings right now. The idea is to use LazyJSValue, since we can only allocate heap objects after compilation is finished. In the case of LazyJaValues of BigInts, the plan is to record following information:

1. lhs and rhs operands;
2. Type of operation;

To have a robust implementation and fold constants properly, lhs and rhs should be LazyJSValues that also can be computed on further steps.
We need to change JSBigInt API to support arithmetic operations that can't fail due OOM.
Also, we need to guarantee when constant fold happens that we won't overflow BigInt::maxSize.
Comment 2 Caio Lima 2019-01-26 10:33:08 PST
Created attachment 360242 [details]
WIP - Patch

Here is a very simple version to illustrate what I have in mind now. I'm creating LazyBigIntValue to store required information to calculate BigInts properly. A LazyJSValue(NewBigInt) can have KnowValue or other LazyBigIntValue as operands. This enables us fold cascaded constants. The Folding is being done during Strengthreduction, following String rules as well.
Comment 3 Caio Lima 2019-01-28 05:27:03 PST
(In reply to Caio Lima from comment #1)
> What I have in mind to make it possible is to follow what we do with Strings
> right now. The idea is to use LazyJSValue, since we can only allocate heap
> objects after compilation is finished. In the case of LazyJaValues of
> BigInts, the plan is to record following information:
> 
> 1. lhs and rhs operands;
> 2. Type of operation;
> 
> To have a robust implementation and fold constants properly, lhs and rhs
> should be LazyJSValues that also can be computed on further steps.
> We need to change JSBigInt API to support arithmetic operations that can't
> fail due OOM.
> Also, we need to guarantee when constant fold happens that we won't overflow
> BigInt::maxSize.

I think we also can have a special case when BigInts are proven to be 64-bit.
Comment 4 Saam Barati 2019-01-31 00:04:22 PST
Sounds good to me