[llvm] [IndVarSimplify] Fix `IndVarSimplify` to skip on unfolding predicates when the loop contains control convergence operations. (PR #165643)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 02:01:01 PDT 2025
================
@@ -1859,6 +1859,37 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
}
}
+ // If the loop body uses a convergence token defined within the loop, skip
+ // predication. This is to avoid changing the convergence behavior of the
+ // loop.
+ SmallVector<BasicBlock *, 16> blocks = ExitingBlocks;
+ SmallVector<Value *, 16> tokens = {};
+ size_t index = 0; // Assume Exiting Blocks are sorted.
+ while (index < blocks.size()) {
+ BasicBlock *BB = blocks[index];
+ index++;
+ const auto exitingBlockName = BB->getName();
+ for (Instruction &I : *BB) {
+ // Check if the instruction uses any convergence tokens.
+ if (auto *CB = dyn_cast<CallBase>(&I);
+ CB && !isa<ConvergenceControlInst>(&I)) {
+ auto token = CB->getConvergenceControlToken();
+ if (token && llvm::is_contained(tokens, token)) {
+ return false;
+ }
+ }
+ if (isa<ConvergenceControlInst>(&I)) {
+ tokens.push_back(cast<Value>(&I));
+ }
+ }
+
+ for (BasicBlock *Succ : successors(BB)) {
----------------
nikic wrote:
This is very inefficient. It would make more sense to look for any convergence control tokens defined in the loop and inspect their users. Instead of inspecting the entire function reachable from the loop exit.
https://github.com/llvm/llvm-project/pull/165643
More information about the llvm-commits
mailing list