Skip to content

[mlir][arith] adding addition regression tests #96973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 8, 2024

Conversation

pingshiyu
Copy link
Contributor

arith addition regression tests, a component of the large #92272

@pingshiyu
Copy link
Contributor Author

@kuhar @banach-space

@llvmbot
Copy link
Member

llvmbot commented Jun 27, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-arith

Author: Jacob Yu (pingshiyu)

Changes

arith addition regression tests, a component of the large #92272


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

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/addition.mlir (+57)
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
+}

@pingshiyu pingshiyu changed the title [mlir][arith] adding addition unit tests [mlir][arith] adding addition regression tests Jun 27, 2024
@pingshiyu pingshiyu force-pushed the arith-regression-addition branch from 3a32bcc to fb7b9d2 Compare June 29, 2024 17:43
Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for addressing my comments and for pushing on this!

@pingshiyu
Copy link
Contributor Author

pingshiyu commented Jul 6, 2024

@banach-space thank you for taking your time over the last week (and 8 weeks ago!) going through these PRs!

I'll add the rest of the tests in the same format, more to come tomorrow - but hopefully should be quicker to review since we have the format established :)

@kuhar, could you please take a look sometime & give a tick if all LGTY? (along with #96975 and #96974)

@pingshiyu
Copy link
Contributor Author

pingshiyu commented Jul 8, 2024

sorry I don't have

@banach-space thank you for taking your time over the last week (and 8 weeks ago!) going through these PRs!

I'll add the rest of the tests in the same format, more to come tomorrow - but hopefully should be quicker to review since we have the format established :)

@kuhar, could you please take a look sometime & give a tick if all LGTY? (along with #96975 and #96974)

Thank you @banach-space and @kuhar for going through this tranche of changes! I don't have write rights to LLVM unfortunately so would be great if you could also push the merge button on these PRs too :)

@kuhar kuhar merged commit 66a2058 into llvm:main Jul 8, 2024
5 of 6 checks passed
@kuhar
Copy link
Member

kuhar commented Jul 8, 2024

@pingshiyu merged

@pingshiyu
Copy link
Contributor Author

@kuhar thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants