[Mlir-commits] [mlir] [mlir][AMDGPU] Canonicalize masks on global_load_async_to_lds (PR #197280)

Erick Ochoa Lopez llvmlistbot at llvm.org
Tue May 12 12:52:32 PDT 2026


================
@@ -1065,6 +1065,31 @@ LogicalResult GlobalLoadAsyncToLDSOp::verify() {
   return success();
 }
 
+static LogicalResult
+foldGlobalLoadAsyncToLDSConstantMask(GlobalLoadAsyncToLDSOp op,
+                                     PatternRewriter &rewriter) {
+  Value mask = op.getMask();
+  if (!mask)
+    return failure();
+
+  APInt maskValue;
+  if (!matchPattern(mask, m_ConstantInt(&maskValue)))
+    return failure();
+
+  if (maskValue.isZero()) {
+    rewriter.eraseOp(op);
+    return success();
+  }
+
+  rewriter.modifyOpInPlace(op, [&]() { op.getMaskMutable().clear(); });
+  return success();
+}
+
+void GlobalLoadAsyncToLDSOp::getCanonicalizationPatterns(
+    RewritePatternSet &results, MLIRContext *context) {
+  results.add(foldGlobalLoadAsyncToLDSConstantMask);
+}
----------------
amd-eochoalo wrote:

I would split this into two patterns, one for all-zeros in canonicalization and one for all-ones in a fold.

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


More information about the Mlir-commits mailing list