Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8245158: C2: Enable SLP for some manually unrolled loops
Browse files Browse the repository at this point in the history
In SuperWord::find_align_to_ref(), only discard unalignable memory ops if memory references should be aligned on this platform.

Reviewed-by: roland, thartmann
  • Loading branch information
Pengfei Li committed Jun 2, 2020
1 parent d42bfef commit 30aa1b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/hotspot/share/opto/superword.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2020, 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
Expand Down Expand Up @@ -615,7 +615,7 @@ void SuperWord::find_adjacent_refs() {
// alignment is set and vectors will be aligned.
bool create_pack = true;
if (memory_alignment(mem_ref, best_iv_adjustment) == 0 || _do_vector_loop) {
if (!Matcher::misaligned_vectors_ok() || AlignVector) {
if (vectors_should_be_aligned()) {
int vw = vector_width(mem_ref);
int vw_best = vector_width(best_align_to_mem_ref);
if (vw > vw_best) {
Expand All @@ -640,7 +640,7 @@ void SuperWord::find_adjacent_refs() {
} else {
// Allow independent (different type) unaligned memory operations
// if HW supports them.
if (!Matcher::misaligned_vectors_ok() || AlignVector) {
if (vectors_should_be_aligned()) {
create_pack = false;
} else {
// Check if packs of the same memory type but
Expand Down Expand Up @@ -776,8 +776,9 @@ MemNode* SuperWord::find_align_to_ref(Node_List &memops, int &idx) {
for (uint i = 0; i < memops.size(); i++) {
MemNode* s1 = memops.at(i)->as_Mem();
SWPointer p1(s1, this, NULL, false);
// Discard if pre loop can't align this reference
if (!ref_is_alignable(p1)) {
// Only discard unalignable memory references if vector memory references
// should be aligned on this platform.
if (vectors_should_be_aligned() && !ref_is_alignable(p1)) {
*cmp_ct.adr_at(i) = 0;
continue;
}
Expand Down Expand Up @@ -998,7 +999,9 @@ int SuperWord::get_iv_adjustment(MemNode* mem_ref) {
// several iterations are needed to align memory operations in main-loop even
// if offset is 0.
int iv_adjustment_in_bytes = (stride_sign * vw - (offset % vw));
assert(((ABS(iv_adjustment_in_bytes) % elt_size) == 0),
// iv_adjustment_in_bytes must be a multiple of elt_size if vector memory
// references should be aligned on this platform.
assert((ABS(iv_adjustment_in_bytes) % elt_size) == 0 || !vectors_should_be_aligned(),
"(%d) should be divisible by (%d)", iv_adjustment_in_bytes, elt_size);
iv_adjustment = iv_adjustment_in_bytes/elt_size;
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/hotspot/share/opto/superword.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2020, 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
Expand Down Expand Up @@ -370,6 +370,9 @@ class SuperWord : public ResourceObj {
// Ensure node_info contains element "i"
void grow_node_info(int i) { if (i >= _node_info.length()) _node_info.at_put_grow(i, SWNodeInfo::initial); }

// should we align vector memory references on this platform?
bool vectors_should_be_aligned() { return !Matcher::misaligned_vectors_ok() || AlignVector; }

// memory alignment for a node
int alignment(Node* n) { return _node_info.adr_at(bb_idx(n))->_alignment; }
void set_alignment(Node* n, int a) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_alignment = a; }
Expand Down

0 comments on commit 30aa1b0

Please sign in to comment.