Skip to content

Commit 11e28bd

Browse files
committed
8324794: C2 SuperWord: do not ignore reductions in SuperWord::unrolling_analysis
Reviewed-by: chagedorn, kvn
1 parent d51aaf6 commit 11e28bd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/hotspot/share/opto/superword.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ void SuperWord::unrolling_analysis(int &local_loop_unroll_factor) {
177177
for (uint i = 0; i < lpt()->_body.size(); i++) {
178178
Node* n = lpt()->_body.at(i);
179179
if (n == cl->incr() ||
180-
is_marked_reduction(n) ||
181180
n->is_AddP() ||
182181
n->is_Cmp() ||
183182
n->is_Bool() ||

test/hotspot/jtreg/compiler/loopopts/superword/TestUnorderedReductionPartialVectorization.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -64,7 +64,7 @@ public void runTests() throws Exception {
6464
IRNode.OR_REDUCTION_V, "> 0",},
6565
applyIfCPUFeatureOr = {"avx2", "true"})
6666
static long test1(int[] data, long sum) {
67-
for (int i = 0; i < data.length; i++) {
67+
for (int i = 0; i < data.length; i+=2) {
6868
// Mixing int and long ops means we only end up allowing half of the int
6969
// loads in one pack, and we have two int packs. The first pack has one
7070
// of the pairs missing because of the store, which creates a dependency.
@@ -77,6 +77,17 @@ static long test1(int[] data, long sum) {
7777
int v = data[i]; // int read
7878
data[0] = 0; // ruin the first pack
7979
sum |= v; // long reduction (and implicit cast from int to long)
80+
81+
// This example used to rely on that reductions were ignored in SuperWord::unrolling_analysis,
82+
// and hence the largest data type in the loop was the ints. This would then unroll the doubles
83+
// for twice the vector length, and this resulted in us having twice as many packs. Because of
84+
// the store "data[0] = 0", the first packs were destroyed, since they do not have power of 2
85+
// size.
86+
// Now, we no longer ignore reductions, and now we unroll half as much before SuperWord. This
87+
// means we would only get one pack per operation, and that one would get ruined, and we have
88+
// no vectorization. We now ensure there are again 2 packs per operation with a 2x hand unroll.
89+
int v2 = data[i + 1];
90+
sum |= v2;
8091
}
8192
return sum;
8293
}

0 commit comments

Comments
 (0)