[llvm] [NFC] Move RemoveRedundantDbgInstrs outside of inner loop in JumpThreading (PR #123008)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 20:06:44 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: William Huang (huangjd)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/123008.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/JumpThreading.cpp (+7-6)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123008
More information about the llvm-commits
mailing list