Skip to content

Commit 39ecf52

Browse files
authored
JIT: Allow baseline intrinsics in JIT code unconditionally (#116196)
* allow any baseline intrinsics in JIT * formatting * remove IsBaselineSimdIsaSupported * update comments
1 parent 5f3e1ff commit 39ecf52

17 files changed

+136
-420
lines changed

src/coreclr/jit/codegenarm64.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,7 +3613,7 @@ void CodeGen::genCodeForCpObj(GenTreeBlk* cpObjNode)
36133613
// On ARM64, SIMD loads/stores provide 8-byte atomicity guarantees when aligned to 8 bytes.
36143614
regNumber tmpSimdReg1 = REG_NA;
36153615
regNumber tmpSimdReg2 = REG_NA;
3616-
if ((slots >= 4) && compiler->IsBaselineSimdIsaSupported())
3616+
if (slots >= 4)
36173617
{
36183618
tmpSimdReg1 = internalRegisters.Extract(cpObjNode, RBM_ALLFLOAT);
36193619
tmpSimdReg2 = internalRegisters.Extract(cpObjNode, RBM_ALLFLOAT);
@@ -3644,8 +3644,8 @@ void CodeGen::genCodeForCpObj(GenTreeBlk* cpObjNode)
36443644
// Copy at least two slots at a time
36453645
if (nonGcSlots >= 2)
36463646
{
3647-
// Do 4 slots at a time if SIMD is supported
3648-
if ((nonGcSlots >= 4) && compiler->IsBaselineSimdIsaSupported())
3647+
// Do 4 slots at a time with SIMD instructions
3648+
if (nonGcSlots >= 4)
36493649
{
36503650
// We need SIMD temp regs now
36513651
tmp1 = tmpSimdReg1;

src/coreclr/jit/codegenxarch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3302,7 +3302,7 @@ void CodeGen::genCodeForInitBlkUnroll(GenTreeBlk* node)
33023302
// INITBLK zeroes a struct that contains GC pointers and can be observed by
33033303
// other threads (i.e. when dstAddr is not an address of a local).
33043304
// For example, this can happen when initializing a struct field of an object.
3305-
const bool canUse16BytesSimdMov = !node->IsOnHeapAndContainsReferences() && compiler->IsBaselineSimdIsaSupported();
3305+
const bool canUse16BytesSimdMov = !node->IsOnHeapAndContainsReferences();
33063306
const bool willUseSimdMov = canUse16BytesSimdMov && (size >= XMM_REGSIZE_BYTES);
33073307

33083308
if (!src->isContained())

src/coreclr/jit/compiler.cpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,11 +1920,15 @@ void Compiler::compSetProcessor()
19201920
opts.compSupportsISAReported.Reset();
19211921
opts.compSupportsISAExactly.Reset();
19221922

1923-
// The VM will set the ISA flags depending on actual hardware support
1924-
// and any specified config switches specified by the user. The exception
1925-
// here is for certain "artificial ISAs" such as Vector64/128/256 where they
1926-
// don't actually exist. The JIT is in charge of adding those and ensuring
1927-
// the total sum of flags is still valid.
1923+
// The VM will set the ISA flags depending on actual hardware support and any
1924+
// config values specified by the user. Config may cause the VM to omit baseline
1925+
// ISAs from the supported set. We force their inclusion here so that JIT code
1926+
// can use them unconditionally, but we will honor the config when resolving
1927+
// managed HWIntrinsic methods.
1928+
//
1929+
// We also take care of adding the virtual vector ISAs (i.e. Vector64/128/256/512)
1930+
// here, based on the combination of hardware ISA support and config values.
1931+
19281932
#if defined(TARGET_XARCH)
19291933
// If the VM passed in a virtual vector ISA, it was done to communicate PreferredVectorBitWidth.
19301934
// No check is done for the validity of the value, since it will be clamped to max supported by
@@ -1955,10 +1959,14 @@ void Compiler::compSetProcessor()
19551959
!instructionSetFlags.HasInstructionSet(InstructionSet_Vector256) &&
19561960
!instructionSetFlags.HasInstructionSet(InstructionSet_Vector512));
19571961

1958-
if (instructionSetFlags.HasInstructionSet(InstructionSet_X86Base))
1959-
{
1960-
instructionSetFlags.AddInstructionSet(InstructionSet_Vector128);
1961-
}
1962+
// Ensure required baseline ISAs are supported in JIT code, even if not passed in by the VM.
1963+
instructionSetFlags.AddInstructionSet(InstructionSet_X86Base);
1964+
#ifdef TARGET_AMD64
1965+
instructionSetFlags.AddInstructionSet(InstructionSet_X86Base_X64);
1966+
#endif // TARGET_AMD64
1967+
1968+
// We can now add the virtual vector ISAs as appropriate. Vector128 is part of the required baseline.
1969+
instructionSetFlags.AddInstructionSet(InstructionSet_Vector128);
19621970

19631971
if (instructionSetFlags.HasInstructionSet(InstructionSet_AVX))
19641972
{
@@ -1970,11 +1978,15 @@ void Compiler::compSetProcessor()
19701978
instructionSetFlags.AddInstructionSet(InstructionSet_Vector512);
19711979
}
19721980
#elif defined(TARGET_ARM64)
1973-
if (instructionSetFlags.HasInstructionSet(InstructionSet_AdvSimd))
1974-
{
1975-
instructionSetFlags.AddInstructionSet(InstructionSet_Vector64);
1976-
instructionSetFlags.AddInstructionSet(InstructionSet_Vector128);
1977-
}
1981+
// Ensure required baseline ISAs are supported in JIT code, even if not passed in by the VM.
1982+
instructionSetFlags.AddInstructionSet(InstructionSet_ArmBase);
1983+
instructionSetFlags.AddInstructionSet(InstructionSet_ArmBase_Arm64);
1984+
instructionSetFlags.AddInstructionSet(InstructionSet_AdvSimd);
1985+
instructionSetFlags.AddInstructionSet(InstructionSet_AdvSimd_Arm64);
1986+
1987+
// Add virtual vector ISAs. These are both supported as part of the required baseline.
1988+
instructionSetFlags.AddInstructionSet(InstructionSet_Vector64);
1989+
instructionSetFlags.AddInstructionSet(InstructionSet_Vector128);
19781990
#endif // TARGET_ARM64
19791991

19801992
assert(instructionSetFlags.Equals(EnsureInstructionSetFlagsAreValid(instructionSetFlags)));
@@ -5956,11 +5968,8 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
59565968
}
59575969
}
59585970

5959-
if (JitConfig.EnableHWIntrinsic() != 0)
5960-
{
5961-
instructionSetFlags.AddInstructionSet(InstructionSet_ArmBase);
5962-
instructionSetFlags.AddInstructionSet(InstructionSet_AdvSimd);
5963-
}
5971+
instructionSetFlags.AddInstructionSet(InstructionSet_ArmBase);
5972+
instructionSetFlags.AddInstructionSet(InstructionSet_AdvSimd);
59645973

59655974
if (JitConfig.EnableArm64Aes() != 0)
59665975
{
@@ -6029,10 +6038,7 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
60296038
}
60306039
}
60316040

