RESOLVED FIXED 186174
[BigInt] Add ValueMod into DFG
https://bugs.webkit.org/show_bug.cgi?id=186174
Summary [BigInt] Add ValueMod into DFG
Caio Lima
Reported 2018-05-31 19:08:59 PDT
...
Attachments
WIP - Patch (19.53 KB, patch)
2018-12-14 06:17 PST, Caio Lima
no flags
WIP - Patch (25.22 KB, patch)
2018-12-18 03:31 PST, Caio Lima
no flags
Benchmarks (96.30 KB, text/plain)
2018-12-18 03:34 PST, Caio Lima
no flags
WIP - Patch (27.87 KB, patch)
2018-12-18 16:16 PST, Caio Lima
no flags
Patch (28.04 KB, patch)
2018-12-19 05:59 PST, Caio Lima
no flags
Patch (28.07 KB, patch)
2018-12-19 06:08 PST, Caio Lima
no flags
Patch (27.40 KB, patch)
2019-01-03 10:25 PST, Caio Lima
no flags
Benchmarks (95.20 KB, text/plain)
2019-01-03 10:27 PST, Caio Lima
no flags
Patch (27.38 KB, patch)
2019-01-19 07:34 PST, Caio Lima
no flags
Patch (42.15 KB, patch)
2019-01-23 06:45 PST, Caio Lima
no flags
Benchmarks (95.66 KB, text/plain)
2019-01-23 07:02 PST, Caio Lima
no flags
Patch (42.34 KB, patch)
2019-01-23 16:33 PST, Caio Lima
no flags
Patch (36.06 KB, patch)
2019-01-24 04:32 PST, Caio Lima
no flags
Patch (36.12 KB, patch)
2019-02-01 17:20 PST, Caio Lima
no flags
Patch (36.15 KB, patch)
2019-02-17 14:25 PST, Caio Lima
no flags
Patch (39.92 KB, patch)
2019-03-08 07:37 PST, Caio Lima
no flags
Patch (40.01 KB, patch)
2019-04-09 12:36 PDT, Caio Lima
no flags
Patch (40.03 KB, patch)
2019-05-03 09:46 PDT, Caio Lima
no flags
Archive of layout-test-results from ews210 for win-future (13.52 MB, application/zip)
2019-05-03 11:06 PDT, EWS Watchlist
no flags
Patch (39.95 KB, patch)
2019-05-07 18:29 PDT, Caio Lima
no flags
Archive of layout-test-results from ews210 for win-future (13.42 MB, application/zip)
2019-05-07 23:45 PDT, EWS Watchlist
no flags
Patch (39.95 KB, patch)
2019-05-08 06:03 PDT, Caio Lima
no flags
Archive of layout-test-results from ews215 for win-future (13.73 MB, application/zip)
2019-05-08 09:09 PDT, EWS Watchlist
no flags
Patch (39.95 KB, patch)
2019-05-08 10:03 PDT, Caio Lima
no flags
Caio Lima
Comment 1 2018-12-13 04:37:42 PST
*** Bug 192662 has been marked as a duplicate of this bug. ***
Caio Lima
Comment 2 2018-12-14 06:17:22 PST
Created attachment 357312 [details] WIP - Patch
Caio Lima
Comment 3 2018-12-18 03:31:39 PST
Created attachment 357558 [details] WIP - Patch
Caio Lima
Comment 4 2018-12-18 03:34:44 PST
Created attachment 357559 [details] Benchmarks This patch seems perf neutral on x86_64
Caio Lima
Comment 5 2018-12-18 16:16:30 PST
Created attachment 357630 [details] WIP - Patch
Caio Lima
Comment 6 2018-12-19 05:59:11 PST
Caio Lima
Comment 7 2018-12-19 06:08:41 PST
Yusuke Suzuki
Comment 8 2018-12-30 12:02:33 PST
Comment on attachment 357671 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=357671&action=review > Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:529 > + Edge& leftChild = node->child1(); > + Edge& rightChild = node->child2(); > + > + if (Node::shouldSpeculateBigInt(leftChild.node(), rightChild.node())) { > + fixEdge<BigIntUse>(leftChild); > + fixEdge<BigIntUse>(rightChild); > + break; > + } > + > + if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) { > + node->setOp(ArithMod); > + node->setResult(NodeResultNumber); > + fixupArithDivInt32(node, leftChild, rightChild); > + break; > + } > + > + if (leftChild->shouldSpeculateNotCell() && rightChild->shouldSpeculateNotCell()) { > + fixDoubleOrBooleanEdge(leftChild); > + fixDoubleOrBooleanEdge(rightChild); > + node->setOp(ArithMod); > + node->setResult(NodeResultDouble); > + break; > + } > + > + fixEdge<UntypedUse>(leftChild); > + fixEdge<UntypedUse>(rightChild); > + break; This code is different from ValueDiv code. Could you explain the story behind this difference?
Caio Lima
Comment 9 2018-12-30 14:52:02 PST
Comment on attachment 357671 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=357671&action=review >> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:529 >> + break; > > This code is different from ValueDiv code. Could you explain the story behind this difference? Rules like ArithDiv will make ValueMod(Boolean, ...) fall back to ValueMod(Untyped, Untyped), causing perf regression into some microbenchmarks. Because of this, we introduced the rule of speculating Double or Boolean when ```shouldSpeculateNotCell``` is true in both operands.
Caio Lima
Comment 10 2019-01-03 10:25:28 PST
Caio Lima
Comment 11 2019-01-03 10:27:41 PST
Created attachment 358260 [details] Benchmarks Changed the Patch to have same Fixup rules for ValueDiv and ValueMod. This change seems perf neutral.
Caio Lima
Comment 12 2019-01-07 09:33:38 PST
Ping Review.
Caio Lima
Comment 13 2019-01-19 07:34:21 PST
Saam Barati
Comment 14 2019-01-20 14:43:55 PST
Comment on attachment 359609 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=359609&action=review Mostly LGTM, but you have a bug in doesGC() > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:920 > + case ValueMod: Would be nice to do some constant folding. It makes sense to abstract away the constant folding done in ArithDiv. Just because we have UntypedUse does not mean we can't constant fold. > Source/JavaScriptCore/dfg/DFGDoesGC.cpp:108 > + case ValueMod: This should return true when BigIntUse. Also, same for all of the above operations since they can allocate a BigInt. > Source/JavaScriptCore/dfg/DFGOperations.cpp:376 > + if (WTF::holds_alternative<JSBigInt*>(leftNumeric) || WTF::holds_alternative<JSBigInt*>(rightNumeric)) { > + if (WTF::holds_alternative<JSBigInt*>(leftNumeric) && WTF::holds_alternative<JSBigInt*>(rightNumeric)) > + RELEASE_AND_RETURN(scope, JSValue::encode(JSBigInt::remainder(exec, WTF::get<JSBigInt*>(leftNumeric), WTF::get<JSBigInt*>(rightNumeric)))); > + > + return throwVMTypeError(exec, scope, "Invalid mix of BigInt and other type in remainder operation."); > + } Nit: There is a lot of code w.r.t BigInts that use this same branch pattern. It'd be nice to just generalize it in some function that accepts lambdas.
Caio Lima
Comment 15 2019-01-21 05:00:29 PST
Comment on attachment 359609 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=359609&action=review Thank you very much for the review! >> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:920 >> + case ValueMod: > > Would be nice to do some constant folding. It makes sense to abstract away the constant folding done in ArithDiv. Just because we have UntypedUse does not mean we can't constant fold. Ok. I'll work on that. >> Source/JavaScriptCore/dfg/DFGDoesGC.cpp:108 >> + case ValueMod: > > This should return true when BigIntUse. Also, same for all of the above operations since they can allocate a BigInt. Oops. Since we change the rule on Clobberize, I forgot to change this behavior as well. >> Source/JavaScriptCore/dfg/DFGOperations.cpp:376 >> + } > > Nit: There is a lot of code w.r.t BigInts that use this same branch pattern. It'd be nice to just generalize it in some function that accepts lambdas. I agree. I want to try this in a separated patch, since last time I tried to implement with lambdas resulted in performance regressions.
Caio Lima
Comment 16 2019-01-23 06:45:32 PST
Caio Lima
Comment 17 2019-01-23 07:02:02 PST
Created attachment 359877 [details] Benchmarks Patch seems perf neutral on x86_64.
Caio Lima
Comment 18 2019-01-23 16:33:36 PST
Caio Lima
Comment 19 2019-01-24 04:32:42 PST
Caio Lima
Comment 20 2019-01-28 15:10:43 PST
Ping Review
Caio Lima
Comment 21 2019-02-01 17:20:32 PST
Caio Lima
Comment 22 2019-02-17 14:25:11 PST
Caio Lima
Comment 23 2019-03-08 07:37:42 PST
Caio Lima
Comment 24 2019-04-09 12:36:24 PDT
Caio Lima
Comment 25 2019-04-23 14:05:47 PDT
Ping Review
Caio Lima
Comment 26 2019-05-03 09:46:02 PDT
EWS Watchlist
Comment 27 2019-05-03 11:06:54 PDT
Comment on attachment 368939 [details] Patch Attachment 368939 [details] did not pass win-ews (win): Output: https://webkit-queues.webkit.org/results/12089239 New failing tests: svg/repaint/remove-background-property-on-root.html
EWS Watchlist
Comment 28 2019-05-03 11:06:58 PDT
Created attachment 368952 [details] Archive of layout-test-results from ews210 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews210 Port: win-future Platform: CYGWIN_NT-10.0-17763-3.0.5-338.x86_64-x86_64-64bit
Saam Barati
Comment 29 2019-05-06 13:08:01 PDT
Comment on attachment 368939 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=368939&action=review Mostly LGTM, but I think I found a constant folding bug. > Source/JavaScriptCore/ChangeLog:21 > + constant even if prediction propagation and fixup phases fail. nit: Those phase don't "fail". They predict types. I think you can just remove this sentence or rephrase to specify they picked less general types. > Source/JavaScriptCore/ChangeLog:38 > + ValueMod(BigIntUse) doesn't clobberize world because it only calls > + `operationModBigInt`. nice. > Source/JavaScriptCore/ChangeLog:45 > + ValueMod(BigIntUse) can trigger GC since it allocates intermediate > + JSBigInt to perform calculation. ValueMod(UntypedUse) can trigger GC > + because it can execute arbritary code from user. nice > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:237 > +bool AbstractInterpreter<AbstractStateType>::handleConstantDivOp(Node* node) I think you have a bug here where if we're doing BigInt Mod/Div, we need to ensure the constants are bigint. Like, it's wrong to constant fold this if lhs/rhs are int32, but we are speculating BigInt. Would be good to have a test for this. I believe you can create a test using Yusuke's fuzzer agent infrastructure. > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:5229 > + if (leftChild.useKind() == BigIntUse && rightChild.useKind() == BigIntUse) { nit: I think you can use node->binaryUseKind() == BigIntUse
Caio Lima
Comment 30 2019-05-06 20:47:34 PDT
(In reply to Saam Barati from comment #29) > Comment on attachment 368939 [details] > > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:237 > > +bool AbstractInterpreter<AbstractStateType>::handleConstantDivOp(Node* node) > > I think you have a bug here where if we're doing BigInt Mod/Div, we need to > ensure the constants are bigint. Like, it's wrong to constant fold this if > lhs/rhs are int32, but we are speculating BigInt. > > Would be good to have a test for this. I believe you can create a test using > Yusuke's fuzzer agent infrastructure. Oh right. With this I can force a scenario to have the following code ``` @1 - JSConstant(Int32: 10) @2 - JSConstant(Int32: 2) @3 - ValueMod(BigInt, @1, @2) ``` However I don't see how it is possible to have a case described above, since `executeEdges(node)` will make impossible to prove that @1 and @2 are int32 (or Number) while we are speculating BigInt. I agree that `AbstractInterpreter::executeEffects` shouldn't rely on `executeEdges` and this check is necessary, but I don't know how to add a test where AI proves children as Int32 having `node->binaryUseKind() == BigInt`. IIUC, it is not possible to have this case during constant folding, but we can have this issue on other analysis that rely on AI.
Saam Barati
Comment 31 2019-05-07 14:36:05 PDT
(In reply to Caio Lima from comment #30) > (In reply to Saam Barati from comment #29) > > Comment on attachment 368939 [details] > > > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:237 > > > +bool AbstractInterpreter<AbstractStateType>::handleConstantDivOp(Node* node) > > > > I think you have a bug here where if we're doing BigInt Mod/Div, we need to > > ensure the constants are bigint. Like, it's wrong to constant fold this if > > lhs/rhs are int32, but we are speculating BigInt. > > > > Would be good to have a test for this. I believe you can create a test using > > Yusuke's fuzzer agent infrastructure. > > Oh right. With this I can force a scenario to have the following code > ``` > @1 - JSConstant(Int32: 10) > @2 - JSConstant(Int32: 2) > @3 - ValueMod(BigInt, @1, @2) > ``` > > However I don't see how it is possible to have a case described above, since > `executeEdges(node)` will make impossible to prove that @1 and @2 are int32 > (or Number) while we are speculating BigInt. I agree that > `AbstractInterpreter::executeEffects` shouldn't rely on `executeEdges` and > this check is necessary, but I don't know how to add a test where AI proves > children as Int32 having `node->binaryUseKind() == BigInt`. IIUC, it is not > possible to have this case during constant folding, but we can have this > issue on other analysis that rely on AI. Yeah your correct. We'll end up calling AbstractValue::clear() in such a scenario.
Saam Barati
Comment 32 2019-05-07 14:38:12 PDT
Comment on attachment 368939 [details] Patch r=me
Caio Lima
Comment 33 2019-05-07 18:29:05 PDT
EWS Watchlist
Comment 34 2019-05-07 23:45:05 PDT
Comment on attachment 369347 [details] Patch Attachment 369347 [details] did not pass win-ews (win): Output: https://webkit-queues.webkit.org/results/12130680 New failing tests: security/contentSecurityPolicy/video-with-file-url-allowed-by-media-src-star.html
EWS Watchlist
Comment 35 2019-05-07 23:45:07 PDT
Created attachment 369361 [details] Archive of layout-test-results from ews210 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews210 Port: win-future Platform: CYGWIN_NT-10.0-17763-3.0.5-338.x86_64-x86_64-64bit
Caio Lima
Comment 36 2019-05-08 06:03:41 PDT
EWS Watchlist
Comment 37 2019-05-08 09:09:36 PDT
Comment on attachment 369381 [details] Patch Attachment 369381 [details] did not pass win-ews (win): Output: https://webkit-queues.webkit.org/results/12133528 New failing tests: svg/repaint/remove-border-property-on-root.html http/tests/css/filters-on-iframes.html
EWS Watchlist
Comment 38 2019-05-08 09:09:41 PDT
Created attachment 369390 [details] Archive of layout-test-results from ews215 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews215 Port: win-future Platform: CYGWIN_NT-10.0-17763-3.0.5-338.x86_64-x86_64-64bit
Caio Lima
Comment 39 2019-05-08 09:55:30 PDT
(In reply to Build Bot from comment #37) > Comment on attachment 369381 [details] > Patch > > Attachment 369381 [details] did not pass win-ews (win): > Output: https://webkit-queues.webkit.org/results/12133528 > > New failing tests: > svg/repaint/remove-border-property-on-root.html > http/tests/css/filters-on-iframes.html I think these failures are unrelated with the patch.
WebKit Commit Bot
Comment 40 2019-05-08 09:58:46 PDT
Comment on attachment 369381 [details] Patch Rejecting attachment 369381 [details] from commit-queue. Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-01', 'validate-changelog', '--check-oops', '--non-interactive', 369381, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit ChangeLog entry in PerformanceTests/ChangeLog contains OOPS!. Full output: https://webkit-queues.webkit.org/results/12134158
Caio Lima
Comment 41 2019-05-08 10:03:33 PDT
WebKit Commit Bot
Comment 42 2019-05-08 12:38:22 PDT
Comment on attachment 369393 [details] Patch Clearing flags on attachment: 369393 Committed r245063: <https://trac.webkit.org/changeset/245063>
WebKit Commit Bot
Comment 43 2019-05-08 12:38:25 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 44 2019-05-08 12:39:34 PDT
Note You need to log in before you can comment on or make changes to this bug.