[llvm-branch-commits] [llvm] [SimplifyCFG] Avoid threading loop-header branches in convergent functions (PR #204958)

Shilei Tian via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jun 25 06:50:07 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()))
----------------
shiltian wrote:

Thanks for the insight. Let me think about it more.

https://github.com/llvm/llvm-project/pull/204958


More information about the llvm-branch-commits mailing list