[llvm] [NFC][SPIRV] Move `SPIRVStripConvergenceIntrinsics` to Utils (PR #188537)

Deric C. via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 14:54:59 PDT 2026


================
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass strips convergence intrinsics and convergencectrl operand bundles,
+// as those are only useful when modifying the CFG during IR passes.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Utils/StripConvergenceIntrinsics.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Transforms/Utils.h"
+
+using namespace llvm;
+
+static bool stripConvergenceIntrinsics(Function &F) {
+  bool Changed = false;
+
+  // Iterate in reverse order so that uses of convergence tokens are removed
+  // before the convergence intrinsics that define them.
+  for (BasicBlock &BB : reverse(F)) {
----------------
Icohedron wrote:

This assumption isn't necessarily always true; basic blocks can appear in any order and define variables used by basic blocks that appear before it.
```llvm
 define void @reversed_block_order() convergent {
 entry:
   br label %B

 A:
   call void @convergent_callee() [ "convergencectrl"(token %tok) ]
   ret void

 B:
   %tok = call token @llvm.experimental.convergence.anchor()
   br label %A
 }
```
`%tok` would be removed even though it is used by `call void @convergent_callee() [ "convergencectrl"(token %tok) ]` later.

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


More information about the llvm-commits mailing list