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

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

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 11, 16
    • Fix Version/s: 16
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      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

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

                Dates

                Created:
                Updated:
                Resolved: