RFR: 8261137: Optimization of Box nodes in uncommon_trap

Wang Huang whuang at openjdk.java.net
Fri Feb 5 07:18:43 UTC 2021


On Thu, 4 Feb 2021 10:01:50 GMT, Eric Liu <github.com+10482586+theRealELiu at openjdk.org> wrote:

> I was wandering if we can remove the useless `if` as it's always true in this case. Do you know why this kind of `if` haven't been eliminated by GVN phase?
It is a good idea . However, C2 might not optimize some `if` for many reasons: 
*  This situation can also be triggered in calling other method. For example :
  ```
public class MyBenchmark {

    static int[] data = new int[10000];

    static {
        for(int i = 0; i < data.length; ++i) {
            data[i] = 299;
        }
    }

    @Benchmark
    public void testMethod(Blackhole bh) {
      int sum = 0;
      for (int i = 0; i < data.length; i++) {
        Integer ii = Integer.valueOf(data[i]);
        sum += abs(ii);
      }
      bh.consume(sum);
    }

    public int abs(Integer ii) {
      if (ii.intValue() > 0) {
        return ii.intValue();
      } else {
        return 0 - ii.intValue();
      }
    }
}
 The method `abs` will be inlined when it is hot enough. However, this `If` can not be eliminated.
*  The case in the JDK-8261137 is just like this case: 
public class MyBenchmark {

    static int[] data = new int[10000];

    static {
        for(int i = 0; i < data.length; ++i) {
            data[i] = i * 1337 % 7331;
        }
    }

    @Benchmark
    public void testMethod(Blackhole bh) {
      int sum = 0;
      for (int i = 0; i < data.length; i++) {
          Integer ii = Integer.valueOf(data[i]);
          if (i < 100000) {
              sum += ii.intValue();
          }
      }
      bh.consume(sum);
    }
}

-------------

PR: https://git.openjdk.java.net/jdk/pull/2401


More information about the hotspot-compiler-dev mailing list