Skip to content

Commit c5fae2e

Browse files
committed
Adds if-conversion lowering for Intel platform.
Major changes include: 1. Adding `ccmp` (and promoted cmp) logic into emitter backend. 2. Hooking `TryLowerAndOrToCCMP` from ARM pathway into Intel pathway. 3. Hooking `optimizeCompareChainCondBlock` from ARM pathway into Intel pathway.
1 parent 69c7a29 commit c5fae2e

21 files changed

+945
-128
lines changed

src/coreclr/jit/codegen.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ class CodeGen final : public CodeGenInterface
649649
#if defined(TARGET_AMD64)
650650
void genAmd64EmitterUnitTestsSse2();
651651
void genAmd64EmitterUnitTestsApx();
652+
void genAmd64EmitterUnitTestsCCMP();
652653
#endif
653654

654655
#endif // defined(DEBUG)
@@ -911,6 +912,9 @@ class CodeGen final : public CodeGenInterface
911912
#ifdef TARGET_ARM64
912913
void genCodeForCCMP(GenTreeCCMP* ccmp);
913914
#endif
915+
#ifdef TARGET_AMD64
916+
void genCodeForCCMP(GenTreeCCMP* ccmp);
917+
#endif // TARGET_AMD64
914918
void genCodeForSelect(GenTreeOp* select);
915919
void genIntrinsic(GenTreeIntrinsic* treeNode);
916920
void genPutArgStk(GenTreePutArgStk* treeNode);
@@ -1655,6 +1659,8 @@ class CodeGen final : public CodeGenInterface
16551659
static insOpts ShiftOpToInsOpts(genTreeOps op);
16561660
#elif defined(TARGET_XARCH)
16571661
static instruction JumpKindToCmov(emitJumpKind condition);
1662+
static instruction JumpKindToCcmp(emitJumpKind condition);
1663+
static insOpts OptsFromCFlags(insCflags flags);
16581664
#endif
16591665

16601666
#if !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64)

src/coreclr/jit/codegenlinear.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,10 @@ void CodeGen::genEmitterUnitTests()
27022702
{
27032703
genAmd64EmitterUnitTestsApx();
27042704
}
2705+
if (unitTestSectionAll || (strstr(unitTestSection, "ccmp") != nullptr))
2706+
{
2707+
genAmd64EmitterUnitTestsCCMP();
2708+
}
27052709

27062710
#elif defined(TARGET_ARM64)
27072711
if (unitTestSectionAll || (strstr(unitTestSection, "general") != nullptr))

src/coreclr/jit/codegenxarch.cpp

Lines changed: 209 additions & 26 deletions
Large diffs are not rendered by default.

src/coreclr/jit/compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ void Compiler::compSetProcessor()
22992299
if (canUseApxEncoding())
23002300
{
23012301
// TODO-Xarch-apx:
2302-
// At this stage, since no machine will pass the CPUID check for APX, we need a special stress mode that
2302+
// At this stage, since no machine will pass the CPUID check for APX, we need a special stress mode that
23032303
// enables REX2 on incompatible platform, `DoJitStressRex2Encoding` is expected to be removed eventually.
23042304
codeGen->GetEmitter()->SetUseRex2Encoding(true);
23052305
codeGen->GetEmitter()->SetUsePromotedEVEXEncoding(true);

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7091,6 +7091,8 @@ class Compiler
70917091
bool optSwitchConvert(BasicBlock* firstBlock, int testsCount, ssize_t* testValues, weight_t falseLikelihood, GenTree* nodeToTest);
70927092
bool optSwitchDetectAndConvert(BasicBlock* firstBlock);
70937093

7094+
bool optSwitchDetectLikely(BasicBlock* firstBlock);
7095+
70947096
PhaseStatus optInvertLoops(); // Invert loops so they're entered at top and tested at bottom.
70957097
PhaseStatus optOptimizeFlow(); // Simplify flow graph and do tail duplication
70967098
PhaseStatus optOptimizeLayout(); // Optimize the BasicBlock layout of the method

src/coreclr/jit/emit.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,12 @@ class emitter
797797
unsigned _idCustom5 : 1;
798798
unsigned _idCustom6 : 1;
799799

800-
#define _idEvexbContext (_idCustom6 << 1) | _idCustom5 /* Evex.b: embedded broadcast, embedded rounding, embedded SAE */
801-
#define _idEvexNdContext _idCustom5 /* bits used for the APX-EVEX.nd context for promoted legacy instructions */
802-
#define _idEvexNfContext _idCustom6 /* bits used for the APX-EVEX.nf context for promoted legacy/vex instructions */
800+
#define _idEvexbContext (_idCustom6 << 1) | _idCustom5 /* Evex.b: embedded broadcast, embedded rounding, embedded SAE \
801+
*/
802+
#define _idEvexNdContext _idCustom5 /* bits used for the APX-EVEX.nd context for promoted legacy instructions */
803+
#define _idEvexNfContext _idCustom6 /* bits used for the APX-EVEX.nf context for promoted legacy/vex instructions */
804+
#define _idEvexDFV (_idCustom4 << 3) | (_idCustom3 << 2) | (_idCustom2 << 1) | _idCustom1
805+
803806
#endif // TARGET_XARCH
804807

805808
#ifdef TARGET_ARM64
@@ -1015,6 +1018,7 @@ class emitter
10151018
regNumber _idReg3 : REGNUM_BITS;
10161019
regNumber _idReg4 : REGNUM_BITS;
10171020
};
1021+
10181022
#elif defined(TARGET_LOONGARCH64)
10191023
struct
10201024
{
@@ -1674,7 +1678,6 @@ class emitter
16741678

16751679
_idCustom5 = ((value >> 0) & 1);
16761680
_idCustom6 = ((value >> 1) & 1);
1677-
16781681
}
16791682

16801683
unsigned idGetEvexbContext() const
@@ -1736,6 +1739,21 @@ class emitter
17361739
assert(!idIsEvexNfContextSet());
17371740
_idEvexNfContext = 1;
17381741
}
1742+
1743+
unsigned idGetEvexDFV() const
1744+
{
1745+
return _idEvexDFV;
1746+
}
1747+
1748+
void idSetEvexDFV(insOpts instOptions)
1749+
{
1750+
unsigned value = static_cast<unsigned>((instOptions & INS_OPTS_EVEX_dfv_MASK) >> 8);
1751+
1752+
_idCustom1 = ((value >> 0) & 1);
1753+
_idCustom2 = ((value >> 1) & 1);
1754+
_idCustom3 = ((value >> 2) & 1);
1755+
_idCustom4 = ((value >> 3) & 1);
1756+
}
17391757
#endif
17401758

17411759
#ifdef TARGET_ARMARCH

src/coreclr/jit/emitjmps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#if defined(TARGET_XARCH)
1010

11+
// todo-anthony : should we define the cc for ccmp here?
12+
1113
// jump reverse instruction
1214
JMP_SMALL(jmp , jmp , jmp )
1315
JMP_SMALL(jo , jno , jo )

0 commit comments

Comments
 (0)