- Revision
- 202790
- Author
- [email protected]
- Date
- 2016-07-03 10:46:39 -0700 (Sun, 03 Jul 2016)
Log Message
DFG LICM needs to go all-in on the idea that some loops can't be LICMed
https://bugs.webkit.org/show_bug.cgi?id=159388
Reviewed by Mark Lam.
Some time ago I acknowledged that LICM required loops to meet certain requirements that
may get broken by the time we do LICM, like that the terminal of the pre-header is ExitOK.
It used to be that we just ignored that requirement and would hoist anyway, but since
r189126 we've stopped hoisting out of loops that don't have ExitOK. We also added tests
for the case that the pre-header doesn't exist or is invalid.
It turns out that this patch didn't go far enough: even though it made LICM avoid loops
that had an invalid pre-header, the part that updated the AI state in nested loops still
assumed that these loops had valid pre-headers. We would crash in null dereference in
that loop if a nested loop had an invalid pre-header.
The fix is simple: don't update the AI state of nested loops that don't have pre-headers,
since we won't try to hoist out of those loops anyway.
* dfg/DFGLICMPhase.cpp:
(JSC::DFG::LICMPhase::attemptHoist):
* tests/stress/licm-no-pre-header-nested.js: Added. This would always crash before this fix.
(foo):
* tests/stress/licm-pre-header-cannot-exit-nested.js: Added. This was a failed attempt at a test, but I figure it's good to have weird code anyway.
(foo):
(valueOf):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (202789 => 202790)
--- trunk/Source/_javascript_Core/ChangeLog 2016-07-03 17:08:20 UTC (rev 202789)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-07-03 17:46:39 UTC (rev 202790)
@@ -1,3 +1,32 @@
+2016-07-02 Filip Pizlo <[email protected]>
+
+ DFG LICM needs to go all-in on the idea that some loops can't be LICMed
+ https://bugs.webkit.org/show_bug.cgi?id=159388
+
+ Reviewed by Mark Lam.
+
+ Some time ago I acknowledged that LICM required loops to meet certain requirements that
+ may get broken by the time we do LICM, like that the terminal of the pre-header is ExitOK.
+ It used to be that we just ignored that requirement and would hoist anyway, but since
+ r189126 we've stopped hoisting out of loops that don't have ExitOK. We also added tests
+ for the case that the pre-header doesn't exist or is invalid.
+
+ It turns out that this patch didn't go far enough: even though it made LICM avoid loops
+ that had an invalid pre-header, the part that updated the AI state in nested loops still
+ assumed that these loops had valid pre-headers. We would crash in null dereference in
+ that loop if a nested loop had an invalid pre-header.
+
+ The fix is simple: don't update the AI state of nested loops that don't have pre-headers,
+ since we won't try to hoist out of those loops anyway.
+
+ * dfg/DFGLICMPhase.cpp:
+ (JSC::DFG::LICMPhase::attemptHoist):
+ * tests/stress/licm-no-pre-header-nested.js: Added. This would always crash before this fix.
+ (foo):
+ * tests/stress/licm-pre-header-cannot-exit-nested.js: Added. This was a failed attempt at a test, but I figure it's good to have weird code anyway.
+ (foo):
+ (valueOf):
+
2016-06-30 Filip Pizlo <[email protected]>
Scopes that are not under TDZ should still push their variables onto the TDZ stack so that lifting TDZ doesn't bypass that scope
Modified: trunk/Source/_javascript_Core/dfg/DFGLICMPhase.cpp (202789 => 202790)
--- trunk/Source/_javascript_Core/dfg/DFGLICMPhase.cpp 2016-07-03 17:08:20 UTC (rev 202789)
+++ trunk/Source/_javascript_Core/dfg/DFGLICMPhase.cpp 2016-07-03 17:46:39 UTC (rev 202790)
@@ -324,6 +324,12 @@
if (!subLoop)
continue;
BasicBlock* subPreHeader = m_data[subLoop->index()].preHeader;
+ // We may not have given this loop a pre-header because either it didn't have exitOK
+ // or the header had multiple predecessors that it did not dominate. In that case the
+ // loop wouldn't be a hoisting candidate anyway, so we don't have to do anything.
+ if (!subPreHeader)
+ continue;
+ // The pre-header's tail may be unreachable, in which case we have nothing to do.
if (!subPreHeader->cfaDidFinish)
continue;
m_state.initializeTo(subPreHeader);
Added: trunk/Source/_javascript_Core/tests/stress/licm-no-pre-header-nested.js (0 => 202790)
--- trunk/Source/_javascript_Core/tests/stress/licm-no-pre-header-nested.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/licm-no-pre-header-nested.js 2016-07-03 17:46:39 UTC (rev 202790)
@@ -0,0 +1,23 @@
+//@ runMiscFTLNoCJITTest("--createPreHeaders=false")
+
+function foo(array, y) {
+ var x = 0;
+ var j = 0;
+ do {
+ x = y * 3;
+ var result = 0;
+ var i = 0;
+ if (!array.length)
+ array = [1];
+ do {
+ result += array[i++];
+ } while (i < array.length)
+ j++;
+ } while (j < 3);
+ return result + x;
+}
+
+noInline(foo);
+
+for (var i = 0; i < 10000; ++i)
+ foo([1, 2, 3], 42);
Added: trunk/Source/_javascript_Core/tests/stress/licm-pre-header-cannot-exit-nested.js (0 => 202790)
--- trunk/Source/_javascript_Core/tests/stress/licm-pre-header-cannot-exit-nested.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/licm-pre-header-cannot-exit-nested.js 2016-07-03 17:46:39 UTC (rev 202790)
@@ -0,0 +1,21 @@
+//@ runMiscFTLNoCJITTest("--createPreHeaders=false")
+
+function foo(object, predicate) {
+ for (var j = 0; j < 10; ++j) {
+ var result = 0;
+ var i = 0;
+ if (DFGTrue())
+ predicate = 42;
+ while (predicate >= 42) {
+ result += object.array[i++];
+ if (i >= object.array.length)
+ break;
+ }
+ }
+ return result;
+}
+
+noInline(foo);
+
+for (var i = 0; i < 10000; ++i)
+ foo({array: [1, 2, 3]}, {valueOf: function() { return 42; }});
Modified: trunk/Source/WTF/benchmarks/LockFairnessTest.cpp (202789 => 202790)
--- trunk/Source/WTF/benchmarks/LockFairnessTest.cpp 2016-07-03 17:08:20 UTC (rev 202789)
+++ trunk/Source/WTF/benchmarks/LockFairnessTest.cpp 2016-07-03 17:46:39 UTC (rev 202790)
@@ -48,12 +48,13 @@
NO_RETURN void usage()
{
- printf("Usage: LockFairnessTest yieldspinlock|pausespinlock|wordlock|lock|barginglock|bargingwordlock|thunderlock|thunderwordlock|cascadelock|cascadewordlockhandofflock|mutex|all <num threads> <seconds per test>\n");
+ printf("Usage: LockFairnessTest yieldspinlock|pausespinlock|wordlock|lock|barginglock|bargingwordlock|thunderlock|thunderwordlock|cascadelock|cascadewordlockhandofflock|mutex|all <num threads> <seconds per test> <microseconds in critical section>\n");
exit(1);
}
unsigned numThreads;
double secondsPerTest;
+unsigned microsecondsInCriticalSection;
struct Benchmark {
template<typename LockType>
@@ -72,9 +73,19 @@
threads[threadIndex] = createThread(
"Benchmark Thread",
[&, threadIndex] () {
+ if (!microsecondsInCriticalSection) {
+ while (keepGoing) {
+ lock.lock();
+ counts[threadIndex]++;
+ lock.unlock();
+ }
+ return;
+ }
+
while (keepGoing) {
lock.lock();
counts[threadIndex]++;
+ usleep(microsecondsInCriticalSection);
lock.unlock();
}
});
@@ -85,8 +96,8 @@
sleep(secondsPerTest);
+ keepGoing = false;
lock.lock();
- keepGoing = false;
dataLog(name, ": ");
CommaPrinter comma;
@@ -106,9 +117,10 @@
{
WTF::initializeThreading();
- if (argc != 4
+ if (argc != 5
|| sscanf(argv[2], "%u", &numThreads) != 1
- || sscanf(argv[3], "%lf", &secondsPerTest) != 1)
+ || sscanf(argv[3], "%lf", &secondsPerTest) != 1
+ || sscanf(argv[4], "%u", µsecondsInCriticalSection) != 1)
usage();
runEverything<Benchmark>(argv[1]);