Diff
Modified: trunk/JSTests/ChangeLog (204946 => 204947)
--- trunk/JSTests/ChangeLog 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/JSTests/ChangeLog 2016-08-25 01:21:43 UTC (rev 204947)
@@ -1,3 +1,12 @@
+2016-08-24 Benjamin Poulain <[email protected]>
+
+ [JSC] Make FRound work with any type
+ https://bugs.webkit.org/show_bug.cgi?id=161129
+
+ Reviewed by Geoffrey Garen.
+
+ * stress/arith-fround-on-various-types.js: Added.
+
2016-08-24 Filip Pizlo <[email protected]>
Unreviewed, roll out r204901, r204897, r204866, r204856, r204854.
Added: trunk/JSTests/stress/arith-fround-on-various-types.js (0 => 204947)
--- trunk/JSTests/stress/arith-fround-on-various-types.js (rev 0)
+++ trunk/JSTests/stress/arith-fround-on-various-types.js 2016-08-25 01:21:43 UTC (rev 204947)
@@ -0,0 +1,190 @@
+"use strict";
+
+let froundOfPi = Math.fround(Math.PI);
+let froundOfE = Math.fround(Math.E);
+
+let validInputTestCases = [
+ // input as string, expected result as string.
+ ["undefined", "NaN"],
+ ["null", "0"],
+ ["0", "0"],
+ ["-0.", "-0"],
+ ["1.", "1"],
+ ["Math.PI", "" + froundOfPi],
+ ["Math.E", "" + froundOfE],
+ ["Infinity", "Infinity"],
+ ["-Infinity", "-Infinity"],
+ ["NaN", "NaN"],
+ ["\"WebKit\"", "NaN"],
+ ["\"" + Math.PI + "\"", "" + froundOfPi],
+ ["{ valueOf: () => { return Math.E; } }", "" + froundOfE],
+ ["{ valueOf: () => { return 1; } }", "1"],
+ ["{ valueOf: () => { return Math.PI; } }", "" + froundOfPi],
+];
+
+let validInputTypedTestCases = validInputTestCases.map((element) => { return [eval("(" + element[0] + ")"), eval(element[1])] });
+
+function isIdentical(result, expected)
+{
+ if (expected === expected) {
+ if (result !== expected)
+ return false;
+ if (!expected && 1 / expected === -Infinity && 1 / result !== -Infinity)
+ return false;
+
+ return true;
+ }
+ return result !== result;
+}
+
+// Test Math.fround() without arguments.
+function opaqueFRoundNoArgument() {
+ return Math.fround();
+}
+noInline(opaqueFRoundNoArgument);
+noOSRExitFuzzing(opaqueFRoundNoArgument);
+
+function testNoArgument() {
+ for (let i = 0; i < 1e4; ++i) {
+ let output = opaqueFRoundNoArgument();
+ if (output === output) {
+ throw "Failed opaqueFRoundNoArgument";
+ }
+ }
+ if (numberOfDFGCompiles(opaqueFRoundNoArgument) > 1)
+ throw "The call without arguments should never exit.";
+}
+testNoArgument();
+
+// Test Math.fround() with a very polymorphic input. All test cases are seen at each iteration.
+function opaqueAllTypesFround(argument) {
+ return Math.fround(argument);
+}
+noInline(opaqueAllTypesFround);
+noOSRExitFuzzing(opaqueAllTypesFround);
+
+function testAllTypesCall() {
+ for (let i = 0; i < 1e3; ++i) {
+ for (let testCaseInput of validInputTypedTestCases) {
+ let output = opaqueAllTypesFround(testCaseInput[0]);
+ if (!isIdentical(output, testCaseInput[1]))
+ throw "Failed testAllTypesCall for input " + testCaseInput[0] + " expected " + testCaseInput[1] + " got " + output;
+ }
+ }
+ if (numberOfDFGCompiles(opaqueAllTypesFround) > 2)
+ throw "We should have detected fround() was polymorphic and generated a generic version.";
+}
+testAllTypesCall();
+
+
+// Test Math.fround() on a completely typed input. Every call see only one type.
+function testSingleTypeCall() {
+ for (let testCaseInput of validInputTestCases) {
+ eval(`
+ function opaqueFround(argument) {
+ return Math.fround(argument);
+ }
+ noInline(opaqueFround);
+ noOSRExitFuzzing(opaqueFround);
+
+ for (let i = 0; i < 1e4; ++i) {
+ if (!isIdentical(opaqueFround(${testCaseInput[0]}), ${testCaseInput[1]})) {
+ throw "Failed testSingleTypeCall()";
+ }
+ }
+ if (numberOfDFGCompiles(opaqueFround) > 1)
+ throw "We should have compiled a single fround for the expected type.";
+ `);
+ }
+}
+testSingleTypeCall();
+
+
+// Verify we call valueOf() exactly once per call.
+function opaqueFroundForSideEffects(argument) {
+ return Math.fround(argument);
+}
+noInline(opaqueFroundForSideEffects);
+noOSRExitFuzzing(opaqueFroundForSideEffects);
+
+function testSideEffect() {
+ let testObject = {
+ counter: 0,
+ valueOf: function() { ++this.counter; return 16; }
+ };
+ let fround16 = Math.fround(16);
+ for (let i = 0; i < 1e4; ++i) {
+ if (opaqueFroundForSideEffects(testObject) !== fround16)
+ throw "Incorrect result in testSideEffect()";
+ }
+ if (testObject.counter !== 1e4)
+ throw "Failed testSideEffect()";
+ if (numberOfDFGCompiles(opaqueFroundForSideEffects) > 1)
+ throw "opaqueFroundForSideEffects() is predictable, it should only be compiled once.";
+}
+testSideEffect();
+
+
+// Verify SQRT is not subject to CSE if the argument has side effects.
+function opaqueFroundForCSE(argument) {
+ return Math.fround(argument) + Math.fround(argument) + Math.fround(argument);
+}
+noInline(opaqueFroundForCSE);
+noOSRExitFuzzing(opaqueFroundForCSE);
+
+function testCSE() {
+ let testObject = {
+ counter: 0,
+ valueOf: function() { ++this.counter; return 16; }
+ };
+ let fround16 = Math.fround(16);
+ let threeFround16 = fround16 + fround16 + fround16;
+ for (let i = 0; i < 1e4; ++i) {
+ if (opaqueFroundForCSE(testObject) !== threeFround16)
+ throw "Incorrect result in testCSE()";
+ }
+ if (testObject.counter !== 3e4)
+ throw "Failed testCSE()";
+ if (numberOfDFGCompiles(opaqueFroundForCSE) > 1)
+ throw "opaqueFroundForCSE() is predictable, it should only be compiled once.";
+}
+testCSE();
+
+
+// Test exceptions in the argument.
+function testException() {
+ let counter = 0;
+ function opaqueFroundWithException(argument) {
+ let result = Math.fround(argument);
+ ++counter;
+ return result;
+ }
+ noInline(opaqueFroundWithException);
+
+ let testObject = { valueOf: () => { return 64; } };
+ let fround64 = Math.fround(64);
+
+ // Warm up without exception.
+ for (let i = 0; i < 1e3; ++i) {
+ if (opaqueFroundWithException(testObject) !== fround64)
+ throw "Incorrect result in opaqueFroundWithException()";
+ }
+
+ let testThrowObject = { valueOf: () => { throw testObject; return 64; } };
+
+ for (let i = 0; i < 1e2; ++i) {
+ try {
+ if (opaqueFroundWithException(testThrowObject) !== 8)
+ throw "This code should not be reached!!";
+ } catch (e) {
+ if (e !== testObject) {
+ throw "Wrong object thrown from opaqueFroundWithException."
+ }
+ }
+ }
+
+ if (counter !== 1e3) {
+ throw "Invalid count in testException()";
+ }
+}
+testException();
Modified: trunk/Source/_javascript_Core/ChangeLog (204946 => 204947)
--- trunk/Source/_javascript_Core/ChangeLog 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-08-25 01:21:43 UTC (rev 204947)
@@ -1,3 +1,38 @@
+2016-08-24 Benjamin Poulain <[email protected]>
+
+ [JSC] Make FRound work with any type
+ https://bugs.webkit.org/show_bug.cgi?id=161129
+
+ Reviewed by Geoffrey Garen.
+
+ Math.fround() does nothing with arguments past the first one
+ (https://tc39.github.io/ecma262/#sec-math.fround).
+ We can unify ArithFRound with the other single-input intrinsics.
+
+ Everything else is same old: if the input type is not a number,
+ be pessimistic about everything and do a C call.
+
+ * dfg/DFGAbstractInterpreterInlines.h:
+ (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+ * dfg/DFGByteCodeParser.cpp:
+ (JSC::DFG::ByteCodeParser::handleIntrinsicCall):
+ * dfg/DFGClobberize.h:
+ (JSC::DFG::clobberize):
+ * dfg/DFGFixupPhase.cpp:
+ (JSC::DFG::FixupPhase::fixupNode):
+ * dfg/DFGNodeType.h:
+ * dfg/DFGOperations.cpp:
+ * dfg/DFGOperations.h:
+ * dfg/DFGSpeculativeJIT.cpp:
+ (JSC::DFG::SpeculativeJIT::compileArithFRound):
+ * dfg/DFGSpeculativeJIT.h:
+ * dfg/DFGSpeculativeJIT32_64.cpp:
+ (JSC::DFG::SpeculativeJIT::compile):
+ * dfg/DFGSpeculativeJIT64.cpp:
+ (JSC::DFG::SpeculativeJIT::compile):
+ * ftl/FTLLowerDFGToB3.cpp:
+ (JSC::FTL::DFG::LowerDFGToB3::compileArithFRound):
+
2016-08-24 Andreas Kling <[email protected]>
Shrink DFG::OSRExit a bit.
Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h 2016-08-25 01:21:43 UTC (rev 204947)
@@ -974,7 +974,10 @@
setConstant(node, jsDoubleNumber(static_cast<float>(child.asNumber())));
break;
}
- forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
+ SpeculatedType froundType = SpecFullNumber;
+ if (node->child1().useKind() == DoubleRepUse)
+ froundType = typeOfDoubleUnaryOp(forNode(node->child1()).m_type);
+ forNode(node).setType(froundType);
break;
}
Modified: trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -2140,41 +2140,40 @@
case MaxIntrinsic:
return handleMinMax(resultOperand, ArithMax, registerOffset, argumentCountIncludingThis, insertChecks);
- case SqrtIntrinsic:
case CosIntrinsic:
+ case FRoundIntrinsic:
+ case LogIntrinsic:
case SinIntrinsic:
- case LogIntrinsic: {
+ case SqrtIntrinsic: {
if (argumentCountIncludingThis == 1) {
insertChecks();
set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantNaN)));
return true;
}
-
+
+ NodeType nodeType = Unreachable;
switch (intrinsic) {
- case SqrtIntrinsic:
- insertChecks();
- set(VirtualRegister(resultOperand), addToGraph(ArithSqrt, get(virtualRegisterForArgument(1, registerOffset))));
- return true;
-
case CosIntrinsic:
- insertChecks();
- set(VirtualRegister(resultOperand), addToGraph(ArithCos, get(virtualRegisterForArgument(1, registerOffset))));
- return true;
-
+ nodeType = ArithCos;
+ break;
+ case FRoundIntrinsic:
+ nodeType = ArithFRound;
+ break;
+ case LogIntrinsic:
+ nodeType = ArithLog;
+ break;
case SinIntrinsic:
- insertChecks();
- set(VirtualRegister(resultOperand), addToGraph(ArithSin, get(virtualRegisterForArgument(1, registerOffset))));
- return true;
-
- case LogIntrinsic:
- insertChecks();
- set(VirtualRegister(resultOperand), addToGraph(ArithLog, get(virtualRegisterForArgument(1, registerOffset))));
- return true;
-
+ nodeType = ArithSin;
+ break;
+ case SqrtIntrinsic:
+ nodeType = ArithSqrt;
+ break;
default:
RELEASE_ASSERT_NOT_REACHED();
- return false;
}
+ insertChecks();
+ set(VirtualRegister(resultOperand), addToGraph(nodeType, get(virtualRegisterForArgument(1, registerOffset))));
+ return true;
}
case PowIntrinsic: {
@@ -2476,15 +2475,6 @@
return true;
}
- case FRoundIntrinsic: {
- if (argumentCountIncludingThis != 2)
- return false;
- insertChecks();
- VirtualRegister operand = virtualRegisterForArgument(1, registerOffset);
- set(VirtualRegister(resultOperand), addToGraph(ArithFRound, get(operand)));
- return true;
- }
-
case DFGTrueIntrinsic: {
insertChecks();
set(VirtualRegister(resultOperand), jsConstant(jsBoolean(true)));
Modified: trunk/Source/_javascript_Core/dfg/DFGClobberize.h (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGClobberize.h 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGClobberize.h 2016-08-25 01:21:43 UTC (rev 204947)
@@ -154,7 +154,6 @@
case ArithMin:
case ArithMax:
case ArithPow:
- case ArithFRound:
case GetScope:
case SkipScope:
case GetGlobalObject:
@@ -187,6 +186,7 @@
return;
case ArithCos:
+ case ArithFRound:
case ArithLog:
case ArithSin:
case ArithSqrt:
Modified: trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -387,6 +387,7 @@
}
case ArithCos:
+ case ArithFRound:
case ArithLog:
case ArithSin:
case ArithSqrt: {
@@ -397,11 +398,6 @@
fixEdge<UntypedUse>(child1);
break;
}
- case ArithFRound: {
- fixDoubleOrBooleanEdge(node->child1());
- node->setResult(NodeResultDouble);
- break;
- }
case LogicalNot: {
if (node->child1()->shouldSpeculateBoolean()) {
Modified: trunk/Source/_javascript_Core/dfg/DFGNodeType.h (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGNodeType.h 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGNodeType.h 2016-08-25 01:21:43 UTC (rev 204947)
@@ -152,7 +152,7 @@
macro(ArithAbs, NodeResultNumber | NodeMustGenerate) \
macro(ArithMin, NodeResultNumber) \
macro(ArithMax, NodeResultNumber) \
- macro(ArithFRound, NodeResultNumber) \
+ macro(ArithFRound, NodeResultDouble) \
macro(ArithPow, NodeResultDouble) \
macro(ArithRandom, NodeResultDouble | NodeMustGenerate) \
macro(ArithRound, NodeResultNumber) \
Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGOperations.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -334,6 +334,18 @@
return cos(a);
}
+double JIT_OPERATION operationArithFRound(ExecState* exec, EncodedJSValue encodedOp1)
+{
+ VM* vm = &exec->vm();
+ NativeCallFrameTracer tracer(vm, exec);
+
+ JSValue op1 = JSValue::decode(encodedOp1);
+ double a = op1.toNumber(exec);
+ if (UNLIKELY(vm->exception()))
+ return JSValue::encode(JSValue());
+ return static_cast<float>(a);
+}
+
double JIT_OPERATION operationArithLog(ExecState* exec, EncodedJSValue encodedOp1)
{
VM* vm = &exec->vm();
Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.h (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGOperations.h 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.h 2016-08-25 01:21:43 UTC (rev 204947)
@@ -54,6 +54,7 @@
EncodedJSValue JIT_OPERATION operationValueAddNotNumber(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
EncodedJSValue JIT_OPERATION operationValueDiv(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
double JIT_OPERATION operationArithCos(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
+double JIT_OPERATION operationArithFRound(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
double JIT_OPERATION operationArithLog(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
double JIT_OPERATION operationArithSin(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
double JIT_OPERATION operationArithSqrt(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -4538,6 +4538,26 @@
}
}
+void SpeculativeJIT::compileArithFRound(Node* node)
+{
+ if (node->child1().useKind() == DoubleRepUse) {
+ SpeculateDoubleOperand op1(this, node->child1());
+ FPRTemporary result(this, op1);
+ m_jit.convertDoubleToFloat(op1.fpr(), result.fpr());
+ m_jit.convertFloatToDouble(result.fpr(), result.fpr());
+ doubleResult(result.fpr(), node);
+ return;
+ }
+
+ JSValueOperand op1(this, node->child1());
+ JSValueRegs op1Regs = op1.jsValueRegs();
+ flushRegisters();
+ FPRResult result(this);
+ callOperation(operationArithFRound, result.fpr(), op1Regs);
+ m_jit.exceptionCheck();
+ doubleResult(result.fpr(), node);
+}
+
void SpeculativeJIT::compileArithMod(Node* node)
{
switch (node->binaryUseKind()) {
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h 2016-08-25 01:21:43 UTC (rev 204947)
@@ -2474,6 +2474,7 @@
void compileArithNegate(Node*);
void compileArithMul(Node*);
void compileArithDiv(Node*);
+ void compileArithFRound(Node*);
void compileArithMod(Node*);
void compileArithPow(Node*);
void compileArithRounding(Node*);
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -2367,16 +2367,9 @@
compileArithSqrt(node);
break;
- case ArithFRound: {
- SpeculateDoubleOperand op1(this, node->child1());
- FPRTemporary result(this, op1);
-
- m_jit.convertDoubleToFloat(op1.fpr(), result.fpr());
- m_jit.convertFloatToDouble(result.fpr(), result.fpr());
-
- doubleResult(result.fpr(), node);
+ case ArithFRound:
+ compileArithFRound(node);
break;
- }
case ArithRandom:
compileArithRandom(node);
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -2491,16 +2491,9 @@
compileArithSqrt(node);
break;
- case ArithFRound: {
- SpeculateDoubleOperand op1(this, node->child1());
- FPRTemporary result(this, op1);
-
- m_jit.convertDoubleToFloat(op1.fpr(), result.fpr());
- m_jit.convertFloatToDouble(result.fpr(), result.fpr());
-
- doubleResult(result.fpr(), node);
+ case ArithFRound:
+ compileArithFRound(node);
break;
- }
case ArithRandom:
compileArithRandom(node);
Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (204946 => 204947)
--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2016-08-25 00:46:43 UTC (rev 204946)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2016-08-25 01:21:43 UTC (rev 204947)
@@ -2315,7 +2315,13 @@
void compileArithFRound()
{
- setDouble(m_out.fround(lowDouble(m_node->child1())));
+ if (m_node->child1().useKind() == DoubleRepUse) {
+ setDouble(m_out.fround(lowDouble(m_node->child1())));
+ return;
+ }
+ LValue argument = lowJSValue(m_node->child1());
+ LValue result = vmCall(Double, m_out.operation(operationArithFRound), m_callFrame, argument);
+ setDouble(result);
}
void compileArithNegate()