Skip to content

[mlir][arith] Add truncation and extension integration tests #98182

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 3 commits into
base: main
Choose a base branch
from

Conversation

pingshiyu
Copy link
Contributor

Trunc/ext operations 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

Author: Jacob Yu (pingshiyu)

Changes

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


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

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/trunc-ext.mlir (+90)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/trunc-ext.mlir b/mlir/test/Integration/Dialect/Arith/CPU/trunc-ext.mlir
new file mode 100644
index 0000000000000..4c27f2bf7b318
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/trunc-ext.mlir
@@ -0,0 +1,90 @@
+// 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 @extsi_i1_i16(%v1 : i1) {
+    vector.print str "@extsi_i1_i16\n"
+    %0 = arith.extsi %v1 : i1 to i16
+    vector.print %0 : i16
+    return
+}
+
+func.func @extui_i1_i64(%v1 : i1) {
+    vector.print str "@extui_i1_i64\n"
+    %0 = arith.extui %v1 : i1 to i64
+    vector.print %0 : i64
+    return
+}
+
+func.func @trunci_i16_i8(%v1 : i16) {
+    vector.print str "@trunci_i16_i8\n"
+    %0 = arith.trunci %v1 : i16 to i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @extsi() {
+    // ------------------------------------------------
+    // Test extending from i1
+    // ------------------------------------------------
+    %true = arith.constant -1 : i1
+
+    // extsi on 1 : i1
+    // extsi(1: i1) = -1 : i16
+    // CHECK-LABEL: @extsi_i1_i16
+    // CHECK-NEXT:  -1
+    func.call @extsi_i1_i16(%true) : (i1) -> ()
+
+    // ------------------------------------------------
+    // TODO: Test extension from i8, i16 etc..
+    // ------------------------------------------------
+
+    return
+}
+
+func.func @extui() {
+    // ------------------------------------------------
+    // Test extending from i1
+    // ------------------------------------------------
+    %true = arith.constant true
+
+    // extui should extend i1 with 0 bits not 1s
+    // extui(1 : i1) = 1 : i64
+    // CHECK-LABEL: @extui_i1_i64
+    // CHECK-NEXT:  1
+    func.call @extui_i1_i64(%true) : (i1) -> ()
+
+    // ------------------------------------------------
+    // TODO: Test extension from i8, i16 etc..
+    // ------------------------------------------------
+
+    return
+}
+
+func.func @trunci() {
+    // ------------------------------------------------
+    // Test truncating from i16
+    // ------------------------------------------------
+
+    // trunci on 20194 : i16
+    // trunci(20194 : i16) = -30 : i8
+    // CHECK-LABEL: @trunci_i16_i8
+    // CHECK-NEXT:  -30
+    %c20194 = arith.constant 20194 : i16
+    func.call @trunci_i16_i8(%c20194) : (i16) -> ()
+
+    // ------------------------------------------------
+    // TODO: Test truncation of i1, i8 etc..
+    // ------------------------------------------------
+
+    return
+}
+
+func.func @entry() {
+    func.call @extsi() : () -> ()
+    func.call @extui() : () -> ()
+    func.call @trunci() : () -> ()
+    return
+}

@pingshiyu pingshiyu changed the title [mlir][arith] Add truncation and extension regressions [mlir][arith] Add truncation and extension integration tests Jul 23, 2024
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 % nit

Comment on lines +32 to +33
%true = arith.constant -1 : i1

Copy link
Member

Choose a reason for hiding this comment

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

Why do we use -1 here but true in the test below? Should we make this consistent across the test cases?

@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.

4 participants