[Mlir-commits] [mlir] [mlir][arith] Add more canonicalization and integration tests coverage (PR #92272)

Jacob Yu llvmlistbot at llvm.org
Wed May 15 13:49:28 PDT 2024


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

>From bda65c65482ed65dc5a2030301e4256256e2311f Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Wed, 15 May 2024 15:31:40 +0100
Subject: [PATCH 1/2] [mlir][arith] new regression tests from independent
 interpreter development

---
 mlir/test/Dialect/Arith/canonicalize.mlir     | 30 +++++++++++
 .../Dialect/Arith/CPU/test-semantics.mlir     | 52 +++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir

diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir b/mlir/test/Dialect/Arith/canonicalize.mlir
index e4f95bb0545a2..aa79ad1bead56 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -3022,6 +3022,36 @@ func.func @minsi_i0() -> i0 {
   return %minsi : i0
 }
 
+// CHECK-LABEL: @extsiOnI1
+//       CHECK: %[[TRUE:.*]] = arith.constant true
+//       CHECK: %[[CST:.*]] = arith.constant -1 : i16
+//       CHECK: return %[[TRUE]], %[[CST]]
+func.func @extsiOnI1() -> (i1, i16) {
+  %true = arith.constant -1 : i1
+  %0 = arith.extsi %true : i1 to i16
+  return %true, %0 : i1, i16
+}
+
+// CHECK-LABEL: @extuiOn1I1
+//       CHECK: %[[TRUE:.*]] = arith.constant true
+//       CHECK: %[[CST:.*]] = arith.constant 1 : i64
+//       CHECK: return %[[TRUE]], %[[CST]]
+func.func @extuiOn1I1() -> (i1, i64) {
+  %true = arith.constant true
+  %0 = arith.extui %true : i1 to i64
+  return %true, %0 : i1, i64
+}
+
+// CHECK-LABEL: @trunciI16ToI8
+//       CHECK: %[[CST:.*]] = arith.constant 20194 : i16
+//       CHECK: %[[CST2:.*]] = arith.constant -30 : i8
+//       CHECK: return %[[CST]], %[[CST2]]
+func.func @trunciI16ToI8() -> (i16, i8) {
+  %c20194_i16 = arith.constant 20194 : i16
+  %0 = arith.trunci %c20194_i16 : i16 to i8
+  return %c20194_i16, %0 : i16, i8
+}
+
 // CHECK-LABEL: @mulsi_extended_i0
 //       CHECK:   %[[ZERO:.*]] = arith.constant 0 : i0
 //       CHECK:   return %[[ZERO]], %[[ZERO]] : i0
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir b/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir
new file mode 100644
index 0000000000000..cd1cad4d56da9
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir
@@ -0,0 +1,52 @@
+// Regression test suite from an independent development of Arith's
+// semantics and a fuzzer
+
+// 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
+
+module {
+  func.func @extsiOnI1() {
+    %true = arith.constant -1 : i1
+    %0 = arith.extsi %true : i1 to i16
+    vector.print %true : i1
+    vector.print %0 : i16
+    return
+  }
+
+  func.func @extuiOn1I1() {
+    %true = arith.constant true
+    %0 = arith.extui %true : i1 to i64
+    vector.print %true : i1
+    vector.print %0 : i64
+    return
+  }
+
+  func.func @trunciI16ToI8() {
+    %c20194_i16 = arith.constant 20194 : i16
+    %0 = arith.trunci %c20194_i16 : i16 to i8
+    vector.print %c20194_i16 : i16
+    vector.print %0 : i8
+    return
+  }
+
+  func.func @entry() {
+
+    // CHECK:      1
+    // CHECK:      -1
+    func.call @extsiOnI1() : () -> ()
+    
+    // CHECK:      1
+    // CHECK:      1
+    func.call @extuiOn1I1() : () -> ()
+
+    // CHECK:      20194
+    // CHECK:      -30
+    func.call @trunciI16ToI8() : () -> ()
+
+
+    return
+  }
+}
\ No newline at end of file

>From 060398397aac1cede7a8d2101277e349ab4f0416 Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Wed, 15 May 2024 21:49:20 +0100
Subject: [PATCH 2/2] Update
 mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir

Co-authored-by: Fehr Mathieu <mathieu.fehr at gmail.com>
---
 mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir b/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir
index cd1cad4d56da9..bc909f0bfbccf 100644
--- a/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir
+++ b/mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir
@@ -49,4 +49,4 @@ module {
 
     return
   }
-}
\ No newline at end of file
+}



More information about the Mlir-commits mailing list