Title: [141301] trunk/Source/_javascript_Core
Revision
141301
Author
[email protected]
Date
2013-01-30 13:02:20 -0800 (Wed, 30 Jan 2013)

Log Message

REGRESSION(140504): pure CSE no longer matches things, 10% regression on Kraken
https://bugs.webkit.org/show_bug.cgi?id=108366

Reviewed by Geoffrey Garen and Mark Hahnenberg.
        
This was a longstanding bug that was revealed by http://trac.webkit.org/changeset/140504.
Pure CSE requires that the Node::flags() that may affect the behavior of a node match,
when comparing a possibly redundant node to its possible replacement. It was doing this
by comparing Node::arithNodeFlags(), which as the name might appear to suggest, returns
just those flag bits that correspond to actual node behavior and not auxiliary things.
Unfortunately, Node::arithNodeFlags() wasn't actually masking off the irrelevant bits.
This worked prior to r140504 because CSE itself didn't mutate the flags, so there was a
very high probability that matching nodes would also have completely identical flag bits
(even the ones that aren't relevant to arithmetic behavior, like NodeDoesNotExit). But
r140504 moved one of CSE's side-tables (m_relevantToOSR) into a flag bit for quicker
access. These bits would be mutated as the CSE ran over a basic block, in such a way that
there was a very high probability that the possible replacement would already have the
bit set, while the redundant node did not have the bit set. Since Node::arithNodeFlags()
returned all of the bits, this would cause CSEPhase::pureCSE() to reject the match
almost every time.
        
The solution is to make Node::arithNodeFlags() do as its name suggests: only return those
flags that are relevant to arithmetic behavior. This patch introduces a new mask that
represents those bits, and includes NodeBehaviorMask and NodeBackPropMask, which are both
used for queries on Node::arithNodeFlags(), and both affect arithmetic code gen. None of
the other flags are relevant to Node::arithNodeFlags() since they either correspond to
information already conveyed by the opcode (like NodeResultMask, NodeMustGenerate,
NodeHasVarArgs, NodeClobbersWorld, NodeMightClobber) or information that doesn't affect
the result that the node will produce or any of the queries performed on the result of
Node::arithNodeFlags (NodeDoesNotExit and of course NodeRelevantToOSR).
        
This is a 10% speed-up on Kraken, undoing the regression from r140504.

* dfg/DFGNode.h:
(JSC::DFG::Node::arithNodeFlags):
* dfg/DFGNodeFlags.h:
(DFG):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (141300 => 141301)


--- trunk/Source/_javascript_Core/ChangeLog	2013-01-30 20:51:07 UTC (rev 141300)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-01-30 21:02:20 UTC (rev 141301)
@@ -1,3 +1,43 @@
+2013-01-30  Filip Pizlo  <[email protected]>
+
+        REGRESSION(140504): pure CSE no longer matches things, 10% regression on Kraken
+        https://bugs.webkit.org/show_bug.cgi?id=108366
+
+        Reviewed by Geoffrey Garen and Mark Hahnenberg.
+        
+        This was a longstanding bug that was revealed by http://trac.webkit.org/changeset/140504.
+        Pure CSE requires that the Node::flags() that may affect the behavior of a node match,
+        when comparing a possibly redundant node to its possible replacement. It was doing this
+        by comparing Node::arithNodeFlags(), which as the name might appear to suggest, returns
+        just those flag bits that correspond to actual node behavior and not auxiliary things.
+        Unfortunately, Node::arithNodeFlags() wasn't actually masking off the irrelevant bits.
+        This worked prior to r140504 because CSE itself didn't mutate the flags, so there was a
+        very high probability that matching nodes would also have completely identical flag bits
+        (even the ones that aren't relevant to arithmetic behavior, like NodeDoesNotExit). But
+        r140504 moved one of CSE's side-tables (m_relevantToOSR) into a flag bit for quicker
+        access. These bits would be mutated as the CSE ran over a basic block, in such a way that
+        there was a very high probability that the possible replacement would already have the
+        bit set, while the redundant node did not have the bit set. Since Node::arithNodeFlags()
+        returned all of the bits, this would cause CSEPhase::pureCSE() to reject the match
+        almost every time.
+        
+        The solution is to make Node::arithNodeFlags() do as its name suggests: only return those
+        flags that are relevant to arithmetic behavior. This patch introduces a new mask that
+        represents those bits, and includes NodeBehaviorMask and NodeBackPropMask, which are both
+        used for queries on Node::arithNodeFlags(), and both affect arithmetic code gen. None of
+        the other flags are relevant to Node::arithNodeFlags() since they either correspond to
+        information already conveyed by the opcode (like NodeResultMask, NodeMustGenerate,
+        NodeHasVarArgs, NodeClobbersWorld, NodeMightClobber) or information that doesn't affect
+        the result that the node will produce or any of the queries performed on the result of
+        Node::arithNodeFlags (NodeDoesNotExit and of course NodeRelevantToOSR).
+        
+        This is a 10% speed-up on Kraken, undoing the regression from r140504.
+
+        * dfg/DFGNode.h:
+        (JSC::DFG::Node::arithNodeFlags):
+        * dfg/DFGNodeFlags.h:
+        (DFG):
+
 2013-01-29  Mark Hahnenberg  <[email protected]>
 
         Structure::m_outOfLineCapacity is unnecessary

Modified: trunk/Source/_javascript_Core/dfg/DFGNode.h (141300 => 141301)


--- trunk/Source/_javascript_Core/dfg/DFGNode.h	2013-01-30 20:51:07 UTC (rev 141300)
+++ trunk/Source/_javascript_Core/dfg/DFGNode.h	2013-01-30 21:02:20 UTC (rev 141301)
@@ -442,7 +442,7 @@
     // to know if it can speculate on negative zero.
     NodeFlags arithNodeFlags()
     {
-        NodeFlags result = m_flags;
+        NodeFlags result = m_flags & NodeArithFlagsMask;
         if (op() == ArithMul || op() == ArithDiv || op() == ArithMod)
             return result;
         return result & ~NodeNeedsNegZero;

Modified: trunk/Source/_javascript_Core/dfg/DFGNodeFlags.h (141300 => 141301)


--- trunk/Source/_javascript_Core/dfg/DFGNodeFlags.h	2013-01-30 20:51:07 UTC (rev 141300)
+++ trunk/Source/_javascript_Core/dfg/DFGNodeFlags.h	2013-01-30 21:02:20 UTC (rev 141301)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -61,6 +61,8 @@
 #define NodeUsedAsInt            0x1000 // The result of this computation is known to be used in a context that prefers, but does not require, integer values.
 #define NodeUsedAsIntLocally     0x2000 // Same as NodeUsedAsInt, but within the same basic block.
 
+#define NodeArithFlagsMask       (NodeBehaviorMask | NodeBackPropMask)
+
 #define NodeDoesNotExit          0x4000 // This flag is negated to make it natural for the default to be that a node does exit.
 
 #define NodeRelevantToOSR        0x8000
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to