[Mlir-commits] [mlir] [mlir][arith] adding addition regression tests (PR #96973)
Jacob Yu
llvmlistbot at llvm.org
Fri Jun 28 04:28:54 PDT 2024
https://github.com/pingshiyu updated https://github.com/llvm/llvm-project/pull/96973
>From 1dc9f4d4c395e26b550fd6c257d87efe2725bed3 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Thu, 27 Jun 2024 22:55:54 +0100
Subject: [PATCH 1/2] adding addition unit tests
---
.../Dialect/Arith/CPU/addition.mlir | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 mlir/test/Integration/Dialect/Arith/CPU/addition.mlir
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir b/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir
new file mode 100644
index 0000000000000..0833ebf1c8ecc
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir
@@ -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() {
+ // addui_extended overflow bit is treated as -1
+ // addui_extended -1633386 -1643386 = ... 1 (overflow because negative numbers are large positive numbers)
+ // CHECK-NEXT: 0
+ %c-16433886_i64 = arith.constant -16433886 : i64
+ %sum, %overflow = arith.addui_extended %c-16433886_i64, %c-16433886_i64 : i64, i1
+ %false = arith.constant false
+ %0 = arith.cmpi sge, %overflow, %false : i1
+ vector.print %0 : i1 // but prints as "1"
+ return
+}
+
+func.func @entry() {
+ func.call @zero_plus_one_on_i1() : () -> ()
+ func.call @addui_extended_i1() : () -> ()
+ func.call @addui_extended_overflow_bit_is_n1() : () -> ()
+ return
+}
>From dc39c96d5e03246fdf3dabcf6c7810c28e962775 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Fri, 28 Jun 2024 12:28:49 +0100
Subject: [PATCH 2/2] reindented
---
.../Dialect/Arith/CPU/addition.mlir | 72 +++++++++----------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir b/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir
index 0833ebf1c8ecc..b3a4cb039b0dc 100644
--- a/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir
+++ b/mlir/test/Integration/Dialect/Arith/CPU/addition.mlir
@@ -9,49 +9,49 @@
// 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
+ // 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
+ // 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() {
- // addui_extended overflow bit is treated as -1
- // addui_extended -1633386 -1643386 = ... 1 (overflow because negative numbers are large positive numbers)
- // CHECK-NEXT: 0
- %c-16433886_i64 = arith.constant -16433886 : i64
- %sum, %overflow = arith.addui_extended %c-16433886_i64, %c-16433886_i64 : i64, i1
- %false = arith.constant false
- %0 = arith.cmpi sge, %overflow, %false : i1
- vector.print %0 : i1 // but prints as "1"
- return
+ // addui_extended overflow bit is treated as -1
+ // addui_extended -1633386 -1643386 = ... 1 (overflow because negative numbers are large positive numbers)
+ // CHECK-NEXT: 0
+ %c-16433886_i64 = arith.constant -16433886 : i64
+ %sum, %overflow = arith.addui_extended %c-16433886_i64, %c-16433886_i64 : i64, i1
+ %false = arith.constant false
+ %0 = arith.cmpi sge, %overflow, %false : i1
+ vector.print %0 : i1 // but prints as "1"
+ return
}
func.func @entry() {
- func.call @zero_plus_one_on_i1() : () -> ()
- func.call @addui_extended_i1() : () -> ()
- func.call @addui_extended_overflow_bit_is_n1() : () -> ()
- return
+ func.call @zero_plus_one_on_i1() : () -> ()
+ func.call @addui_extended_i1() : () -> ()
+ func.call @addui_extended_overflow_bit_is_n1() : () -> ()
+ return
}
More information about the Mlir-commits
mailing list