Skip to content

Commit dc01e99

Browse files
Fix JitOptRepeat (#94250)
1. Remove an assertion checking assert that can be invalid under JitOptRepeat, where we might lose information that a constant was ever a handle. 2. Disable JIT/Directed/debugging/debuginfo/tester.csproj under OptRepeat: optimizations mess with its debug info expectations. 3. Enable JitOptRepeat under stress
1 parent a027afb commit dc01e99

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/coreclr/jit/assertionprop.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,13 @@ void Compiler::optPrintAssertion(AssertionDsc* curAssertion, AssertionIndex asse
866866
printf("Exact Type MT(0x%p %s)", dspPtr(iconVal),
867867
eeGetClassName((CORINFO_CLASS_HANDLE)iconVal));
868868
}
869+
870+
// We might want to assert:
871+
// assert(curAssertion->op2.HasIconFlag());
872+
// However, if we run CSE with shared constant mode, we may end up with an expression instead
873+
// of the original handle value. If we then use JitOptRepeat to re-build value numbers, we lose
874+
// knowledge that the constant was ever a handle, as the expression creating the original value
875+
// was not (and can't be) assigned a handle flag.
869876
}
870877
else if (curAssertion->op1.kind == O1K_SUBTYPE)
871878
{
@@ -1876,7 +1883,6 @@ void Compiler::optDebugCheckAssertion(AssertionDsc* assertion)
18761883
{
18771884
case O1K_EXACT_TYPE:
18781885
case O1K_SUBTYPE:
1879-
assert(assertion->op2.HasIconFlag());
18801886
break;
18811887
case O1K_LCLVAR:
18821888
assert((lvaGetDesc(assertion->op1.lcl.lclNum)->lvType != TYP_REF) ||
@@ -5428,6 +5434,25 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, Stat
54285434
if (parent != nullptr)
54295435
{
54305436
parent->ReplaceOperand(useEdge, newTree);
5437+
5438+
// If the parent is a GT_IND and we replaced the child with a handle constant, we might need
5439+
// to mark the GT_IND as invariant. This is the same as what gtNewIndOfIconHandleNode() does.
5440+
// Review: should some kind of more general morphing take care of this?
5441+
// Should this share code with gtNewIndOfIconHandleNode()?
5442+
5443+
if (parent->OperIs(GT_IND) && newTree->IsIconHandle())
5444+
{
5445+
GenTreeFlags iconFlags = newTree->GetIconHandleFlag();
5446+
if (GenTree::HandleKindDataIsInvariant(iconFlags))
5447+
{
5448+
parent->gtFlags |= GTF_IND_INVARIANT;
5449+
if (iconFlags == GTF_ICON_STR_HDL)
5450+
{
5451+
// String literals are never null
5452+
parent->gtFlags |= GTF_IND_NONNULL;
5453+
}
5454+
}
5455+
}
54315456
}
54325457
else
54335458
{

src/coreclr/jit/jitconfigvalues.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ CONFIG_STRING(JitEnableInductionVariableOptsRange, W("JitEnableInductionVariable
521521
CONFIG_INTEGER(JitDoSsa, W("JitDoSsa"), 1) // Perform Static Single Assignment (SSA) numbering on the variables
522522
CONFIG_INTEGER(JitDoValueNumber, W("JitDoValueNumber"), 1) // Perform value numbering on method expressions
523523

524-
CONFIG_INTEGER(JitEnableOptRepeat, W("JitEnableOptRepeat"), 0) // If zero, do not allow JitOptRepeat
524+
CONFIG_INTEGER(JitEnableOptRepeat, W("JitEnableOptRepeat"), 1) // If zero, do not allow JitOptRepeat
525525
CONFIG_METHODSET(JitOptRepeat, W("JitOptRepeat")) // Runs optimizer multiple times on specified methods
526526
CONFIG_INTEGER(JitOptRepeatCount, W("JitOptRepeatCount"), 2) // Number of times to repeat opts when repeating
527527
CONFIG_STRING(JitOptRepeatRange, W("JitOptRepeatRange")) // Enable JitOptRepeat based on method hash range

src/tests/JIT/Directed/debugging/debuginfo/tester.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<CLRTestEnvironmentVariable Include="DOTNET_JitNoForwardSub" Value="1" />
1515
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableHeadTailMerge" Value="0" />
1616
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableCrossBlockLocalAssertionProp" Value="0" />
17+
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableOptRepeat" Value="0" />
1718

1819
<ProjectReference Include="tests_d.ilproj" Aliases="tests_d" />
1920
<ProjectReference Include="tests_r.ilproj" Aliases="tests_r" />

0 commit comments

Comments
 (0)