RFR: 8322694: C1: Handle Constant and IfOp in NullCheckEliminator [v2]

Denghui Dong ddong at openjdk.org
Fri Jan 19 06:19:30 UTC 2024


On Wed, 3 Jan 2024 13:37:21 GMT, Denghui Dong <ddong at openjdk.org> wrote:

>> This patch added the support for Constant and IfOn in NullCheckEliminator to eliminate more null check.
>> 
>> testing: tier 1-4 no extra test failure
>
> Denghui Dong has updated the pull request incrementally with one additional commit since the last revision:
> 
>   update

Hi,

I wrote a simple test to verify the IR.

My test:

import java.util.Random;
class Test {

  public static void main(String... args) throws Exception {
    Random r = new Random();
    for (;;) {
      getHash(r.nextInt());
    }
  }


  public static int getHash(int i) {
    String text = i % 2 == 1 ? "Hello" : "World";
    int result = text.hashCode();
    return result;
  }
}


Run with `-XX:-Inline -XX:+PrintIR -XX:TieredStopAtLevel=1 -XX:CompileCommand=compileonly,Test::getHash Test` (fastdebug)

IR before code generation with this patch:

IR before code generation
B4 [0, 0] -> B5
empty stack
inlining depth 0
__bci__use__tid____instr____________________________________
. 0    0     20    std entry B5

B5 (S) [0, 0] -> B0 dom B4 pred: B4
empty stack
inlining depth 0
__bci__use__tid____instr____________________________________
. 0    0     19    goto B0

B0 (SV) [0, 21] dom B5 pred: B5
empty stack
inlining depth 0
__bci__use__tid____instr____________________________________
  1    1    i5     2
. 2    1    i6     i4 % i5
  3    1    i7     1
  4    1    a21    <instance 0x00007f7d08036348 klass=java/lang/String>
  4    1    a22    <instance 0x00007f7d08036340 klass=java/lang/String>
. 4    3    a23    i6 != i7 ? a21 : a22
. 16   0    a14    null_check(a23) (eliminated)
. 16   2    i15    a23.invokespecial()
                   java/lang/String.hashCode()I
. 21   0    i16    ireturn i15


We can see that null_check is eliminated.

IR before code generation without this patch:

IR before code generation
B4 [0, 0] -> B5
empty stack
inlining depth 0
__bci__use__tid____instr____________________________________
. 0    0     20    std entry B5

B5 (S) [0, 0] -> B0 dom B4 pred: B4
empty stack
inlining depth 0
__bci__use__tid____instr____________________________________
. 0    0     19    goto B0

B0 (SV) [0, 21] dom B5 pred: B5
empty stack
inlining depth 0
__bci__use__tid____instr____________________________________
  1    1    i5     2
. 2    1    i6     i4 % i5
  3    1    i7     1
  4    1    a21    <instance 0x00007f46c0036348 klass=java/lang/String>
  4    1    a22    <instance 0x00007f46c0036340 klass=java/lang/String>
. 4    3    a23    i6 != i7 ? a21 : a22
. 16   0    a14    null_check(a23)
. 16   2    i15    a23.invokespecial()
                   java/lang/String.hashCode()I
. 21   0    i16    ireturn i15

I have tested this patch with tier 1-4. There are some test failures caused by my environment.

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

PR Comment: https://git.openjdk.org/jdk/pull/17191#issuecomment-1899826148
PR Comment: https://git.openjdk.org/jdk/pull/17191#issuecomment-1899829359


More information about the hotspot-compiler-dev mailing list