Title: [197445] trunk/Source/_javascript_Core
- Revision
- 197445
- Author
- [email protected]
- Date
- 2016-03-01 23:53:20 -0800 (Tue, 01 Mar 2016)
Log Message
[JSC] Simplify ArithMod(ArithMod(x, const1), const2) if const2 >= const1
https://bugs.webkit.org/show_bug.cgi?id=154904
Reviewed by Saam Barati.
The ASM test "ubench" has a "x % 10 % 255".
The second modulo should be eliminated.
This is a 15% improvement on ASMJS' ubench.
* dfg/DFGStrengthReductionPhase.cpp:
(JSC::DFG::StrengthReductionPhase::handleNode):
* tests/stress/arith-modulo-twice.js: Added.
(opaqueModuloSmaller):
(opaqueModuloEqual):
(opaqueModuloLarger):
(opaqueModuloSmallerNeg):
(opaqueModuloEqualNeg):
(opaqueModuloLargerNeg):
(opaqueExpectedOther):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (197444 => 197445)
--- trunk/Source/_javascript_Core/ChangeLog 2016-03-02 07:12:08 UTC (rev 197444)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-03-02 07:53:20 UTC (rev 197445)
@@ -1,3 +1,26 @@
+2016-03-01 Benjamin Poulain <[email protected]>
+
+ [JSC] Simplify ArithMod(ArithMod(x, const1), const2) if const2 >= const1
+ https://bugs.webkit.org/show_bug.cgi?id=154904
+
+ Reviewed by Saam Barati.
+
+ The ASM test "ubench" has a "x % 10 % 255".
+ The second modulo should be eliminated.
+
+ This is a 15% improvement on ASMJS' ubench.
+
+ * dfg/DFGStrengthReductionPhase.cpp:
+ (JSC::DFG::StrengthReductionPhase::handleNode):
+ * tests/stress/arith-modulo-twice.js: Added.
+ (opaqueModuloSmaller):
+ (opaqueModuloEqual):
+ (opaqueModuloLarger):
+ (opaqueModuloSmallerNeg):
+ (opaqueModuloEqualNeg):
+ (opaqueModuloLargerNeg):
+ (opaqueExpectedOther):
+
2016-03-01 Ryosuke Niwa <[email protected]>
Unreviewed. Update the status of Proxy objects to "In Development".
Modified: trunk/Source/_javascript_Core/dfg/DFGStrengthReductionPhase.cpp (197444 => 197445)
--- trunk/Source/_javascript_Core/dfg/DFGStrengthReductionPhase.cpp 2016-03-02 07:12:08 UTC (rev 197444)
+++ trunk/Source/_javascript_Core/dfg/DFGStrengthReductionPhase.cpp 2016-03-02 07:53:20 UTC (rev 197445)
@@ -36,6 +36,7 @@
#include "DFGPredictionPropagationPhase.h"
#include "DFGVariableAccessDataDump.h"
#include "JSCInlines.h"
+#include <cstdlib>
namespace JSC { namespace DFG {
@@ -172,6 +173,21 @@
}
break;
+ case ArithMod:
+ // On Integers
+ // In: ArithMod(ArithMod(x, const1), const2)
+ // Out: Identity(ArithMod(x, const1))
+ // if const1 <= const2.
+ if (m_node->binaryUseKind() == Int32Use
+ && m_node->child2()->isInt32Constant()
+ && m_node->child1()->op() == ArithMod
+ && m_node->child1()->binaryUseKind() == Int32Use
+ && m_node->child1()->child2()->isInt32Constant()
+ && std::abs(m_node->child1()->child2()->asInt32()) <= std::abs(m_node->child2()->asInt32())) {
+ convertToIdentityOverChild1();
+ }
+ break;
+
case ValueRep:
case Int52Rep:
case DoubleRep: {
Added: trunk/Source/_javascript_Core/tests/stress/arith-modulo-twice.js (0 => 197445)
--- trunk/Source/_javascript_Core/tests/stress/arith-modulo-twice.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/arith-modulo-twice.js 2016-03-02 07:53:20 UTC (rev 197445)
@@ -0,0 +1,61 @@
+function opaqueModuloSmaller(a)
+{
+ return (a % 5) % 13;
+}
+noInline(opaqueModuloSmaller);
+
+function opaqueModuloEqual(a)
+{
+ return (a % 5) % 5;
+}
+noInline(opaqueModuloEqual);
+
+function opaqueModuloLarger(a)
+{
+ return (a % 13) % 5;
+}
+noInline(opaqueModuloLarger);
+
+function opaqueModuloSmallerNeg(a)
+{
+ return (a % -5) % -13;
+}
+noInline(opaqueModuloSmallerNeg);
+
+function opaqueModuloEqualNeg(a)
+{
+ return (a % 5) % -5;
+}
+noInline(opaqueModuloEqualNeg);
+
+function opaqueModuloLargerNeg(a)
+{
+ return (a % -13) % 5;
+}
+noInline(opaqueModuloLargerNeg);
+
+let testReducibleCases = [opaqueModuloSmaller, opaqueModuloEqual, opaqueModuloSmallerNeg, opaqueModuloEqualNeg];
+let testOtherCases = [opaqueModuloLarger, opaqueModuloLargerNeg];
+
+function opaqueExpectedOther(doubleInput)
+{
+ return (doubleInput - 2147483648) % 13.0 % 5.0;
+}
+noInline(opaqueExpectedOther);
+noDFG(opaqueExpectedOther);
+
+// Warm up with integers. The test for NegZero should not be eliminated here.
+for (let i = 1; i < 1e4; ++i) {
+ let excpectedReduced = i % 5;
+ for (let testFunction of testReducibleCases) {
+ let result = testFunction(i);
+ if (result !== excpectedReduced)
+ throw "" + testFunction.name + "(i), returned: " + result + " at i = " + i + " expected " + expectedOther;
+ }
+ let expectedOther = opaqueExpectedOther(i + 2147483648);
+ for (let testFunction of testOtherCases) {
+ let result = testFunction(i);
+ if (result !== expectedOther)
+ throw "" + testFunction.name + "(i), returned: " + result + " at i = " + i + " expected " + expectedOther;
+ }
+}
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes