[PATCH] D153561: [SCCPSolver] Speed up SCCPSolver by avoiding repeated work list elements

Tamás Danyluk via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 08:28:26 PDT 2023


tdanyluk created this revision.
tdanyluk added reviewers: george.karpenkov, labrinea, llvm-commits.
Herald added a subscriber: hiraditya.
Herald added a project: All.
tdanyluk requested review of this revision.
Herald added a project: LLVM.

If a value is already the last element of the worklist, then I think that we don't have to add it again, it is not needed to process it repeatedly.

For some long Triton-generated LLVM IR, this can cause a ~100x speedup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153561

Files:
  llvm/lib/Transforms/Utils/SCCPSolver.cpp


Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -838,9 +838,16 @@
 }
 
 void SCCPInstVisitor::pushToWorkList(ValueLatticeElement &IV, Value *V) {
-  if (IV.isOverdefined())
-    return OverdefinedInstWorkList.push_back(V);
-  InstWorkList.push_back(V);
+  if (IV.isOverdefined()) {
+    if (OverdefinedInstWorkList.empty() ||
+        OverdefinedInstWorkList.back() != V) {
+      OverdefinedInstWorkList.push_back(V);
+    }
+    return;
+  }
+  if (InstWorkList.empty() || InstWorkList.back() != V) {
+    InstWorkList.push_back(V);
+  }
 }
 
 void SCCPInstVisitor::pushToWorkListMsg(ValueLatticeElement &IV, Value *V) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153561.533618.patch
Type: text/x-patch
Size: 784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230622/45772f19/attachment.bin>


More information about the llvm-commits mailing list