[Mlir-commits] [mlir] [mlir] Add missing materialization function diag for dialect convertion (PR #207689)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jul 6 02:44:42 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-arith

Author: lonely eagle (linuxlonelyeagle)

<details>
<summary>Changes</summary>

This Patch adds more precise diagnostics for when a pass is missing a target/source materialization function, making it easier to locate the issue in the pass.

---
Full diff: https://github.com/llvm/llvm-project/pull/207689.diff


3 Files Affected:

- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+11) 
- (modified) mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir (+2-2) 
- (modified) mlir/test/Transforms/test-legalize-type-conversion.mlir (+10-10) 


``````````diff
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index c76e3808d3b37..a27fcc888f1eb 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3383,6 +3383,17 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
       rewriter.replaceOp(op, newMaterialization);
       return success();
     }
+    StringRef direction =
+        info.getMaterializationKind() == MaterializationKind::Target ? "target"
+                                                                     : "source";
+    InFlightDiagnostic diag = op.emitError()
+                              << "miss " << direction
+                              << " materialization function from ("
+                              << inputOperands.getTypes() << ") to ("
+                              << op.getResultTypes() << ")";
+    diag.attachNote(op->getUsers().begin()->getLoc())
+        << "require this materialization is here";
+    return failure();
   }
 
   InFlightDiagnostic diag = op->emitError()
diff --git a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
index 44f09b920ed4f..6be6f4f04e5d5 100644
--- a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
+++ b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
@@ -45,9 +45,9 @@ func.func @unsupported_argument_type(%arg0: vector<4xi128>) -> vector<4xi64> {
 
 // Ensure this case not crash
 func.func @unsupported_vector(%arg0: vector<2xi1>) {
-  // expected-error at +1 {{failed to legalize unresolved materialization from ('vector<2x2xi32>') to ('vector<2xi64>') that remained live after conversion}}
+  // expected-error at +1 {{miss source materialization function from ('vector<2x2xi32>') to ('vector<2xi64>')}}
   %cst_0 = arith.constant dense<0> : vector<2xi64>
-  // expected-note at +1 {{see existing live user here}}
+  // expected-note at +1 {{require this materialization is here}}
   %0 = vector.mask %arg0 { vector.multi_reduction <xor>, %cst_0, %cst_0 [] : vector<2xi64> to vector<2xi64> } : vector<2xi1> -> vector<2xi64>
   return
 }
diff --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir
index 1453045c3bfbc..5dcfb34ceb39d 100644
--- a/mlir/test/Transforms/test-legalize-type-conversion.mlir
+++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir
@@ -2,9 +2,9 @@
 
 
 func.func @test_invalid_arg_materialization(
-  // expected-error at below {{failed to legalize unresolved materialization from () to ('i16') that remained live after conversion}}
+  // expected-error at below {{miss source materialization function from () to ('i16')}}
   %arg0: i16) {
-  // expected-note at below{{see existing live user here}}
+  // expected-note at below{{require this materialization is here}}
   "foo.return"(%arg0) : (i16) -> ()
 }
 
@@ -21,18 +21,18 @@ func.func @test_valid_arg_materialization(%arg0: i64) {
 // -----
 
 func.func @test_invalid_result_materialization() {
-  // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+  // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
   %result = "test.type_producer"() : () -> f16
-  // expected-note at below{{see existing live user here}}
+  // expected-note at below{{require this materialization is here}}
   "foo.return"(%result) : (f16) -> ()
 }
 
 // -----
 
 func.func @test_invalid_result_materialization() {
-  // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+  // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
   %result = "test.type_producer"() : () -> f16
-  // expected-note at below{{see existing live user here}}
+  // expected-note at below{{require this materialization is here}}
   "foo.return"(%result) : (f16) -> ()
 }
 
@@ -50,9 +50,9 @@ func.func @test_transitive_use_materialization() {
 // -----
 
 func.func @test_transitive_use_invalid_materialization() {
-  // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+  // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
   %result = "test.another_type_producer"() : () -> f16
-  // expected-note at below{{see existing live user here}}
+  // expected-note at below{{require this materialization is here}}
   "foo.return"(%result) : (f16) -> ()
 }
 
@@ -194,9 +194,9 @@ gpu.module @cuda_events {
 // hashes and could differ with LLVM_ENABLE_REVERSE_ITERATION.
 
 func.func @test_deterministic_materialization_order() {
-  // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+  // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
   %a = "test.type_producer"() : () -> f16
   %b = "test.type_producer"() : () -> f16
-  // expected-note at below {{see existing live user here}}
+  // expected-note at below {{require this materialization is here}}
   "foo.return"(%a, %b) : (f16, f16) -> ()
 }

``````````

</details>


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


More information about the Mlir-commits mailing list