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

[vector] RangeChecks are not eliminated in counted loop with Vector API

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: repo-panama
    • Fix Version/s: repo-panama
    • Component/s: hotspot
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      When doing performance test with JMH, I found that Vector API version of int ADD test is slower than auto vectorization( test code [1]). after changing loop stride from vector length to 1, the performance got better both in my local X86 and AArch64 platform. The data is as followed.
                                         scalar original Modified
      jmh/ADD#size(1024) 100% 94% 102% X86
      jmh/ADD#size(1024) 100% 75% 95% AArch64

       After investigation, the root cause is that two RangeChecks are not eliminated in counted loop when loop stride is vector length([1] vectAdd). But when loop stride is 1([1] vectAdd2), all the RangeChecks can be eliminated in counted loop. Two RangeChecks which are not eliminated are listed as follows.
      Detailed counted loop files are also attached.

        C ID:1375 471 RangeCheck === 1375 470 [[ 472 475 ]] P=0.999999, C=-1.000000 Type:{0:control, 1:control} !jvms: java.util.Objects::checkIndex @ bci:3 jdk.incubator.vector.VectorIntrinsics::checkFromIndexSize @ bci:43 jdk.incubator.vector.IntVector::fromArray @ bci:12 TestIntVector::vectAdd @ bci:23
        C ID:471 472 IfTrue === 471 [[ 1301 1113 ]] #1 Type:control !orig=[1063],[1252],[1104] !jvms: java.util.Objects::checkIndex @ bci:3

        C ID:472 1113 RangeCheck === 472 1112 [[ 1114 1117 ]] P=0.999999, C=-1.000000 Type:{0:control, 1:control} !jvms: java.util.Objects::checkIndex @ bci:3 jdk.incubator.vector.VectorIntrinsics::checkFromIndexSize @ bci:43 jdk.incubator.vector.IntVector::intoArray @ bci:12 TestIntVector::vectAdd @ bci:40
        C ID:1113 1114 IfTrue === 1113 [[ 1374 1349 ]] #1 Type:control !jvms: java.util.Objects::checkIndex @ bci:3

      We need to consider how to eliminate these RangeCheck nodes when loop stride is vector length.


      [1] Test code
      Auto vectorization code:
        public static void add(int[] a, int[] b, int[] c) {
            for (int i = 0; i < a.length; i++) {
                c[i] = a[i] + b[i];
            }
        }

      Vector API code:
        public static void vectAdd(int[] a, int[] b, int[] c) {
            for (int i = 0; i < a.length; i += SPECIES.length()) {
                IntVector av = IntVector.fromArray(SPECIES, a, i);
                IntVector bv = IntVector.fromArray(SPECIES, b, i);
                av.lanewise(VectorOperators.ADD, bv).intoArray(c, i);
            }
        }

      Modified Vector API code:
        public static void vectAdd2(int[] a, int[] b, int[] c) {
            for (int i = 0; i < a.length/SPECIES.length(); i++) {
                IntVector av = IntVector.fromArray(SPECIES, a, (i*SPECIES.length()));
                IntVector bv = IntVector.fromArray(SPECIES, b, (i*SPECIES.length()));
                av.lanewise(VectorOperators.ADD, bv).intoArray(c, (i*SPECIES.length()));
            }
        }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              yzhang Yang Zhang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: