Skip to content
Permalink
Browse files
8259398: Super word not applied to a loop with byteArrayViewVarHandle
Reviewed-by: vlivanov, thartmann, chagedorn
  • Loading branch information
Vladimir Kozlov committed Feb 1, 2021
1 parent 80760a3 commit 02d586e13edcdf6be03b15e9416cc63b6ea1c8c1
Showing with 51 additions and 16 deletions.
  1. +8 −14 src/hotspot/share/opto/superword.cpp
  2. +43 −2 test/hotspot/jtreg/compiler/vectorization/TestBufferVectorization.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -3893,12 +3893,7 @@ bool SWPointer::scaled_iv(Node* n) {
NOT_PRODUCT(_tracer.scaled_iv_6(n, _scale);)
return true;
}
} else if (opc == Op_ConvI2L) {
if (n->in(1)->Opcode() == Op_CastII &&
n->in(1)->as_CastII()->has_range_check()) {
// Skip range check dependent CastII nodes
n = n->in(1);
}
} else if (opc == Op_ConvI2L || opc == Op_CastII) {
if (scaled_iv_plus_offset(n->in(1))) {
NOT_PRODUCT(_tracer.scaled_iv_7(n);)
return true;
@@ -3995,15 +3990,14 @@ bool SWPointer::offset_plus_k(Node* n, bool negate) {
}

if (!is_main_loop_member(n)) {
// 'n' is loop invariant. Skip range check dependent CastII nodes before checking if 'n' is dominating the pre loop.
// 'n' is loop invariant. Skip ConvI2L and CastII nodes before checking if 'n' is dominating the pre loop.
if (opc == Op_ConvI2L) {
n = n->in(1);
if (n->Opcode() == Op_CastII &&
n->as_CastII()->has_range_check()) {
// Skip range check dependent CastII nodes
assert(!is_main_loop_member(n), "sanity");
n = n->in(1);
}
}
if (n->Opcode() == Op_CastII) {
// Skip CastII nodes
assert(!is_main_loop_member(n), "sanity");
n = n->in(1);
}
// Check if 'n' can really be used as invariant (not in main loop and dominating the pre loop).
if (invariant(n)) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,10 +33,14 @@
* @run main compiler.vectorization.TestBufferVectorization buffer
* @run main compiler.vectorization.TestBufferVectorization bufferHeap
* @run main compiler.vectorization.TestBufferVectorization bufferDirect
* @run main compiler.vectorization.TestBufferVectorization arrayView
*/

package compiler.vectorization;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
@@ -51,6 +55,7 @@
final static int offset = buffer.arrayOffset();
final static IntBuffer heap_buffer_byte_to_int = ByteBuffer.allocate(N * Integer.BYTES).order(ByteOrder.nativeOrder()).asIntBuffer();
final static IntBuffer direct_buffer_byte_to_int = ByteBuffer.allocateDirect(N * Integer.BYTES).order(ByteOrder.nativeOrder()).asIntBuffer();
final static VarHandle VH_arr_view = MethodHandles.byteArrayViewVarHandle(int[].class, ByteOrder.nativeOrder()).withInvokeExactBehavior();
final static String arch = System.getProperty("os.arch");

interface Test {
@@ -153,9 +158,42 @@ public void verify() {
}
}

static class TestArrayView implements Test {
final byte[] b_arr = new byte[N * Integer.BYTES];

public void init() {
for (int k = 0; k < N; k++) {
VH_arr_view.set(b_arr, k, k);
}
}

public void run() {
for (int k = 0; k < b_arr.length; k += 4) {
int v = (int) VH_arr_view.get(b_arr, k);
VH_arr_view.set(b_arr, k, v + 1);
}
}

public void verify() {
init(); // reset
// Save initial INT values
final int[] i_arr = new int[N];
for (int k = 0; k < i_arr.length; k++) {
i_arr[k] = (int) VH_arr_view.get(b_arr, k * Integer.BYTES);
}
run(); // run compiled code
for (int k = 0; k < i_arr.length; k++) {
int v = (int) VH_arr_view.get(b_arr, k * Integer.BYTES);
if (v != (i_arr[k] + 1)) {
throw new RuntimeException(" Invalid result: VH_arr_view.get(b_arr, " + (k * Integer.BYTES) + "): " + v + " != " + (i_arr[k] + 1));
}
}
}
}

public static void main(String[] args) {
if (args.length == 0) {
throw new RuntimeException(" Missing test name: array, arrayOffset, buffer, bufferHeap, bufferDirect");
throw new RuntimeException(" Missing test name: array, arrayOffset, buffer, bufferHeap, bufferDirect, arrayView");
}

Test te;
@@ -175,6 +213,9 @@ public static void main(String[] args) {
case "bufferDirect":
te = new TestBuffer(direct_buffer_byte_to_int);
break;
case "arrayView":
te = new TestArrayView();
break;
default:
throw new RuntimeException(" Unknown test: " + args[0]);
}

0 comments on commit 02d586e

Please sign in to comment.