8336860: x86: Change integer src operand for CMoveL of 0 and 1 to long

Reviewed-by: epeter, chagedorn, shade, qamai, jbhateja
This commit is contained in:
Jasmine Karthikeyan 2024-09-04 13:44:24 +00:00
parent c7d15f1fe0
commit 6f8714ee19
4 changed files with 109 additions and 4 deletions

View File

@ -6388,7 +6388,7 @@ instruct cmovP_regUCF2_eq(cmpOpUCF2 cop, rFlagsRegUCF cr, rRegP dst, rRegP src)
ins_pipe(pipe_cmov_reg);
%}
instruct cmovL_imm_01(rRegL dst, immI_1 src, rFlagsReg cr, cmpOp cop)
instruct cmovL_imm_01(rRegL dst, immL1 src, rFlagsReg cr, cmpOp cop)
%{
predicate(n->in(2)->in(2)->is_Con() && n->in(2)->in(2)->get_long() == 0);
match(Set dst (CMoveL (Binary cop cr) (Binary src dst)));
@ -6426,7 +6426,7 @@ instruct cmovL_mem(cmpOp cop, rFlagsReg cr, rRegL dst, memory src)
ins_pipe(pipe_cmov_mem); // XXX
%}
instruct cmovL_imm_01U(rRegL dst, immI_1 src, rFlagsRegU cr, cmpOpU cop)
instruct cmovL_imm_01U(rRegL dst, immL1 src, rFlagsRegU cr, cmpOpU cop)
%{
predicate(n->in(2)->in(2)->is_Con() && n->in(2)->in(2)->get_long() == 0);
match(Set dst (CMoveL (Binary cop cr) (Binary src dst)));
@ -6452,7 +6452,7 @@ instruct cmovL_regU(cmpOpU cop, rFlagsRegU cr, rRegL dst, rRegL src)
ins_pipe(pipe_cmov_reg); // XXX
%}
instruct cmovL_imm_01UCF(rRegL dst, immI_1 src, rFlagsRegUCF cr, cmpOpUCF cop)
instruct cmovL_imm_01UCF(rRegL dst, immL1 src, rFlagsRegUCF cr, cmpOpUCF cop)
%{
predicate(n->in(2)->in(2)->is_Con() && n->in(2)->in(2)->get_long() == 0);
match(Set dst (CMoveL (Binary cop cr) (Binary src dst)));

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package compiler.c2.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* bug 8336860
* @summary Verify codegen for CMoveL with constants 0 and 1
* @library /test/lib /
* @run driver compiler.c2.irTests.CMoveLConstants
*/
public class CMoveLConstants {
public static void main(String[] args) {
TestFramework.run();
}
@Test
@IR(applyIfPlatform = {"x64", "true"}, counts = {IRNode.X86_CMOVEL_IMM01, "1"}, phase = CompilePhase.FINAL_CODE)
public static long testSigned(int a, int b) {
return a > b ? 1L : 0L;
}
@Test
@IR(applyIfPlatform = {"x64", "true"}, counts = {IRNode.X86_CMOVEL_IMM01U, "1"}, phase = CompilePhase.FINAL_CODE)
public static long testUnsigned(int a, int b) {
return Integer.compareUnsigned(a, b) > 0 ? 1L : 0L;
}
@Test
@IR(applyIfPlatform = {"x64", "true"}, counts = {IRNode.X86_CMOVEL_IMM01UCF, "1"}, phase = CompilePhase.FINAL_CODE)
public static long testFloat(float a, float b) {
return a > b ? 1L : 0L;
}
@DontCompile
public void assertResults(int a, int b) {
Asserts.assertEQ(a > b ? 1L : 0L, testSigned(a, b));
Asserts.assertEQ(Integer.compareUnsigned(a, b) > 0 ? 1L : 0L, testUnsigned(a, b));
Asserts.assertEQ((float) a > (float) b ? 1L : 0L, testFloat(a, b));
}
@Run(test = {"testSigned", "testUnsigned", "testFloat"})
public void runMethod() {
assertResults(10, 20);
assertResults(20, 10);
}
}

View File

@ -2233,6 +2233,21 @@ public class IRNode {
machOnlyNameRegex(X86_TESTL_REG, "testL_reg");
}
public static final String X86_CMOVEL_IMM01 = PREFIX + "X86_CMOVEL_IMM01" + POSTFIX;
static {
machOnlyNameRegex(X86_CMOVEL_IMM01, "cmovL_imm_01");
}
public static final String X86_CMOVEL_IMM01U = PREFIX + "X86_CMOVEL_IMM01U" + POSTFIX;
static {
machOnlyNameRegex(X86_CMOVEL_IMM01U, "cmovL_imm_01U");
}
public static final String X86_CMOVEL_IMM01UCF = PREFIX + "X86_CMOVEL_IMM01UCF" + POSTFIX;
static {
machOnlyNameRegex(X86_CMOVEL_IMM01UCF, "cmovL_imm_01UCF");
}
/*
* Utility methods to set up IR_NODE_MAPPINGS.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. 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
@ -26,6 +26,8 @@ import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.Random;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@ -38,6 +40,16 @@ public class BasicRules {
static final int INT_IMM = 100;
static final long LONG_IMM = 100;
@Setup(Level.Iteration)
public void setup() {
Random random = new Random(1000);
for (int i = 0; i < 1024; i++) {
INT_ARRAY[i] = random.nextInt();
LONG_ARRAY[i] = random.nextLong();
}
}
@Benchmark
public void andL_rReg_imm255(Blackhole bh) {
for (int i = 0; i < LONG_ARRAY.length; i++) {
@ -125,5 +137,12 @@ public class BasicRules {
bh.consume(LONG_ARRAY[i] - LONG_IMM);
}
}
@Benchmark
public void cmovL_imm_01(Blackhole bh) {
for (int i = 0; i < INT_ARRAY.length; i++) {
bh.consume(INT_ARRAY[i] > 0 ? 1L : 0L);
}
}
}