[llvm-branch-commits] [llvm] [SimplifyCFG] Avoid threading loop-header branches in convergent functions (PR #204958)
Hongyu Chen via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jun 25 07:09:19 PDT 2026
================
@@ -3713,7 +3713,10 @@ bool SimplifyCFGOpt::foldCondBranchOnValueKnownInPredecessor(CondBrInst *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.
- if (Options.NeedCanonicalLoop && is_contained(LoopHeaders, BI->getParent()))
+ // Also avoid threading loop headers in convergent functions, since changing
+ // the branch structure can change the dynamic instances of convergent ops.
+ if ((Options.NeedCanonicalLoop || BI->getFunction()->isConvergent()) &&
+ is_contained(LoopHeaders, BI->getParent()))
----------------
XChy wrote:
AFAIK, JumpThreading performs similar transformations and uses `LoopHeaders` too. But it is just for heuristics.
https://github.com/llvm/llvm-project/pull/204958
More information about the llvm-branch-commits
mailing list