[Mlir-commits] [mlir] [mlir][Arith][EmitC] Add tests for bail-out on arith.constant conversion (PR #201565)

ioana ghiban llvmlistbot at llvm.org
Mon Jun 8 04:14:51 PDT 2026


https://github.com/ioghiban updated https://github.com/llvm/llvm-project/pull/201565

>From 550575d016fc355efbeb7d6d81235fd497dad6f4 Mon Sep 17 00:00:00 2001
From: Ioana Ghiban <ioana.ghiban at arm.com>
Date: Thu, 4 Jun 2026 14:18:01 +0200
Subject: [PATCH 1/3] [mlir][Arith][EmitC] Add tests for bail-out on
 arith.constant conversion

---
 .../Conversion/ArithToEmitC/ArithToEmitC.cpp  |  3 +++
 .../ArithToEmitC/arith-to-emitc-failed.mlir   | 24 +++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
index d003dc7a6dff3..cfce60b693f13 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
@@ -62,6 +62,9 @@ class ArithConstantOpConversionPattern
     Type newTy = this->getTypeConverter()->convertType(arithConst.getType());
     if (!newTy)
       return rewriter.notifyMatchFailure(arithConst, "type conversion failed");
+    if (isa<MemRefType>(arithConst.getType()))
+      return rewriter.notifyMatchFailure(arithConst,
+                                         "memref constants are not supported");
     rewriter.replaceOpWithNewOp<emitc::ConstantOp>(arithConst, newTy,
                                                    adaptor.getValue());
     return success();
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
index fba4483d316f4..02dc388d3da86 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
@@ -21,3 +21,27 @@ func.func @unsuppoted_emitc_type(%arg0: i4, %arg1: i4) {
   %0 = arith.addi %arg0, %arg1 : i4
   return
 }
+
+// -----
+
+func.func private @rank0_constant() -> memref<i64> {
+  // expected-error at +1 {{failed to legalize operation 'arith.constant'}}
+  %0 = arith.constant dense<-1> : memref<i64>
+  return %0 : memref<i64>
+}
+
+// -----
+
+func.func private @rank1_constant() -> memref<1xi64> {
+  // expected-error at +1 {{failed to legalize operation 'arith.constant'}}
+  %0 = arith.constant dense<[-1]> : memref<1xi64>
+  return %0 : memref<1xi64>
+}
+
+// -----
+
+func.func private @return_rank2_constant() -> memref<1x1xi64> {
+  // expected-error at +1 {{failed to legalize operation 'arith.constant'}}
+  %0 = arith.constant dense<[[-1]]> : memref<1x1xi64>
+  return %0 : memref<1x1xi64>
+}

>From 35e00bfe439c2671489bdfd72f9f8faadd09aa8e Mon Sep 17 00:00:00 2001
From: Ioana Ghiban <ioana.ghiban at arm.com>
Date: Thu, 4 Jun 2026 16:41:03 +0200
Subject: [PATCH 2/3] Fixup

---
 mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
index 02dc388d3da86..79344bd0a7181 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
@@ -40,7 +40,7 @@ func.func private @rank1_constant() -> memref<1xi64> {
 
 // -----
 
-func.func private @return_rank2_constant() -> memref<1x1xi64> {
+func.func private @rank2_constant() -> memref<1x1xi64> {
   // expected-error at +1 {{failed to legalize operation 'arith.constant'}}
   %0 = arith.constant dense<[[-1]]> : memref<1x1xi64>
   return %0 : memref<1x1xi64>

>From 5be69b6ad48edf313bc817d4ec41bcb6887911f0 Mon Sep 17 00:00:00 2001
From: Ioana Ghiban <ioana.ghiban at arm.com>
Date: Mon, 8 Jun 2026 13:10:51 +0200
Subject: [PATCH 3/3] Remove dead code

---
 mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
index cfce60b693f13..d003dc7a6dff3 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
@@ -62,9 +62,6 @@ class ArithConstantOpConversionPattern
     Type newTy = this->getTypeConverter()->convertType(arithConst.getType());
     if (!newTy)
       return rewriter.notifyMatchFailure(arithConst, "type conversion failed");
-    if (isa<MemRefType>(arithConst.getType()))
-      return rewriter.notifyMatchFailure(arithConst,
-                                         "memref constants are not supported");
     rewriter.replaceOpWithNewOp<emitc::ConstantOp>(arithConst, newTy,
                                                    adaptor.getValue());
     return success();



More information about the Mlir-commits mailing list