190 }
191
192 @Test
193 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
194 counts = {IRNode.STORE_VECTOR, ">0",
195 IRNode.LOAD_VECTOR_I, "> 0"})
196 public int[] multipleStoresWithCommonSubExpression() {
197 int[] res1 = new int[SIZE];
198 int[] res2 = new int[SIZE];
199 int[] res3 = new int[SIZE];
200 for (int i = 0; i < SIZE; i++) {
201 res1[i] = a[i] * b[i];
202 res2[i] = c[i] * d[i];
203 res3[i] = res1[i] + res2[i];
204 }
205 return res3;
206 }
207
208 @Test
209 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
210 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
211 counts = {IRNode.STORE_VECTOR, ">0",
212 IRNode.LOAD_VECTOR_S, "> 0",
213 IRNode.LOAD_VECTOR_I, "> 0"})
214 public int[] multipleOpsWith2DifferentTypes() {
215 short[] res1 = new short[SIZE];
216 int[] res2 = new int[SIZE];
217 for (int i = 0; i < SIZE; i++) {
218 res1[i] = (short) (s1[i] + s2[i]);
219 res2[i] = a[i] + b[i];
220 // We have a mix of int and short loads/stores.
221 // With UseCompactObjectHeaders and AlignVector,
222 // we must 8-byte align all vector loads/stores.
223 //
224 // int:
225 // adr = base + UNSAFE.ARRAY_INT_BASE_OFFSET + 4*iter
226 // = 16 (or 12 if UseCompactObjectHeaders=true)
227 // If UseCompactObjectHeaders=false: iter % 2 = 0
228 // If UseCompactObjectHeaders=true: iter % 2 = 1
229 //
230 // byte:
231 // adr = base + UNSAFE.ARRAY_BYTE_BASE_OFFSET + 1*iter
232 // = 16 (or 12 if UseCompactObjectHeaders=true)
233 // If UseCompactObjectHeaders=false: iter % 8 = 0
234 // If UseCompactObjectHeaders=true: iter % 8 = 4
235 //
236 // -> we cannot align both if UseCompactObjectHeaders=true.
237 }
238 return res2;
239 }
240
241 @Test
242 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
243 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
244 counts = {IRNode.STORE_VECTOR, ">0",
245 IRNode.LOAD_VECTOR_I, IRNode.VECTOR_SIZE_ANY, "> 0",
246 IRNode.LOAD_VECTOR_L, "> 0"})
247 public long[] multipleOpsWith3DifferentTypes() {
248 short[] res1 = new short[SIZE];
249 int[] res2 = new int[SIZE];
250 long[] res3 = new long[SIZE];
251 for (int i = 0; i < SIZE; i++) {
252 res1[i] = (short) (s1[i] + s2[i]);
253 res2[i] = a[i] + b[i];
254 res3[i] = l1[i] + l2[i];
255 // We have a mix of int and short loads/stores.
256 // With UseCompactObjectHeaders and AlignVector,
257 // we must 8-byte align all vector loads/stores.
258 //
259 // int:
260 // adr = base + UNSAFE.ARRAY_INT_BASE_OFFSET + 4*iter
261 // = 16 (or 12 if UseCompactObjectHeaders=true)
262 // If UseCompactObjectHeaders=false: iter % 2 = 0
263 // If UseCompactObjectHeaders=true: iter % 2 = 1
264 //
265 // byte:
266 // adr = base + UNSAFE.ARRAY_BYTE_BASE_OFFSET + 1*iter
267 // = 16 (or 12 if UseCompactObjectHeaders=true)
268 // If UseCompactObjectHeaders=false: iter % 8 = 0
269 // If UseCompactObjectHeaders=true: iter % 8 = 4
270 //
271 // -> we cannot align both if UseCompactObjectHeaders=true.
272 }
273 return res3;
274 }
275
276 @Test
277 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
278 counts = {IRNode.STORE_VECTOR, ">0",
279 IRNode.LOAD_VECTOR_S, IRNode.VECTOR_SIZE_ANY, "> 0",
280 IRNode.LOAD_VECTOR_L, "> 0"})
281 public long[] multipleOpsWith2NonAdjacentTypes() {
282 short[] res1 = new short[SIZE];
283 long[] res2 = new long[SIZE];
284 for (int i = 0; i < SIZE; i++) {
285 res1[i] = (short) (s1[i] + s2[i]);
286 res2[i] = l1[i] + l2[i];
287 }
288 return res2;
289 }
290
291 @Test
292 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
293 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
294 counts = {IRNode.STORE_VECTOR, ">0",
295 IRNode.LOAD_VECTOR_S, "> 0",
296 IRNode.LOAD_VECTOR_I, "> 0"})
297 public int[] multipleOpsWith2DifferentTypesAndConstant() {
298 short[] res1 = new short[SIZE];
299 int[] res2 = new int[SIZE];
300 for (int i = 0; i < SIZE; i++) {
301 res1[i] = (short) (s1[i] + s2[i]);
302 res2[i] = a[i] + 88888888;;
303 // We have a mix of int and short loads/stores.
304 // With UseCompactObjectHeaders and AlignVector,
305 // we must 8-byte align all vector loads/stores.
306 //
307 // int:
308 // adr = base + UNSAFE.ARRAY_INT_BASE_OFFSET + 4*iter
309 // = 16 (or 12 if UseCompactObjectHeaders=true)
310 // If UseCompactObjectHeaders=false: iter % 2 = 0
311 // If UseCompactObjectHeaders=true: iter % 2 = 1
312 //
313 // byte:
314 // adr = base + UNSAFE.ARRAY_BYTE_BASE_OFFSET + 1*iter
315 // = 16 (or 12 if UseCompactObjectHeaders=true)
316 // If UseCompactObjectHeaders=false: iter % 8 = 0
317 // If UseCompactObjectHeaders=true: iter % 8 = 4
318 //
319 // -> we cannot align both if UseCompactObjectHeaders=true.
320 }
321 return res2;
322 }
323
324 @Test
325 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
326 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
327 counts = {IRNode.STORE_VECTOR, ">0",
328 IRNode.LOAD_VECTOR_S, "> 0",
329 IRNode.LOAD_VECTOR_I, "> 0"})
330 public int[] multipleOpsWith2DifferentTypesAndInvariant() {
331 short[] res1 = new short[SIZE];
332 int[] res2 = new int[SIZE];
333 for (int i = 0; i < SIZE; i++) {
334 res1[i] = (short) (s1[i] + s2[i]);
335 res2[i] = a[i] * intInv;
336 // We have a mix of int and short loads/stores.
337 // With UseCompactObjectHeaders and AlignVector,
338 // we must 8-byte align all vector loads/stores.
339 //
340 // int:
341 // adr = base + UNSAFE.ARRAY_INT_BASE_OFFSET + 4*iter
342 // = 16 (or 12 if UseCompactObjectHeaders=true)
343 // If UseCompactObjectHeaders=false: iter % 2 = 0
344 // If UseCompactObjectHeaders=true: iter % 2 = 1
345 //
346 // byte:
347 // adr = base + UNSAFE.ARRAY_BYTE_BASE_OFFSET + 1*iter
348 // = 16 (or 12 if UseCompactObjectHeaders=true)
349 // If UseCompactObjectHeaders=false: iter % 8 = 0
350 // If UseCompactObjectHeaders=true: iter % 8 = 4
351 //
352 // -> we cannot align both if UseCompactObjectHeaders=true.
353 }
354 return res2;
355 }
356
357 @Test
358 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
359 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
360 counts = {IRNode.STORE_VECTOR, ">0",
361 IRNode.LOAD_VECTOR_S, "> 0",
362 IRNode.LOAD_VECTOR_I, "> 0"})
363 public int[] multipleOpsWith2DifferentTypesAndComplexExpression() {
364 short[] res1 = new short[SIZE];
365 int[] res2 = new int[SIZE];
366 for (int i = 0; i < SIZE; i++) {
367 res1[i] = (short) (s1[i] + s2[i]);
368 res2[i] = a[i] * (b[i] + intInv * c[i] & 0xfffffa);
369 // same argument as in multipleOpsWith2DifferentTypesAndInvariant.
370 }
371 return res2;
372 }
373
374 @Test
375 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse3", "true"},
376 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
377 counts = {IRNode.STORE_VECTOR, ">0",
378 IRNode.LOAD_VECTOR_S, "> 0",
379 IRNode.LOAD_VECTOR_I, "> 0"})
380 public int[] multipleOpsWith2DifferentTypesAndSharedOp() {
381 int i = 0, sum = 0;
382 int[] res1 = new int[SIZE];
383 short[] res2 = new short[SIZE];
384 while (++i < SIZE) {
385 sum += (res1[i]--);
386 res2[i]++;
387 // We have a mix of int and short loads/stores.
388 // With UseCompactObjectHeaders and AlignVector,
389 // we must 8-byte align all vector loads/stores.
390 //
391 // int:
392 // adr = base + UNSAFE.ARRAY_INT_BASE_OFFSET + 4*iter
393 // = 16 (or 12 if UseCompactObjectHeaders=true)
394 // If UseCompactObjectHeaders=false: iter % 2 = 0
395 // If UseCompactObjectHeaders=true: iter % 2 = 1
396 //
397 // byte:
398 // adr = base + UNSAFE.ARRAY_BYTE_BASE_OFFSET + 1*iter
399 // = 16 (or 12 if UseCompactObjectHeaders=true)
400 // If UseCompactObjectHeaders=false: iter % 8 = 0
401 // If UseCompactObjectHeaders=true: iter % 8 = 4
402 //
403 // -> we cannot align both if UseCompactObjectHeaders=true.
404 }
405 return res1;
406 }
407
408 @Test
409 // POPULATE_INDEX seems to mess with vectorization, see JDK-8332878.
410 public int[] fillIndexPlusStride() {
411 int[] res = new int[SIZE];
412 for (int i = 0; i < SIZE; i++) {
413 res[i] = i + 1;
414 }
415 return res;
416 }
417
418 @Test
419 // POPULATE_INDEX seems to mess with vectorization, see JDK-8332878.
420 public int[] addArrayWithIndex() {
421 int[] res = new int[SIZE];
422 for (int i = 0; i < SIZE; i++) {
423 res[i] = a[i] + i;
430 public short[] multiplyAddShortIndex() {
431 short[] res = new short[SIZE];
432 for (int i = 0; i < SIZE; i++) {
433 res[i] = (short) (i * i + i);
434 }
435 return res;
436 }
437
438 @Test
439 // POPULATE_INDEX seems to mess with vectorization, see JDK-8332878.
440 public int[] multiplyBySumOfIndexAndInvariant() {
441 int[] res = new int[SIZE];
442 for (int i = 0; i < SIZE; i++) {
443 res[i] = a[i] * (i + 10 + intInv);
444 }
445 return res;
446 }
447
448 @Test
449 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
450 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false"},
451 counts = {IRNode.STORE_VECTOR, ">0"})
452 public int[] manuallyUnrolledStride2() {
453 int[] res = new int[SIZE];
454 for (int i = 0; i < SIZE - 1; i += 2) {
455 res[i] = a[i] * b[i];
456 res[i + 1] = a[i + 1] * b[i + 1];
457 // Hand-unrolling can mess with alignment!
458 //
459 // With UseCompactObjectHeaders and AlignVector,
460 // we must 8-byte align all vector loads/stores.
461 //
462 // adr = base + UNSAFE.ARRAY_INT_BASE_OFFSET + 8*iter
463 // = 16 (or 12 if UseCompactObjectHeaders=true)
464 // If UseCompactObjectHeaders=false: 16 divisible by 8 -> vectorize
465 // If UseCompactObjectHeaders=true: 12 not divisibly by 8 -> not vectorize
466 }
467 return res;
468 }
469
470 @Test
471 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
472 counts = {IRNode.STORE_VECTOR, ">0",
473 IRNode.LOAD_VECTOR_I, "> 0"})
474 public int partialVectorizableLoop() {
475 int[] res = new int[SIZE];
476 int k = 9;
477 for (int i = 0; i < SIZE / 2; i++) {
478 res[i] = a[i] * b[i];
479 k = 3 * k + 1;
480 }
481 return k;
482 }
483 }
|
190 }
191
192 @Test
193 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
194 counts = {IRNode.STORE_VECTOR, ">0",
195 IRNode.LOAD_VECTOR_I, "> 0"})
196 public int[] multipleStoresWithCommonSubExpression() {
197 int[] res1 = new int[SIZE];
198 int[] res2 = new int[SIZE];
199 int[] res3 = new int[SIZE];
200 for (int i = 0; i < SIZE; i++) {
201 res1[i] = a[i] * b[i];
202 res2[i] = c[i] * d[i];
203 res3[i] = res1[i] + res2[i];
204 }
205 return res3;
206 }
207
208 @Test
209 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
210 counts = {IRNode.STORE_VECTOR, ">0",
211 IRNode.LOAD_VECTOR_S, "> 0",
212 IRNode.LOAD_VECTOR_I, "> 0"})
213 public int[] multipleOpsWith2DifferentTypes() {
214 short[] res1 = new short[SIZE];
215 int[] res2 = new int[SIZE];
216 for (int i = 0; i < SIZE; i++) {
217 res1[i] = (short) (s1[i] + s2[i]);
218 res2[i] = a[i] + b[i];
219 }
220 return res2;
221 }
222
223 @Test
224 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
225 counts = {IRNode.STORE_VECTOR, ">0",
226 IRNode.LOAD_VECTOR_I, IRNode.VECTOR_SIZE_ANY, "> 0",
227 IRNode.LOAD_VECTOR_L, "> 0"})
228 public long[] multipleOpsWith3DifferentTypes() {
229 short[] res1 = new short[SIZE];
230 int[] res2 = new int[SIZE];
231 long[] res3 = new long[SIZE];
232 for (int i = 0; i < SIZE; i++) {
233 res1[i] = (short) (s1[i] + s2[i]);
234 res2[i] = a[i] + b[i];
235 res3[i] = l1[i] + l2[i];
236 }
237 return res3;
238 }
239
240 @Test
241 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
242 counts = {IRNode.STORE_VECTOR, ">0",
243 IRNode.LOAD_VECTOR_S, IRNode.VECTOR_SIZE_ANY, "> 0",
244 IRNode.LOAD_VECTOR_L, "> 0"})
245 public long[] multipleOpsWith2NonAdjacentTypes() {
246 short[] res1 = new short[SIZE];
247 long[] res2 = new long[SIZE];
248 for (int i = 0; i < SIZE; i++) {
249 res1[i] = (short) (s1[i] + s2[i]);
250 res2[i] = l1[i] + l2[i];
251 }
252 return res2;
253 }
254
255 @Test
256 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"},
257 counts = {IRNode.STORE_VECTOR, ">0",
258 IRNode.LOAD_VECTOR_S, "> 0",
259 IRNode.LOAD_VECTOR_I, "> 0"})
260 public int[] multipleOpsWith2DifferentTypesAndConstant() {
261 short[] res1 = new short[SIZE];
262 int[] res2 = new int[SIZE];
263 for (int i = 0; i < SIZE; i++) {
264 res1[i] = (short) (s1[i] + s2[i]);
265 res2[i] = a[i] + 88888888;;
266 }
267 return res2;
268 }
269
270 @Test
271 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
272 counts = {IRNode.STORE_VECTOR, ">0",
273 IRNode.LOAD_VECTOR_S, "> 0",
274 IRNode.LOAD_VECTOR_I, "> 0"})
275 public int[] multipleOpsWith2DifferentTypesAndInvariant() {
276 short[] res1 = new short[SIZE];
277 int[] res2 = new int[SIZE];
278 for (int i = 0; i < SIZE; i++) {
279 res1[i] = (short) (s1[i] + s2[i]);
280 res2[i] = a[i] * intInv;
281 }
282 return res2;
283 }
284
285 @Test
286 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
287 counts = {IRNode.STORE_VECTOR, ">0",
288 IRNode.LOAD_VECTOR_S, "> 0",
289 IRNode.LOAD_VECTOR_I, "> 0"})
290 public int[] multipleOpsWith2DifferentTypesAndComplexExpression() {
291 short[] res1 = new short[SIZE];
292 int[] res2 = new int[SIZE];
293 for (int i = 0; i < SIZE; i++) {
294 res1[i] = (short) (s1[i] + s2[i]);
295 res2[i] = a[i] * (b[i] + intInv * c[i] & 0xfffffa);
296 }
297 return res2;
298 }
299
300 @Test
301 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse3", "true"},
302 counts = {IRNode.STORE_VECTOR, ">0",
303 IRNode.LOAD_VECTOR_S, "> 0",
304 IRNode.LOAD_VECTOR_I, "> 0"})
305 public int[] multipleOpsWith2DifferentTypesAndSharedOp() {
306 int i = 0, sum = 0;
307 int[] res1 = new int[SIZE];
308 short[] res2 = new short[SIZE];
309 while (++i < SIZE) {
310 sum += (res1[i]--);
311 res2[i]++;
312 }
313 return res1;
314 }
315
316 @Test
317 // POPULATE_INDEX seems to mess with vectorization, see JDK-8332878.
318 public int[] fillIndexPlusStride() {
319 int[] res = new int[SIZE];
320 for (int i = 0; i < SIZE; i++) {
321 res[i] = i + 1;
322 }
323 return res;
324 }
325
326 @Test
327 // POPULATE_INDEX seems to mess with vectorization, see JDK-8332878.
328 public int[] addArrayWithIndex() {
329 int[] res = new int[SIZE];
330 for (int i = 0; i < SIZE; i++) {
331 res[i] = a[i] + i;
338 public short[] multiplyAddShortIndex() {
339 short[] res = new short[SIZE];
340 for (int i = 0; i < SIZE; i++) {
341 res[i] = (short) (i * i + i);
342 }
343 return res;
344 }
345
346 @Test
347 // POPULATE_INDEX seems to mess with vectorization, see JDK-8332878.
348 public int[] multiplyBySumOfIndexAndInvariant() {
349 int[] res = new int[SIZE];
350 for (int i = 0; i < SIZE; i++) {
351 res[i] = a[i] * (i + 10 + intInv);
352 }
353 return res;
354 }
355
356 @Test
357 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
358 counts = {IRNode.STORE_VECTOR, ">0"})
359 public int[] manuallyUnrolledStride2() {
360 int[] res = new int[SIZE];
361 for (int i = 0; i < SIZE - 1; i += 2) {
362 res[i] = a[i] * b[i];
363 res[i + 1] = a[i + 1] * b[i + 1];
364 }
365 return res;
366 }
367
368 @Test
369 @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse4.1", "true"},
370 counts = {IRNode.STORE_VECTOR, ">0",
371 IRNode.LOAD_VECTOR_I, "> 0"})
372 public int partialVectorizableLoop() {
373 int[] res = new int[SIZE];
374 int k = 9;
375 for (int i = 0; i < SIZE / 2; i++) {
376 res[i] = a[i] * b[i];
377 k = 3 * k + 1;
378 }
379 return k;
380 }
381 }
|