[Mlir-commits] [mlir] [mlir][arith] adding addition regression tests (PR #96973)

Andrzej WarzyƄski llvmlistbot at llvm.org
Fri Jun 28 07:15:41 PDT 2024


================
@@ -0,0 +1,57 @@
+// Tests arith operations on i1 type.
+// 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 @zero_plus_one_on_i1() {
+  // addi on i1
+  // addi(0, 1) : i1 = 1 : i1; addi(0, -1) : i1 = 1
+  // CHECK:      1
+  // CHECK-NEXT: 1
+  // CHECK-NEXT: 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 @addui_extended_i1() {
+  // addui_extended on i1
+  // addui_extended 1 1 : i1 = 0, 1
+  // CHECK-NEXT: 0
+  // CHECK-NEXT: 1
+  %true = arith.constant 1 : i1
+  %sum, %overflow = arith.addui_extended %true, %true : i1, i1
+  vector.print %sum : i1
+  vector.print %overflow : i1
+  return
+}
+
+func.func @addui_extended_overflow_bit_is_n1() {
----------------
banach-space wrote:

I don't quite follow this test - why not add `-1` and `-1`? Does using `i64` matter ? Why not `i8`? And what does `n1` stand for in `addui_extended_overflow_bit_is_n1`? 

IMHO, you should simply extend `@addui_extended_i1` to e.g. `@addui_extended_i64`:
```mlir
func.func @addui_extended_i64() {
  %val = arith.constant -1 : i64
  %sum, %overflow = arith.addui_extended %val, %val : i64, i64
  vector.print %sum : i64
  vector.print %overflow : i64
  return
}
```

This way, it will be super easy to see what "new" (compared to previous tests) is being checked in this method.

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


More information about the Mlir-commits mailing list