RFR: 8351994: Enable Extended EVEX to REX2/REX demotion when src and dst are the same

Sandhya Viswanathan sviswanathan at openjdk.org
Wed Apr 9 23:31:37 UTC 2025


On Fri, 4 Apr 2025 01:15:36 GMT, Srinivas Vamsi Parasa <sparasa at openjdk.org> wrote:

> The current scheme for Intel APX NDD code generation favors the emission of NDD instruction on APX-enabled targets, even if destination and source registers are the same. To prevent this, this PR extends the assembler layer to demote EEVEX to REX encoding if dst matches with source operands.

src/hotspot/cpu/x86/assembler_x86.cpp line 13770:

> 13768:                            InstructionAttr *attributes, bool no_flags, bool use_prefixq) {
> 13769:   // Demote RegRegReg instructions
> 13770:   if (!no_flags && dst_enc == nds_enc) {

This could be replaced by call to is_demotable().

src/hotspot/cpu/x86/assembler_x86.cpp line 13771:

> 13769:   // Demote RegRegReg instructions
> 13770:   if (!no_flags && dst_enc == nds_enc) {
> 13771:     return use_prefixq? prefixq_and_encode(dst_enc, src_enc) : prefix_and_encode(dst_enc, src_enc);

Nit pick, need space before ? as below:
use_prefixq ? prefixq_and_encode

src/hotspot/cpu/x86/assembler_x86.cpp line 13780:

> 13778:                            InstructionAttr *attributes, bool no_flags, bool use_prefixq) {
> 13779:   // Demote RegReg and RegRegImm instructions
> 13780:   if (!no_flags && dst_enc == nds_enc) {

This could be replaced by call to is_demotable().

src/hotspot/cpu/x86/assembler_x86.cpp line 13818:

> 13816: }
> 13817: 
> 13818: bool Assembler::is_demotable(bool no_flags, int dst_enc, int nds_enc, int src_enc) {

src_enc is not being used in this method so could be removed.

src/hotspot/cpu/x86/assembler_x86.cpp line 17185:

> 17183:   InstructionAttr attributes(AVX_128bit, /* vex_w */ false, /* legacy_mode */ false, /* no_mask_reg */ true, /* uses_vl */ false);
> 17184:   // Encoding Format : eevex_prefix (4 bytes) | opcode_cc | modrm
> 17185:   int encode =  evex_prefix_and_encode_ndd(0, 0, dst->encoding(), VEX_SIMD_F2, /* MAP4 */VEX_OPCODE_0F_3C, &attributes); //TODO: check this

This should not be demoted.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24431#discussion_r2036263931
PR Review Comment: https://git.openjdk.org/jdk/pull/24431#discussion_r2036260211
PR Review Comment: https://git.openjdk.org/jdk/pull/24431#discussion_r2036264622
PR Review Comment: https://git.openjdk.org/jdk/pull/24431#discussion_r2036257623
PR Review Comment: https://git.openjdk.org/jdk/pull/24431#discussion_r2036258489


More information about the hotspot-compiler-dev mailing list