[llvm] 1a219e9 - [X86] Support EVEX compression from MOVBErr to BSWAP (#79775)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 30 00:57:55 PST 2024
Author: XinWang10
Date: 2024-01-30T16:57:51+08:00
New Revision: 1a219e989f07eef06fbc9f75ad0c07ebdc652334
URL: https://github.com/llvm/llvm-project/commit/1a219e989f07eef06fbc9f75ad0c07ebdc652334
DIFF: https://github.com/llvm/llvm-project/commit/1a219e989f07eef06fbc9f75ad0c07ebdc652334.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/X86/X86CompressEVEX.cpp
llvm/test/CodeGen/X86/apx/compress-evex.mir
llvm/utils/TableGen/X86ManualCompressEVEXTables.def
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86CompressEVEX.cpp b/llvm/lib/Target/X86/X86CompressEVEX.cpp
index a9704e30478d1..7191e05178610 100644
--- a/llvm/lib/Target/X86/X86CompressEVEX.cpp
+++ b/llvm/lib/Target/X86/X86CompressEVEX.cpp
@@ -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);
@@ -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;
diff --git a/llvm/test/CodeGen/X86/apx/compress-evex.mir b/llvm/test/CodeGen/X86/apx/compress-evex.mir
index 5a3d7ceb10c43..997a8395aa752 100644
--- a/llvm/test/CodeGen/X86/apx/compress-evex.mir
+++ b/llvm/test/CodeGen/X86/apx/compress-evex.mir
@@ -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
+
+...
diff --git a/llvm/utils/TableGen/X86ManualCompressEVEXTables.def b/llvm/utils/TableGen/X86ManualCompressEVEXTables.def
index 58ca10e9e10f8..77cf65be68425 100644
--- a/llvm/utils/TableGen/X86ManualCompressEVEXTables.def
+++ b/llvm/utils/TableGen/X86ManualCompressEVEXTables.def
@@ -328,4 +328,6 @@ ENTRY(VBROADCASTSDZ256rm, VBROADCASTSDYrm)
ENTRY(VBROADCASTSDZ256rr, VBROADCASTSDYrr)
ENTRY(VPBROADCASTQZ256rm, VPBROADCASTQYrm)
ENTRY(VPBROADCASTQZ256rr, VPBROADCASTQYrr)
+ENTRY(MOVBE32rr, BSWAP32r)
+ENTRY(MOVBE64rr, BSWAP64r)
#undef ENTRY
More information about the llvm-commits
mailing list