[Mlir-commits] [mlir] [mlir][EmitC] Add tests for arith.max/min float/signed int conversions (PR #190160)
ioana ghiban
llvmlistbot at llvm.org
Thu Apr 23 05:35:42 PDT 2026
https://github.com/ioghiban updated https://github.com/llvm/llvm-project/pull/190160
>From 2a5baf48f1d8e03da0c67d2f3f7b29e44d2a5ca1 Mon Sep 17 00:00:00 2001
From: Ioana Ghiban <ioana.ghiban at arm.com>
Date: Tue, 31 Mar 2026 16:47:33 +0200
Subject: [PATCH 1/2] [mlir][EmitC] Add tests for arith.max/min float/signed
int conversions
Assisted-by: Codex (refine tests and comments).
I reviewed all code and tests before submission.
---
.../ArithToEmitC/arith-expand-to-emitc.mlir | 65 +++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir b/mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir
new file mode 100644
index 0000000000000..3950bbe8514f1
--- /dev/null
+++ b/mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir
@@ -0,0 +1,65 @@
+// RUN: mlir-opt -arith-expand -convert-arith-to-emitc %s | FileCheck %s
+
+/// This file checks the combined `-arith-expand | -convert-arith-to-emitc`
+/// pipeline with intentionally minimal FileCheck coverage.
+/// The full expansion is covered in `test/Dialect/Arith/expand-ops.mlir`, and
+/// the full ArithToEmitC lowering is covered in
+/// `test/Conversion/ArithToEmitC/arith-to-emitc.mlir`; this test only covers
+/// that the combination of the two produces the expected EmitC ops.
+
+/// Vector cases excluded because `arith.maximumf`/`arith.minimumf` expansion
+/// introduces `arith.cmpf`, and ArithToEmitC cannot convert `VectorType`.
+/// i.e. operand conversion for `vector<...>` fails before `cmpf` lowering.
+
+/// Tensor cases excluded because `arith.maximumf`/`arith.minimumf` expansion
+/// introduces `arith.cmpf`, but ArithToEmitC only lowers scalar `cmpf`.
+/// i.e. `cmpf` rejects tensors with: "only supported on floats, not
+/// tensors/vectors thereof".
+
+// CHECK-LABEL: func @maximumf
+// CHECK-SAME: %[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32) -> f32
+func.func @maximumf(%a: f32, %b: f32) -> f32 {
+// CHECK-NOT: arith
+// CHECK: %[[CMP:.*]] = emitc.cmp gt, %[[ARG0]], %[[ARG1]] : (f32, f32) -> i1
+// CHECK: %[[OR:.*]] = emitc.logical_or %{{.*}}, %[[CMP]] : i1, i1
+// CHECK: %[[SEL0:.*]] = emitc.conditional %[[OR]], %[[ARG0]], %[[ARG1]] : f32
+// CHECK: %[[SEL1:.*]] = emitc.conditional %{{.*}}, %[[ARG1]], %[[SEL0]] : f32
+ %result = arith.maximumf %a, %b : f32
+// CHECK: return %[[SEL1]] : f32
+ return %result : f32
+}
+
+// CHECK-LABEL: func @minimumf
+// CHECK-SAME: %[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32) -> f32
+func.func @minimumf(%a: f32, %b: f32) -> f32 {
+// CHECK-NOT: arith
+// CHECK: %[[CMP:.*]] = emitc.cmp lt, %[[ARG0]], %[[ARG1]] : (f32, f32) -> i1
+// CHECK: %[[OR:.*]] = emitc.logical_or %{{.*}}, %[[CMP]] : i1, i1
+// CHECK: %[[SEL0:.*]] = emitc.conditional %[[OR]], %[[ARG0]], %[[ARG1]] : f32
+// CHECK: %[[SEL1:.*]] = emitc.conditional %{{.*}}, %[[ARG1]], %[[SEL0]] : f32
+ %result = arith.minimumf %a, %b : f32
+// CHECK: return %[[SEL1]] : f32
+ return %result : f32
+}
+
+// CHECK-LABEL: func @minsi
+// CHECK-SAME: %[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32) -> i32
+func.func @minsi(%a: i32, %b: i32) -> i32 {
+// CHECK-NOT: arith
+// CHECK: %[[CMP:.*]] = emitc.cmp lt, %[[ARG0]], %[[ARG1]] : (i32, i32) -> i1
+// CHECK: %[[SEL:.*]] = emitc.conditional %[[CMP]], %[[ARG0]], %[[ARG1]] : i32
+ %result = arith.minsi %a, %b : i32
+// CHECK: return %[[SEL]] : i32
+ return %result : i32
+}
+
+// CHECK-LABEL: func @maxsi
+// CHECK-SAME: %[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32) -> i32
+func.func @maxsi(%a: i32, %b: i32) -> i32 {
+// CHECK-NOT: arith
+// CHECK: %[[CMP:.*]] = emitc.cmp gt, %[[ARG0]], %[[ARG1]] : (i32, i32) -> i1
+// CHECK: %[[SEL:.*]] = emitc.conditional %[[CMP]], %[[ARG0]], %[[ARG1]] : i32
+ %result = arith.maxsi %a, %b : i32
+// CHECK: return %[[SEL]] : i32
+ return %result : i32
+}
>From b5912ccf167d4f677c7ce52d4e6f95099b135631 Mon Sep 17 00:00:00 2001
From: Ioana Ghiban <ioana.ghiban at arm.com>
Date: Thu, 23 Apr 2026 14:26:49 +0200
Subject: [PATCH 2/2] Address first round of comments
---
.../EmitC/arith/ops.mlir} | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
rename mlir/test/{Conversion/ArithToEmitC/arith-expand-to-emitc.mlir => Dialect/EmitC/arith/ops.mlir} (84%)
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir b/mlir/test/Dialect/EmitC/arith/ops.mlir
similarity index 84%
rename from mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir
rename to mlir/test/Dialect/EmitC/arith/ops.mlir
index 3950bbe8514f1..a7838a8ae610f 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-expand-to-emitc.mlir
+++ b/mlir/test/Dialect/EmitC/arith/ops.mlir
@@ -7,14 +7,9 @@
/// `test/Conversion/ArithToEmitC/arith-to-emitc.mlir`; this test only covers
/// that the combination of the two produces the expected EmitC ops.
-/// Vector cases excluded because `arith.maximumf`/`arith.minimumf` expansion
-/// introduces `arith.cmpf`, and ArithToEmitC cannot convert `VectorType`.
-/// i.e. operand conversion for `vector<...>` fails before `cmpf` lowering.
-
-/// Tensor cases excluded because `arith.maximumf`/`arith.minimumf` expansion
-/// introduces `arith.cmpf`, but ArithToEmitC only lowers scalar `cmpf`.
-/// i.e. `cmpf` rejects tensors with: "only supported on floats, not
-/// tensors/vectors thereof".
+/// `arith.maximumf`/`arith.minimumf` expand through `arith.cmpf`.
+/// Vector cases excluded because ArithToEmitC cannot convert `VectorType`.
+/// Tensor cases excluded because ArithToEmitC only lowers scalar `cmpf`.
// CHECK-LABEL: func @maximumf
// CHECK-SAME: %[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32) -> f32
More information about the Mlir-commits
mailing list