Bug 160108 - op_mul/ArithMul(Untyped,Untyped) should be an IC
Summary: op_mul/ArithMul(Untyped,Untyped) should be an IC
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-22 16:59 PDT by Saam Barati
Modified: 2016-07-25 12:06 PDT (History)
13 users (show)

See Also:


Attachments
WIP (55.03 KB, patch)
2016-07-22 18:39 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (63.67 KB, patch)
2016-07-24 21:10 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (64.10 KB, patch)
2016-07-25 10:03 PDT, Saam Barati
mark.lam: review+
Details | Formatted Diff | Diff
patch for landing (64.09 KB, patch)
2016-07-25 11:15 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
benchmarks (5.94 KB, application/octet-stream)
2016-07-25 11:54 PDT, Saam Barati
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2016-07-22 16:59:02 PDT
...
Comment 1 Saam Barati 2016-07-22 18:39:22 PDT
Created attachment 284392 [details]
WIP

WIP with a bunch of data gathering code in it.
Comment 2 Saam Barati 2016-07-24 21:10:31 PDT
Created attachment 284462 [details]
patch
Comment 3 WebKit Commit Bot 2016-07-24 21:12:57 PDT
Attachment 284462 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/jit/JITAddGenerator.cpp:171:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/JavaScriptCore/jit/JITMathIC.h:32:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 2 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Saam Barati 2016-07-25 10:03:18 PDT
Created attachment 284495 [details]
patch
Comment 5 Mark Lam 2016-07-25 10:04:08 PDT
Comment on attachment 284462 [details]
patch

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

> Source/JavaScriptCore/jit/JITMulGenerator.cpp:53
> +    if (lhs.isOnlyNonNumber() && rhs.isOnlyNonNumber())

Shouldn't this be ((lhs.isOnlyNonNumber() || rhs.isOnlyNonNumber())?

I wonder why the op_mul.js tests didn't catch this scenario.  Can you look into adding a test case or a new test file as appropriate?  Oh, I think you'll end up returning JITMathICInlineResult::GenerateFullSnippet below, and that will still work though less efficiently.

> Source/JavaScriptCore/jit/JITMulGenerator.cpp:200
> +    if (!m_arithProfile || !shouldEmitProfiling)

I think this should be (!m_arithProfile && !shouldEmitProfiling).
Comment 6 WebKit Commit Bot 2016-07-25 10:06:05 PDT
Attachment 284495 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/jit/JITAddGenerator.cpp:171:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Saam Barati 2016-07-25 10:07:05 PDT
Comment on attachment 284462 [details]
patch

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

>> Source/JavaScriptCore/jit/JITMulGenerator.cpp:53
>> +    if (lhs.isOnlyNonNumber() && rhs.isOnlyNonNumber())
> 
> Shouldn't this be ((lhs.isOnlyNonNumber() || rhs.isOnlyNonNumber())?
> 
> I wonder why the op_mul.js tests didn't catch this scenario.  Can you look into adding a test case or a new test file as appropriate?  Oh, I think you'll end up returning JITMathICInlineResult::GenerateFullSnippet below, and that will still work though less efficiently.

Yes this is tricky. We only degrade generating if both have proven to not be numbers. We are more optimistic if one has been a number, that the other might also be a number. We can play around with this heuristic in the future. It might even be helpful to have counts.

>> Source/JavaScriptCore/jit/JITMulGenerator.cpp:200
>> +    if (!m_arithProfile || !shouldEmitProfiling)
> 
> I think this should be (!m_arithProfile && !shouldEmitProfiling).

No, that's not quite right.
If we don't have an ArithProfile, we don't emit profiling. If shouldEmitProfiling is false, we don't emit profiling.
Hence for ||
Comment 8 Mark Lam 2016-07-25 10:11:20 PDT
(In reply to comment #7)
> Comment on attachment 284462 [details]
> patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=284462&action=review
> 
> >> Source/JavaScriptCore/jit/JITMulGenerator.cpp:53
> >> +    if (lhs.isOnlyNonNumber() && rhs.isOnlyNonNumber())
> > 
> > Shouldn't this be ((lhs.isOnlyNonNumber() || rhs.isOnlyNonNumber())?
> > 
> > I wonder why the op_mul.js tests didn't catch this scenario.  Can you look into adding a test case or a new test file as appropriate?  Oh, I think you'll end up returning JITMathICInlineResult::GenerateFullSnippet below, and that will still work though less efficiently.
> 
> Yes this is tricky. We only degrade generating if both have proven to not be
> numbers. We are more optimistic if one has been a number, that the other
> might also be a number. We can play around with this heuristic in the
> future. It might even be helpful to have counts.

OK.  Good point.

> >> Source/JavaScriptCore/jit/JITMulGenerator.cpp:200
> >> +    if (!m_arithProfile || !shouldEmitProfiling)
> > 
> > I think this should be (!m_arithProfile && !shouldEmitProfiling).
> 
> No, that's not quite right.
> If we don't have an ArithProfile, we don't emit profiling. If
> shouldEmitProfiling is false, we don't emit profiling.
> Hence for ||

Oh, you're right.  I had a mistake in my reasoning.
Comment 9 Mark Lam 2016-07-25 10:54:45 PDT
Comment on attachment 284495 [details]
patch

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

r=me with fixes.

> Source/JavaScriptCore/ChangeLog:11
> +        work over arbitrary IC snippets. This will making adding Div/Sub/Pow in the

typo: /will making/will make/.

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:1326
> +    other.m_jit = nullptr;

I think you should also set "other.m_fpr = InvalidFPRReg;" similar to the GPRTemporary version.

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:3122
> +        if (LIKELY(m_jit))

Should this be "if (LIKELY(m_jit && m_fpr != InvalidFPRReg)" similar to the GPRTemporary version?

Looking at the constructors, I see no way that m_fpr can be invalid unless the allocator fails.  I'm thinking we should have the GPRTemporary and FPRTemporary code behaves consistently, either by adding the invalid check, or asserting that the reg is never invalid at destruction time.
Comment 10 Saam Barati 2016-07-25 11:09:41 PDT
Comment on attachment 284495 [details]
patch

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

>> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:3122
>> +        if (LIKELY(m_jit))
> 
> Should this be "if (LIKELY(m_jit && m_fpr != InvalidFPRReg)" similar to the GPRTemporary version?
> 
> Looking at the constructors, I see no way that m_fpr can be invalid unless the allocator fails.  I'm thinking we should have the GPRTemporary and FPRTemporary code behaves consistently, either by adding the invalid check, or asserting that the reg is never invalid at destruction time.

Mark and I spoke offline, we're going to probably make GPRTemporary behave more like FPRTemporary in another bug.
Comment 11 Saam Barati 2016-07-25 11:15:44 PDT
Created attachment 284503 [details]
patch for landing
Comment 12 WebKit Commit Bot 2016-07-25 11:17:48 PDT
Attachment 284503 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/jit/JITAddGenerator.cpp:171:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Saam Barati 2016-07-25 11:54:49 PDT
Created attachment 284511 [details]
benchmarks

looks neutral, or maybe a slight win.
Comment 14 Saam Barati 2016-07-25 12:06:43 PDT
landed in:
https://trac.webkit.org/changeset/203693