[PATCH] D111661: [FuncSpec] Only visit uses of the instruction instead of every constant use.

duk via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 12 10:42:46 PDT 2021


duck-37 created this revision.
duck-37 added a reviewer: SjoerdMeijer.
Herald added subscribers: snehasish, ormris, hiraditya.
duck-37 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This drastically reduces the time this pass takes on larger modules (15 minutes to 30 seconds on a 500MB LTO module I'm working with)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111661

Files:
  llvm/lib/Transforms/IPO/FunctionSpecialization.cpp


Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -303,10 +303,14 @@
         isConstant(IV) ? Solver.getConstant(IV) : UndefValue::get(V->getType());
     V->replaceAllUsesWith(Const);
 
-    for (auto *U : Const->users())
-      if (auto *I = dyn_cast<Instruction>(U))
+    // Using replaceUsesWithIf is probably the easiest way to do this without
+    // duplicating code.
+    V->replaceUsesWithIf(Const, [&](auto &U) {
+      if (auto *I = dyn_cast<Instruction>(U.getUser()))
         if (Solver.isBlockExecutable(I->getParent()))
           Solver.visit(I);
+      return true;
+    });
 
     // Remove the instruction from Block and Solver.
     if (auto *I = dyn_cast<Instruction>(V)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111661.379108.patch
Type: text/x-patch
Size: 885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211012/bc6cc12b/attachment.bin>


More information about the llvm-commits mailing list