Skip to content

Commit 50447b0

Browse files
authored
Enable AVX2 optimistically with AVX on NAOT (#114575)
* enable AVX2 optimistically with AVX on NAOT * don't change getPreferredVectorByteLength * restrict Vector<T> size when AVX2 is not in the baseline supported ISAs
1 parent 8df4955 commit 50447b0

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

src/coreclr/jit/hwintrinsic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ NamedIntrinsic HWIntrinsicInfo::lookupId(Compiler* comp,
10911091
{
10921092
return NI_IsSupported_True;
10931093
}
1094-
else
1094+
else if (isSupportedProp)
10951095
{
10961096
assert(comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI));
10971097
return NI_IsSupported_Dynamic;

src/coreclr/tools/Common/InstructionSetHelpers.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,24 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
198198

199199
// If AVX was enabled, we can opportunistically enable instruction sets which use the VEX encodings
200200
Debug.Assert(InstructionSet.X64_AVX == InstructionSet.X86_AVX);
201+
Debug.Assert(InstructionSet.X64_AVX2 == InstructionSet.X86_AVX2);
201202
if (supportedInstructionSet.HasInstructionSet(InstructionSet.X64_AVX))
202203
{
203-
// TODO: Enable optimistic usage of AVX2 once we validate it doesn't break Vector<T> usage
204-
// optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("avx2");
205-
206-
if (supportedInstructionSet.HasInstructionSet(InstructionSet.X64_AVX2))
207-
{
208-
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("avxvnni");
209-
}
210-
204+
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("avx2");
211205
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("fma");
212206
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("bmi");
213207
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("bmi2");
208+
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("avxvnni");
214209
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("vpclmul");
215210
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("gfni_v256");
211+
212+
// If AVX2 is not in the supported set, we need to restrict the optimistic Vector<T> size, because
213+
// 256-bit Vector<T> cannot be fully accelerated based on AVX2 being in the optimistic set only.
214+
215+
if (!supportedInstructionSet.HasInstructionSet(InstructionSet.X64_AVX2))
216+
{
217+
maxVectorTBitWidth = 128;
218+
}
216219
}
217220

218221
Debug.Assert(InstructionSet.X64_AVX512F == InstructionSet.X86_AVX512F);

src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,39 @@ static int Main()
114114
bool? ExpectedSse42 = true;
115115
bool? ExpectedPopcnt = null;
116116
bool? ExpectedAvx = true;
117-
bool? ExpectedAvx2 = false; // TODO: Fix once opportunistic Avx2 is allowed
117+
bool? ExpectedAvx2 = null;
118118
bool? ExpectedFma = null;
119119
bool? ExpectedBmi1 = null;
120120
bool? ExpectedBmi2 = null;
121-
bool? ExpectedAvxVnni = false; // TODO: Fix once opportunistic Avx2 is allowed
121+
bool? ExpectedAvxVnni = null;
122+
bool? ExpectedAvx10v1 = false;
123+
bool? ExpectedAvx10v1V512 = false;
124+
bool? ExpectedAvx512F = false;
125+
bool? ExpectedAvx512BW = false;
126+
bool? ExpectedAvx512CD = false;
127+
bool? ExpectedAvx512DQ = false;
128+
bool? ExpectedAvx512Vbmi = false;
129+
bool? ExpectedX86Serialize = null;
130+
bool? ExpectedGfni = null;
131+
bool? ExpectedGfniV256 = null;
132+
bool? ExpectedGfniV512 = false;
133+
#elif AVX_INTRINSICS_NO_AVX2
134+
bool? ExpectedSse3 = true;
135+
bool? ExpectedSsse3 = true;
136+
bool? ExpectedAes = null;
137+
bool? ExpectedLzcnt = null;
138+
bool? ExpectedPclmulqdq = null;
139+
bool? ExpectedPclmulqdqV256 = null;
140+
bool? ExpectedPclmulqdqV512 = false;
141+
bool? ExpectedSse41 = true;
142+
bool? ExpectedSse42 = true;
143+
bool? ExpectedPopcnt = null;
144+
bool? ExpectedAvx = true;
145+
bool? ExpectedAvx2 = false;
146+
bool? ExpectedFma = null;
147+
bool? ExpectedBmi1 = null;
148+
bool? ExpectedBmi2 = null;
149+
bool? ExpectedAvxVnni = false;
122150
bool? ExpectedAvx10v1 = false;
123151
bool? ExpectedAvx10v1V512 = false;
124152
bool? ExpectedAvx512F = false;

src/tests/nativeaot/SmokeTests/HardwareIntrinsics/X64Avx_NoAvx2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- Test infra issue on apple devices: https://github.com/dotnet/runtime/issues/89917 -->
99
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
1010
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
11-
<DefineConstants>$(DefineConstants);AVX_INTRINSICS;VECTORT128_INTRINSICS</DefineConstants>
11+
<DefineConstants>$(DefineConstants);AVX_INTRINSICS_NO_AVX2;VECTORT128_INTRINSICS</DefineConstants>
1212
<RequiresProcessIsolation>true</RequiresProcessIsolation>
1313
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>
1414
</PropertyGroup>

0 commit comments

Comments
 (0)