[Mlir-commits] [mlir] [mlir][Arith][EmitC] Bail-out on arith.constant conversions to EmitC (PR #201565)

ioana ghiban llvmlistbot at llvm.org
Thu Jun 4 07:41:34 PDT 2026


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

>From 8cdb24520a8d295176f7e4e06f667401a8916335 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/2] [mlir][Arith][EmitC] Bail-out on arith.constant
 conversions to EmitC

---
 .../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 30683ef8259ea5b53b4a68bc0181be6e0033ff4b 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/2] 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>



More information about the Mlir-commits mailing list