158 lines · plain
1// Check that the wide integer `arith.max*i`/`min*i` emulation produces the2// same result as wide ops. Emulate i16 ops with i8 ops.3// Ops in functions prefixed with `emulate` will be emulated using i8 types.4 5// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \6// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \7// RUN: mlir-runner -e entry -entry-point-result=void \8// RUN: --shared-libs=%mlir_c_runner_utils | \9// RUN: FileCheck %s --match-full-lines10 11// RUN: mlir-opt %s --test-arith-emulate-wide-int="widest-int-supported=8" \12// RUN: --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \13// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \14// RUN: mlir-runner -e entry -entry-point-result=void \15// RUN: --shared-libs=%mlir_c_runner_utils | \16// RUN: FileCheck %s --match-full-lines17 18func.func @emulate_maxui(%lhs : i16, %rhs : i16) -> (i16) {19 %res = arith.maxui %lhs, %rhs : i1620 return %res : i1621}22 23func.func @check_maxui(%lhs : i16, %rhs : i16) -> () {24 %res = func.call @emulate_maxui(%lhs, %rhs) : (i16, i16) -> (i16)25 vector.print %res : i1626 return27}28 29func.func @emulate_maxsi(%lhs : i16, %rhs : i16) -> (i16) {30 %res = arith.maxsi %lhs, %rhs : i1631 return %res : i1632}33 34func.func @check_maxsi(%lhs : i16, %rhs : i16) -> () {35 %res = func.call @emulate_maxsi(%lhs, %rhs) : (i16, i16) -> (i16)36 vector.print %res : i1637 return38}39 40func.func @emulate_minui(%lhs : i16, %rhs : i16) -> (i16) {41 %res = arith.minui %lhs, %rhs : i1642 return %res : i1643}44 45func.func @check_minui(%lhs : i16, %rhs : i16) -> () {46 %res = func.call @emulate_minui(%lhs, %rhs) : (i16, i16) -> (i16)47 vector.print %res : i1648 return49}50 51func.func @emulate_minsi(%lhs : i16, %rhs : i16) -> (i16) {52 %res = arith.minsi %lhs, %rhs : i1653 return %res : i1654}55 56func.func @check_minsi(%lhs : i16, %rhs : i16) -> () {57 %res = func.call @emulate_minsi(%lhs, %rhs) : (i16, i16) -> (i16)58 vector.print %res : i1659 return60}61 62 63func.func @entry() {64 %cst0 = arith.constant 0 : i1665 %cst1 = arith.constant 1 : i1666 %cst7 = arith.constant 7 : i1667 %cst_n1 = arith.constant -1 : i1668 %cst1337 = arith.constant 1337 : i1669 %cst4096 = arith.constant 4096 : i1670 %cst_i16_min = arith.constant -32768 : i1671 72 // CHECK: 073 // CHECK-NEXT: 174 // CHECK-NEXT: 175 // CHECK-NEXT: 176 // CHECK-NEXT: -177 // CHECK-NEXT: -178 // CHECK-NEXT: -179 // CHECK-NEXT: 133780 // CHECK-NEXT: 409681 // CHECK-NEXT: -3276882 func.call @check_maxui(%cst0, %cst0) : (i16, i16) -> ()83 func.call @check_maxui(%cst0, %cst1) : (i16, i16) -> ()84 func.call @check_maxui(%cst1, %cst0) : (i16, i16) -> ()85 func.call @check_maxui(%cst1, %cst1) : (i16, i16) -> ()86 func.call @check_maxui(%cst_n1, %cst1) : (i16, i16) -> ()87 func.call @check_maxui(%cst1, %cst_n1) : (i16, i16) -> ()88 func.call @check_maxui(%cst_n1, %cst1337) : (i16, i16) -> ()89 func.call @check_maxui(%cst1337, %cst1337) : (i16, i16) -> ()90 func.call @check_maxui(%cst4096, %cst4096) : (i16, i16) -> ()91 func.call @check_maxui(%cst1337, %cst_i16_min) : (i16, i16) -> ()92 93 // CHECK-NEXT: 094 // CHECK-NEXT: 195 // CHECK-NEXT: 196 // CHECK-NEXT: 197 // CHECK-NEXT: 198 // CHECK-NEXT: 199 // CHECK-NEXT: 1337100 // CHECK-NEXT: 1337101 // CHECK-NEXT: 4096102 // CHECK-NEXT: 1337103 func.call @check_maxsi(%cst0, %cst0) : (i16, i16) -> ()104 func.call @check_maxsi(%cst0, %cst1) : (i16, i16) -> ()105 func.call @check_maxsi(%cst1, %cst0) : (i16, i16) -> ()106 func.call @check_maxsi(%cst1, %cst1) : (i16, i16) -> ()107 func.call @check_maxsi(%cst_n1, %cst1) : (i16, i16) -> ()108 func.call @check_maxsi(%cst1, %cst_n1) : (i16, i16) -> ()109 func.call @check_maxsi(%cst_n1, %cst1337) : (i16, i16) -> ()110 func.call @check_maxsi(%cst1337, %cst1337) : (i16, i16) -> ()111 func.call @check_maxsi(%cst4096, %cst4096) : (i16, i16) -> ()112 func.call @check_maxsi(%cst1337, %cst_i16_min) : (i16, i16) -> ()113 114 // CHECK-NEXT: 0115 // CHECK-NEXT: 0116 // CHECK-NEXT: 0117 // CHECK-NEXT: 1118 // CHECK-NEXT: 1119 // CHECK-NEXT: 1120 // CHECK-NEXT: 1337121 // CHECK-NEXT: 1337122 // CHECK-NEXT: 4096123 // CHECK-NEXT: 1337124 func.call @check_minui(%cst0, %cst0) : (i16, i16) -> ()125 func.call @check_minui(%cst0, %cst1) : (i16, i16) -> ()126 func.call @check_minui(%cst1, %cst0) : (i16, i16) -> ()127 func.call @check_minui(%cst1, %cst1) : (i16, i16) -> ()128 func.call @check_minui(%cst_n1, %cst1) : (i16, i16) -> ()129 func.call @check_minui(%cst1, %cst_n1) : (i16, i16) -> ()130 func.call @check_minui(%cst_n1, %cst1337) : (i16, i16) -> ()131 func.call @check_minui(%cst1337, %cst1337) : (i16, i16) -> ()132 func.call @check_minui(%cst4096, %cst4096) : (i16, i16) -> ()133 func.call @check_minui(%cst1337, %cst_i16_min) : (i16, i16) -> ()134 135 // CHECK-NEXT: 0136 // CHECK-NEXT: 0137 // CHECK-NEXT: 0138 // CHECK-NEXT: 1139 // CHECK-NEXT: -1140 // CHECK-NEXT: -1141 // CHECK-NEXT: -1142 // CHECK-NEXT: 1337143 // CHECK-NEXT: 4096144 // CHECK-NEXT: -32768145 func.call @check_minsi(%cst0, %cst0) : (i16, i16) -> ()146 func.call @check_minsi(%cst0, %cst1) : (i16, i16) -> ()147 func.call @check_minsi(%cst1, %cst0) : (i16, i16) -> ()148 func.call @check_minsi(%cst1, %cst1) : (i16, i16) -> ()149 func.call @check_minsi(%cst_n1, %cst1) : (i16, i16) -> ()150 func.call @check_minsi(%cst1, %cst_n1) : (i16, i16) -> ()151 func.call @check_minsi(%cst_n1, %cst1337) : (i16, i16) -> ()152 func.call @check_minsi(%cst1337, %cst1337) : (i16, i16) -> ()153 func.call @check_minsi(%cst4096, %cst4096) : (i16, i16) -> ()154 func.call @check_minsi(%cst1337, %cst_i16_min) : (i16, i16) -> ()155 156 return157}158