Skip to content

Commit 45f1b72

Browse files
author
Sandhya Viswanathan
committed
8287697: Limit auto vectorization to 32-byte vector on Cascade Lake
Reviewed-by: kvn, jbhateja
1 parent 39ec58b commit 45f1b72

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

src/hotspot/cpu/x86/vm_version_x86.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,25 @@ void VM_Version::get_processor_features() {
12951295
FLAG_SET_DEFAULT(MaxVectorSize, max_vector_size);
12961296
}
12971297

1298+
if (FLAG_IS_DEFAULT(SuperWordMaxVectorSize)) {
1299+
if (FLAG_IS_DEFAULT(UseAVX) && UseAVX > 2 &&
1300+
is_intel_skylake() && _stepping >= 5) {
1301+
// Limit auto vectorization to 256 bit (32 byte) by default on Cascade Lake
1302+
FLAG_SET_DEFAULT(SuperWordMaxVectorSize, MIN2(MaxVectorSize, (intx)32));
1303+
} else {
1304+
FLAG_SET_DEFAULT(SuperWordMaxVectorSize, MaxVectorSize);
1305+
}
1306+
} else {
1307+
if (SuperWordMaxVectorSize > MaxVectorSize) {
1308+
warning("SuperWordMaxVectorSize cannot be greater than MaxVectorSize %i", (int) MaxVectorSize);
1309+
FLAG_SET_DEFAULT(SuperWordMaxVectorSize, MaxVectorSize);
1310+
}
1311+
if (!is_power_of_2(SuperWordMaxVectorSize)) {
1312+
warning("SuperWordMaxVectorSize must be a power of 2, setting to MaxVectorSize: %i", (int) MaxVectorSize);
1313+
FLAG_SET_DEFAULT(SuperWordMaxVectorSize, MaxVectorSize);
1314+
}
1315+
}
1316+
12981317
#if defined(COMPILER2) && defined(ASSERT)
12991318
if (MaxVectorSize > 0) {
13001319
if (supports_avx() && PrintMiscellaneous && Verbose && TraceNewVectors) {

src/hotspot/share/opto/c2_globals.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
"actual size could be less depending on elements type") \
8383
range(0, max_jint) \
8484
\
85+
product(intx, SuperWordMaxVectorSize, 64, DIAGNOSTIC, \
86+
"Vector size limit in bytes for superword, " \
87+
"superword vector size limit in bytes") \
88+
range(0, max_jint) \
89+
\
8590
product(intx, ArrayOperationPartialInlineSize, 0, DIAGNOSTIC, \
8691
"Partial inline size used for small array operations" \
8792
"(e.g. copy,cmp) acceleration.") \

src/hotspot/share/opto/superword.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ bool SuperWord::transform_loop(IdealLoopTree* lpt, bool do_optimization) {
199199
return success;
200200
}
201201

202+
//------------------------------max vector size------------------------------
203+
int SuperWord::max_vector_size(BasicType bt) {
204+
int max_vector = Matcher::max_vector_size(bt);
205+
int sw_max_vector_limit = SuperWordMaxVectorSize / type2aelembytes(bt);
206+
if (max_vector > sw_max_vector_limit) {
207+
max_vector = sw_max_vector_limit;
208+
}
209+
return max_vector;
210+
}
211+
202212
//------------------------------early unrolling analysis------------------------------
203213
void SuperWord::unrolling_analysis(int &local_loop_unroll_factor) {
204214
bool is_slp = true;
@@ -217,7 +227,7 @@ void SuperWord::unrolling_analysis(int &local_loop_unroll_factor) {
217227
ignored_loop_nodes[i] = -1;
218228
}
219229

220-
int max_vector = Matcher::max_vector_size(T_BYTE);
230+
int max_vector = max_vector_size(T_BYTE);
221231

222232
// Process the loop, some/all of the stack entries will not be in order, ergo
223233
// need to preprocess the ignored initial state before we process the loop
@@ -352,7 +362,7 @@ void SuperWord::unrolling_analysis(int &local_loop_unroll_factor) {
352362

353363
if (is_java_primitive(bt) == false) continue;
354364

355-
int cur_max_vector = Matcher::max_vector_size(bt);
365+
int cur_max_vector = max_vector_size(bt);
356366

357367
// If a max vector exists which is not larger than _local_loop_unroll_factor
358368
// stop looking, we already have the max vector to map to.
@@ -991,7 +1001,7 @@ int SuperWord::get_vw_bytes_special(MemNode* s) {
9911001
}
9921002
}
9931003
if (should_combine_adjacent) {
994-
vw = MIN2(Matcher::max_vector_size(btype)*type2aelembytes(btype), vw * 2);
1004+
vw = MIN2(max_vector_size(btype)*type2aelembytes(btype), vw * 2);
9951005
}
9961006
}
9971007

@@ -1689,7 +1699,7 @@ void SuperWord::combine_packs() {
16891699
Node_List* p1 = _packset.at(i);
16901700
if (p1 != NULL) {
16911701
BasicType bt = velt_basic_type(p1->at(0));
1692-
uint max_vlen = Matcher::max_vector_size(bt); // Max elements in vector
1702+
uint max_vlen = max_vector_size(bt); // Max elements in vector
16931703
assert(is_power_of_2(max_vlen), "sanity");
16941704
uint psize = p1->size();
16951705
if (!is_power_of_2(psize)) {

src/hotspot/share/opto/superword.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ class SuperWord : public ResourceObj {
327327

328328
bool transform_loop(IdealLoopTree* lpt, bool do_optimization);
329329

330+
int max_vector_size(BasicType bt);
331+
330332
void unrolling_analysis(int &local_loop_unroll_factor);
331333

332334
// Accessors for SWPointer

src/hotspot/share/opto/vectornode.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,17 @@ int VectorNode::replicate_opcode(BasicType bt) {
294294
}
295295
}
296296

297+
bool VectorNode::vector_size_supported(BasicType bt, uint vlen) {
298+
return (Matcher::vector_size_supported(bt, vlen) &&
299+
(vlen * type2aelembytes(bt) <= (uint)SuperWordMaxVectorSize));
300+
}
301+
297302
// Also used to check if the code generator
298303
// supports the vector operation.
299304
bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
300305
if (is_java_primitive(bt) &&
301306
(vlen > 1) && is_power_of_2(vlen) &&
302-
Matcher::vector_size_supported(bt, vlen)) {
307+
vector_size_supported(bt, vlen)) {
303308
int vopc = VectorNode::opcode(opc, bt);
304309
// For rotate operation we will do a lazy de-generation into
305310
// OrV/LShiftV/URShiftV pattern if the target does not support
@@ -1320,7 +1325,7 @@ Node* ReductionNode::make_reduction_input(PhaseGVN& gvn, int opc, BasicType bt)
13201325
bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
13211326
if (is_java_primitive(bt) &&
13221327
(vlen > 1) && is_power_of_2(vlen) &&
1323-
Matcher::vector_size_supported(bt, vlen)) {
1328+
VectorNode::vector_size_supported(bt, vlen)) {
13241329
int vopc = ReductionNode::opcode(opc, bt);
13251330
return vopc != opc && Matcher::match_rule_supported_vector(vopc, vlen, bt);
13261331
}

src/hotspot/share/opto/vectornode.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class VectorNode : public TypeNode {
8888

8989
static int opcode(int opc, BasicType bt);
9090
static int replicate_opcode(BasicType bt);
91+
static bool vector_size_supported(BasicType bt, uint vlen);
9192
static bool implemented(int opc, uint vlen, BasicType bt);
9293
static bool is_shift(Node* n);
9394
static bool is_vshift_cnt(Node* n);

0 commit comments

Comments
 (0)