[llvm] [SimpleLoopUnswitch] Don't latch-redirect trivial unswitch across convergent ops (PR #207047)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 22:22:06 PDT 2026
================
@@ -603,9 +616,14 @@ static bool unswitchTrivialBranch(Loop &L, CondBrInst &BI, DominatorTree &DT,
}
bool ModifiedBranch = false;
+ // we can't redirect the branch to the exit block if the loop latch has side
+ // effects or if the loop exit PHIs are not loop invariant. We also can't
+ // redirect the branch to the exit block if the loop contains convergent or
+ // token operations, as this would violate the semantics of those operations.
if (LatchIdx && areLoopExitPHIsLoopInvariant(L, *LoopLatch, *ULExit) &&
!llvm::any_of(*LoopLatch,
- [](Instruction &I) { return I.mayHaveSideEffects(); })) {
+ [](Instruction &I) { return I.mayHaveSideEffects(); }) &&
+ !loopContainsConvergentOrTokenOp(L)) {
----------------
amehsan wrote:
I believe this bug is not limited to the new trivial unswitching cases that we catch after #204934 , so you need to add proper checks elsewhere too.
Even before that patch this bug exists: if you have a convergent call before the branch and that branch is trivially unswitched, this bug will be reproducible.
https://github.com/llvm/llvm-project/pull/207047
More information about the llvm-commits
mailing list