Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/hotspot/cpu/aarch64/aarch64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(0, 0);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return true;
}

// Is this branch offset short enough that a short branch can be used?
//
// NOTE: If the platform does not provide any short branch variants, then
Expand Down Expand Up @@ -7906,31 +7910,31 @@ instruct membar_volatile() %{
instruct castX2P(iRegPNoSp dst, iRegL src) %{
match(Set dst (CastX2P src));

// We still assign cost here because two-address instructions may bring
// side impact, i.e., spilling.
ins_cost(INSN_COST);
format %{ "mov $dst, $src\t# long -> ptr" %}

format %{ "castX2P $src\t# long -> ptr" %}
size(0);
ins_encode %{
if ($dst$$reg != $src$$reg) {
__ mov(as_Register($dst$$reg), as_Register($src$$reg));
}
/* empty encoding */
assert($dst$$reg == $src$$reg, "We can't remove it when dst != src");
%}

ins_pipe(ialu_reg);
ins_pipe(pipe_class_empty);
%}

instruct castP2X(iRegLNoSp dst, iRegP src) %{
match(Set dst (CastP2X src));

// We still assign cost here because two-address instructions may bring
// side impact, i.e., spilling.
ins_cost(INSN_COST);
format %{ "mov $dst, $src\t# ptr -> long" %}

format %{ "castP2X $src\t# ptr -> long" %}
size(0);
ins_encode %{
if ($dst$$reg != $src$$reg) {
__ mov(as_Register($dst$$reg), as_Register($src$$reg));
}
/* empty encoding */
assert($dst$$reg == $src$$reg, "We can't remove it when dst != src");
%}

ins_pipe(ialu_reg);
ins_pipe(pipe_class_empty);
%}

// Convert oop into int for vectors alignment masking
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/arm/arm.ad
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(0, 0);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return false;
}

// Vector width in bytes
int Matcher::vector_width_in_bytes(BasicType bt) {
return MaxVectorSize;
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/ppc/ppc.ad
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(0, 0);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return false;
}

// Vector width in bytes.
int Matcher::vector_width_in_bytes(BasicType bt) {
if (SuperwordUseVSX) {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/riscv/riscv.ad
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(0, 0);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return false;
}

// Is this branch offset short enough that a short branch can be used?
//
// NOTE: If the platform does not provide any short branch variants, then
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/s390/s390.ad
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(0, 0);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return false;
}

//----------SUPERWORD HELPERS----------------------------------------

// Vector width in bytes.
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/x86/x86_32.ad
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(0, 0);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return false;
}

// Is this branch offset short enough that a short branch can be used?
//
// NOTE: If the platform does not provide any short branch variants, then
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/x86/x86_64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,10 @@ OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
return OptoRegPair(hi, lo);
}

bool Matcher::use_same_src_and_dest_reg_for_CastX2P(void) {
return false;
}

// Is this branch offset short enough that a short branch can be used?
//
// NOTE: If the platform does not provide any short branch variants, then
Expand Down
15 changes: 14 additions & 1 deletion src/hotspot/share/adlc/output_h.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
Expand Down Expand Up @@ -1688,6 +1688,19 @@ void ArchDesc::declareClasses(FILE *fp) {
// Identify which input register matches the input register.
uint matching_input = instr->two_address(_globalNames);

// Allocate the same src and dest register for CastX2P and CastP2X
// on some target platforms, then we can remove the instructions in
// the final assembly.
if (strcmp("CastX2P", instr->ideal_Opcode(_globalNames)) == 0 ||
strcmp("CastP2X", instr->ideal_Opcode(_globalNames)) == 0) {
assert(matching_input == 0, "");
fprintf(fp," virtual uint two_adr() const {\n");
fprintf(fp," if (Matcher::use_same_src_and_dest_reg_for_CastX2P())\n");
fprintf(fp," return oper_input_base();\n");
fprintf(fp," return 0;\n");
fprintf(fp," }\n");
}

// Generate the method if it returns != 0 otherwise use MachNode::two_adr()
if( matching_input != 0 ) {
fprintf(fp," virtual uint two_adr() const ");
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/opto/matcher.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -456,6 +456,10 @@ class Matcher : public PhaseTransform {
static bool supports_vector_calling_convention();
static OptoRegPair vector_return_value(uint ideal_reg);

// Is it preferred to use the same src and dest register for CastX2P and
// CastP2X? If true, we can remove the instructions in the final assembly.
static bool use_same_src_and_dest_reg_for_CastX2P();

// Is this branch offset small enough to be addressed by a short branch?
bool is_short_branch_offset(int rule, int br_size, int offset);

Expand Down