Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8302662

[SuperWord] Vectorize loop when value from last iteration is used after loop

XMLWordPrintable

      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.

        1. Test.java
          0.8 kB
          Emanuel Peter

            jbhateja Jatin Bhateja
            epeter Emanuel Peter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: