[Mlir-commits] [mlir] [mlir][arith] new integration tests from independent interpreter development (PR #92272)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed May 15 07:39:15 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-arith

Author: Jacob Yu (pingshiyu)

<details>
<summary>Changes</summary>

I've recently been writing some fuzzers/interpreters to validate passes in MLIR for incorrect compilations.

It found a bunch of bugs in the `arith` folders, optimisations and lowering.

However, during the development process, I ran into a lot more bugs within my own interpreter. This resulted in a fairly amount of regression tests for the interpreter.

I thought it might be a good idea to add these into the MLIR codebase - these could guard against potential bugs that may be introduced in the future, for example (if they made the same mistakes as I did :p).

The tests are mostly end-to-end ones so it seems to me are best adapted as tests in the `Integration` folder. However, it could also be adapted as canonicalization tests (caveat being it can't exercise lowering code).

I've added a few ways these can be adapted on the files in the initial commit, which includes just a few of the unit tests. 

Please do let me know if adding these would be helpful, and what's the preferred format for them. 

Once/if that's all agreed upon I can add the rest of the regression suite!

---
Full diff: https://github.com/llvm/llvm-project/pull/92272.diff


2 Files Affected:

- (modified) mlir/test/Dialect/Arith/canonicalize.mlir (+30) 
- (added) mlir/test/Integration/Dialect/Arith/CPU/test-semantics.mlir (+52) 


``````````diff
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

``````````

</details>


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


More information about the Mlir-commits mailing list