[llvm] [SimplifyCFG] Avoid threading for loop headers (PR #151142)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 29 08:27:11 PDT 2025
================
@@ -3604,15 +3605,23 @@ foldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
return false;
}
-static bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
- DomTreeUpdater *DTU,
- const DataLayout &DL,
- AssumptionCache *AC) {
+#include <iostream>
+
+bool SimplifyCFGOpt::foldCondBranchOnValueKnownInPredecessor(BranchInst *BI) {
+ // Note: If BB is a loop header then there is a risk that threading introduces
+ // a non-canonical loop by moving a back edge. So we avoid this optimization
+ // for loop headers if NeedCanonicalLoop is set.
+ bool InHeader = is_contained(LoopHeaders, BI->getParent());
----------------
nikic wrote:
Avoid the variable and move this behind the `&&` for short-circuiting. No need to do this linear scan if !NeedCanonicalLoop.
https://github.com/llvm/llvm-project/pull/151142
More information about the llvm-commits
mailing list