[Mlir-commits] [llvm] [mlir] [mlir][emitc] Ensure memref-to-emitc applies type converter to memref element types (PR #203742)

Andrzej Warzyński llvmlistbot at llvm.org
Thu Jun 18 06:13:22 PDT 2026


================
@@ -0,0 +1,32 @@
+// RUN: mlir-opt -convert-to-emitc -split-input-file %s | FileCheck %s
+
+// CHECK-LABEL: emitc.func @test_memref_alloc()
+func.func @test_memref_alloc() {
+  // CHECK: %[[SIZEOF:.*]] = call_opaque "sizeof"() <{args = [!emitc.opaque<"TestElementT">]}> : () -> !emitc.size_t
+  // CHECK: %[[C10:.*]] = "emitc.constant"() <{value = 10 : index}> : () -> index
+  // CHECK: %[[BYTES:.*]] = mul %[[SIZEOF]], %[[C10]] : (!emitc.size_t, index) -> !emitc.size_t
+  // CHECK: %[[MALLOC:.*]] = call_opaque "malloc"(%[[BYTES]]) : (!emitc.size_t) -> !emitc.ptr<!emitc.opaque<"void">>
+  // CHECK: %[[CAST:.*]] = cast %[[MALLOC]] : !emitc.ptr<!emitc.opaque<"void">> to !emitc.ptr<!emitc.opaque<"TestElementT">>
+  %0 = memref.alloc() : memref<10x!test.memref_element>
+  return
+}
+
+// -----
+
+// CHECK-LABEL:   emitc.func @test_memref_copy(
+// CHECK-SAME:      %[[ARG0:.*]]: !emitc.array<10x!emitc.opaque<"TestElementT">>,
+// CHECK-SAME:      %[[ARG1:.*]]: !emitc.array<10x!emitc.opaque<"TestElementT">>) {
+func.func @test_memref_copy(%arg0: memref<10x!test.memref_element>, %arg1: memref<10x!test.memref_element>) {
+  // CHECK:           %[[C0_0:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
+  // CHECK:           %[[SUB_0:.*]] = subscript %[[ARG0]][%[[C0_0]]] : (!emitc.array<10x!emitc.opaque<"TestElementT">>, index) -> !emitc.lvalue<!emitc.opaque<"TestElementT">>
+  // CHECK:           %[[ADDR_0:.*]] = address_of %[[SUB_0]] : !emitc.lvalue<!emitc.opaque<"TestElementT">>
+  // CHECK:           %[[C0_1:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
+  // CHECK:           %[[SUB_1:.*]] = subscript %[[ARG1]][%[[C0_1]]] : (!emitc.array<10x!emitc.opaque<"TestElementT">>, index) -> !emitc.lvalue<!emitc.opaque<"TestElementT">>
+  // CHECK:           %[[ADDR_1:.*]] = address_of %[[SUB_1]] : !emitc.lvalue<!emitc.opaque<"TestElementT">>
+  // CHECK:           %[[SIZEOF:.*]] = call_opaque "sizeof"() <{args = [!emitc.opaque<"TestElementT">]}> : () -> !emitc.size_t
+  // CHECK:           %[[C10:.*]] = "emitc.constant"() <{value = 10 : index}> : () -> index
+  // CHECK:           %[[BYTES:.*]] = mul %[[SIZEOF]], %[[C10]] : (!emitc.size_t, index) -> !emitc.size_t
+  // CHECK:           call_opaque "memcpy"(%[[ADDR_1]], %[[ADDR_0]], %[[BYTES]]) : (!emitc.ptr<!emitc.opaque<"TestElementT">>, !emitc.ptr<!emitc.opaque<"TestElementT">>, !emitc.size_t) -> ()
----------------
banach-space wrote:

This checks quite a lot, but the patch itself is only about sizeof for custom types. I’d suggest trimming the CHECK lines so the test focuses only on the behavior modified here.

Assuming the surrounding logic is already covered by existing tests, this would also align better with the FileCheck best practices:

> Tests should be minimal, and only check what is absolutely necessary.

https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices

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


More information about the Mlir-commits mailing list