[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:05 PDT 2026
================
@@ -549,6 +549,19 @@ static Loop *getTopMostExitingLoop(const BasicBlock *ExitBB,
return TopMost;
}
+/// Check if a loop contains convergent or token operations.
+static bool loopContainsConvergentOrTokenOp(const Loop &L) {
+ for (const auto *BB : L.blocks())
+ for (const auto &I : *BB) {
+ if (I.getType()->isTokenTy() && I.isUsedOutsideOfBlock(BB))
+ return true;
+ if (const auto *CB = dyn_cast<CallBase>(&I))
+ if (CB->isConvergent())
+ return true;
+ }
+ return false;
----------------
amehsan wrote:
My understanding of `convergent` and `TokenTy` is limited, so please correct me if I miss something here.
You are checking all the instructions in the loop. IIUC we only need to check the instructions that come before the branch and also instructions in the Latch:
The problem occurs when a convergent call is executed before the transformation and not executed after the transformation. For instructions not in the latch and not before the branch the following is correct: Any thread for which the condition is true will execute these instructions before and after the transformation. Any thread for which the condition is false will not execute these instructions before and after the transformation.
I don't understand why we need to worry about `TokenTy` and do not see anything in the description or your testcase. Could you clarify/
https://github.com/llvm/llvm-project/pull/207047
More information about the llvm-commits
mailing list