Skip to content

Commit 0607416

Browse files
Fix AltJit and VectorT ISA specification (#113901)
* Fix AltJit and VectorT ISA specification When running as an AltJit when the generated code will not be used (either because of a mismatched VM, or because RunAltJitCode=0), the JIT overwrites the passed in ISAs. When it does so, it zeros out the VectorT* ISA flags. Instead of this, carry over the existing ISA flags. This should work for same-architecture SPMI replays. I'm not sure if additional logic for specifically setting the VectorT* ISA is required for other scenarios, or if incorporating similar logic to `EEJitManager::SetCpuInfo()` into `Compiler::compCompile()` is required. Adds new JIT debugging helpers `dIsa()` and `dIsaFlags()` to dump out string representations of `CORINFO_InstructionSet` and `CORINFO_InstructionSetFlags`. Fixes #113869 * Only copy over VectorT ISAs for matching VM case That is, AltJit on same architecture (matching VM) with RunAltJitCode=0.
1 parent ed56fe6 commit 0607416

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/coreclr/jit/compiler.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -5995,6 +5995,7 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
59955995

59965996
if (enableAvailableIsas)
59975997
{
5998+
CORINFO_InstructionSetFlags currentInstructionSetFlags = compileFlags->GetInstructionSetFlags();
59985999
CORINFO_InstructionSetFlags instructionSetFlags;
59996000

60006001
// We need to assume, by default, that all flags coming from the VM are invalid.
@@ -6008,6 +6009,15 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
60086009
// needing to have the hardware in question.
60096010

60106011
#if defined(TARGET_ARM64)
6012+
if (info.compMatchedVM)
6013+
{
6014+
// Keep the existing VectorT* ISAs.
6015+
if (currentInstructionSetFlags.HasInstructionSet(InstructionSet_VectorT128))
6016+
{
6017+
instructionSetFlags.AddInstructionSet(InstructionSet_VectorT128);
6018+
}
6019+
}
6020+
60116021
if (JitConfig.EnableHWIntrinsic() != 0)
60126022
{
60136023
instructionSetFlags.AddInstructionSet(InstructionSet_ArmBase);
@@ -6063,6 +6073,23 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
60636073
instructionSetFlags.AddInstructionSet(InstructionSet_Sve);
60646074
}
60656075
#elif defined(TARGET_XARCH)
6076+
if (info.compMatchedVM)
6077+
{
6078+
// Keep the existing VectorT* ISAs.
6079+
if (currentInstructionSetFlags.HasInstructionSet(InstructionSet_VectorT128))
6080+
{
6081+
instructionSetFlags.AddInstructionSet(InstructionSet_VectorT128);
6082+
}
6083+
if (currentInstructionSetFlags.HasInstructionSet(InstructionSet_VectorT256))
6084+
{
6085+
instructionSetFlags.AddInstructionSet(InstructionSet_VectorT256);
6086+
}
6087+
if (currentInstructionSetFlags.HasInstructionSet(InstructionSet_VectorT512))
6088+
{
6089+
instructionSetFlags.AddInstructionSet(InstructionSet_VectorT512);
6090+
}
6091+
}
6092+
60666093
if (JitConfig.EnableHWIntrinsic() != 0)
60676094
{
60686095
instructionSetFlags.AddInstructionSet(InstructionSet_X86Base);
@@ -9352,6 +9379,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
93529379
* The following don't require a Compiler* to work:
93539380
* dRegMask : Display a regMaskTP (call dspRegMask(mask)).
93549381
* dBlockList : Display a BasicBlockList*.
9382+
* dIsa : Display a CORINFO_InstructionSet
9383+
* dIsaFlags : Display a CORINFO_InstructionSetFlags
93559384
*
93569385
* The following find an object in the IR and return it, as well as setting a global variable with the value that can
93579386
* be used in the debugger (e.g., in the watch window, or as a way to get an address for data breakpoints).
@@ -9435,6 +9464,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94359464
// Functions which don't require a Compiler*
94369465
#pragma comment(linker, "/include:dRegMask")
94379466
#pragma comment(linker, "/include:dBlockList")
9467+
#pragma comment(linker, "/include:dIsa")
9468+
#pragma comment(linker, "/include:dIsaFlags")
94389469

94399470
// Functions which search for objects in the IR
94409471
#pragma comment(linker, "/include:dFindTreeInTree")
@@ -10319,6 +10350,41 @@ JITDBGAPI void __cdecl dBlockList(BasicBlockList* list)
1031910350
printf("\n");
1032010351
}
1032110352

10353+
JITDBGAPI void __cdecl dIsa(const CORINFO_InstructionSet isa)
10354+
{
10355+
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
10356+
printf("===================================================================== dIsa %u\n", sequenceNumber++);
10357+
printf("%s\n", InstructionSetToString(isa));
10358+
}
10359+
10360+
JITDBGAPI void __cdecl dIsaFlags(const CORINFO_InstructionSetFlags& isaFlags)
10361+
{
10362+
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
10363+
printf("===================================================================== dIsaFlags %u\n", sequenceNumber++);
10364+
if (isaFlags.IsEmpty())
10365+
{
10366+
printf("<empty>\n");
10367+
}
10368+
else
10369+
{
10370+
bool first = true;
10371+
// The flags start at '1'. We don't know the last flag, so compute the maximum.
10372+
// It would be better if CORINFO_InstructionSet defined InstructionSet_FIRST and InstructionSet_LAST,
10373+
// or even better, if CORINFO_InstructionSetFlags defined an iterator over the instruction sets in the flags.
10374+
CORINFO_InstructionSet isaFirst = (CORINFO_InstructionSet)1;
10375+
CORINFO_InstructionSet isaLast = (CORINFO_InstructionSet)(sizeof(CORINFO_InstructionSetFlags) * 8 - 1);
10376+
for (CORINFO_InstructionSet isa = isaFirst; isa <= isaLast; isa = (CORINFO_InstructionSet)((int)isa + 1))
10377+
{
10378+
if (isaFlags.HasInstructionSet(isa))
10379+
{
10380+
printf("%s%s", first ? "" : " ", InstructionSetToString(isa));
10381+
first = false;
10382+
}
10383+
}
10384+
}
10385+
printf("\n");
10386+
}
10387+
1032210388
// Global variables available in debug mode. That are set by debug APIs for finding
1032310389
// Trees, Stmts, and/or Blocks using id or bbNum.
1032410390
// That can be used in watch window or as a way to get address of fields for data breakpoints.

0 commit comments

Comments
 (0)