Bug 192966 - DFGByteCodeParser rules for bitwise operations should consider type of their operands
Summary: DFGByteCodeParser rules for bitwise operations should consider type of their ...
Status: RESOLVED FIXED
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: InRadar
Depends on:
Blocks: 182216 192663 192664
  Show dependency treegraph
 
Reported: 2018-12-20 17:34 PST by Caio Lima
Modified: 2019-01-15 02:16 PST (History)
8 users (show)

See Also:


Attachments
Patch (9.04 KB, patch)
2018-12-20 19:20 PST, Caio Lima
no flags Details | Formatted Diff | Diff
Benchmarks (96.83 KB, text/plain)
2018-12-20 19:33 PST, Caio Lima
no flags Details
Patch (9.82 KB, patch)
2019-01-10 05:44 PST, Caio Lima
no flags Details | Formatted Diff | Diff
Benchmarks (95.03 KB, text/plain)
2019-01-10 05:48 PST, Caio Lima
no flags Details
Patch (11.51 KB, patch)
2019-01-14 18:34 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 2018-12-20 17:34:18 PST
Current implementation relies into `getPrediction()` to emit ArithBitOp or ValueBitOp. This rule is not efficient because there cases where we don't have profiling information and we sendup always emitting OSRExit or ValueBitOp.
Comment 1 Caio Lima 2018-12-20 19:20:08 PST
Created attachment 357918 [details]
Patch
Comment 2 Caio Lima 2018-12-20 19:33:09 PST
Created attachment 357919 [details]
Benchmarks

This patch seems perf neutral on x86_64
Comment 3 Yusuke Suzuki 2018-12-30 11:49:13 PST
Comment on attachment 357918 [details]
Patch

r=me
Comment 4 Caio Lima 2018-12-30 14:56:45 PST
(In reply to Yusuke Suzuki from comment #3)
> Comment on attachment 357918 [details]
> Patch
> 
> r=me

Thx for the review. I'm investigating a regression into zlib before landing.
Comment 5 Caio Lima 2018-12-31 07:22:07 PST
(In reply to Caio Lima from comment #4)
> (In reply to Yusuke Suzuki from comment #3)
> > Comment on attachment 357918 [details]
> > Patch
> > 
> > r=me
> 
> Thx for the review. I'm investigating a regression into zlib before landing.

We had a false alarm into zlib, but there is an odd case into Microbenchmark/slow-ternary. The problem is when we compile a function without executing some bitwise op. Since on ToT we emit ArithBitOp using ```getPrediction()```, generated code end up emitting ForceOSRExit when there is no profiling info. Because of this, we don't emit the rest of code followed by this block and the final version of the code is much simpler than the version we generated with this patch. Even though the ToT compiled code has an ForceOSRexit, the function runs almost all iterations before it fallback to Baseline JIT, and since the code is smaller, I think this makes ToT version run faster. 
I personally think that such regression comparing ToT and changes is acceptable, since our current rules emitting AirthBitOp and ValueBitOp are wrong, mainly because we don't benefit from prediction propagation on cases that profile is inexistent.

What do you think about this result? I'm going to wait for your comments before moving forward.
Comment 6 Caio Lima 2019-01-02 07:04:41 PST
(In reply to Caio Lima from comment #5)
> 
> We had a false alarm into zlib, but there is an odd case into
> Microbenchmark/slow-ternary. The problem is when we compile a function
> without executing some bitwise op. Since on ToT we emit ArithBitOp using
> ```getPrediction()```, generated code end up emitting ForceOSRExit when
> there is no profiling info. Because of this, we don't emit the rest of code
> followed by this block and the final version of the code is much simpler
> than the version we generated with this patch. Even though the ToT compiled
> code has an ForceOSRexit, the function runs almost all iterations before it
> fallback to Baseline JIT, and since the code is smaller, I think this makes
> ToT version run faster.

To illustrate better what I'm saying, here is the DFG code generated by ToT version (https://pastebin.com/3XEcYw7x) and here is DFG code generated with proposed changes (https://pastebin.com/MFRqGwvu). We can find the difference on Block #3 (line 110 and 118 in each file) where ToT version has ForceOSRExit, while changes version keeps generating code properly. ToT version removes Block #4-#9 while our changes version generates almost all of them.
Comment 7 Caio Lima 2019-01-07 09:32:49 PST
Ping discussion on comment #5
Comment 8 Caio Lima 2019-01-10 05:44:20 PST
Created attachment 358784 [details]
Patch
Comment 9 Caio Lima 2019-01-10 05:48:02 PST
Created attachment 358786 [details]
Benchmarks

According this report, these changes are perf neutral. The changes comparing to previous version is that we are using getHeapPrediction() to set prediction propagation of ValueBitOp.
Comment 10 Caio Lima 2019-01-14 02:51:44 PST
Ping Review
Comment 11 Yusuke Suzuki 2019-01-14 14:43:19 PST
Comment on attachment 358784 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=358784&action=review

r=me

> Source/JavaScriptCore/ChangeLog:11
> +        for ValueBitOp to use `getHeapPrediction()`. 

Can we have a test to ensure that JSC does not perform compile-fail loops?
Like the following code would pose the issue if something is wrong.

var object = { valueOf() { return integer; } };
// object with bit operation, which will produce Int32, but the operands of bit operation includes object.
Comment 12 Caio Lima 2019-01-14 18:34:05 PST
Comment on attachment 358784 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=358784&action=review

Thank you very much for the review!

>> Source/JavaScriptCore/ChangeLog:11
>> +        for ValueBitOp to use `getHeapPrediction()`. 
> 
> Can we have a test to ensure that JSC does not perform compile-fail loops?
> Like the following code would pose the issue if something is wrong.
> 
> var object = { valueOf() { return integer; } };
> // object with bit operation, which will produce Int32, but the operands of bit operation includes object.

Nice, added.
Comment 13 Caio Lima 2019-01-14 18:34:21 PST
Created attachment 359115 [details]
Patch
Comment 14 WebKit Commit Bot 2019-01-15 02:14:37 PST
Comment on attachment 359115 [details]
Patch

Clearing flags on attachment: 359115

Committed r239980: <https://trac.webkit.org/changeset/239980>
Comment 15 WebKit Commit Bot 2019-01-15 02:14:39 PST
All reviewed patches have been landed.  Closing bug.
Comment 16 Radar WebKit Bug Importer 2019-01-15 02:16:05 PST
<rdar://problem/47279811>