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

Jacob Yu llvmlistbot at llvm.org
Wed May 15 14:24:14 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/4] [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/4] 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
+}

>From d67d02af849c54904a3047a9bf484cf9f874baec Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Wed, 15 May 2024 22:05:04 +0100
Subject: [PATCH 3/4] fix up! adding check-nexts

---
 .../Dialect/Arith/CPU/test-int-trunc-ext.mlir | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir

diff --git a/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir b/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir
new file mode 100644
index 0000000000000..bb494d889ea8f
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir
@@ -0,0 +1,49 @@
+// tests arith truncation and extension operations.
+
+// 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-NEXT: -1
+    func.call @extsiOnI1() : () -> ()
+    
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 1
+    func.call @extuiOn1I1() : () -> ()
+
+    // CHECK-NEXT: 20194
+    // CHECK-NEXT: -30
+    func.call @trunciI16ToI8() : () -> ()
+
+    return
+  }
+}
\ No newline at end of file

>From 21c34310b294044ac98dc809740ebcdfae6a8bbd Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Wed, 15 May 2024 22:24:02 +0100
Subject: [PATCH 4/4] formatting

---
 .../test/Dialect/Arith/canonicalize-mini.mlir | 31 ++++++++
 .../Dialect/Arith/CPU/test-int-trunc-ext.mlir | 70 +++++++++----------
 2 files changed, 65 insertions(+), 36 deletions(-)
 create mode 100644 mlir/test/Dialect/Arith/canonicalize-mini.mlir

diff --git a/mlir/test/Dialect/Arith/canonicalize-mini.mlir b/mlir/test/Dialect/Arith/canonicalize-mini.mlir
new file mode 100644
index 0000000000000..57a4453e041a9
--- /dev/null
+++ b/mlir/test/Dialect/Arith/canonicalize-mini.mlir
@@ -0,0 +1,31 @@
+// RUN: mlir-opt %s -canonicalize="test-convergence" --split-input-file | FileCheck %s
+
+// 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
+}
\ No newline at end of file
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir b/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir
index bb494d889ea8f..c8d773d948d27 100644
--- a/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir
+++ b/mlir/test/Integration/Dialect/Arith/CPU/test-int-trunc-ext.mlir
@@ -6,44 +6,42 @@
 // 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 @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 @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 @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-NEXT: -1
-    func.call @extsiOnI1() : () -> ()
-    
-    // CHECK-NEXT: 1
-    // CHECK-NEXT: 1
-    func.call @extuiOn1I1() : () -> ()
+func.func @entry() {
+  // CHECK:      1
+  // CHECK-NEXT: -1
+  func.call @extsiOnI1() : () -> ()
+  
+  // CHECK-NEXT: 1
+  // CHECK-NEXT: 1
+  func.call @extuiOn1I1() : () -> ()
 
-    // CHECK-NEXT: 20194
-    // CHECK-NEXT: -30
-    func.call @trunciI16ToI8() : () -> ()
+  // CHECK-NEXT: 20194
+  // CHECK-NEXT: -30
+  func.call @trunciI16ToI8() : () -> ()
 
-    return
-  }
-}
\ No newline at end of file
+  return
+}



More information about the Mlir-commits mailing list