[Mlir-commits] [mlir] [mlir][gpu] Eliminate redundant gpu.barrier ops (PR #71575)

Lei Zhang llvmlistbot at llvm.org
Tue Nov 7 13:25:09 PST 2023


================
@@ -1139,6 +1139,34 @@ void ShuffleOp::build(OpBuilder &builder, OperationState &result, Value value,
         mode);
 }
 
+//===----------------------------------------------------------------------===//
+// BarrierOp
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+/// Remove gpu.barrier after gpu.barrier, the threads are already synchronized!
+struct EraseRedundantGpuBarrierOpPairs : public OpRewritePattern<BarrierOp> {
+public:
+  using OpRewritePattern::OpRewritePattern;
+
+  LogicalResult matchAndRewrite(BarrierOp op,
+                                PatternRewriter &rewriter) const final {
+    if (isa<BarrierOp>(op->getNextNode())) {
+      rewriter.eraseOp(op->getNextNode());
----------------
antiagainst wrote:

In patterns, typically we want to touch the current op under inspection. So this should delete the current node.

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


More information about the Mlir-commits mailing list