[llvm] [LoopFusion] Do not fuse loops containing convergent operations (PR #203460)

Ehsan Amiri via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 06:04:31 PDT 2026


================
@@ -203,6 +204,16 @@ struct FusionCandidate {
                                  "Loop contains an atomic access");
           return;
         }
+        // A convergent operation requires the set of threads executing it to be
+        // unchanged; fusion moves it into a different loop, so reject the
+        // candidate. See LangRef on the 'convergent' attribute.
+        if (const auto *CB = dyn_cast<CallBase>(&I); CB && CB->isConvergent()) {
+          invalidate();
+          ++ContainsConvergentOp;
+          reportInvalidCandidate("ContainsConvergentOp",
+                                 "Loop contains a convergent operation");
+          return;
+        }
----------------
amehsan wrote:

if there is any function call in the loop we have to disable fusion unless we can prove safety. It is interesting that we missed that. I would suggest for now just check existence of `CallBase` and drop the check for `convergent`

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


More information about the llvm-commits mailing list