Bug 160954 - [JSC] ArithSqrt should work with any argument type
Summary: [JSC] ArithSqrt should work with any argument type
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-17 23:02 PDT by Benjamin Poulain
Modified: 2016-08-19 19:02 PDT (History)
5 users (show)

See Also:


Attachments
Patch (18.32 KB, patch)
2016-08-17 23:08 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (26.89 KB, patch)
2016-08-19 17:01 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (28.38 KB, patch)
2016-08-19 17:25 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2016-08-17 23:02:37 PDT
[JSC] ArithSqrt should work with any argument type
Comment 1 Benjamin Poulain 2016-08-17 23:08:37 PDT
Created attachment 286364 [details]
Patch
Comment 2 Saam Barati 2016-08-17 23:50:14 PDT
Comment on attachment 286364 [details]
Patch

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

r=me

> Source/JavaScriptCore/ChangeLog:24
> +        with Filip, we decided not to use ToNumber+ArithSqrt despite

Out of curiosity, why not go with this design?
We have variants of Untyped math support in different places.
I wonder if we'd be better of just inserting ToNumber everywhere
instead of explicitly supporting UntypedUse everywhere. What do you think?

> JSTests/stress/arith-sqrt-on-various-types.js:117
> +    if (numberOfDFGCompiles(opaqueSqrtForCSE) > 1)

Is this compatible with OSR exit fuzzing?
Comment 3 Benjamin Poulain 2016-08-18 00:26:40 PDT
(In reply to comment #2)
> Out of curiosity, why not go with this design?
> We have variants of Untyped math support in different places.
> I wonder if we'd be better of just inserting ToNumber everywhere
> instead of explicitly supporting UntypedUse everywhere. What do you think?

Filip does not like the idea because we do not have explicit ways to relate those operations.

If you were to insert an operation between the "ToNumber" and "ArithSqrt", and that operation exits, there is no way to execute the Math.sqrt without calling ToNumber again.
There is also the risk of changing ToNumber such that it exits in some cases.

To split an op into multiple nodes, the side effects should be done on the last node.

> > JSTests/stress/arith-sqrt-on-various-types.js:117
> > +    if (numberOfDFGCompiles(opaqueSqrtForCSE) > 1)
> 
> Is this compatible with OSR exit fuzzing?

Hum, it is not! I did not think about that.

Any idea how to test this properly? I want to enforce that we no longer OSR Exit like crazy.
Maybe I should just have a function to tell this particular block should not be subject to fuzzing.
Comment 4 Saam Barati 2016-08-18 11:51:11 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > Out of curiosity, why not go with this design?
> > We have variants of Untyped math support in different places.
> > I wonder if we'd be better of just inserting ToNumber everywhere
> > instead of explicitly supporting UntypedUse everywhere. What do you think?
> 
> Filip does not like the idea because we do not have explicit ways to relate
> those operations.
> 
> If you were to insert an operation between the "ToNumber" and "ArithSqrt",
> and that operation exits, there is no way to execute the Math.sqrt without
> calling ToNumber again.
> There is also the risk of changing ToNumber such that it exits in some cases.
I think the concern of doing something that exits between the two nodes
is a real concern. However, if ToNumber decides to start exiting at some
point for some reason, I think that'd be fine. ToNumber can't exit to
to_number after it has already performed its side effects. So I think
that this problem exists irrespective of this patch. Regardless, I agree
that we should not split this into two nodes.

> 
> To split an op into multiple nodes, the side effects should be done on the
> last node.
Right.
> 
> > > JSTests/stress/arith-sqrt-on-various-types.js:117
> > > +    if (numberOfDFGCompiles(opaqueSqrtForCSE) > 1)
> > 
> > Is this compatible with OSR exit fuzzing?
> 
> Hum, it is not! I did not think about that.
> 
> Any idea how to test this properly? I want to enforce that we no longer OSR
> Exit like crazy.
> Maybe I should just have a function to tell this particular block should not
> be subject to fuzzing.
You could do that for this test since you don't really want OSR exit fuzzing to
take place for this block, since you want to enforce that we compile a block
that doesn't exit at all. I'm not sure what's the nicest way to write such a function.
I guess you could flip a bit on the UnlinkedCodeBlock, that way, every CodeBlock
can ask its UnlinkedCodeBlock if it partakes in OSR exit fuzzing.
Comment 5 Benjamin Poulain 2016-08-19 17:01:20 PDT
Created attachment 286499 [details]
Patch
Comment 6 Saam Barati 2016-08-19 17:11:37 PDT
Comment on attachment 286499 [details]
Patch

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

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:198
> +        || canUseOSRExitFuzzing(m_jit.graph().baselineCodeBlockFor(m_origin.semantic)))

I think you want:
if (!canUseOSRExitFuzzing(m_jit.graph().baselineCodeBlockFor(m_origin.semantic)) || !doOSRExitFuzzing()) as the condition here.
It's probably better for canUseOSRExitFuzzing to come first so doOSRExitFuzzing won't perform its side effects if canUseOSRExitFuzzing is false.
You also want to negate the condition otherwise you'll never emit checks when fuzzing is enabled.
Comment 7 Benjamin Poulain 2016-08-19 17:25:41 PDT
Created attachment 286503 [details]
Patch
Comment 8 WebKit Commit Bot 2016-08-19 19:02:24 PDT
Comment on attachment 286503 [details]
Patch

Clearing flags on attachment: 286503

Committed r204670: <http://trac.webkit.org/changeset/204670>
Comment 9 WebKit Commit Bot 2016-08-19 19:02:28 PDT
All reviewed patches have been landed.  Closing bug.