RFR: 8311923: TestIRMatching.java fails on RISC-V

Gui Cao gcao at openjdk.org
Wed Jul 12 08:45:34 UTC 2023


Hi, we are experiencing test failures in test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java using fastdebug:


One or more @IR rules failed:

Failed IR Rules (1) of Methods (1)
----------------------------------
1) Method "public java.lang.Object[] ir_framework.tests.CheckCastArray.arrayCopy(java.lang.Object[],java.lang.Class)" - [Failed IR rules: 1]:
   * @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeatureOr={}, applyIfCPUFeature={}, counts={}, failOn={"_#CHECKCAST_ARRAYCOPY#_"}, applyIfAnd={}, applyIfOr={}, applyIfNot={})"
     > Phase "PrintOptoAssembly":
       - failOn: Graph contains forbidden nodes:
         * Constraint 1: "(.*((?i:call_leaf_nofp,runtime)|CALL,\\s?runtime leaf nofp|BCTRL.*.leaf call).*checkcast_arraycopy.*)"
           - Matched forbidden node:
             * 15a +   CALL, runtime leaf nofp 0x0000003f7fbd9600	#@CallLeafNoFPDirect checkcast_arraycopy

>>> Check stdout for compilation output of the failed methods


After troubleshooting, the problem is related to the definition of the matching rules for the CHECKCAST_ARRAY, CHECKCAST_ARRAY_OF fields in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java:

    public static final String CHECKCAST_ARRAY = PREFIX + "CHECKCAST_ARRAY" + POSTFIX;
    static {
        String regex = "(((?i:cmp|CLFI|CLR).*precise \[.*:|.*(?i:mov|or).*precise \[.*:.*\\R.*(cmp|CMP|CLR))" + END;
        optoOnly(CHECKCAST_ARRAY, regex);
    }

    public static final String CHECKCAST_ARRAY_OF = COMPOSITE_PREFIX + "CHECKCAST_ARRAY_OF" + POSTFIX;
    static {
        String regex = "(((?i:cmp|CLFI|CLR).*precise \[.*" + IS_REPLACED + ":|.*(?i:mov|or).*precise \[.*" + IS_REPLACED + ":.*\\R.*(cmp|CMP|CLR))" + END;
        optoOnly(CHECKCAST_ARRAY_OF, regex);
    }

This rule is used to match the Opto compilation log of the `array()/arrayCopy()` method of the subclass CheckCastArray in test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java. If the match does not work, the above test fails.

The `array()` part of the Opto log for CheckCastArray on the aarch64 platform is as follows:

06c     B2: #	out( B5 B3 ) <- in( B1 )  Freq: 0.999999
06c +   mov  R12, narrowklass: precise [ir_framework/tests/MyClass: 0x0000ffff58420808 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact *	# compressed klass ptr
074 +   cmp  R10, R12	 // compressed ptr
078     bne  B5	# unsigned  P=0.100000 C=-1.000000

The `array()` part of the Opto log for CheckCastArray on the riscv platform is as follows:

054     B2: #	out( B5 B3 ) <- in( B1 )  Freq: 0.999999
054 +   mv  R29, narrowklass: precise [ir_framework/tests/MyClass: 0x0000003f34437df8 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact *	# compressed klass ptr, #@loadConNKlass
062 +   bne  R7, R29, B5	#@cmpN_branch  P=0.100000 C=-1.000000

>From the above Opto log, we can see that the match rule of CHECKCAST_ARRAY in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java can be matched with aarch64. However, on the riscv platform, since the mv instruction is generated, it does not correspond to the matching rule, so the test case fails. To solve this problem, we modified the match rules defined by CHECKCAST_ARRAY, CHECKCAST_ARRAY_OF in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java to include the mv directive in the match rules.


Same problem with ALLOC_ARRAY, ALLOC_ARRAY_OF in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java

    public static final String ALLOC_ARRAY = PREFIX + "ALLOC_ARRAY" + POSTFIX;
    static {
        String optoRegex = "(.*precise \[.*\\R((.*(?i:mov|xor|nop|spill).*|\\s*|.*(LGHI|LI).*)\\R)*.*(?i:call,static).*wrapper for: _new_array_Java" + END;
        allocNodes(ALLOC_ARRAY, "AllocateArray", optoRegex);
    }

    public static final String ALLOC_ARRAY_OF = COMPOSITE_PREFIX + "ALLOC_ARRAY_OF" + POSTFIX;
    static {
        String regex = "(.*precise \[.*" + IS_REPLACED + ":.*\\R((.*(?i:mov|xorl|nop|spill).*|\\s*|.*(LGHI|LI).*)\\R)*.*(?i:call,static).*wrapper for: _new_array_Java" + END;
        optoOnly(ALLOC_ARRAY_OF, regex);
    }

This rule is used to match the compilation log of the `allocArray()` method of the subclass AllocArray in test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java, and if it doesn't match it also fails. test fails.
The `allocArray()` part of the Opto log for AllocArray on the aarch64 platform is as follows:

1a8     B14: #	out( B17 B15 ) <- in( B1 )  Freq: 0.000100017
1a8 +   mov  R1, precise [ir_framework/tests/MyClass: 0x0000ffff244beb58 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact *	# ptr
	
1b4     call,static 0x0000ffff6fb9c540 	// ==>  wrapper for: _new_array_Java
        # ir_framework.tests.AllocArray::allocArray @ bci:2 (line 930) L[0]=_ STK[0]=R29
        # OopMap {rfp=Oop off=440/0x1b8}

The `allocArray()` part of the Opto log for AllocArray on the riscv platform is as follows:

16a     B14: #	out( B17 B15 ) <- in( B1 )  Freq: 0.000100017
16a +   mv  R11, precise [ir_framework/tests/MyClass: 0x00007fff4c34c018 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact *	# ptr, #@loadConP
182 +   li R12, #2	# int, #@loadConI
184     CALL,static 0x00007fff9bb74840	#@CallStaticJavaDirect wrapper for: _new_array_Java
        # ir_framework.tests.AllocArray::allocArray @ bci:2 (line 930) L[0]=_ STK[0]=R8
        # OopMap {fp=Oop off=392/0x188}

As we can see in the above logs, the aarch64 log matches the empty line under precise, which also matches the ALLOC_ARRAY_OF rule in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java, but in the riscv log. precise is followed by the li, which doesn't match the rule and therefore also causes the test case to fail. To solve this problem, we firstly modified the loadConI, loadConL nodes in riscv.ad, and changed the log message of li into mv, and secondly, we modified the ALLOC_ARRAY and ALLOC_ARRAY_OF match rule in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java, and added the mv directive to the match rule.

## Testing:
qemu system and unmatched board:
- [x]  test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java (fastdebug)

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

Commit messages:
 - 8311923: TestIRMatching.java fails on RISC-V

Changes: https://git.openjdk.org/jdk/pull/14848/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14848&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8311923
  Stats: 9 lines in 2 files changed: 0 ins; 0 del; 9 mod
  Patch: https://git.openjdk.org/jdk/pull/14848.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14848/head:pull/14848

PR: https://git.openjdk.org/jdk/pull/14848


More information about the hotspot-compiler-dev mailing list