xref: /llvm-project/mlir/test/Integration/Dialect/Arith/CPU/test-wide-int-emulation-shrui-i16.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// Check that the wide integer `arith.shrui` emulation produces the same result as wide
2// `arith.shrui`. Emulate i16 ops with i8 ops.
3
4// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
5// RUN:             --convert-func-to-llvm --convert-arith-to-llvm | \
6// RUN:   mlir-runner -e entry -entry-point-result=void \
7// RUN:                   --shared-libs=%mlir_c_runner_utils | \
8// RUN:   FileCheck %s --match-full-lines
9
10// RUN: mlir-opt %s --test-arith-emulate-wide-int="widest-int-supported=8" \
11// RUN:             --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
12// RUN:             --convert-func-to-llvm --convert-arith-to-llvm | \
13// RUN:   mlir-runner -e entry -entry-point-result=void \
14// RUN:                   --shared-libs=%mlir_c_runner_utils | \
15// RUN:   FileCheck %s --match-full-lines
16
17// Ops in this function *only* will be emulated using i8 types.
18func.func @emulate_shrui(%lhs : i16, %rhs : i16) -> (i16) {
19  %res = arith.shrui %lhs, %rhs : i16
20  return %res : i16
21}
22
23func.func @check_shrui(%lhs : i16, %rhs : i16) -> () {
24  %res = func.call @emulate_shrui(%lhs, %rhs) : (i16, i16) -> (i16)
25  vector.print %res : i16
26  return
27}
28
29func.func @entry() {
30  %cst0 = arith.constant 0 : i16
31  %cst1 = arith.constant 1 : i16
32  %cst2 = arith.constant 2 : i16
33  %cst7 = arith.constant 7 : i16
34  %cst8 = arith.constant 8 : i16
35  %cst9 = arith.constant 9 : i16
36  %cst15 = arith.constant 15 : i16
37
38  %cst_n1 = arith.constant -1 : i16
39
40  %cst1337 = arith.constant 1337 : i16
41  %cst_n1337 = arith.constant -1337 : i16
42
43  %cst_i16_min = arith.constant -32768 : i16
44
45  // CHECK:      0
46  // CHECK-NEXT: 0
47  // CHECK-NEXT: 0
48  // CHECK-NEXT: 1
49  // CHECK-NEXT: 32767
50  // CHECK-NEXT: 1
51  func.call @check_shrui(%cst0, %cst0) : (i16, i16) -> ()
52  func.call @check_shrui(%cst0, %cst1) : (i16, i16) -> ()
53  func.call @check_shrui(%cst1, %cst1) : (i16, i16) -> ()
54  func.call @check_shrui(%cst1, %cst0) : (i16, i16) -> ()
55  func.call @check_shrui(%cst_n1, %cst1) : (i16, i16) -> ()
56  func.call @check_shrui(%cst_n1, %cst15) : (i16, i16) -> ()
57
58  // CHECK-NEXT: 1337
59  // CHECK-NEXT: 334
60  // CHECK-NEXT: 10
61  // CHECK-NEXT: 5
62  // CHECK-NEXT: 2
63  // CHECK-NEXT: 0
64  func.call @check_shrui(%cst1337, %cst0) : (i16, i16) -> ()
65  func.call @check_shrui(%cst1337, %cst2) : (i16, i16) -> ()
66  func.call @check_shrui(%cst1337, %cst7) : (i16, i16) -> ()
67  func.call @check_shrui(%cst1337, %cst8) : (i16, i16) -> ()
68  func.call @check_shrui(%cst1337, %cst9) : (i16, i16) -> ()
69  func.call @check_shrui(%cst1337, %cst15) : (i16, i16) -> ()
70
71  // CHECK-NEXT: -1337
72  // CHECK-NEXT: 16049
73  // CHECK-NEXT: 501
74  // CHECK-NEXT: 250
75  // CHECK-NEXT: 125
76  // CHECK-NEXT: 1
77  func.call @check_shrui(%cst_n1337, %cst0) : (i16, i16) -> ()
78  func.call @check_shrui(%cst_n1337, %cst2) : (i16, i16) -> ()
79  func.call @check_shrui(%cst_n1337, %cst7) : (i16, i16) -> ()
80  func.call @check_shrui(%cst_n1337, %cst8) : (i16, i16) -> ()
81  func.call @check_shrui(%cst_n1337, %cst9) : (i16, i16) -> ()
82  func.call @check_shrui(%cst_n1337, %cst15) : (i16, i16) -> ()
83
84  // CHECK-NEXT: 16384
85  // CHECK-NEXT: 8192
86  // CHECK-NEXT: 256
87  // CHECK-NEXT: 128
88  // CHECK-NEXT: 64
89  // CHECK-NEXT: 1
90  func.call @check_shrui(%cst_i16_min, %cst1) : (i16, i16) -> ()
91  func.call @check_shrui(%cst_i16_min, %cst2) : (i16, i16) -> ()
92  func.call @check_shrui(%cst_i16_min, %cst7) : (i16, i16) -> ()
93  func.call @check_shrui(%cst_i16_min, %cst8) : (i16, i16) -> ()
94  func.call @check_shrui(%cst_i16_min, %cst9) : (i16, i16) -> ()
95  func.call @check_shrui(%cst_i16_min, %cst15) : (i16, i16) -> ()
96
97  return
98}
99