[Mlir-commits] [mlir] ba55ef3 - [mlir][IR] Fix `RewriterBase::replaceUsesWithIf(ValueRange)` in dialect conversion (#172883)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Dec 19 08:19:41 PST 2025


Author: Babak
Date: 2025-12-19T17:19:37+01:00
New Revision: ba55ef32ef9214804b421090767a27f14abd9439

URL: https://github.com/llvm/llvm-project/commit/ba55ef32ef9214804b421090767a27f14abd9439
DIFF: https://github.com/llvm/llvm-project/commit/ba55ef32ef9214804b421090767a27f14abd9439.diff

LOG: [mlir][IR] Fix `RewriterBase::replaceUsesWithIf(ValueRange)` in dialect conversion (#172883)

`ConversionPatternRewriter::replaceUsesWithIf` does not support the
`allUsesReplaced` flag and asserts that it's not set. However the
`ValueRange` overload of `RewriterBase::replaceUsesWithIf` always passes
this flag when calling the virtual overload of `replaceUsesWithIf`. This
means calls made to `RewriterBase::replaceUsesWithIf` from a
`ConversionPattern` crash, whether the `allUsesReplaced` flag is set or
not.

This change tweaks `RewriterBase::replaceUsesWithIf` to only pass that
flag if the callee has set it.

Added: 
    

Modified: 
    mlir/lib/IR/PatternMatch.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/PatternMatch.cpp b/mlir/lib/IR/PatternMatch.cpp
index 8bc0fcd4517d8..226e4e518d3e0 100644
--- a/mlir/lib/IR/PatternMatch.cpp
+++ b/mlir/lib/IR/PatternMatch.cpp
@@ -278,9 +278,9 @@ void RewriterBase::replaceUsesWithIf(ValueRange from, ValueRange to,
   assert(from.size() == to.size() && "incorrect number of replacements");
   bool allReplaced = true;
   for (auto it : llvm::zip_equal(from, to)) {
-    bool r;
+    bool r = true;
     replaceUsesWithIf(std::get<0>(it), std::get<1>(it), functor,
-                      /*allUsesReplaced=*/&r);
+                      /*allUsesReplaced=*/allUsesReplaced ? &r : nullptr);
     allReplaced &= r;
   }
   if (allUsesReplaced)


        


More information about the Mlir-commits mailing list