From dfec0b3053b9d433fa3770ff31bc540406db4ba8 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Tue, 15 Feb 2022 16:51:04 +0800 Subject: [PATCH] [FuncSpec] Save compilation time by caching uses for propagation 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. This is done by caching uses before replacing. Differential Revision: https://reviews.llvm.org/D119815 --- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp index 9b6246b..832fa46 100644 --- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -344,12 +344,17 @@ public: LLVM_DEBUG(dbgs() << "FnSpecialization: Replacing " << *V << "\nFnSpecialization: with " << *Const << "\n"); - V->replaceAllUsesWith(Const); - - for (auto *U : Const->users()) + // Record uses of V to avoid visiting irrelevant uses of const later. + SmallVector UseInsts; + for (auto *U : V->users()) if (auto *I = dyn_cast(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(V)) { -- 2.7.4