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

Andrzej Warzyński llvmlistbot at llvm.org
Fri May 17 04:32:34 PDT 2024


================
@@ -0,0 +1,146 @@
+// tests arith operations on i1 type.
+
+// 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 @zeroPlusOneOnI1() {
+    // addi on i1
+    // addi(0, 1) : i1 = 1 : i1; addi(0, -1) : i1 = 1
+    %false = arith.constant 0 : i1
+    %true = arith.constant 1 : i1
+    %true_0 = arith.constant -1 : i1
+    vector.print %true_0 : i1
+    %0 = arith.addi %false, %true : i1
+    vector.print %0 : i1
+    %1 = arith.addi %false, %true_0 : i1
+    vector.print %1 : i1
+    return
+}
+
+func.func @i1Printing() {
+    // printing i1 values
+    // print(0 : i1) = '0'; print(1 : i1) = '1'; print(-1 : i1) = '1'
+    %false = arith.constant false
+    %true = arith.constant 1 : i1
+    %true_0 = arith.constant -1 : i1
+    vector.print %false : i1
+    vector.print %true : i1
+    vector.print %true_0 : i1
+    return
+}
+
+func.func @signedComparisonOnI1s() {
+    // signed comparisons on i1s
+    // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true
+    %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 @sge0And1IsTrue() {
+    // sge 0 -1, sge 0 1, should be true
+    // sge 0 -1 == sge 0 1 == true (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 @divsiI1SignedRepr() {
----------------
banach-space wrote:

This might be a personal thing, but I find test names with underscores much easier to parse:
```
divsi_i1_signed_rep
```
This way:
*  it's super easy to see that that are 4 key things that define this test: Op (`divsi`), data type (`i1`), signness (`signed`) ... not sure what `rep` means 😅 
* find similar tests for other types, e.g.`index` would give you: `divsi_index_signed_rep`
* it's easy to find inconsistent names, e.g. `zeroPlusOneOnI1` (this follows different naming even though it's testing `addi`)
* data types use similar capitalisation to what MLIR uses, e.g. `I32` vs `i32`

But honestly, this might be a matter of personal preference.

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


More information about the Mlir-commits mailing list