Skip to content

Commit fb72a44

Browse files
committed
[X86] Emit NDD2NonNDD entris in the EVEX comprerssion table, NFCI
This patch is a straightfoward change based on the design in #77202. It does not have any effect since we haven't supported compressing ND to non-ND in X86CompressEVEX.cpp.
1 parent c8c5256 commit fb72a44

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

llvm/lib/Target/X86/X86CompressEVEX.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,27 @@ static bool performCustomAdjustments(MachineInstr &MI, unsigned NewOpc) {
221221
}
222222

223223
static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
224-
const MCInstrDesc &Desc = MI.getDesc();
224+
uint64_t TSFlags = MI.getDesc().TSFlags;
225225

226226
// Check for EVEX instructions only.
227-
if ((Desc.TSFlags & X86II::EncodingMask) != X86II::EVEX)
227+
if ((TSFlags & X86II::EncodingMask) != X86II::EVEX)
228228
return false;
229229

230-
// Check for EVEX instructions with mask or broadcast as in these cases
231-
// the EVEX prefix is needed in order to carry this information
232-
// thus preventing the transformation to VEX encoding.
233-
if (Desc.TSFlags & (X86II::EVEX_K | X86II::EVEX_B))
230+
// Instructions with mask or 512-bit vector can't be converted to VEX.
231+
if (TSFlags & (X86II::EVEX_K | X86II::EVEX_L2))
234232
return false;
235233

236-
// Check for EVEX instructions with L2 set. These instructions are 512-bits
237-
// and can't be converted to VEX.
238-
if (Desc.TSFlags & X86II::EVEX_L2)
234+
// EVEX_B has several meanings.
235+
// AVX512:
236+
// register form: rounding control or SAE
237+
// memory form: broadcast
238+
//
239+
// APX:
240+
// MAP4: NDD
241+
//
242+
// For AVX512 cases, EVEX prefix is needed in order to carry this information
243+
// thus preventing the transformation to VEX encoding.
244+
if (TSFlags & X86II::EVEX_B)
239245
return false;
240246

241247
ArrayRef<X86CompressEVEXTableEntry> Table = ArrayRef(X86CompressEVEXTable);
@@ -245,11 +251,8 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
245251
if (I == Table.end() || I->OldOpc != Opc)
246252
return false;
247253

248-
if (usesExtendedRegister(MI))
249-
return false;
250-
if (!checkVEXInstPredicate(Opc, ST))
251-
return false;
252-
if (!performCustomAdjustments(MI, I->NewOpc))
254+
if (usesExtendedRegister(MI) || !checkVEXInstPredicate(Opc, ST) ||
255+
!performCustomAdjustments(MI, I->NewOpc))
253256
return false;
254257

255258
const MCInstrDesc &NewDesc = ST.getInstrInfo()->get(I->NewOpc);
@@ -272,7 +275,7 @@ bool CompressEVEXPass::runOnMachineFunction(MachineFunction &MF) {
272275
}
273276
#endif
274277
const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
275-
if (!ST.hasAVX512() && !ST.hasEGPR())
278+
if (!ST.hasAVX512() && !ST.hasEGPR() && !ST.hasNDD())
276279
return false;
277280

278281
bool Changed = false;

llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ void X86CompressEVEXTablesEmitter::run(raw_ostream &OS) {
135135

136136
for (const CodeGenInstruction *Inst : NumberedInstructions) {
137137
const Record *Rec = Inst->TheDef;
138+
StringRef Name = Rec->getName();
138139
// _REV instruction should not appear before encoding optimization
139140
if (!Rec->isSubClassOf("X86Inst") ||
140-
Rec->getValueAsBit("isAsmParserOnly") ||
141-
Rec->getName().ends_with("_REV"))
141+
Rec->getValueAsBit("isAsmParserOnly") || Name.ends_with("_REV"))
142142
continue;
143143

144144
// Promoted legacy instruction is in EVEX space, and has REX2-encoding
@@ -149,18 +149,19 @@ void X86CompressEVEXTablesEmitter::run(raw_ostream &OS) {
149149
X86Local::ExplicitEVEX)
150150
continue;
151151

152-
if (NoCompressSet.find(Rec->getName()) != NoCompressSet.end())
152+
if (NoCompressSet.find(Name) != NoCompressSet.end())
153153
continue;
154154

155155
RecognizableInstrBase RI(*Inst);
156156

157+
bool IsND = RI.OpMap == X86Local::T_MAP4 && RI.HasEVEX_B && RI.HasVEX_4V;
157158
// Add VEX encoded instructions to one of CompressedInsts vectors according
158159
// to it's opcode.
159160
if (RI.Encoding == X86Local::VEX)
160161
CompressedInsts[RI.Opcode].push_back(Inst);
161162
// Add relevant EVEX encoded instructions to PreCompressionInsts
162-
else if (RI.Encoding == X86Local::EVEX && !RI.HasEVEX_K && !RI.HasEVEX_B &&
163-
!RI.HasEVEX_L2)
163+
else if (RI.Encoding == X86Local::EVEX && !RI.HasEVEX_K && !RI.HasEVEX_L2 &&
164+
(!RI.HasEVEX_B || IsND))
164165
PreCompressionInsts.push_back(Inst);
165166
}
166167

@@ -176,6 +177,12 @@ void X86CompressEVEXTablesEmitter::run(raw_ostream &OS) {
176177
} else if (Name.ends_with("_EVEX")) {
177178
if (auto *NewRec = Records.getDef(Name.drop_back(5)))
178179
NewInst = &Target.getInstruction(NewRec);
180+
} else if (Name.ends_with("_ND")) {
181+
if (auto *NewRec = Records.getDef(Name.drop_back(3))) {
182+
auto &TempInst = Target.getInstruction(NewRec);
183+
if (isRegisterOperand(TempInst.Operands[0].Rec))
184+
NewInst = &TempInst;
185+
}
179186
} else {
180187
// For each pre-compression instruction look for a match in the appropriate
181188
// vector (instructions with the same opcode) using function object

0 commit comments

Comments
 (0)