xref: /llvm-project/mlir/test/Integration/Dialect/Arith/CPU/test-wide-int-emulation-shli-i16.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// Check that the wide integer `arith.shli` emulation produces the same result as wide
2// `arith.shli`. 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_shli(%lhs : i16, %rhs : i16) -> (i16) {
19  %res = arith.shli %lhs, %rhs : i16
20  return %res : i16
21}
22
23func.func @check_shli(%lhs : i16, %rhs : i16) -> () {
24  %res = func.call @emulate_shli(%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
42  %cst_i16_min = arith.constant -32768 : i16
43
44  // CHECK:      0
45  // CHECK-NEXT: 0
46  // CHECK-NEXT: 1
47  // CHECK-NEXT: 2
48  // CHECK-NEXT: -2
49  // CHECK-NEXT: -32768
50  func.call @check_shli(%cst0, %cst0) : (i16, i16) -> ()
51  func.call @check_shli(%cst0, %cst1) : (i16, i16) -> ()
52  func.call @check_shli(%cst1, %cst0) : (i16, i16) -> ()
53  func.call @check_shli(%cst1, %cst1) : (i16, i16) -> ()
54  func.call @check_shli(%cst_n1, %cst1) : (i16, i16) -> ()
55  func.call @check_shli(%cst_n1, %cst15) : (i16, i16) -> ()
56
57  // CHECK-NEXT: 1337
58  // CHECK-NEXT: 5348
59  // CHECK-NEXT: -25472
60  // CHECK-NEXT: 14592
61  // CHECK-NEXT: 29184
62  // CHECK-NEXT: -32768
63  // CHECK-NEXT: 0
64  func.call @check_shli(%cst1337, %cst0) : (i16, i16) -> ()
65  func.call @check_shli(%cst1337, %cst2) : (i16, i16) -> ()
66  func.call @check_shli(%cst1337, %cst7) : (i16, i16) -> ()
67  func.call @check_shli(%cst1337, %cst8) : (i16, i16) -> ()
68  func.call @check_shli(%cst1337, %cst9) : (i16, i16) -> ()
69  func.call @check_shli(%cst1337, %cst15) : (i16, i16) -> ()
70  func.call @check_shli(%cst_i16_min, %cst1) : (i16, i16) -> ()
71
72  return
73}
74