[Mlir-commits] [mlir] [mlir] Avoid verifying live user in conversion diagnostic (PR #210566)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 18 19:14:01 PDT 2026
https://github.com/qyingwu created https://github.com/llvm/llvm-project/pull/210566
##Summary
Fixes #207350.
During dialect conversion, MLIR may emit an error for an unresolved materialization that remains live after conversion. The diagnostic also prints one existing live user.
That live user can be nested under IR that is temporarily not verifiable while conversion is in progress. In the issue reproducer, the live user is inside a `spirv.func`. Printing it without special flags causes the printer to verify the surrounding operation, which can enter SPIR-V verification on transient conversion IR and crash.
This patch prints the live user with `OpPrintingFlags().assumeVerified()` so the diagnostic path does not re-verify transient IR while reporting the conversion failure.
##Tests
```
ninja -C build mlir-opt FileCheck count not
build/bin/llvm-lit -v mlir/test/Transforms/test-legalize-erased-op-with-uses.mlir
build/bin/llvm-lit -v mlir/test/Transforms/test-legalize-type-conversion.mlir mlir/test/
Transforms/test-legalize-unknown-root.mlir mlir/test/Transforms/test-legalize-erased-op-with-uses.mlir
build/bin/llvm-lit -v mlir/test/Transforms
ninja -C build check-mlir
```
>From 4821f857074a82b620cc3a788e55652cbef25824 Mon Sep 17 00:00:00 2001
From: qyingwu <qiyingwu at utexas.edu>
Date: Sat, 18 Jul 2026 19:10:29 -0700
Subject: [PATCH] [mlir] Avoid verifying live user in conversion diagnostic
---
.../Transforms/Utils/DialectConversion.cpp | 6 ++++--
.../test-legalize-erased-op-with-uses.mlir | 21 ++++++++++++++++++-
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index c76e3808d3b37..9a0bffbc4e068 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3391,8 +3391,10 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
<< inputOperands.getTypes() << ") to ("
<< op.getResultTypes()
<< ") that remained live after conversion";
- diag.attachNote(op->getUsers().begin()->getLoc())
- << "see existing live user here: " << *op->getUsers().begin();
+ Operation *liveUser = *op->getUsers().begin();
+ diag.attachNote(liveUser->getLoc())
+ << "see existing live user here: "
+ << OpWithFlags(liveUser, OpPrintingFlags().assumeVerified());
return failure();
}
diff --git a/mlir/test/Transforms/test-legalize-erased-op-with-uses.mlir b/mlir/test/Transforms/test-legalize-erased-op-with-uses.mlir
index 031442b0ee2da..829ff2f183e53 100644
--- a/mlir/test/Transforms/test-legalize-erased-op-with-uses.mlir
+++ b/mlir/test/Transforms/test-legalize-erased-op-with-uses.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-legalize-unknown-root-patterns -verify-diagnostics
+// RUN: mlir-opt %s -test-legalize-unknown-root-patterns -split-input-file -verify-diagnostics
// Test that an error is emitted when an operation is marked as "erased", but
// has users that live across the conversion.
@@ -8,3 +8,22 @@ func.func @remove_all_ops(%arg0: i32) -> i32 {
// expected-note at below {{see existing live user here}}
return %0 : i32
}
+
+// -----
+
+// Test that diagnostics can print a live user under an op that is not
+// verifiable while the conversion is in progress.
+module {
+ spirv.func @remove_test_ops() -> i32 "None" {
+ %cst1_i32 = spirv.Constant 1 : i32
+ // expected-error at below {{failed to legalize unresolved materialization from () to ('i32') that remained live after conversion}}
+ %0 = test.with_bounds {smax = 0 : si32, smin = 0 : si32, umax = 0 : i32, umin = 0 : ui32} : i32
+ %1 = builtin.unrealized_conversion_cast %cst1_i32 : i32 to i32
+ // expected-note at below {{see existing live user here}}
+ %2 = spirv.IAdd %0, %1 : i32
+ %3 = builtin.unrealized_conversion_cast %2 : i32 to i32
+ %4 = test.reflect_bounds %3 : i32
+ %5 = builtin.unrealized_conversion_cast %4 : i32 to i32
+ spirv.ReturnValue %5 : i32
+ }
+}
More information about the Mlir-commits
mailing list