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

Code that uses Object.checkIndex() range checks doesn't optimize well

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P3
    • 16
    • 11, 16
    • hotspot
    • b28

    Description

      From Paul:

      We have been investigating range check issues when using the Vector API. The recommended approach for loops is to express the upper bound using the method VectorSpecies.loopBound as in say:

      @Benchmark
      public float[] vector1() {
          int i = 0;
          for (; i < SPECIES.loopBound(a.length); i += SPECIES.length()) {
              // FloatVector va, vb, vc;
              var va = FloatVector.fromArray(SPECIES, a, i);
              var vb = FloatVector.fromArray(SPECIES, b, i);
              var vc = va.fma(va, vb.mul(vb)).neg();
              vc.intoArray(r, i);
          }

          for (; i < a.length; i++) {
              r[i] = Math.fma(a[i], a[i], b[i] * b[i]) * -1.0f;
          }

          return r;
      }

      However, this does not result in the removal of bounds checks from within the loop when loading/storing the vectors from/to memory.

      Attachments

        Issue Links

          Activity

            People

              roland Roland Westrelin
              roland Roland Westrelin
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: