Skip to content

Commit 0dff5b5

Browse files
authored
[X86][APX] Compress setzucc with memory operand to setcc (#170842)
setzucc with memory operand is same as setcc but the later is shorter.
1 parent 315c904 commit 0dff5b5

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

llvm/lib/Target/X86/X86CompressEVEX.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// c. NDD (EVEX) -> non-NDD (legacy)
1616
// d. NF_ND (EVEX) -> NF (EVEX)
1717
// e. NonNF (EVEX) -> NF (EVEX)
18+
// f. SETZUCCm (EVEX) -> SETCCm (legacy)
1819
//
1920
// Compression a, b and c can always reduce code size, with some exceptions
2021
// such as promoted 16-bit CRC32 which is as long as the legacy version.
@@ -216,14 +217,15 @@ static bool CompressEVEXImpl(MachineInstr &MI, MachineBasicBlock &MBB,
216217
// memory form: broadcast
217218
//
218219
// APX:
219-
// MAP4: NDD
220+
// MAP4: NDD, ZU
220221
//
221222
// For AVX512 cases, EVEX prefix is needed in order to carry this information
222223
// thus preventing the transformation to VEX encoding.
223224
bool IsND = X86II::hasNewDataDest(TSFlags);
224-
if (TSFlags & X86II::EVEX_B && !IsND)
225-
return false;
226225
unsigned Opc = MI.getOpcode();
226+
bool IsSetZUCCm = Opc == X86::SETZUCCm;
227+
if (TSFlags & X86II::EVEX_B && !IsND && !IsSetZUCCm)
228+
return false;
227229
// MOVBE*rr is special because it has semantic of NDD but not set EVEX_B.
228230
bool IsNDLike = IsND || Opc == X86::MOVBE32rr || Opc == X86::MOVBE64rr;
229231
bool IsRedundantNDD = IsNDLike ? IsRedundantNewDataDest(Opc) : false;
@@ -339,7 +341,7 @@ bool CompressEVEXPass::runOnMachineFunction(MachineFunction &MF) {
339341
}
340342
#endif
341343
const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
342-
if (!ST.hasAVX512() && !ST.hasEGPR() && !ST.hasNDD())
344+
if (!ST.hasAVX512() && !ST.hasEGPR() && !ST.hasNDD() && !ST.hasZU())
343345
return false;
344346

345347
bool Changed = false;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,11 @@ body: |
139139
$ax = XOR16rr_ND $ax, killed $di, implicit-def dead $eflags
140140
RET64 $rax
141141
...
142+
---
143+
name: setzuccm_2_setccm
144+
body: |
145+
bb.0.entry:
146+
liveins: $eflags
147+
; CHECK: sete 7(%rsp) # EVEX TO LEGACY Compression encoding: [0x0f,0x94,0x44,0x24,0x07]
148+
SETZUCCm $rsp, 1, $noreg, 7, $noreg, 4, implicit killed $eflags
149+
...

llvm/test/TableGen/x86-instr-mapping.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static const X86TableEntry X86CompressEVEXTable[] = {
158158
{ X86::SARX32rr_EVEX, X86::SARX32rr },
159159
{ X86::SARX64rm_EVEX, X86::SARX64rm },
160160
{ X86::SARX64rr_EVEX, X86::SARX64rr },
161+
{ X86::SETZUCCm, X86::SETCCm },
161162
{ X86::SHLX32rm_EVEX, X86::SHLX32rm },
162163
{ X86::SHLX32rr_EVEX, X86::SHLX32rr },
163164
{ X86::SHLX64rm_EVEX, X86::SHLX64rm },

llvm/utils/TableGen/X86InstrMappingEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,14 @@ void X86InstrMappingEmitter::emitCompressEVEXTable(
189189
RecognizableInstrBase RI(*Inst);
190190

191191
bool IsND = RI.OpMap == X86Local::T_MAP4 && RI.HasEVEX_B && RI.HasVEX_4V;
192+
bool IsSETZUCCm = Name == "SETZUCCm";
192193
// Add VEX encoded instructions to one of CompressedInsts vectors according
193194
// to it's opcode.
194195
if (RI.Encoding == X86Local::VEX)
195196
CompressedInsts[RI.Opcode].push_back(Inst);
196197
// Add relevant EVEX encoded instructions to PreCompressionInsts
197198
else if (RI.Encoding == X86Local::EVEX && !RI.HasEVEX_K && !RI.HasEVEX_L2 &&
198-
(!RI.HasEVEX_B || IsND))
199+
(!RI.HasEVEX_B || IsND || IsSETZUCCm))
199200
PreCompressionInsts.push_back(Inst);
200201
}
201202

llvm/utils/TableGen/X86ManualInstrMapping.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ ENTRY(VBROADCASTSDZ256rm, VBROADCASTSDYrm)
333333
ENTRY(VBROADCASTSDZ256rr, VBROADCASTSDYrr)
334334
ENTRY(VPBROADCASTQZ256rm, VPBROADCASTQYrm)
335335
ENTRY(VPBROADCASTQZ256rr, VPBROADCASTQYrr)
336+
ENTRY(SETZUCCm, SETCCm)
336337
#undef ENTRY
337338

338339
#ifndef NOCOMP_ND

0 commit comments

Comments
 (0)