[llvm] [NFC] Move RemoveRedundantDbgInstrs outside of inner loop in JumpThreading (PR #123008)
William Huang via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 20:06:07 PST 2025
https://github.com/huangjd created https://github.com/llvm/llvm-project/pull/123008
This cleanup action only needs to be performed once when the entire optimization is converged. Doing it in every iteration has a very high time-complexity, as it queries every dbg value in a dense map
Compare before and after for one internal source file with many basic blocks
![image](https://github.com/user-attachments/assets/1dac76a9-a974-4068-9aa1-4041f963fa8e)
![image](https://github.com/user-attachments/assets/73ea2ef1-d1f4-4064-8826-8c13fb539b8d)
>90% reduction in this extreme case.
>From 8aecbedfe3cd2df357007b498f861a3210b2685d Mon Sep 17 00:00:00 2001
From: William Huang <williamjhuang at google.com>
Date: Tue, 14 Jan 2025 22:46:02 -0500
Subject: [PATCH] [NFC] Move RemoveRedundantDbgInstrs outside of inner loop in
JumpThreading
This cleanup action only needs to be performed once when the entire optimization
is converged. Doing it in every iteration has a very high
time-complexity.
---
llvm/lib/Transforms/Scalar/JumpThreading.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 300a564e222e16..aae54d9763789b 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -330,11 +330,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
while (processBlock(&BB)) // Thread all of the branches we can over BB.
Changed = ChangedSinceLastAnalysisUpdate = true;
- // Jump threading may have introduced redundant debug values into BB
- // which should be removed.
- if (Changed)
- RemoveRedundantDbgInstrs(&BB);
-
// Stop processing BB if it's the entry or is now deleted. The following
// routines attempt to eliminate BB and locating a suitable replacement
// for the entry is non-trivial.
@@ -366,7 +361,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
// detect and transform nested loops later.
!LoopHeaders.count(&BB) && !LoopHeaders.count(Succ) &&
TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU.get())) {
- RemoveRedundantDbgInstrs(Succ);
// BB is valid for cleanup here because we passed in DTU. F remains
// BB's parent until a DTU->getDomTree() event.
LVI->eraseBlock(&BB);
@@ -377,6 +371,13 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
EverChanged |= Changed;
} while (Changed);
+ // Jump threading may have introduced redundant debug values into BB which
+ // should be removed.
+ if (EverChanged)
+ for (auto &BB : *F) {
+ RemoveRedundantDbgInstrs(&BB);
+ }
+
LoopHeaders.clear();
return EverChanged;
}
More information about the llvm-commits
mailing list