Title: [287203] trunk/Source/_javascript_Core
Revision
287203
Author
[email protected]
Date
2021-12-17 13:05:42 -0800 (Fri, 17 Dec 2021)

Log Message

Support WasmAddress in B3 CSE
https://bugs.webkit.org/show_bug.cgi?id=234051
<rdar://problem/86552957>

Reviewed by Filip Pizlo and Yusuke Suzuki.

This patch adds support in B3's CSE phase to handle WasmAddressValue computations.
The reason this can't partake in pure CSE is that WasmAddressValue reads pinned.
To support this, we keep track of which blocks write pinned. If we're trying to
replace a value V2 with V1 because it appears there is a redundancy, we check if
any paths from V1 to V2 write pinned. If none do, we proceed with the replacement.

* b3/B3EliminateCommonSubexpressions.cpp:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (287202 => 287203)


--- trunk/Source/_javascript_Core/ChangeLog	2021-12-17 20:55:28 UTC (rev 287202)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-12-17 21:05:42 UTC (rev 287203)
@@ -1,3 +1,19 @@
+2021-12-17  Saam Barati  <[email protected]>
+
+        Support WasmAddress in B3 CSE
+        https://bugs.webkit.org/show_bug.cgi?id=234051
+        <rdar://problem/86552957>
+
+        Reviewed by Filip Pizlo and Yusuke Suzuki.
+
+        This patch adds support in B3's CSE phase to handle WasmAddressValue computations.
+        The reason this can't partake in pure CSE is that WasmAddressValue reads pinned.
+        To support this, we keep track of which blocks write pinned. If we're trying to
+        replace a value V2 with V1 because it appears there is a redundancy, we check if
+        any paths from V1 to V2 write pinned. If none do, we proceed with the replacement.
+
+        * b3/B3EliminateCommonSubexpressions.cpp:
+
 2021-12-17  Zan Dobersek  <[email protected]>
 
         [RISCV64] Implement linking and patching support in RISCV64Assembler

Modified: trunk/Source/_javascript_Core/b3/B3EliminateCommonSubexpressions.cpp (287202 => 287203)


--- trunk/Source/_javascript_Core/b3/B3EliminateCommonSubexpressions.cpp	2021-12-17 20:55:28 UTC (rev 287202)
+++ trunk/Source/_javascript_Core/b3/B3EliminateCommonSubexpressions.cpp	2021-12-17 21:05:42 UTC (rev 287203)
@@ -42,6 +42,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/ListDump.h>
 #include <wtf/RangeSet.h>
+#include <wtf/Scope.h>
 
 namespace JSC { namespace B3 {
 
@@ -144,10 +145,14 @@
 
     RangeSet<HeapRange> reads; // This only gets used for forward store elimination.
     RangeSet<HeapRange> writes; // This gets used for both load and store elimination.
-    bool fence;
+    bool fence { false };
+    bool writesPinned { false };
 
     MemoryValueMap storesAtHead;
     MemoryValueMap memoryValuesAtTail;
+
+    // This Maps x->y in "y = WasmAddress(@x)"
+    HashMap<Value*, Value*> m_candidateWasmAddressesAtTail;
 };
 
 class CSE {
@@ -188,6 +193,14 @@
 
                 if (memory)
                     data.memoryValuesAtTail.add(memory);
+
+                if (WasmAddressValue* wasmAddress = value->as<WasmAddressValue>())
+                    data.m_candidateWasmAddressesAtTail.add(wasmAddress->child(0), wasmAddress);
+
+                if (effects.writesPinned) {
+                    data.writesPinned = true;
+                    data.m_candidateWasmAddressesAtTail.clear();
+                }
             }
 
             if (B3EliminateCommonSubexpressionsInternal::verbose)
@@ -237,15 +250,28 @@
 
         if (m_pureCSE.process(m_value, m_dominators)) {
             ASSERT(!m_value->effects().writes);
+            ASSERT(!m_value->effects().writesPinned);
             m_changed = true;
             return;
         }
 
+        if (WasmAddressValue* wasmAddress = m_value->as<WasmAddressValue>()) {
+            processWasmAddressValue(wasmAddress);
+            return;
+        }
+
+        Effects effects = m_value->effects();
+
+        if (effects.writesPinned) {
+            m_data.writesPinned = true;
+            m_data.m_candidateWasmAddressesAtTail.clear();
+        }
+
         MemoryValue* memory = m_value->as<MemoryValue>();
         if (memory && processMemoryBeforeClobber(memory))
             return;
 
-        if (HeapRange writes = m_value->effects().writes)
+        if (HeapRange writes = effects.writes)
             clobber(m_data, writes);
         
         if (memory)
@@ -694,6 +720,59 @@
         return matches;
     }
 
+    void processWasmAddressValue(WasmAddressValue* wasmAddress)
+    {
+        Value* ptr = wasmAddress->child(0);
+
+        if (Value* replacement = m_data.m_candidateWasmAddressesAtTail.get(ptr)) {
+            wasmAddress->replaceWithIdentity(replacement);
+            m_changed = true;
+            return;
+        }
+
+        auto addPtrOnScopeExit = makeScopeExit([&] {
+            m_data.m_candidateWasmAddressesAtTail.add(ptr, wasmAddress);
+        });
+
+        if (m_data.writesPinned) {
+            // Someone before us in this block wrote to pinned. So we have no
+            // hope of finding a match if the above search failed.
+            return;
+        }
+
+        Value* candidateReplacement = nullptr;
+        BasicBlock* dominator = nullptr;
+        m_dominators.forAllStrictDominatorsOf(m_block, [&] (BasicBlock* block) {
+            if (candidateReplacement)
+                return;
+
+            if (Value* replacement = m_impureBlockData[block].m_candidateWasmAddressesAtTail.get(ptr)) {
+                candidateReplacement = replacement;
+                dominator = block;
+            }
+        });
+
+        if (!candidateReplacement)
+            return;
+
+        BlockWorklist worklist;
+        worklist.pushAll(m_block->predecessors());
+        while (BasicBlock* block = worklist.pop()) {
+            if (block == dominator)
+                break;
+            if (m_impureBlockData[block].writesPinned) {
+                candidateReplacement = nullptr;
+                break;
+            }
+            worklist.pushAll(block->predecessors());
+        }
+
+        if (candidateReplacement) {
+            wasmAddress->replaceWithIdentity(candidateReplacement);
+            m_changed = true;
+        }
+    }
+
     Procedure& m_proc;
 
     Dominators& m_dominators;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to