Currently, we do not vectorize loops like this:
static double test(double[] data1, double[] data2) {
double last = 1;
for (int i = 2; i < N-2; i++) {
double v = data1[i] * 1.54;
data2[i] = v;
// Having use of last iteration values prevents vectorization
last = v; // Remove this to make it vectorize !
}
return last;
}
See Test.java attached.
./java -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,Test::test -XX:+TraceSuperWord Test.java
The issue may to be that "SuperWord::filter_packs" requires all uses to be vectors. Here, the "last" has a scalar use which is after the loop.
One might have to "unpack" the corresponding vector from the last iteration (take the uppermost value in the vector).
Related to RFE JDK-8302652.
Found this during work on JDK-8302139.