[PATCH] D119815: [FuncSpec]Save compilation time by caching uses of replaced value

Bin Cheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 15 01:08:34 PST 2022


bin.cheng created this revision.
bin.cheng added reviewers: snehasish, SjoerdMeijer, ChuanqiXu.
Herald added subscribers: ormris, hiraditya.
bin.cheng requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Hi,
This patch saves compilation time by caching uses of replace value.

We only need to do propagation on use instructions of the original value, rather than the replacing const value which might have lots of irrelavant uses.  As an example, it improves LTO compilation time by 3~4% for one example case in speccpu2017 with Function Specialization enabled.

Thanks,
bin


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119815

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
@@ -344,12 +344,17 @@
     LLVM_DEBUG(dbgs() << "FnSpecialization: Replacing " << *V
                       << "\nFnSpecialization: with " << *Const << "\n");
 
-    V->replaceAllUsesWith(Const);
-
-    for (auto *U : Const->users())
+    // Cache uses so that we can do propagation after replacing it with const.
+    SmallVector<Instruction *, 8> UseInsts;
+    for (auto *U : V->users())
       if (auto *I = dyn_cast<Instruction>(U))
         if (Solver.isBlockExecutable(I->getParent()))
-          Solver.visit(I);
+          UseInsts.push_back(I);
+
+    V->replaceAllUsesWith(Const);
+
+    for (auto *I : UseInsts)
+      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: D119815.408747.patch
Type: text/x-patch
Size: 987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220215/999a5777/attachment.bin>


More information about the llvm-commits mailing list