Skip to content

Commit 83bf4b6

Browse files
Ensure that the CpuId tests set preferredVectorByteLength to a non-zero value (#88623)
* Ensure that the CpuId tests set preferredVectorByteLength to a non-zero value * Ensure getPreferredVectorByteLength takes NAOT into account * Don't condition the preferred vector byte length based on stress mode
1 parent f44e2e6 commit 83bf4b6

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

src/coreclr/jit/compiler.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -2306,13 +2306,10 @@ void Compiler::compSetProcessor()
23062306
// users can override this with `DOTNET_PreferredVectorBitWidth=512` to
23072307
// allow using such instructions where hardware support is available.
23082308
//
2309-
// Under stress, sometimes leave the preferred vector width at 512, even if that means
2310-
// throttling. This helps with test coverage on test machines that might be older.
2309+
// Do not condition this based on stress mode as it makes the support
2310+
// reported inconsistent across methods and breaks expectations/functionality
23112311

2312-
if (!compStressCompile(STRESS_GENERIC_VARN, 20))
2313-
{
2314-
preferredVectorByteLength = 256 / 8;
2315-
}
2312+
preferredVectorByteLength = 256 / 8;
23162313
}
23172314
}
23182315

src/coreclr/jit/hwintrinsic.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,9 @@ NamedIntrinsic HWIntrinsicInfo::lookupId(Compiler* comp,
495495
return NI_Illegal;
496496
}
497497

498-
bool isIsaSupported = comp->compSupportsHWIntrinsic(isa);
499-
bool isHardwareAcceleratedProp = (strcmp(methodName, "get_IsHardwareAccelerated") == 0);
498+
bool isIsaSupported = comp->compSupportsHWIntrinsic(isa);
499+
bool isHardwareAcceleratedProp = (strcmp(methodName, "get_IsHardwareAccelerated") == 0);
500+
uint32_t vectorByteLength = 0;
500501

501502
#ifdef TARGET_XARCH
502503
if (isHardwareAcceleratedProp)
@@ -505,25 +506,21 @@ NamedIntrinsic HWIntrinsicInfo::lookupId(Compiler* comp,
505506
// but we want IsHardwareAccelerated to return true only when all of them are (there are
506507
// still can be cases where e.g. Sse41 might give an additional boost for Vector128, but it's
507508
// not important enough to bump the minimal Sse version here)
509+
508510
if (strcmp(className, "Vector128") == 0)
509511
{
510-
isa = InstructionSet_SSE2;
512+
isa = InstructionSet_SSE2;
513+
vectorByteLength = 16;
511514
}
512515
else if (strcmp(className, "Vector256") == 0)
513516
{
514-
if (comp->getPreferredVectorByteLength() < 32)
515-
{
516-
return NI_IsSupported_False;
517-
}
518-
isa = InstructionSet_AVX2;
517+
isa = InstructionSet_AVX2;
518+
vectorByteLength = 32;
519519
}
520520
else if (strcmp(className, "Vector512") == 0)
521521
{
522-
if (comp->getPreferredVectorByteLength() < 64)
523-
{
524-
return NI_IsSupported_False;
525-
}
526-
isa = InstructionSet_AVX512F;
522+
isa = InstructionSet_AVX512F;
523+
vectorByteLength = 64;
527524
}
528525
}
529526
#endif
@@ -556,7 +553,8 @@ NamedIntrinsic HWIntrinsicInfo::lookupId(Compiler* comp,
556553
// When the compiler doesn't support ISA or when it does but the target hardware does
557554
// not and we aren't in a scenario with support for a dynamic check, we want to return false.
558555

559-
if (isIsaSupported && comp->compSupportsHWIntrinsic(isa))
556+
if (isIsaSupported && comp->compSupportsHWIntrinsic(isa) &&
557+
(vectorByteLength <= comp->getPreferredVectorByteLength()))
560558
{
561559
if (!comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) || comp->compExactlyDependsOn(isa))
562560
{

src/tests/JIT/HardwareIntrinsics/X86/X86Base/CpuId.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,14 @@ public unsafe static void CpuId()
256256
}
257257
}
258258

259-
if (isVector512Throttling)
259+
if (isAvx512HierarchyDisabled || isVector512Throttling)
260260
{
261261
preferredVectorByteLength = 256 / 8;
262262
}
263+
else
264+
{
265+
preferredVectorByteLength = 512 / 8;
266+
}
263267
}
264268

265269
if (IsBitIncorrect(ecx, 1, typeof(Avx512Vbmi), Avx512Vbmi.IsSupported, "AVX512VBMI", ref isHierarchyDisabled))

src/tests/readytorun/HardwareIntrinsics/X86/CpuId.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,14 @@ public unsafe static int Main()
251251
}
252252
}
253253

254-
if (isVector512Throttling)
254+
if (isAvx512HierarchyDisabled || isVector512Throttling)
255255
{
256256
preferredVectorByteLength = 256 / 8;
257257
}
258+
else
259+
{
260+
preferredVectorByteLength = 512 / 8;
261+
}
258262
}
259263

260264
if (IsBitIncorrect(ecx, 1, typeof(Avx512Vbmi), Avx512Vbmi.IsSupported, "AVX512VBMI", ref isHierarchyDisabled))

0 commit comments

Comments
 (0)