[Mlir-commits] [mlir] [mlir][arith] adding comparison regression tests (PR #96974)

Jacob Yu llvmlistbot at llvm.org
Fri Jun 28 04:28:20 PDT 2024


https://github.com/pingshiyu updated https://github.com/llvm/llvm-project/pull/96974

>From d7602dbf472727dee99b128098bc258d7b913999 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Thu, 27 Jun 2024 22:57:37 +0100
Subject: [PATCH 1/2] adding comparison unit tests

---
 .../Dialect/Arith/CPU/comparison.mlir         | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir

diff --git a/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
new file mode 100644
index 0000000000000..85b70b2cad5a0
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
@@ -0,0 +1,61 @@
+// Tests comparison operations.
+// These tests are intended to be target agnostic: they should yield the same results 
+// regardless of the target platform.
+
+// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
+// RUN:             --convert-func-to-llvm --convert-arith-to-llvm | \
+// RUN:   mlir-cpu-runner -e entry -entry-point-result=void \
+// RUN:                   --shared-libs=%mlir_c_runner_utils | \
+// RUN:   FileCheck %s --match-full-lines
+
+func.func @signed_comparison_on_i1s() {
+    // signed comparisons on i1s
+    // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true
+    // CHECK:      0
+    // CHECK-NEXT: 0
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 1
+    %false = arith.constant false
+    %true = arith.constant true
+    %0 = arith.cmpi slt, %false, %true : i1
+    %1 = arith.cmpi sle, %false, %true : i1
+    %2 = arith.cmpi sgt, %false, %true : i1
+    %3 = arith.cmpi sge, %false, %true : i1
+    vector.print %0 : i1
+    vector.print %1 : i1
+    vector.print %2 : i1
+    vector.print %3 : i1
+    return
+}
+
+func.func @sge_0_1_is_true() {
+    // sge 0 -1, sge 0 1, should be true
+    // sge 0 -1 == sge 0 1 == true (1)
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 1
+    %false = arith.constant 0 : i1
+    %true = arith.constant 1 : i1
+    %true_0 = arith.constant -1 : i1
+    %0 = arith.cmpi sge, %false, %true : i1
+    %1 = arith.cmpi sge, %false, %true_0 : i1
+    vector.print %0 : i1
+    vector.print %1 : i1
+    return
+}
+
+func.func @zero_ult_min_index() {
+    // 0 `ult` -2^63 = true
+    // CHECK-NEXT: 1
+    %c0 = arith.constant 0 : index
+    %c-9223372036854775808 = arith.constant -9223372036854775808 : index
+    %0 = arith.cmpi ult, %c0, %c-9223372036854775808 : index
+    vector.print %0 : i1
+    return
+}
+
+func.func @entry() {
+    func.call @signed_comparison_on_i1s() : () -> ()
+    func.call @sge_0_1_is_true() : () -> ()
+    func.call @zero_ult_min_index() : () -> ()
+    return
+}

>From 4909f9ee497218eb43e25e0395028e95638fb0c9 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Fri, 28 Jun 2024 12:28:15 +0100
Subject: [PATCH 2/2] reindented

---
 .../Dialect/Arith/CPU/comparison.mlir         | 80 +++++++++----------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
index 85b70b2cad5a0..83fa7d7cbe509 100644
--- a/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
+++ b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
@@ -9,53 +9,53 @@
 // RUN:   FileCheck %s --match-full-lines
 
 func.func @signed_comparison_on_i1s() {
-    // signed comparisons on i1s
-    // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true
-    // CHECK:      0
-    // CHECK-NEXT: 0
-    // CHECK-NEXT: 1
-    // CHECK-NEXT: 1
-    %false = arith.constant false
-    %true = arith.constant true
-    %0 = arith.cmpi slt, %false, %true : i1
-    %1 = arith.cmpi sle, %false, %true : i1
-    %2 = arith.cmpi sgt, %false, %true : i1
-    %3 = arith.cmpi sge, %false, %true : i1
-    vector.print %0 : i1
-    vector.print %1 : i1
-    vector.print %2 : i1
-    vector.print %3 : i1
-    return
+  // signed comparisons on i1s
+  // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true
+  // CHECK:      0
+  // CHECK-NEXT: 0
+  // CHECK-NEXT: 1
+  // CHECK-NEXT: 1
+  %false = arith.constant false
+  %true = arith.constant true
+  %0 = arith.cmpi slt, %false, %true : i1
+  %1 = arith.cmpi sle, %false, %true : i1
+  %2 = arith.cmpi sgt, %false, %true : i1
+  %3 = arith.cmpi sge, %false, %true : i1
+  vector.print %0 : i1
+  vector.print %1 : i1
+  vector.print %2 : i1
+  vector.print %3 : i1
+  return
 }
 
 func.func @sge_0_1_is_true() {
-    // sge 0 -1, sge 0 1, should be true
-    // sge 0 -1 == sge 0 1 == true (1)
-    // CHECK-NEXT: 1
-    // CHECK-NEXT: 1
-    %false = arith.constant 0 : i1
-    %true = arith.constant 1 : i1
-    %true_0 = arith.constant -1 : i1
-    %0 = arith.cmpi sge, %false, %true : i1
-    %1 = arith.cmpi sge, %false, %true_0 : i1
-    vector.print %0 : i1
-    vector.print %1 : i1
-    return
+  // sge 0 -1, sge 0 1, should be true
+  // sge 0 -1 == sge 0 1 == true (1)
+  // CHECK-NEXT: 1
+  // CHECK-NEXT: 1
+  %false = arith.constant 0 : i1
+  %true = arith.constant 1 : i1
+  %true_0 = arith.constant -1 : i1
+  %0 = arith.cmpi sge, %false, %true : i1
+  %1 = arith.cmpi sge, %false, %true_0 : i1
+  vector.print %0 : i1
+  vector.print %1 : i1
+  return
 }
 
 func.func @zero_ult_min_index() {
-    // 0 `ult` -2^63 = true
-    // CHECK-NEXT: 1
-    %c0 = arith.constant 0 : index
-    %c-9223372036854775808 = arith.constant -9223372036854775808 : index
-    %0 = arith.cmpi ult, %c0, %c-9223372036854775808 : index
-    vector.print %0 : i1
-    return
+  // 0 `ult` -2^63 = true
+  // CHECK-NEXT: 1
+  %c0 = arith.constant 0 : index
+  %c-9223372036854775808 = arith.constant -9223372036854775808 : index
+  %0 = arith.cmpi ult, %c0, %c-9223372036854775808 : index
+  vector.print %0 : i1
+  return
 }
 
 func.func @entry() {
-    func.call @signed_comparison_on_i1s() : () -> ()
-    func.call @sge_0_1_is_true() : () -> ()
-    func.call @zero_ult_min_index() : () -> ()
-    return
+  func.call @signed_comparison_on_i1s() : () -> ()
+  func.call @sge_0_1_is_true() : () -> ()
+  func.call @zero_ult_min_index() : () -> ()
+  return
 }



More information about the Mlir-commits mailing list