1; RUN: opt < %s -cost-model -analyze -mtriple=systemz-unknown -mcpu=z13 \ 2; RUN: | FileCheck %s -check-prefix=COST 3 4; Check that all divide/remainder instructions are implemented by cheaper instructions. 5; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 -o - | FileCheck %s 6; CHECK-NOT: dsg 7; CHECK-NOT: dl 8 9; Check costs of divisions/remainders by a vector of constants that is *not* 10; a power of two. A sequence containing a multiply and shifts will replace 11; the divide instruction. 12 13; Scalar sdiv 14 15define i64 @fun0(i64 %a) { 16 %r = sdiv i64 %a, 20 17 ret i64 %r 18; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = sdiv i64 %a, 20 19} 20 21define i32 @fun1(i32 %a) { 22 %r = sdiv i32 %a, 20 23 ret i32 %r 24; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = sdiv i32 %a, 20 25} 26 27define i16 @fun2(i16 %a) { 28 %r = sdiv i16 %a, 20 29 ret i16 %r 30; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = sdiv i16 %a, 20 31} 32 33define i8 @fun3(i8 %a) { 34 %r = sdiv i8 %a, 20 35 ret i8 %r 36; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = sdiv i8 %a, 20 37} 38 39; Vector sdiv 40 41define <2 x i64> @fun4(<2 x i64> %a) { 42 %r = sdiv <2 x i64> %a, <i64 20, i64 21> 43 ret <2 x i64> %r 44; COST: Cost Model: Found an estimated cost of 24 for instruction: %r = sdiv <2 x i64> 45} 46 47define <4 x i32> @fun5(<4 x i32> %a) { 48 %r = sdiv <4 x i32> %a, <i32 20, i32 20, i32 20, i32 20> 49 ret <4 x i32> %r 50; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = sdiv <4 x i32> 51} 52 53define <2 x i32> @fun6(<2 x i32> %a) { 54 %r = sdiv <2 x i32> %a, <i32 20, i32 21> 55 ret <2 x i32> %r 56; COST: Cost Model: Found an estimated cost of 25 for instruction: %r = sdiv <2 x i32> 57} 58 59define <8 x i16> @fun7(<8 x i16> %a) { 60 %r = sdiv <8 x i16> %a, <i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 20> 61 ret <8 x i16> %r 62; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = sdiv <8 x i16> 63} 64 65define <4 x i16> @fun8(<4 x i16> %a) { 66 %r = sdiv <4 x i16> %a, <i16 20, i16 20, i16 20, i16 21> 67 ret <4 x i16> %r 68; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = sdiv <4 x i16> 69} 70 71define <16 x i8> @fun9(<16 x i8> %a) { 72 %r = sdiv <16 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20> 73 ret <16 x i8> %r 74; COST: Cost Model: Found an estimated cost of 193 for instruction: %r = sdiv <16 x i8> 75} 76 77define <8 x i8> @fun10(<8 x i8> %a) { 78 %r = sdiv <8 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 21> 79 ret <8 x i8> %r 80; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = sdiv <8 x i8> 81} 82 83; Scalar udiv 84 85define i64 @fun11(i64 %a) { 86 %r = udiv i64 %a, 20 87 ret i64 %r 88; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = udiv i64 %a, 20 89} 90 91define i32 @fun12(i32 %a) { 92 %r = udiv i32 %a, 20 93 ret i32 %r 94; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = udiv i32 %a, 20 95} 96 97define i16 @fun13(i16 %a) { 98 %r = udiv i16 %a, 20 99 ret i16 %r 100; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = udiv i16 %a, 20 101} 102 103define i8 @fun14(i8 %a) { 104 %r = udiv i8 %a, 20 105 ret i8 %r 106; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = udiv i8 107} 108 109; Vector udiv 110 111define <2 x i64> @fun15(<2 x i64> %a) { 112 %r = udiv <2 x i64> %a, <i64 20, i64 20> 113 ret <2 x i64> %r 114; COST: Cost Model: Found an estimated cost of 24 for instruction: %r = udiv <2 x i64> 115} 116 117define <4 x i32> @fun16(<4 x i32> %a) { 118 %r = udiv <4 x i32> %a, <i32 20, i32 20, i32 20, i32 21> 119 ret <4 x i32> %r 120; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = udiv <4 x i32> 121} 122 123define <2 x i32> @fun17(<2 x i32> %a) { 124 %r = udiv <2 x i32> %a, <i32 20, i32 20> 125 ret <2 x i32> %r 126; COST: Cost Model: Found an estimated cost of 25 for instruction: %r = udiv <2 x i32> 127} 128 129define <8 x i16> @fun18(<8 x i16> %a) { 130 %r = udiv <8 x i16> %a, <i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 21> 131 ret <8 x i16> %r 132; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = udiv <8 x i16> 133} 134 135define <4 x i16> @fun19(<4 x i16> %a) { 136 %r = udiv <4 x i16> %a, <i16 20, i16 20, i16 20, i16 20> 137 ret <4 x i16> %r 138; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = udiv <4 x i16> 139} 140 141define <16 x i8> @fun20(<16 x i8> %a) { 142 %r = udiv <16 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 21> 143 ret <16 x i8> %r 144; COST: Cost Model: Found an estimated cost of 193 for instruction: %r = udiv <16 x i8> 145} 146 147define <8 x i8> @fun21(<8 x i8> %a) { 148 %r = udiv <8 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20> 149 ret <8 x i8> %r 150; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = udiv <8 x i8> 151} 152 153; Scalar srem 154 155define i64 @fun22(i64 %a) { 156 %r = srem i64 %a, 20 157 ret i64 %r 158; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = srem i64 159} 160 161define i32 @fun23(i32 %a) { 162 %r = srem i32 %a, 20 163 ret i32 %r 164; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = srem i32 165} 166 167define i16 @fun24(i16 %a) { 168 %r = srem i16 %a, 20 169 ret i16 %r 170; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = srem i16 171} 172 173define i8 @fun25(i8 %a) { 174 %r = srem i8 %a, 20 175 ret i8 %r 176; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = srem i8 177} 178 179; Vector srem 180 181define <2 x i64> @fun26(<2 x i64> %a) { 182 %r = srem <2 x i64> %a, <i64 20, i64 21> 183 ret <2 x i64> %r 184; COST: Cost Model: Found an estimated cost of 24 for instruction: %r = srem <2 x i64> 185} 186 187define <4 x i32> @fun27(<4 x i32> %a) { 188 %r = srem <4 x i32> %a, <i32 20, i32 20, i32 20, i32 20> 189 ret <4 x i32> %r 190; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = srem <4 x i32> 191} 192 193define <2 x i32> @fun28(<2 x i32> %a) { 194 %r = srem <2 x i32> %a, <i32 20, i32 21> 195 ret <2 x i32> %r 196; COST: Cost Model: Found an estimated cost of 25 for instruction: %r = srem <2 x i32> 197} 198 199define <8 x i16> @fun29(<8 x i16> %a) { 200 %r = srem <8 x i16> %a, <i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 20> 201 ret <8 x i16> %r 202; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = srem <8 x i16> 203} 204 205define <4 x i16> @fun30(<4 x i16> %a) { 206 %r = srem <4 x i16> %a, <i16 20, i16 20, i16 20, i16 21> 207 ret <4 x i16> %r 208; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = srem <4 x i16> 209} 210 211define <16 x i8> @fun31(<16 x i8> %a) { 212 %r = srem <16 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20> 213 ret <16 x i8> %r 214; COST: Cost Model: Found an estimated cost of 193 for instruction: %r = srem <16 x i8> 215} 216 217define <8 x i8> @fun32(<8 x i8> %a) { 218 %r = srem <8 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 21> 219 ret <8 x i8> %r 220; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = srem <8 x i8> 221} 222 223; Scalar urem 224 225define i64 @fun33(i64 %a) { 226 %r = urem i64 %a, 20 227 ret i64 %r 228; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = urem i64 229} 230 231define i32 @fun34(i32 %a) { 232 %r = urem i32 %a, 20 233 ret i32 %r 234; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = urem i32 235} 236 237define i16 @fun35(i16 %a) { 238 %r = urem i16 %a, 20 239 ret i16 %r 240; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = urem i16 241} 242 243define i8 @fun36(i8 %a) { 244 %r = urem i8 %a, 20 245 ret i8 %r 246; COST: Cost Model: Found an estimated cost of 10 for instruction: %r = urem i8 247} 248 249; Vector urem 250 251define <2 x i64> @fun37(<2 x i64> %a) { 252 %r = urem <2 x i64> %a, <i64 20, i64 20> 253 ret <2 x i64> %r 254; COST: Cost Model: Found an estimated cost of 24 for instruction: %r = urem <2 x i64> 255} 256 257define <4 x i32> @fun38(<4 x i32> %a) { 258 %r = urem <4 x i32> %a, <i32 20, i32 20, i32 20, i32 21> 259 ret <4 x i32> %r 260; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = urem <4 x i32> 261} 262 263define <2 x i32> @fun39(<2 x i32> %a) { 264 %r = urem <2 x i32> %a, <i32 20, i32 20> 265 ret <2 x i32> %r 266; COST: Cost Model: Found an estimated cost of 25 for instruction: %r = urem <2 x i32> 267} 268 269define <8 x i16> @fun40(<8 x i16> %a) { 270 %r = urem <8 x i16> %a, <i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 20, i16 21> 271 ret <8 x i16> %r 272; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = urem <8 x i16> 273} 274 275define <4 x i16> @fun41(<4 x i16> %a) { 276 %r = urem <4 x i16> %a, <i16 20, i16 20, i16 20, i16 20> 277 ret <4 x i16> %r 278; COST: Cost Model: Found an estimated cost of 49 for instruction: %r = urem <4 x i16> 279} 280 281define <16 x i8> @fun42(<16 x i8> %a) { 282 %r = urem <16 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 21> 283 ret <16 x i8> %r 284; COST: Cost Model: Found an estimated cost of 193 for instruction: %r = urem <16 x i8> 285} 286 287define <8 x i8> @fun43(<8 x i8> %a) { 288 %r = urem <8 x i8> %a, <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20> 289 ret <8 x i8> %r 290; COST: Cost Model: Found an estimated cost of 97 for instruction: %r = urem <8 x i8> 291} 292