14
14
// b. Promoted instruction (EVEX) -> pre-promotion instruction (legacy/VEX)
15
15
// c. NDD (EVEX) -> non-NDD (legacy)
16
16
// d. NF_ND (EVEX) -> NF (EVEX)
17
+ // e. NonNF (EVEX) -> NF (EVEX)
17
18
//
18
19
// Compression a, b and c can always reduce code size, with some exceptions
19
20
// such as promoted 16-bit CRC32 which is as long as the legacy version.
30
31
//
31
32
// Compression d can help hardware decode (HW may skip reading the NDD
32
33
// register) although the instruction length remains unchanged.
34
+ //
35
+ // Compression e can help hardware skip updating EFLAGS although the instruction
36
+ // length remains unchanged.
33
37
// ===----------------------------------------------------------------------===//
34
38
35
39
#include " MCTargetDesc/X86BaseInfo.h"
@@ -219,25 +223,36 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
219
223
return false ;
220
224
// MOVBE*rr is special because it has semantic of NDD but not set EVEX_B.
221
225
bool IsNDLike = IsND || Opc == X86::MOVBE32rr || Opc == X86::MOVBE64rr;
222
- if (IsNDLike && !isRedundantNewDataDest (MI, ST))
226
+ bool IsRedundantNDD = IsNDLike ? isRedundantNewDataDest (MI, ST) : false ;
227
+ // NonNF -> NF only if it's not a compressible NDD instruction and eflags is
228
+ // dead.
229
+ unsigned NFOpc = (ST.hasNF () && !IsRedundantNDD &&
230
+ MI.registerDefIsDead (X86::EFLAGS, /* TRI=*/ nullptr ))
231
+ ? X86::getNFVariant (Opc)
232
+ : 0U ;
233
+ if (IsNDLike && !IsRedundantNDD && !NFOpc)
223
234
return false ;
224
235
225
- ArrayRef<X86TableEntry> Table = ArrayRef (X86CompressEVEXTable);
226
-
227
- Opc = MI.getOpcode ();
228
- const auto *I = llvm::lower_bound (Table, Opc);
229
- if (I == Table.end () || I->OldOpc != Opc) {
230
- assert (!IsNDLike && " Missing entry for ND-like instruction" );
231
- return false ;
232
- }
236
+ unsigned NewOpc = NFOpc;
237
+ if (!NewOpc) {
238
+ ArrayRef<X86TableEntry> Table = ArrayRef (X86CompressEVEXTable);
233
239
234
- if (!IsNDLike) {
235
- if (usesExtendedRegister (MI) || !checkPredicate (I->NewOpc , &ST) ||
236
- !performCustomAdjustments (MI, I->NewOpc ))
240
+ Opc = MI.getOpcode ();
241
+ const auto I = llvm::lower_bound (Table, Opc);
242
+ if (I == Table.end () || I->OldOpc != Opc) {
243
+ assert (!IsNDLike && " Missing entry for ND-like instruction" );
237
244
return false ;
245
+ }
246
+
247
+ if (!IsNDLike) {
248
+ if (usesExtendedRegister (MI) || !checkPredicate (I->NewOpc , &ST) ||
249
+ !performCustomAdjustments (MI, I->NewOpc ))
250
+ return false ;
251
+ }
252
+ NewOpc = I->NewOpc ;
238
253
}
239
254
240
- const MCInstrDesc &NewDesc = ST.getInstrInfo ()->get (I-> NewOpc );
255
+ const MCInstrDesc &NewDesc = ST.getInstrInfo ()->get (NewOpc);
241
256
MI.setDesc (NewDesc);
242
257
unsigned AsmComment;
243
258
switch (NewDesc.TSFlags & X86II::EncodingMask) {
@@ -256,7 +271,7 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
256
271
llvm_unreachable (" Unknown EVEX compression" );
257
272
}
258
273
MI.setAsmPrinterFlag (AsmComment);
259
- if (IsNDLike )
274
+ if (IsRedundantNDD )
260
275
MI.tieOperands (0 , 1 );
261
276
262
277
return true ;
0 commit comments