[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 05:01:52 PDT 2021


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

Make sure `replaceAllUsesWith` is also removed.


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
@@ -301,12 +301,18 @@
       return false;
     auto *Const =
         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.379345.patch
Type: text/x-patch
Size: 1073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211013/cfa308c2/attachment.bin>


More information about the llvm-commits mailing list