1// Check that the wide integer `arith.max*i`/`min*i` emulation produces the 2// 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-lines 10 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-lines 17 18func.func @emulate_maxui(%lhs : i16, %rhs : i16) -> (i16) { 19 %res = arith.maxui %lhs, %rhs : i16 20 return %res : i16 21} 22 23func.func @check_maxui(%lhs : i16, %rhs : i16) -> () { 24 %res = func.call @emulate_maxui(%lhs, %rhs) : (i16, i16) -> (i16) 25 vector.print %res : i16 26 return 27} 28 29func.func @emulate_maxsi(%lhs : i16, %rhs : i16) -> (i16) { 30 %res = arith.maxsi %lhs, %rhs : i16 31 return %res : i16 32} 33 34func.func @check_maxsi(%lhs : i16, %rhs : i16) -> () { 35 %res = func.call @emulate_maxsi(%lhs, %rhs) : (i16, i16) -> (i16) 36 vector.print %res : i16 37 return 38} 39 40func.func @emulate_minui(%lhs : i16, %rhs : i16) -> (i16) { 41 %res = arith.minui %lhs, %rhs : i16 42 return %res : i16 43} 44 45func.func @check_minui(%lhs : i16, %rhs : i16) -> () { 46 %res = func.call @emulate_minui(%lhs, %rhs) : (i16, i16) -> (i16) 47 vector.print %res : i16 48 return 49} 50 51func.func @emulate_minsi(%lhs : i16, %rhs : i16) -> (i16) { 52 %res = arith.minsi %lhs, %rhs : i16 53 return %res : i16 54} 55 56func.func @check_minsi(%lhs : i16, %rhs : i16) -> () { 57 %res = func.call @emulate_minsi(%lhs, %rhs) : (i16, i16) -> (i16) 58 vector.print %res : i16 59 return 60} 61 62 63func.func @entry() { 64 %cst0 = arith.constant 0 : i16 65 %cst1 = arith.constant 1 : i16 66 %cst7 = arith.constant 7 : i16 67 %cst_n1 = arith.constant -1 : i16 68 %cst1337 = arith.constant 1337 : i16 69 %cst4096 = arith.constant 4096 : i16 70 %cst_i16_min = arith.constant -32768 : i16 71 72 // CHECK: 0 73 // CHECK-NEXT: 1 74 // CHECK-NEXT: 1 75 // CHECK-NEXT: 1 76 // CHECK-NEXT: -1 77 // CHECK-NEXT: -1 78 // CHECK-NEXT: -1 79 // CHECK-NEXT: 1337 80 // CHECK-NEXT: 4096 81 // CHECK-NEXT: -32768 82 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: 0 94 // CHECK-NEXT: 1 95 // CHECK-NEXT: 1 96 // CHECK-NEXT: 1 97 // CHECK-NEXT: 1 98 // CHECK-NEXT: 1 99 // CHECK-NEXT: 1337 100 // CHECK-NEXT: 1337 101 // CHECK-NEXT: 4096 102 // CHECK-NEXT: 1337 103 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: 0 115 // CHECK-NEXT: 0 116 // CHECK-NEXT: 0 117 // CHECK-NEXT: 1 118 // CHECK-NEXT: 1 119 // CHECK-NEXT: 1 120 // CHECK-NEXT: 1337 121 // CHECK-NEXT: 1337 122 // CHECK-NEXT: 4096 123 // CHECK-NEXT: 1337 124 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: 0 136 // CHECK-NEXT: 0 137 // CHECK-NEXT: 0 138 // CHECK-NEXT: 1 139 // CHECK-NEXT: -1 140 // CHECK-NEXT: -1 141 // CHECK-NEXT: -1 142 // CHECK-NEXT: 1337 143 // CHECK-NEXT: 4096 144 // CHECK-NEXT: -32768 145 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 return 157} 158