[Mlir-commits] [mlir] [mlir][amdgpu] Remove redundant barriers (PR #175436)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Jan 11 06:17:55 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Ivan Butygin (Hardcode84)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/175436.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td (+5-4)
- (modified) mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp (+19)
- (modified) mlir/test/Dialect/AMDGPU/canonicalize.mlir (+12)
``````````diff
diff --git a/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td b/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td
index 7a8cd89f886a7..bf0711cc27922 100644
--- a/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td
+++ b/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td
@@ -41,7 +41,7 @@ def AMDGPU_Dialect : Dialect {
have chipset-specific differences that can be abstracted over in a useful way.
To give some concrete examples:
-
+
- `amdgpu.mfma` and `amdgpu.wmma` exist in order to make a large set of
intrinsics more compatible with the MLIR type system (such as by allowing
8-bit float vectors to be passed as `vector<N x f8E4M3FN>` or
@@ -105,7 +105,7 @@ def AMDGPU_Dialect : Dialect {
what it does and have found the keywords they'll need for more detail.
Operation documentation should include usage examples.
-
+
Note that this dialect uses LLVM's gfx numbers to refer to individual
architectures/chipsets and not product names or codenames.
}];
@@ -974,6 +974,7 @@ def AMDGPU_LDSBarrierOp : AMDGPU_Op<"lds_barrier"> {
breakpoints set on variables) when debugging.
}];
let assemblyFormat = "attr-dict";
+ let hasCanonicalizer = 1;
}
def AMDGPU_SchedBarrierOpOpt : I32BitEnumAttr<"sched_barrier_opt_enum",
@@ -1285,7 +1286,7 @@ def AMDGPU_SparseMFMAOp :
`vector<2xi16>` (two 16-bit indices).
The `cbsz` and `abid` parameters are repurposed to select the index set.
- If `cbsz == 0`, then `abid[1:0]` selects which index set to use.
+ If `cbsz == 0`, then `abid[1:0]` selects which index set to use.
If `cbsz != 0`, then the very first is selected.
Example:
@@ -1473,7 +1474,7 @@ def AMDGPU_ScaledWMMAOp
number of scales required for each matrix is determined by:
num_scales_A = (M × K) / block_size
num_scales_B = (N × K) / block_size
-
+
The index attributes (`a_first_scale_lane`, `b_first_scale_lane`) select
which lane to start reading scale values from (0 or 16):
- For block size 32, 32 lanes across a single wave are used for the scale
diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
index 787248f9f339e..feeedf2ddb84e 100644
--- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
+++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
@@ -773,6 +773,25 @@ LogicalResult PermlaneSwapOp::verify() {
return success();
}
+namespace {
+
+/// Remove amdgpu.lds_barrier after amdgpu.lds_barrier.
+LogicalResult eraseRedundantLDSBarrierOps(LDSBarrierOp op,
+ PatternRewriter &rewriter) {
+ if (isa_and_nonnull<LDSBarrierOp>(op->getNextNode())) {
+ rewriter.eraseOp(op);
+ return success();
+ }
+ return failure();
+}
+
+} // namespace
+
+void LDSBarrierOp::getCanonicalizationPatterns(RewritePatternSet &results,
+ MLIRContext *context) {
+ results.add(eraseRedundantLDSBarrierOps);
+}
+
//===----------------------------------------------------------------------===//
// MemoryCounterWaitOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/AMDGPU/canonicalize.mlir b/mlir/test/Dialect/AMDGPU/canonicalize.mlir
index cff1d3f2ac1fd..052fabfb300bb 100644
--- a/mlir/test/Dialect/AMDGPU/canonicalize.mlir
+++ b/mlir/test/Dialect/AMDGPU/canonicalize.mlir
@@ -280,3 +280,15 @@ func.func @fuse_memory_counter_wait_not_adjacent() {
amdgpu.memory_counter_wait load(4) store(3) ds(2) exp(1)
return
}
+
+// -----
+
+// Erase duplicate barriers.
+// CHECK-LABEL: func @erase_barriers
+// CHECK-NEXT: amdgpu.lds_barrier
+// CHECK-NEXT: return
+func.func @erase_barriers() {
+ amdgpu.lds_barrier
+ amdgpu.lds_barrier
+ return
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/175436
More information about the Mlir-commits
mailing list