6032-
if (JitConfig.EnableHWIntrinsic() != 0)
6033-
{
6034-
instructionSetFlags.AddInstructionSet(InstructionSet_X86Base);
6035-
}
6041+
instructionSetFlags.AddInstructionSet(InstructionSet_X86Base);
60366042

60376043
if (JitConfig.EnableSSE3() != 0)
60386044
{
@@ -6142,10 +6148,7 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
61426148
instructionSetFlags.AddInstructionSet(InstructionSet_APX);
61436149
}
61446150
#elif defined(TARGET_RISCV64)
6145-
if (JitConfig.EnableHWIntrinsic() != 0)
6146-
{
6147-
instructionSetFlags.AddInstructionSet(InstructionSet_RiscV64Base);
6148-
}
6151+
instructionSetFlags.AddInstructionSet(InstructionSet_RiscV64Base);
61496152

61506153
if (JitConfig.EnableRiscV64Zba() != 0)
61516154
{

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8928,46 +8928,6 @@ class Compiler
89288928
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
89298929
*/
89308930

8931-
bool IsBaselineSimdIsaSupported()
8932-
{
8933-
#ifdef FEATURE_SIMD
8934-
#if defined(TARGET_XARCH)
8935-
CORINFO_InstructionSet minimumIsa = InstructionSet_X86Base;
8936-
#elif defined(TARGET_ARM64)
8937-
CORINFO_InstructionSet minimumIsa = InstructionSet_AdvSimd;
8938-
#elif defined(TARGET_LOONGARCH64)
8939-
// TODO: supporting SIMD feature for LoongArch64.
8940-
assert(!"unimplemented yet on LA");
8941-
CORINFO_InstructionSet minimumIsa = 0;
8942-
#else
8943-
#error Unsupported platform
8944-
#endif // !TARGET_XARCH && !TARGET_ARM64 && !TARGET_LOONGARCH64
8945-
8946-
return compOpportunisticallyDependsOn(minimumIsa);
8947-
#else
8948-
return false;
8949-
#endif
8950-
}
8951-
8952-
#if defined(DEBUG)
8953-
bool IsBaselineSimdIsaSupportedDebugOnly()
8954-
{
8955-
#ifdef FEATURE_SIMD
8956-
#if defined(TARGET_XARCH)
8957-
CORINFO_InstructionSet minimumIsa = InstructionSet_X86Base;
8958-
#elif defined(TARGET_ARM64)
8959-
CORINFO_InstructionSet minimumIsa = InstructionSet_AdvSimd;
8960-
#else
8961-
#error Unsupported platform
8962-
#endif // !TARGET_XARCH && !TARGET_ARM64
8963-
8964-
return compIsaSupportedDebugOnly(minimumIsa);
8965-
#else
8966-
return false;
8967-
#endif // FEATURE_SIMD
8968-
}
8969-
#endif // DEBUG
8970-
89718931
bool isIntrinsicType(CORINFO_CLASS_HANDLE clsHnd)
89728932
{
89738933
return info.compCompHnd->isIntrinsicType(clsHnd);
@@ -9248,29 +9208,12 @@ class Compiler
92489208
{
92499209
return YMM_REGSIZE_BYTES;
92509210
}
9251-
else if (compOpportunisticallyDependsOn(InstructionSet_X86Base))
9252-
{
9253-
return XMM_REGSIZE_BYTES;
9254-
}
92559211
else
92569212
{
9257-
// TODO: We should be returning 0 here, but there are a number of
9258-
// places that don't quite get handled correctly in that scenario
9259-
92609213
return XMM_REGSIZE_BYTES;
92619214
}
92629215
#elif defined(TARGET_ARM64)
9263-
if (compOpportunisticallyDependsOn(InstructionSet_AdvSimd))
9264-
{
9265-
return FP_REGSIZE_BYTES;
9266-
}
9267-
else
9268-
{
9269-
// TODO: We should be returning 0 here, but there are a number of
9270-
// places that don't quite get handled correctly in that scenario
9271-
9272-
return FP_REGSIZE_BYTES;
9273-
}
9216+
return FP_REGSIZE_BYTES;
92749217
#else
92759218
assert(!"getMaxVectorByteLength() unimplemented on target arch");
92769219
unreached();
@@ -9470,7 +9413,7 @@ class Compiler
94709413
assert(size > 0);
94719414
var_types result = TYP_UNDEF;
94729415
#ifdef FEATURE_SIMD
9473-
if (IsBaselineSimdIsaSupported() && (roundDownSIMDSize(size) > 0))
9416+
if (roundDownSIMDSize(size) > 0)
94749417
{
94759418
return getSIMDTypeForSize(roundDownSIMDSize(size));
94769419
}

src/coreclr/jit/decomposelongs.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,8 +1970,6 @@ GenTree* DecomposeLongs::DecomposeHWIntrinsicToScalar(LIR::Use& use, GenTreeHWIn
19701970
}
19711971
else
19721972
{
1973-
assert(m_compiler->compIsaSupportedDebugOnly(InstructionSet_X86Base));
1974-
19751973
GenTree* thirtyTwo = m_compiler->gtNewIconNode(32);
19761974
GenTree* shift = m_compiler->gtNewSimdBinOpNode(GT_RSZ, op1->TypeGet(), simdTmpVar, thirtyTwo,
19771975
node->GetSimdBaseJitType(), simdSize);

0 commit comments

Comments
 (0)