JDK-8302665 : [SuperWord] Allow MulReductionVL not just for avx512dq
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2023-02-16
  • Updated: 2023-02-16
  • Resolved: 2023-02-16
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
tbdResolved
Related Reports
Relates :  
Description
Currently MulReductionVL is only allowed with avx512dq support.

    case Op_MulReductionVL:
      if (VM_Version::supports_avx512dq() == false) {
        return false;
      }

https://github.com/openjdk/jdk/blob/3dfadeebd023efb03a400f2b2656567a4154421a/src/hotspot/cpu/x86/x86.ad#L1437-L1440

The relevant vpmullq  instruction exists also on earlier AVX versions. (Ah no, it actually only exists for AVX512, my bad.)
https://www.felixcloutier.com/x86/pmulld:pmullq

See attached Test.java for an example.

Does not vectorize:
./java -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,Test::test -XX:+TraceSuperWord -XX:UseAVX=2 Test.java

Vectorizes, provided your machine has avx512dq support.
./java -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,Test::test -XX:+TraceSuperWord -XX:UseAVX=3 Test.java

Code snippet:
    static long test(long[] data) {
        long mul = 1;
        for (int i = 2; i < N-2; i++) {
            long v = data[i] + 5;
            mul *= v; // MulReductionVL currently requires avx512dq support
        }
        return mul;
    }

I discovered this during the work of JDK-8302139.
Comments
Actually, I have to correct myself. It seems it is really only implemented for AVX512. Closing it now.
16-02-2023