[Mlir-commits] [mlir] [MLIR][Transforms] Fix dialect conversion inverse mapping (PR #104648)

Billy Zhu llvmlistbot at llvm.org
Fri Aug 16 17:04:25 PDT 2024


https://github.com/zyx-billy updated https://github.com/llvm/llvm-project/pull/104648

>From 15c0f2c4aef81837d7559fcca73b83e8093a8f0f Mon Sep 17 00:00:00 2001
From: Billy Zhu <billyzhu at modular.com>
Date: Fri, 16 Aug 2024 16:09:50 -0700
Subject: [PATCH 1/2] update inverse mapping

---
 mlir/lib/Transforms/Utils/DialectConversion.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 11e593cebc09b3..e71b91c4e54cdf 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2527,6 +2527,7 @@ LogicalResult OperationConverter::legalizeConvertedOpResultTypes(
           opReplacement->getConverter());
       rewriterImpl.mapping.map(result, castValue);
       inverseMapping[castValue].push_back(result);
+      llvm::erase(inverseMapping[newValue], result);
     }
   }
 

>From b449907b7355822d51bd2aa166a0dca573ea29f6 Mon Sep 17 00:00:00 2001
From: Billy Zhu <billyzhu at modular.com>
Date: Fri, 16 Aug 2024 17:04:08 -0700
Subject: [PATCH 2/2] add test case

---
 .../test-legalize-target-materialization-no-uses.mlir      | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mlir/test/Transforms/test-legalize-target-materialization-no-uses.mlir b/mlir/test/Transforms/test-legalize-target-materialization-no-uses.mlir
index 19dd2b2ee4b2f2..04db95ba7a9bac 100644
--- a/mlir/test/Transforms/test-legalize-target-materialization-no-uses.mlir
+++ b/mlir/test/Transforms/test-legalize-target-materialization-no-uses.mlir
@@ -25,3 +25,10 @@ func.func @foo() {
   "test.type_consumer"(%2) : (i64) -> ()
   return
 }
+
+// CHECK-LABEL: @direct_forward
+func.func @direct_forward(%arg0 : i16) -> i16 {
+  // CHECK-NEXT: return
+  %0 = "test.type_changer"(%arg0) : (i16) -> i16
+  return %0 : i16
+}



More information about the Mlir-commits mailing list