56#define COMP_EVEX_DESC "Compressing EVEX instrs when possible"
57#define COMP_EVEX_NAME "x86-compress-evex"
59#define DEBUG_TYPE COMP_EVEX_NAME
63#define GET_X86_COMPRESS_EVEX_TABLE
64#include "X86GenInstrMapping.inc"
77 MachineFunctionProperties::Property::NoVRegs);
83char CompressEVEXPass::ID = 0;
86 auto isHiRegIdx = [](
unsigned Reg) {
88 if (Reg >= X86::XMM16 && Reg <= X86::XMM31)
91 if (Reg >= X86::YMM16 && Reg <= X86::YMM31)
107 "ZMM instructions should not be in the EVEX->VEX tables");
118 unsigned Opc =
MI.getOpcode();
120 case X86::VALIGNDZ128rri:
121 case X86::VALIGNDZ128rmi:
122 case X86::VALIGNQZ128rri:
123 case X86::VALIGNQZ128rmi: {
124 assert((NewOpc == X86::VPALIGNRrri || NewOpc == X86::VPALIGNRrmi) &&
125 "Unexpected new opcode!");
127 (Opc == X86::VALIGNQZ128rri || Opc == X86::VALIGNQZ128rmi) ? 8 : 4;
129 Imm.setImm(Imm.getImm() * Scale);
132 case X86::VSHUFF32X4Z256rmi:
133 case X86::VSHUFF32X4Z256rri:
134 case X86::VSHUFF64X2Z256rmi:
135 case X86::VSHUFF64X2Z256rri:
136 case X86::VSHUFI32X4Z256rmi:
137 case X86::VSHUFI32X4Z256rri:
138 case X86::VSHUFI64X2Z256rmi:
139 case X86::VSHUFI64X2Z256rri: {
140 assert((NewOpc == X86::VPERM2F128rri || NewOpc == X86::VPERM2I128rri ||
141 NewOpc == X86::VPERM2F128rmi || NewOpc == X86::VPERM2I128rmi) &&
142 "Unexpected new opcode!");
144 int64_t ImmVal = Imm.getImm();
146 Imm.setImm(0x20 | ((ImmVal & 2) << 3) | (ImmVal & 1));
149 case X86::VRNDSCALEPDZ128rri:
150 case X86::VRNDSCALEPDZ128rmi:
151 case X86::VRNDSCALEPSZ128rri:
152 case X86::VRNDSCALEPSZ128rmi:
153 case X86::VRNDSCALEPDZ256rri:
154 case X86::VRNDSCALEPDZ256rmi:
155 case X86::VRNDSCALEPSZ256rri:
156 case X86::VRNDSCALEPSZ256rmi:
157 case X86::VRNDSCALESDZrri:
158 case X86::VRNDSCALESDZrmi:
159 case X86::VRNDSCALESSZrri:
160 case X86::VRNDSCALESSZrmi:
161 case X86::VRNDSCALESDZrri_Int:
162 case X86::VRNDSCALESDZrmi_Int:
163 case X86::VRNDSCALESSZrri_Int:
164 case X86::VRNDSCALESSZrmi_Int:
166 int64_t ImmVal = Imm.getImm();
168 if ((ImmVal & 0xf) != ImmVal)
187 auto IsRedundantNewDataDest = [&](
unsigned &Opc) {
195 X86::isCFCMOVCC(
MI.getOpcode()))
202 if (!
Desc.isCommutable() ||
Desc.getNumOperands() < 3 ||
203 !
MI.getOperand(2).isReg() ||
MI.getOperand(2).getReg() != Reg0)
206 ST.getInstrInfo()->commuteInstruction(
MI,
false, 1, 2);
207 Opc =
MI.getOpcode();
224 unsigned Opc =
MI.getOpcode();
226 bool IsNDLike = IsND || Opc == X86::MOVBE32rr || Opc == X86::MOVBE64rr;
227 bool IsRedundantNDD = IsNDLike ? IsRedundantNewDataDest(Opc) :
false;
229 auto GetCompressedOpc = [&](
unsigned Opc) ->
unsigned {
232 if (
I == Table.
end() ||
I->OldOpc != Opc)
242 unsigned NewOpc = IsRedundantNDD
244 : ((IsNDLike && ST.hasNF() &&
245 MI.registerDefIsDead(X86::EFLAGS,
nullptr))
247 : GetCompressedOpc(Opc));
252 const MCInstrDesc &NewDesc = ST.getInstrInfo()->get(NewOpc);
265 "Unknown EVEX2EVEX compression");
270 MI.setAsmPrinterFlag(AsmComment);
272 MI.tieOperands(0, 1);
280 static std::atomic<bool> TableChecked(
false);
281 if (!TableChecked.load(std::memory_order_relaxed)) {
283 "X86CompressEVEXTable is not sorted!");
284 TableChecked.store(
true, std::memory_order_relaxed);
288 if (!
ST.hasAVX512() && !
ST.hasEGPR() && !
ST.hasNDD())
291 bool Changed =
false;
305 return new CompressEVEXPass();
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool performCustomAdjustments(MachineInstr &MI, unsigned NewOpc)
static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST)
static bool usesExtendedRegister(const MachineInstr &MI)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
FunctionPass class - This class is used to implement most global optimizations.
Describe properties that are true of each instruction in the target description file.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ EVEX
EVEX - Specifies that this instruction use EVEX form which provides syntax support up to 32 512-bit r...
@ VEX
VEX - encoding using 0xC4/0xC5.
@ LEGACY
LEGACY - encoding using REX/REX2 or w/o opcode prefix.
bool isZMMReg(MCRegister Reg)
bool hasNewDataDest(uint64_t TSFlags)
bool isApxExtendedReg(MCRegister Reg)
int getFirstAddrOperandIdx(const MachineInstr &MI)
Return the index of the instruction's first address operand, if it has a memory reference,...
unsigned getNonNDVariant(unsigned Opc)
unsigned getNFVariant(unsigned Opc)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createX86CompressEVEXPass()
This pass compress instructions from EVEX space to legacy/VEX/EVEX space when possible in order to re...
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Description of the encoding of one expression Op.