[Mlir-commits] [mlir] [MLIR][XeVM] Wrap in-place op modifications in modifyOpInPlace in LLVMLoadStoreToOCLPattern (PR #188952)

Mehdi Amini llvmlistbot at llvm.org
Fri Mar 27 03:26:47 PDT 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/188952

LLVMLoadStoreToOCLPattern::matchAndRewrite was calling op->removeAttr() and op->setOperand() directly without going through the rewriter API. This caused MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS to report "expected pattern to replace the root operation or modify it in place".

Fix: wrap the direct mutations in rewriter.modifyOpInPlace().

Assisted-by: Claude Code
Fix a failure present with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON.

>From c44e6d30bae32658a1531424614d1aa7b5b661ae Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Thu, 26 Mar 2026 15:57:47 -0700
Subject: [PATCH] [MLIR][XeVM] Wrap in-place op modifications in
 modifyOpInPlace in LLVMLoadStoreToOCLPattern

LLVMLoadStoreToOCLPattern::matchAndRewrite was calling op->removeAttr() and
op->setOperand() directly without going through the rewriter API. This caused
MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS to report "expected pattern to
replace the root operation or modify it in place".

Fix: wrap the direct mutations in rewriter.modifyOpInPlace().

Assisted-by: Claude Code
Fix a failure present with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON.
---
 mlir/lib/Conversion/XeVMToLLVM/XeVMToLLVM.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Conversion/XeVMToLLVM/XeVMToLLVM.cpp b/mlir/lib/Conversion/XeVMToLLVM/XeVMToLLVM.cpp
index 75888ba79447a..05485e6257915 100644
--- a/mlir/lib/Conversion/XeVMToLLVM/XeVMToLLVM.cpp
+++ b/mlir/lib/Conversion/XeVMToLLVM/XeVMToLLVM.cpp
@@ -915,7 +915,7 @@ class LLVMLoadStoreToOCLPattern : public OpConversionPattern<OpType> {
     std::optional<ArrayAttr> optCacheControls =
         getCacheControlMetadata(rewriter, op);
     if (!optCacheControls) {
-      op->removeAttr("cache_control");
+      rewriter.modifyOpInPlace(op, [&]() { op->removeAttr("cache_control"); });
       return success();
     }
 
@@ -929,8 +929,10 @@ class LLVMLoadStoreToOCLPattern : public OpConversionPattern<OpType> {
         rewriter, op->getLoc(), ptr, *optCacheControls, moduleOp);
 
     // Replace the pointer operand with the annotated one.
-    op->setOperand(ptrIdx, annotatedPtr);
-    op->removeAttr("cache_control");
+    rewriter.modifyOpInPlace(op, [&]() {
+      op->setOperand(ptrIdx, annotatedPtr);
+      op->removeAttr("cache_control");
+    });
     return success();
   }
 };



More information about the Mlir-commits mailing list