[Mlir-commits] [mlir] [mlir][arith] Add shift regression tests (PR #98183)

Jacob Yu llvmlistbot at llvm.org
Thu Jul 11 09:10:12 PDT 2024


https://github.com/pingshiyu updated https://github.com/llvm/llvm-project/pull/98183

>From 57e4bb4fa5cc2e164877dd256781174775745a39 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Tue, 9 Jul 2024 16:48:25 +0100
Subject: [PATCH 1/2] tests for shifts in the new format

---
 .../Integration/Dialect/Arith/CPU/shifts.mlir | 160 ++++++++++++++++++
 1 file changed, 160 insertions(+)
 create mode 100644 mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir

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
+}

>From 505ad4e39cd0ba5cbcc2bc48bd7793fef720fcae Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Thu, 11 Jul 2024 17:09:59 +0100
Subject: [PATCH 2/2] reindented

---
 .../Integration/Dialect/Arith/CPU/shifts.mlir | 204 +++++++++---------
 1 file changed, 102 insertions(+), 102 deletions(-)

diff --git a/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir b/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir
index 519ecaf210812..c6f2df8d62212 100644
--- a/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir
+++ b/mlir/test/Integration/Dialect/Arith/CPU/shifts.mlir
@@ -46,115 +46,115 @@ func.func @shli_i1(%v1 : i1, %v2 : i1) {
 }
 
 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
+  // ------------------------------------------------
+  // 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
+  // ------------------------------------------------
+  // 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
+  // ------------------------------------------------
+  // 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
+  func.call @shrsi() : () -> ()
+  func.call @shrui() : () -> ()
+  func.call @shli() : () -> ()
+  return
 }



More information about the Mlir-commits mailing list