Skip to content

[mlir][arith] Add shift integration tests #98183

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pingshiyu
Copy link
Contributor

Shift left/right regression tests, from the original larger PR that has been broken down: #92272

@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-arith

Author: Jacob Yu (pingshiyu)

Changes

Shift left/right regression tests, from the original larger PR that has been broken down: #92272


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

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir (+160)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir b/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir
new file mode 100644
index 0000000000000..519ecaf210812
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir
@@ -0,0 +1,160 @@
+// RUN: mlir-opt %s --test-lower-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 @shrsi_i8(%v1 : i8, %v2 : i8) {
+  vector.print str "@shrsi_i8\n"
+  %res = arith.shrsi %v1, %v2 : i8
+  vector.print %res : i8
+  return
+}
+
+func.func @shrui_i8(%v1 : i8, %v2 : i8) {
+  vector.print str "@shrui_i8\n"
+  %res = arith.shrui %v1, %v2 : i8
+  vector.print %res : i8
+  return
+}
+
+func.func @shli_i8(%v1 : i8, %v2 : i8) {
+  vector.print str "@shli_i8\n"
+  %res = arith.shli %v1, %v2 : i8
+  vector.print %res : i8
+  return
+}
+
+func.func @shrsi_i1(%v1 : i1, %v2 : i1) {
+  vector.print str "@shrsi_i1\n"
+  %res = arith.shrsi %v1, %v2 : i1
+  vector.print %res : i1
+  return
+}
+
+func.func @shrui_i1(%v1 : i1, %v2 : i1) {
+  vector.print str "@shrui_i1\n"
+  %res = arith.shrui %v1, %v2 : i1
+  vector.print %res : i1
+  return
+}
+
+func.func @shli_i1(%v1 : i1, %v2 : i1) {
+  vector.print str "@shli_i1\n"
+  %res = arith.shli %v1, %v2 : i1
+  vector.print %res : i1
+  return
+}
+
+func.func @shrsi() {
+    // ------------------------------------------------
+    // Test i1
+    // ------------------------------------------------
+    %false = arith.constant 0 : i1
+
+    // shift by zero : i1 should be non poison
+    // shrsi 0 0 : i1 = 0
+    // CHECK-LABEL: @shrsi_i1
+    // CHECK-NEXT:  0
+    func.call @shrsi_i1(%false, %false) : (i1, i1) -> ()
+
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %c7 = arith.constant 7 : i8
+    %cn10 = arith.constant -10 : i8
+    %c0 = arith.constant 0 : i8
+
+    // shrsi preserves signs
+    // shrsi -10 7 : i8 = -1
+    // CHECK-LABEL: @shrsi_i8
+    // CHECK-NEXT:  -1
+    func.call @shrsi_i8(%cn10, %c7) : (i8, i8) -> ()
+
+    // shift on zero is identity
+    // shrsi 7 0 : i8 = 7
+    // CHECK-LABEL: @shrsi_i8
+    // CHECK-NEXT:  7
+    func.call @shrsi_i8(%c7, %c0) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: Test i16, i32 etc..
+    // ------------------------------------------------
+
+    return
+}
+
+func.func @shrui() {
+    // ------------------------------------------------
+    // Test i1
+    // ------------------------------------------------
+    %false = arith.constant 0 : i1
+
+    // shift by zero : i1 should be non poison
+    // shrui 0 0 : i1 = 0
+    // CHECK-LABEL: @shrui_i1
+    // CHECK-NEXT:  0
+    func.call @shrui_i1(%false, %false) : (i1, i1) -> ()
+
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %cn10 = arith.constant -10 : i8
+    %c0 = arith.constant 0 : i8
+
+    // shift on zero is identity
+    // shrsi -10 0 : i8 = -10
+    // CHECK-LABEL: @shrui_i8
+    // CHECK-NEXT:  -10
+    func.call @shrui_i8(%cn10, %c0) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: Test i16, i32 etc..
+    // ------------------------------------------------
+
+    return
+}
+
+func.func @shli() {
+    // ------------------------------------------------
+    // Test i1
+    // ------------------------------------------------
+    %false = arith.constant 0 : i1
+
+    // shift by zero : i1 should be non poison
+    // shli 0 0 : i1 = 0
+    // CHECK-LABEL: @shli_i1
+    // CHECK-NEXT:  0
+    func.call @shli_i1(%false, %false) : (i1, i1) -> ()
+
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %c7 = arith.constant 7 : i8
+    %c0 = arith.constant 0 : i8
+    %cn100 = arith.constant -100 : i8
+
+    // shift on zero is identity
+    // shli 7 0 : i8 = 7
+    // CHECK-LABEL: @shli_i8
+    // CHECK-NEXT:  7
+    func.call @shli_i8(%c7, %c0) : (i8, i8) -> ()
+
+    // shli on i8, value goes off into the void (overflow/modulus needed)
+    // shli (-100), 7
+    // CHECK-LABEL: @shli_i8
+    // CHECK-NEXT:  0
+    func.call @shli_i8(%cn100, %c7) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: Test i16, i32 etc..
+    // ------------------------------------------------
+
+    return
+}
+
+func.func @entry() {
+    func.call @shrsi() : () -> ()
+    func.call @shrui() : () -> ()
+    func.call @shli() : () -> ()
+    return
+}

@banach-space banach-space self-requested a review July 21, 2024 15:06
@pingshiyu pingshiyu changed the title [mlir][arith] Add shift regression tests [mlir][arith] Add shift integration tests Jul 23, 2024
// ------------------------------------------------
%false = arith.constant 0 : i1

// shift by zero : i1 should be non poison
Copy link
Member

Choose a reason for hiding this comment

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

We cannot check for poison in integration tests... I'd suggest removing this comment

// ------------------------------------------------
%false = arith.constant 0 : i1

// shift by zero : i1 should be non poison
Copy link
Member

Choose a reason for hiding this comment

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

same here

// ------------------------------------------------
%false = arith.constant 0 : i1

// shift by zero : i1 should be non poison
Copy link
Member

Choose a reason for hiding this comment

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

also here

// CHECK-NEXT: 7
func.call @shli_i8(%c7, %c0) : (i8, i8) -> ()

// shli on i8, value goes off into the void (overflow/modulus needed)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this comment

@joker-eph
Copy link
Collaborator

Same as in the other PR, I'd like to see more motivation for these tests. I'm not sure about the whole value they add (we don't need to have e2e for everything like this!) and a such the description should be fleshed out to make it more clear.

@banach-space
Copy link
Contributor

Given the discussion here:

and the resulting update to the MLIR guidelines on e2e tests:

I suggest that we park this for now.

@pingshiyu, thank you so much for your contribution and for bearing with us throughout this process. Apologies for not resolving the earlier discussion sooner—it would have saved you a lot of effort. I hope this doesn’t discourage you from contributing to MLIR in the future, and we truly appreciate your work!

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.

5 participants