[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
Wed Oct 13 04:53:06 PDT 2021


duck-37 updated this revision to Diff 379343.
duck-37 added a comment.

Make sure not to diff off of a local branch instead of main.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111661/new/

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,17 @@
         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.
+    SmallVector<Instruction *, 8> ReplacedUsers;
+    V->replaceUsesWithIf(Const, [&](auto &U) {
+      if (auto *I = dyn_cast<Instruction>(U.getUser()))
         if (Solver.isBlockExecutable(I->getParent()))
-          Solver.visit(I);
+          ReplacedUsers.push_back(I);
+      return true;
+    });
+    for (auto *I : ReplacedUsers)
+      Solver.visit(I);
 
     // Remove the instruction from Block and Solver.
     if (auto *I = dyn_cast<Instruction>(V)) {


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


More information about the llvm-commits mailing list