JDK-8302662 : [SuperWord] Vectorize loop when value from last iteration is used after loop
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2023-02-16
  • Updated: 2023-02-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
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.
Comments
I found this comment in superword.cpp // For now, return false if not all uses are vector. // Later, implement ExtractNode and allow non-vector uses (maybe // just the ones outside the block.) I think this is exactly what this RFE is about!
23-02-2023

As discussed in email, I assign this to you, [~jbhateja]
17-02-2023