Skip to content

[mlir][arith] Add comparison integration tests #96974

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 14 commits into from
Aug 25, 2024

Conversation

pingshiyu
Copy link
Contributor

Comparison operations regression tests, from the original larger PR that has been broken down: #92272

@pingshiyu
Copy link
Contributor Author

@banach-space @kuhar

@llvmbot
Copy link
Member

llvmbot commented Jun 27, 2024

@llvm/pr-subscribers-mlir-arith

@llvm/pr-subscribers-mlir

Author: Jacob Yu (pingshiyu)

Changes

Comparison operations regression tests, from the original larger PR that has been broken down: #92272


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

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir (+61)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
new file mode 100644
index 0000000000000..85b70b2cad5a0
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
@@ -0,0 +1,61 @@
+// Tests comparison operations.
+// 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 @signed_comparison_on_i1s() {
+    // signed comparisons on i1s
+    // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true
+    // CHECK:      0
+    // CHECK-NEXT: 0
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 1
+    %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 @sge_0_1_is_true() {
+    // sge 0 -1, sge 0 1, should be true
+    // sge 0 -1 == sge 0 1 == true (1)
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 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 @zero_ult_min_index() {
+    // 0 `ult` -2^63 = true
+    // CHECK-NEXT: 1
+    %c0 = arith.constant 0 : index
+    %c-9223372036854775808 = arith.constant -9223372036854775808 : index
+    %0 = arith.cmpi ult, %c0, %c-9223372036854775808 : index
+    vector.print %0 : i1
+    return
+}
+
+func.func @entry() {
+    func.call @signed_comparison_on_i1s() : () -> ()
+    func.call @sge_0_1_is_true() : () -> ()
+    func.call @zero_ult_min_index() : () -> ()
+    return
+}

@banach-space
Copy link
Contributor

Thanks! Could you try to structure this similarly that what you did for #96973? Similar comment re variable names (prefer underscores to hyphens) and re where to place CHECK lines (near the corresponding vector.print).

It might be easier to finish #96973 and #96975 first, and then just replicate the style that we establish there.

@pingshiyu
Copy link
Contributor Author

Thanks! Could you try to structure this similarly that what you did for #96973? Similar comment re variable names (prefer underscores to hyphens) and re where to place CHECK lines (near the corresponding vector.print).

It might be easier to finish #96973 and #96975 first, and then just replicate the style that we establish there.

Yep that's the plan! Once the other two PRs are done I'll use the same style as used there (and for the rest of the tests)

@pingshiyu
Copy link
Contributor Author

I've just pushed a commit updating this with the formats we established in the other PRs.

If everyone is generally happy with the format now and has no further comments, please tick it, and I'll apply the same changes to the other regressions!

@banach-space
Copy link
Contributor

If everyone is generally happy with the format now and has no further comments

I do like the structure (thanks!), but also have a few more comments. I will be sending these shortly. I won't be commenting on other PRs to avoid repetition.

[nit] Please follow https://mlir.llvm.org/getting_started/Contributing/#commit-messages, which links to https://cbea.ms/git-commit/. So, instead of:

[mlir][arith] adding comparison regression tests

it would be:

[mlir][arith] Add comparison regression tests

@pingshiyu pingshiyu changed the title [mlir][arith] adding comparison regression tests [mlir][arith] Add comparison regression tests Jul 6, 2024
@pingshiyu
Copy link
Contributor Author

@banach-space would you be able to take a look at this one too please, and tick if LGTY?

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.

[nit] "Add comparison regression tests " -> these are usually referred to as either "integration" or "e2e" (end-to-end) tests :)

@pingshiyu pingshiyu changed the title [mlir][arith] Add comparison regression tests [mlir][arith] Add comparison integration tests Jul 23, 2024
pingshiyu and others added 3 commits July 23, 2024 14:26
Co-authored-by: Andrzej Warzyński <andrzej.warzynski@gmail.com>
@pingshiyu pingshiyu force-pushed the arith-regression-comparison branch from c115e67 to 3cb8377 Compare July 23, 2024 14:04
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.

Just a few small suggestions

@pingshiyu
Copy link
Contributor Author

thank you @banach-space

I've pushed a commit to address the comments :)

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.

A couple more small suggestions. We are getting there 🙏🏻

@pingshiyu
Copy link
Contributor Author

@banach-space Thanks for the most recent comments!

I've just pushed a commit adding some extra tests and addressing the other comment - please give a tick if all looks good now!

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 all the updates and for bearing with me 🙏🏻

@pingshiyu
Copy link
Contributor Author

Great thank you @banach-space !

One down... 4 more to go 💀

@kuhar would you please be able to have a look as well and if you're happy, tick and merge? (I don't have merge rights)

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

LGTM

@kuhar kuhar merged commit 1c46fc0 into llvm:main Aug 25, 2024
8 checks passed
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