Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,18 @@ bool emitter::IsThreeOperandAVXInstruction(instruction ins) const
return (flags & INS_Flags_Is3OperandInstructionMask) != 0;
}

// Returns true if the AVX insstruction has op1/op2 being commutative
Comment thread
tannergooding marked this conversation as resolved.
Outdated
bool emitter::IsAvxCommutative(instruction ins) const
{
if (!UseVEXEncoding())
{
return false;
}

insFlags flags = CodeGenInterface::instInfo[ins];
return (flags & INS_Flags_IsCommutative) != 0;
}

//------------------------------------------------------------------------
// HasRegularWideForm: Many x86/x64 instructions follow a regular encoding scheme where the
// byte-sized version of an instruction has the lowest bit of the opcode cleared
Expand Down Expand Up @@ -10024,6 +10036,16 @@ void emitter::emitIns_SIMD_R_R_R(
{
if (UseSimdEncoding())
{
if (IsAvxCommutative(ins) && (instOptions == INS_OPTS_NONE))
{
if (!IsExtendedReg(op1Reg) && IsExtendedReg(op2Reg))
{
// We have a VEX encoded commutative instruction in which
// case we want to try to put the non-extended register as
// op2 since this allows the 2-byte VEX prefix to be used.
Comment thread
tannergooding marked this conversation as resolved.
Outdated
std::swap(op1Reg, op2Reg);
}
Comment thread
tannergooding marked this conversation as resolved.
}
emitIns_R_R_R(ins, attr, targetReg, op1Reg, op2Reg, instOptions);
}
else
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/emitxarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ void SetContainsCallNeedingVzeroupper(bool value)
bool IsDstDstSrcAVXInstruction(instruction ins) const;
bool IsDstSrcSrcAVXInstruction(instruction ins) const;
bool IsThreeOperandAVXInstruction(instruction ins) const;
bool IsAvxCommutative(instruction ins) const;
static bool HasRegularWideForm(instruction ins);
static bool HasRegularWideImmediateForm(instruction ins);
static bool DoesWriteZeroFlag(instruction ins);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ enum insFlags : uint64_t
INS_Flags_IsDstSrcSrcAVXInstruction = 1ULL << 27,
INS_Flags_Is3OperandInstructionMask = (INS_Flags_IsDstDstSrcAVXInstruction | INS_Flags_IsDstSrcSrcAVXInstruction),

// The instruction is commutative for op1/op2 and so can have
// these operands swapped if it will result in a smaller encoding.
INS_Flags_IsCommutative = 1ULL << 28,

// w and s bits
INS_FLAGS_Has_Wbit = 1ULL << 29,
INS_FLAGS_Has_Sbit = 1ULL << 30,
Expand Down
Loading
Loading