[Mlir-commits] [mlir] 1c46fc0 - [mlir][arith] Add comparison integration tests (#96974)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Aug 25 10:59:28 PDT 2024
Author: Jacob Yu
Date: 2024-08-25T13:59:25-04:00
New Revision: 1c46fc00f56f25abaefd8d124460599ae06214b4
URL: https://github.com/llvm/llvm-project/commit/1c46fc00f56f25abaefd8d124460599ae06214b4
DIFF: https://github.com/llvm/llvm-project/commit/1c46fc00f56f25abaefd8d124460599ae06214b4.diff
LOG: [mlir][arith] Add comparison integration tests (#96974)
Comparison operations regression tests, from the original larger PR that
has been broken down: https://github.com/llvm/llvm-project/pull/92272
---------
Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
Co-authored-by: Andrzej WarzyĆski <andrzej.warzynski at gmail.com>
Added:
mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
Modified:
Removed:
################################################################################
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 00000000000000..418fbb0c0a94c7
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir
@@ -0,0 +1,174 @@
+// 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 @cmpi_eq_i1(%v1 : i1, %v2 : i1) {
+ vector.print str "@cmpi_eq_i1\n"
+ %res = arith.cmpi eq, %v1, %v2 : i1
+ vector.print %res : i1
+ return
+}
+
+func.func @cmpi_slt_i1(%v1 : i1, %v2 : i1) {
+ vector.print str "@cmpi_slt_i1\n"
+ %res = arith.cmpi slt, %v1, %v2 : i1
+ vector.print %res : i1
+ return
+}
+
+func.func @cmpi_sle_i1(%v1 : i1, %v2 : i1) {
+ vector.print str "@cmpi_sle_i1\n"
+ %res = arith.cmpi sle, %v1, %v2 : i1
+ vector.print %res : i1
+ return
+}
+
+func.func @cmpi_sgt_i1(%v1 : i1, %v2 : i1) {
+ vector.print str "@cmpi_sgt_i1\n"
+ %res = arith.cmpi sgt, %v1, %v2 : i1
+ vector.print %res : i1
+ return
+}
+
+func.func @cmpi_sge_i1(%v1 : i1, %v2 : i1) {
+ vector.print str "@cmpi_sge_i1\n"
+ %res = arith.cmpi sge, %v1, %v2 : i1
+ vector.print %res : i1
+ return
+}
+
+func.func @cmpi_eq() {
+ // ------------------------------------------------
+ // Test i1
+ // ------------------------------------------------
+ %false_i1 = arith.constant 0 : i1
+ %true_i1 = arith.constant 1 : i1
+ %true_i1_n1 = arith.constant -1 : i1
+
+ // int values 1 and -1 are represented with the same bitvector (`0b1`)
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_eq_i1(%true_i1, %true_i1_n1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 0
+ func.call @cmpi_eq_i1(%false_i1, %true_i1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 0
+ func.call @cmpi_eq_i1(%true_i1, %false_i1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_eq_i1(%true_i1, %true_i1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_eq_i1(%false_i1, %false_i1) : (i1, i1) -> ()
+
+ %false = arith.constant false
+ %true = arith.constant true
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_eq_i1(%true, %true_i1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_eq_i1(%false, %false_i1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_eq_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_eq_i1(%true, %true_i1_n1) : (i1, i1) -> ()
+
+ // ------------------------------------------------
+ // TODO: Test i8, i16 etc..
+ // ------------------------------------------------
+ return
+}
+
+func.func @cmpi_signed() {
+ // ------------------------------------------------
+ // Test i1
+ // ------------------------------------------------
+ %false_i1 = arith.constant 0 : i1
+ %true_i1 = arith.constant 1 : i1
+ %true_i1_n1 = arith.constant -1 : i1
+
+ // int values 1 and -1 are represented with the same bitvector (`0b1`)
+ // But, bitvector `1` is interpreted as int value -1 in signed comparison
+
+ // CHECK-LABEL: @cmpi_sge_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_sge_i1(%false_i1, %true_i1_n1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_sge_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_sge_i1(%false_i1, %true_i1) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_sge_i1
+ // CHECK-NEXT: 0
+ func.call @cmpi_sge_i1(%true_i1, %false_i1) : (i1, i1) -> ()
+
+ %false = arith.constant false
+ %true = arith.constant true
+
+ // CHECK-LABEL: @cmpi_slt_i1
+ // CHECK-NEXT: 0
+ func.call @cmpi_slt_i1(%false, %true) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_sle_i1
+ // CHECK-NEXT: 0
+ func.call @cmpi_sle_i1(%false, %true) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_sgt_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_sgt_i1(%false, %true) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_sge_i1
+ // CHECK-NEXT: 1
+ func.call @cmpi_sge_i1(%false, %true) : (i1, i1) -> ()
+
+ // CHECK-LABEL: @cmpi_sge_i1
+ // CHECK-NEXT: 0
+ func.call @cmpi_sge_i1(%true, %false) : (i1, i1) -> ()
+
+ // ------------------------------------------------
+ // TODO: Test i8, i16 etc..
+ // ------------------------------------------------
+ return
+}
+
+func.func @cmpi_ult_index(%v1 : index, %v2 : index) {
+ vector.print str "@cmpi_ult_index\n"
+ %res = arith.cmpi ult, %v1, %v2 : index
+ vector.print %res : i1
+ return
+}
+
+func.func @cmpi_unsigned() {
+ // ------------------------------------------------
+ // Test index
+ // ------------------------------------------------
+ // 0 `ult` -2^63 = true
+ %zero = arith.constant 0 : index
+ %index_min = arith.constant -9223372036854775808 : index
+
+ // CHECK-LABEL: @cmpi_ult_index
+ // CHECK-NEXT: 1
+ func.call @cmpi_ult_index(%zero, %index_min) : (index, index) -> ()
+
+ // ------------------------------------------------
+ // TODO: i1, i8, i16, uge, ule etc..
+ // ------------------------------------------------
+ return
+}
+
+func.func @entry() {
+ func.call @cmpi_eq() : () -> ()
+ func.call @cmpi_signed() : () -> ()
+ func.call @cmpi_unsigned() : () -> ()
+ return
+}
More information about the Mlir-commits
mailing list