Skip to content

Commit 1a219e9

Browse files
authored
[X86] Support EVEX compression from MOVBErr to BSWAP (#79775)
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
1 parent 2800448 commit 1a219e9

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

llvm/lib/Target/X86/X86CompressEVEX.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
225225
//
226226
// For AVX512 cases, EVEX prefix is needed in order to carry this information
227227
// thus preventing the transformation to VEX encoding.
228+
// MOVBE*rr is special because it has semantic of NDD but not set EVEX_B.
229+
bool IsMovberr =
230+
MI.getOpcode() == X86::MOVBE32rr || MI.getOpcode() == X86::MOVBE64rr;
228231
bool IsND = X86II::hasNewDataDest(TSFlags);
229-
if (TSFlags & X86II::EVEX_B)
230-
if (!IsND || !isRedundantNewDataDest(MI, ST))
232+
if ((TSFlags & X86II::EVEX_B) || IsMovberr)
233+
if (!IsND && !IsMovberr || !isRedundantNewDataDest(MI, ST))
231234
return false;
232235

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

242-
if (!IsND) {
245+
if (!IsND && !IsMovberr) {
243246
if (usesExtendedRegister(MI) || !checkPredicate(I->NewOpc, &ST) ||
244247
!performCustomAdjustments(MI, I->NewOpc))
245248
return false;

llvm/test/CodeGen/X86/apx/compress-evex.mir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,13 @@ body: |
7171
renamable $rax = XOR64rr_NF_ND killed renamable $rax, killed renamable $r16
7272
RET64 $rax
7373
...
74+
---
75+
name: bswapr_to_movberr
76+
body: |
77+
bb.0.entry:
78+
liveins: $rax
79+
; CHECK: bswapq %rax # EVEX TO LEGACY Compression encoding: [0x48,0x0f,0xc8]
80+
renamable $rax = MOVBE64rr killed renamable $rax
81+
RET64 killed $rax
82+
83+
...

llvm/utils/TableGen/X86ManualCompressEVEXTables.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,6 @@ ENTRY(VBROADCASTSDZ256rm, VBROADCASTSDYrm)
328328
ENTRY(VBROADCASTSDZ256rr, VBROADCASTSDYrr)
329329
ENTRY(VPBROADCASTQZ256rm, VPBROADCASTQYrm)
330330
ENTRY(VPBROADCASTQZ256rr, VPBROADCASTQYrr)
331+
ENTRY(MOVBE32rr, BSWAP32r)
332+
ENTRY(MOVBE64rr, BSWAP64r)
331333
#undef ENTRY

0 commit comments

Comments
 (0)