Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixOptRepeat and force repeating #100447

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ void Compiler::optPrintAssertion(AssertionDsc* curAssertion, AssertionIndex asse
printf("Exact Type MT(0x%p %s)", dspPtr(iconVal),
eeGetClassName((CORINFO_CLASS_HANDLE)iconVal));
}

// We might want to assert:
// assert(curAssertion->op2.HasIconFlag());
// However, if we run CSE with shared constant mode, we may end up with an expression instead
// of the original handle value. If we then use JitOptRepeat to re-build value numbers, we lose
// knowledge that the constant was ever a handle, as the expression creating the original value
// was not (and can't be) assigned a handle flag.
}
else if (curAssertion->op1.kind == O1K_SUBTYPE)
{
Expand Down Expand Up @@ -1876,7 +1883,6 @@ void Compiler::optDebugCheckAssertion(AssertionDsc* assertion)
{
case O1K_EXACT_TYPE:
case O1K_SUBTYPE:
assert(assertion->op2.HasIconFlag());
break;
case O1K_LCLVAR:
assert((lvaGetDesc(assertion->op1.lcl.lclNum)->lvType != TYP_REF) ||
Expand Down Expand Up @@ -5428,6 +5434,25 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, Stat
if (parent != nullptr)
{
parent->ReplaceOperand(useEdge, newTree);

// If the parent is a GT_IND and we replaced the child with a handle constant, we might need
// to mark the GT_IND as invariant. This is the same as what gtNewIndOfIconHandleNode() does.
// Review: should some kind of more general morphing take care of this?
// Should this share code with gtNewIndOfIconHandleNode()?

if (parent->OperIs(GT_IND) && newTree->IsIconHandle())
{
GenTreeFlags iconFlags = newTree->GetIconHandleFlag();
if (GenTree::HandleKindDataIsInvariant(iconFlags))
{
parent->gtFlags |= GTF_IND_INVARIANT;
if (iconFlags == GTF_ICON_STR_HDL)
{
// String literals are never null
parent->gtFlags |= GTF_IND_NONNULL;
}
}
}
}
else
{
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,14 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
}
}

////////////////// TESTING
if (JitConfig.JitEnableOptRepeat() != 0)
{
opts.optRepeat = true;
opts.optRepeatCount = 4;
JITDUMP("\n*************** JitOptRepeat FORCED; repetition count: %d\n\n", opts.optRepeatCount);
}
////////////////// END TESTING
#endif // OPT_CONFIG

#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ CONFIG_STRING(JitEnableInductionVariableOptsRange, W("JitEnableInductionVariable
CONFIG_INTEGER(JitDoSsa, W("JitDoSsa"), 1) // Perform Static Single Assignment (SSA) numbering on the variables
CONFIG_INTEGER(JitDoValueNumber, W("JitDoValueNumber"), 1) // Perform value numbering on method expressions

CONFIG_INTEGER(JitEnableOptRepeat, W("JitEnableOptRepeat"), 0) // If zero, do not allow JitOptRepeat
CONFIG_INTEGER(JitEnableOptRepeat, W("JitEnableOptRepeat"), 1) // If zero, do not allow JitOptRepeat
CONFIG_METHODSET(JitOptRepeat, W("JitOptRepeat")) // Runs optimizer multiple times on specified methods
CONFIG_INTEGER(JitOptRepeatCount, W("JitOptRepeatCount"), 2) // Number of times to repeat opts when repeating
CONFIG_STRING(JitOptRepeatRange, W("JitOptRepeatRange")) // Enable JitOptRepeat based on method hash range
Expand Down
1 change: 1 addition & 0 deletions src/tests/JIT/Directed/debugging/debuginfo/tester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<CLRTestEnvironmentVariable Include="DOTNET_JitNoForwardSub" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableHeadTailMerge" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableCrossBlockLocalAssertionProp" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableOptRepeat" Value="0" />

<ProjectReference Include="tests_d.ilproj" Aliases="tests_d" />
<ProjectReference Include="tests_r.ilproj" Aliases="tests_r" />
Expand Down
Loading