Skip to content

Commit 123627b

Browse files
authored
[APX] fix a few emitter bugs. (#117791)
1 parent fe3f59b commit 123627b

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/coreclr/jit/emitxarch.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5195,7 +5195,11 @@ inline UNATIVE_OFFSET emitter::emitInsSizeSVCalcDisp(instrDesc* id, code_t code,
51955195
{
51965196
ssize_t compressedDsp;
51975197

5198-
if (TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte))
5198+
// Only the scaling factor of the original EVEX instructions can be changed by embedded broadcast.
5199+
// If the instruction does not have tuple type info, say extended EVEX from APX, the scaling factor is
5200+
// constantly 1, then this optimization cannot be performed, and whether disp8 or disp32 should be applied
5201+
// only depends dspInByte.
5202+
if (TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte) && hasTupleTypeInfo(ins))
51995203
{
52005204
SetEvexCompressedDisplacement(id);
52015205
}
@@ -5368,7 +5372,7 @@ UNATIVE_OFFSET emitter::emitInsSizeAM(instrDesc* id, code_t code)
53685372
{
53695373
ssize_t compressedDsp;
53705374

5371-
if (TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte))
5375+
if (TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte) && hasTupleTypeInfo(ins))
53725376
{
53735377
SetEvexCompressedDisplacement(id);
53745378
}
@@ -14672,13 +14676,16 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
1467214676
assert(isCompressed && dspInByte);
1467314677
dsp = compressedDsp;
1467414678
}
14675-
else if (TakesEvexPrefix(id) || TakesApxExtendedEvexPrefix(id))
14679+
else if (TakesEvexPrefix(id) && !IsBMIInstruction(ins))
1467614680
{
14677-
assert(!TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte));
14681+
assert(!(TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte) && hasTupleTypeInfo(ins)));
1467814682
dspInByte = false;
1467914683
}
1468014684
else
1468114685
{
14686+
// TODO-XArch-APX: for now, Extended Evex instruction will not have compressed displacement, or more
14687+
// accurately, extended evex may not have compressed displacement optimization as the scaling factor is
14688+
// constantly 1.
1468214689
dspInByte = ((signed char)dsp == (ssize_t)dsp);
1468314690
}
1468414691
dspIsZero = (dsp == 0);
@@ -15556,7 +15563,7 @@ BYTE* emitter::emitOutputSV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
1555615563
assert(isCompressed && dspInByte);
1555715564
dsp = (int)compressedDsp;
1555815565
}
15559-
else if (TakesEvexPrefix(id) || TakesApxExtendedEvexPrefix(id))
15566+
else if (TakesEvexPrefix(id) && !IsBMIInstruction(ins))
1556015567
{
1556115568
#if FEATURE_FIXED_OUT_ARGS
1556215569
// TODO-AMD64-CQ: We should be able to accurately predict this when FEATURE_FIXED_OUT_ARGS
@@ -17904,6 +17911,7 @@ BYTE* emitter::emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i)
1790417911
idAmd->idCodeSize(sz);
1790517912

1790617913
code = insCodeRM(ins);
17914+
code = AddX86PrefixIfNeeded(id, code, id->idOpSize());
1790717915
code |= (insEncodeReg345(id, id->idReg1(), EA_PTRSIZE, &code) << 8);
1790817916

1790917917
dst = emitOutputAM(dst, idAmd, code, nullptr);

src/coreclr/jit/instr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ void CodeGen::inst_SET(emitJumpKind condition, regNumber reg, insOpts instOption
692692
assert(INS_setge == (INS_setge_apx + offset));
693693
assert(INS_setle == (INS_setle_apx + offset));
694694
assert(INS_setg == (INS_setg_apx + offset));
695-
ins = (instruction)(ins + offset);
695+
ins = (instruction)(ins - offset);
696696
}
697697
#endif
698698

src/coreclr/jit/lsraxarch.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,12 @@ int LinearScan::BuildShiftRotate(GenTree* tree)
11571157
#endif
11581158
if (!source->isContained())
11591159
{
1160-
tgtPrefUse = BuildUse(source, srcCandidates);
1160+
tgtPrefUse = BuildUse(source, ForceLowGprForApxIfNeeded(source, srcCandidates, getEvexIsSupported()));
11611161
srcCount++;
11621162
}
11631163
else
11641164
{
1165-
srcCount += BuildOperandUses(source, srcCandidates);
1165+
srcCount += BuildOperandUses(source, ForceLowGprForApxIfNeeded(source, srcCandidates, getEvexIsSupported()));
11661166
}
11671167

11681168
if (!tree->isContained())
@@ -1172,6 +1172,9 @@ int LinearScan::BuildShiftRotate(GenTree* tree)
11721172
srcCount += BuildDelayFreeUses(shiftBy, source, SRBM_RCX);
11731173
buildKillPositionsForNode(tree, currentLoc + 1, SRBM_RCX);
11741174
}
1175+
dstCandidates = (tree->GetRegNum() == REG_NA)
1176+
? ForceLowGprForApxIfNeeded(tree, dstCandidates, getEvexIsSupported())
1177+
: dstCandidates;
11751178
BuildDef(tree, dstCandidates);
11761179
}
11771180
else
@@ -3280,8 +3283,8 @@ int LinearScan::BuildMul(GenTree* tree)
32803283
srcCandidates1 = SRBM_RDX;
32813284
}
32823285

3283-
srcCount = BuildOperandUses(op1, srcCandidates1);
3284-
srcCount += BuildOperandUses(op2, srcCandidates2);
3286+
srcCount = BuildOperandUses(op1, ForceLowGprForApxIfNeeded(op1, srcCandidates1, getEvexIsSupported()));
3287+
srcCount += BuildOperandUses(op2, ForceLowGprForApxIfNeeded(op2, srcCandidates2, getEvexIsSupported()));
32853288

32863289
#if defined(TARGET_X86)
32873290
if (tree->OperIs(GT_MUL_LONG))

0 commit comments

Comments
 (0)