Skip to content

Commit

Permalink
[X86] Support EVEX compression from MOVBErr to BSWAP (#79775)
Browse files Browse the repository at this point in the history
APX promoted MOVBE instructions were supported in #77431. The reg2reg
variants of MOVBE are newly introduced by APX and can be optimized to
BSWAP instruction when the 2 register operands are same.

This patch adds manual entries for MOVBErr instructions when we do ndd
to non-ndd compression #77731.
RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
  • Loading branch information
XinWang10 committed Jan 30, 2024
1 parent 2800448 commit 1a219e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions llvm/lib/Target/X86/X86CompressEVEX.cpp
Expand Up @@ -225,9 +225,12 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
//
// For AVX512 cases, EVEX prefix is needed in order to carry this information
// thus preventing the transformation to VEX encoding.
// MOVBE*rr is special because it has semantic of NDD but not set EVEX_B.
bool IsMovberr =
MI.getOpcode() == X86::MOVBE32rr || MI.getOpcode() == X86::MOVBE64rr;
bool IsND = X86II::hasNewDataDest(TSFlags);
if (TSFlags & X86II::EVEX_B)
if (!IsND || !isRedundantNewDataDest(MI, ST))
if ((TSFlags & X86II::EVEX_B) || IsMovberr)
if (!IsND && !IsMovberr || !isRedundantNewDataDest(MI, ST))
return false;

ArrayRef<X86CompressEVEXTableEntry> Table = ArrayRef(X86CompressEVEXTable);
Expand All @@ -239,7 +242,7 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
return false;
}

if (!IsND) {
if (!IsND && !IsMovberr) {
if (usesExtendedRegister(MI) || !checkPredicate(I->NewOpc, &ST) ||
!performCustomAdjustments(MI, I->NewOpc))
return false;
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/X86/apx/compress-evex.mir
Expand Up @@ -71,3 +71,13 @@ body: |
renamable $rax = XOR64rr_NF_ND killed renamable $rax, killed renamable $r16
RET64 $rax
...
---
name: bswapr_to_movberr
body: |
bb.0.entry:
liveins: $rax
; CHECK: bswapq %rax # EVEX TO LEGACY Compression encoding: [0x48,0x0f,0xc8]
renamable $rax = MOVBE64rr killed renamable $rax
RET64 killed $rax
...
2 changes: 2 additions & 0 deletions llvm/utils/TableGen/X86ManualCompressEVEXTables.def
Expand Up @@ -328,4 +328,6 @@ ENTRY(VBROADCASTSDZ256rm, VBROADCASTSDYrm)
ENTRY(VBROADCASTSDZ256rr, VBROADCASTSDYrr)
ENTRY(VPBROADCASTQZ256rm, VPBROADCASTQYrm)
ENTRY(VPBROADCASTQZ256rr, VPBROADCASTQYrr)
ENTRY(MOVBE32rr, BSWAP32r)
ENTRY(MOVBE64rr, BSWAP64r)
#undef ENTRY

0 comments on commit 1a219e9

Please sign in to comment.