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

C2: Turn outer counted loops into strip mined loops when they become inner loops later

XMLWordPrintable

      Currently, we only turn counted loops into strip mined loops when they are inner most loops. This is done when converting a loop into a counted loop in `PhaseIdealLoop::is_counted_loop()`:
      https://github.com/openjdk/jdk/blob/1fe45265e446eeca5dc496085928ce20863a3172/src/hotspot/share/opto/loopnode.cpp#L2251-L2261

      However, when the inner loop is folded, for example due to fully unrolling it or the path to the loop became dead, we will *not* turn it's parent outer loop (if there is one), which is now newly an inner loop, to a strip mined loop.

      This could prevent some optimizations. For example, the following two loops should be completely removed by applying the empty loop removal optimization twice:

      int x = 34;
      for (int i = 0; i < 800; i++) {
          for (int j = 0; j < 1000; j++) {
              x++;
          }
      }
      iFld = x; // Use x

      The empty loop removal optimization is successfully removing the inner loop. But the outer loop still contains a safepoint and we fail to apply the empty loop removal optimization again.

      This RFE proposes to change that limitation of only turning inner counted loops to strip mined loops at counted loop convertion/creation time in is_counted_loop(). This can be done by extracting the outer strip mined loop creation process from is_counted_loop() and turning it into a 2-step process:
      1. For all non-counted loops: Convert into counted loops if possible
      2. For all inner counted loop: Turn into strip mined loops if possible

      All the code should already be there and just needs to be refactored/moved/extracted. We should also add some tests to demonstrate that we can apply more optimizations (e.g. IR tests).

      [~roland] and I think that it should be quite straight forward and worth investigating. But there might be some unexpected issues. Moreover, it could have some unforeseeable side effects by applying more optimizations which could reveal other unrelated existing bugs. Careful testing should be performed.

            dfenacci Damon Fenacci
            chagedorn Christian Hagedorn
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: