From c49553b9773f7d8ad876abcfa66f94e7814575ca Mon Sep 17 00:00:00 2001 From: Fei Gao Date: Thu, 6 Jun 2024 14:24:06 +0000 Subject: [PATCH] Redefine the interface for cmpOpUEqNeLeGt --- src/hotspot/cpu/aarch64/aarch64.ad | 20 +++++++----- .../irTests/TestArrLenCheckOptimization.java | 31 +++++++++++++------ .../compiler/lib/ir_framework/IRNode.java | 17 ++++++---- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad index 41d3e1cd0052e..4d31fbc0812ba 100644 --- a/src/hotspot/cpu/aarch64/aarch64.ad +++ b/src/hotspot/cpu/aarch64/aarch64.ad @@ -5642,10 +5642,10 @@ operand cmpOpUEqNeLeGt() interface(COND_INTER) %{ equal(0x0, "eq"); not_equal(0x1, "ne"); - less(0xb, "lt"); - greater_equal(0xa, "ge"); - less_equal(0xd, "le"); - greater(0xc, "gt"); + less(0x3, "lo"); + greater_equal(0x2, "hs"); + less_equal(0x9, "ls"); + greater(0x8, "hi"); overflow(0x6, "vs"); no_overflow(0x7, "vc"); %} @@ -15694,10 +15694,12 @@ instruct cmpUI_imm0_branch(cmpOpUEqNeLeGt cmp, iRegIorL2I op1, immI0 op2, label ins_encode %{ Label* L = $labl$$label; Assembler::Condition cond = (Assembler::Condition)$cmp$$cmpcode; - if (cond == Assembler::EQ || cond == Assembler::LE) + if (cond == Assembler::EQ || cond == Assembler::LS) { __ cbzw($op1$$Register, *L); - else + } else { + assert(cond == Assembler::NE || cond == Assembler::HI, "unexpected condition"); __ cbnzw($op1$$Register, *L); + } %} ins_pipe(pipe_cmp_branch); %} @@ -15711,10 +15713,12 @@ instruct cmpUL_imm0_branch(cmpOpUEqNeLeGt cmp, iRegL op1, immL0 op2, label labl) ins_encode %{ Label* L = $labl$$label; Assembler::Condition cond = (Assembler::Condition)$cmp$$cmpcode; - if (cond == Assembler::EQ || cond == Assembler::LE) + if (cond == Assembler::EQ || cond == Assembler::LS) { __ cbz($op1$$Register, *L); - else + } else { + assert(cond == Assembler::NE || cond == Assembler::HI, "unexpected condition"); __ cbnz($op1$$Register, *L); + } %} ins_pipe(pipe_cmp_branch); %} diff --git a/test/hotspot/jtreg/compiler/c2/irTests/TestArrLenCheckOptimization.java b/test/hotspot/jtreg/compiler/c2/irTests/TestArrLenCheckOptimization.java index bc1dfbfc070bb..cb955bf14e7c8 100644 --- a/test/hotspot/jtreg/compiler/c2/irTests/TestArrLenCheckOptimization.java +++ b/test/hotspot/jtreg/compiler/c2/irTests/TestArrLenCheckOptimization.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Arm Limited. All rights reserved. + * Copyright (c) 2024, Arm Limited. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,13 +40,13 @@ public class TestArrLenCheckOptimization { int result = 0; @Test - @IR(counts = {IRNode.CBZW_LE, "1"}) + @IR(counts = {IRNode.CBZW_LS, "1"}) void test_le_int(int ia[]) { result += ia[0]; } @Test - @IR(counts = {IRNode.CBNZW_GT, "1"}) + @IR(counts = {IRNode.CBNZW_HI, "1"}) void test_gt_int(int ia[]) { if (ia.length > 0) { result += 0x88; @@ -56,20 +56,33 @@ void test_gt_int(int ia[]) { } @Test - @IR(counts = {IRNode.CBZ_LE, "1"}) + @IR(counts = {IRNode.CBZ_LS, "1"}) void test_le_long(int ia[]) { - int limit = ia.length-1; - for (int i = 0; i < ia.length; i += 1) { - ia[limit-i] = -123; + if (Long.compareUnsigned(ia.length, 0) > 0) { + result += 0x80; + } else { + result -= 1; + } + } + + @Test + @IR(counts = {IRNode.CBZ_HI, "1"}) + void test_gt_long(int ia[]) { + if (Long.compareUnsigned(ia.length, 0) > 0) { + result += 0x82; + } else { + result -= 1; } } - @Run(test = {"test_le_int", "test_gt_int", "test_le_long"}, mode = RunMode.STANDALONE) + @Run(test = {"test_le_int", "test_gt_int", "test_le_long", "test_gt_long"}, + mode = RunMode.STANDALONE) public void test_runner() { for (int i = 0; i < 10_000; i++) { test_le_int(new int[1]); test_gt_int(new int[0]); - test_le_long(new int[i]); + test_le_long(new int[1]); + test_gt_long(new int[0]); } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java index 285a836e3fbe0..efa7ccadfda1b 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java @@ -378,19 +378,24 @@ public class IRNode { beforeMatchingNameRegex(CAST_LL, "CastLL"); } - public static final String CBNZW_GT = PREFIX + "CBNZW_GT" + POSTFIX; + public static final String CBNZW_HI = PREFIX + "CBNZW_HI" + POSTFIX; static { - optoOnly(CBNZW_GT, "cbwgt"); + optoOnly(CBNZW_HI, "cbwhi"); } - public static final String CBZW_LE = PREFIX + "CBZW_LE" + POSTFIX; + public static final String CBZW_LS = PREFIX + "CBZW_LS" + POSTFIX; static { - optoOnly(CBZW_LE, "cbwle"); + optoOnly(CBZW_LS, "cbwls"); } - public static final String CBZ_LE = PREFIX + "CBZ_LE" + POSTFIX; + public static final String CBZ_LS = PREFIX + "CBZ_LS" + POSTFIX; static { - optoOnly(CBZ_LE, "cble"); + optoOnly(CBZ_LS, "cbls"); + } + + public static final String CBZ_HI = PREFIX + "CBZ_HI" + POSTFIX; + static { + optoOnly(CBZ_HI, "cbhi"); } public static final String CHECKCAST_ARRAY = PREFIX + "CHECKCAST_ARRAY" + POSTFIX;