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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jun 8 09:09:40 PDT 2026


Author: ioana ghiban
Date: 2026-06-08T18:09:35+02:00
New Revision: 233c1d22c1ae5ae4159dd8b89fa0a6834d8580a2

URL: https://github.com/llvm/llvm-project/commit/233c1d22c1ae5ae4159dd8b89fa0a6834d8580a2
DIFF: https://github.com/llvm/llvm-project/commit/233c1d22c1ae5ae4159dd8b89fa0a6834d8580a2.diff

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

ArithToEmitC avoids rewriting memref constants to `emitc.constant`,
since the type conversion changes the result type but the attribute
cannot be converted into a valid EmitC initializer.

This patch does not add support for converting these memrefs. It only
makes the existing limitation explicit at the conversion boundary by
adding tests for the standalone conversion pass. This pass marks its
source ops illegal, so when a pattern bails-out the pass reports a
legalization failure. This is the expected behavior and tests document
the unsupported cases directly.

Assisted-by: Codex (refine description). I reviewed all text before
submission.

Added: 
    

Modified: 
    mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
index fba4483d316f4..79344bd0a7181 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 @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