Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Add JitOptRepeat debug config flags #7996

Merged
merged 5 commits into from
Nov 4, 2016

Conversation

JosephTremoulet
Copy link

Add flag JitOptRepeat that specifies a set of methods on which to
iteratively perform global optimizations multiple times, and flag
JitOptRepeatCount to set the number of iterations (default 2) to apply
when JitOptRepeat kicks in.

These flags are debug-only; they are intended to facilitate performing
experiments investigating optimization opportunities missed due to phase
ordering issues.

Also update fgResetForSsa (which is called between iterations) to clear heap data, defnums, and post-order numbers.

@JosephTremoulet
Copy link
Author

@dotnet/jit-contrib PTAL. Verified no diffs (x64 Windows jit-diff) as-is, and passing DDR with repeat count hard-coded to 16.

@@ -513,6 +513,8 @@ CONFIG_STRING_INFO_EX(INTERNAL_JitRange, W("JitRange"), "", CLRConfig::REGUTIL_d
CONFIG_DWORD_INFO_EX(INTERNAL_JITRequired, W("JITRequired"), (unsigned)-1, "", CLRConfig::REGUTIL_default)
CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL_JITRoundFloat, W("JITRoundFloat"), "")
CONFIG_DWORD_INFO_EX(INTERNAL_JitSkipArrayBoundCheck, W("JitSkipArrayBoundCheck"), 0, "", CLRConfig::REGUTIL_default)
CONFIG_STRING_INFO_EX(INTERNAL_JitOptRepeat, W("JitOptRepeat"), "Runs optimizer multiple times on the method", CLRConfig::REGUTIL_default)
CONFIG_DWORD_INFO_EX(INTERNAL_JitOptRepeatCount, W("JitOptRepeatCount"), 2, "Number of times to repeat opts when repeating", CLRConfig::REGUTIL_default)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no need to add these to clrconfigvalues.h as long as they are only used by RyuJIT, and not the VM or other JITs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, Any changes to the jit interface will require more work and it is best to avoid them if possible.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a config value does not constitute a JIT interface change. That said, @BruceForstall is correct: we should be able to confine these definitions to jitconfigvalues.h if they are only used by RyuJIT.


if (doEarlyProp)
do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a while loop so you can set iterations=0?

@@ -4359,6 +4359,7 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
bool doCopyProp = true;
bool doAssertionProp = true;
bool doRangeAnalysis = true;
int iterations = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be unsigned? JitOptRepeatCount can't be specified as negative.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macros that define the config COMPLUS_ settings use signed int, I'm more inclined to match them than to make this unsigned. With the change to a while loop, specifying a negative repeat count would then be the same as specifying zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. But specifying zero is bad currently -- same as specifying something very large due to "do" loop.

// in effect.

void Compiler::ResetOptAnnotations()
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should you assert that JitOptRepeat is set, and JitOptRepeatCount is >1?


void Compiler::RecomputeLoopInfo()
{
// Recompute reachability sets, dominators, and loops.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same asserts here?


if (doSsa)
if (JitConfig.JitOptRepeat().contains(info.compMethodName, info.compClassName, &info.compMethodInfo->args))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost all other uses of JitConfig.*.contains() are in compInitOptions(), so they will be ignored in the fallback JIT if altjit is set, and maybe also ignored in the inlinee compiler. You should probably do the same (and set a flag in Compiler on whether OptRepeat is on or not)

These need to be cleared for the same reasons as the locals' PerSsaData;
their omission seems to be a simple oversight.
SSA construction will overwrite these annotations, but only for reachable
code.  Clear the annotations in all code in `fgResetForSsa` so that
downstream analysis won't stumble over stale/invalid SSA annotations
in unreachable code.
Add flag JitOptRepeat that specifies a set of methods on which to
iteratively perform global optimizations multiple times, and flag
JitOptRepeatCount to set the number of iterations (default 2) to apply
when JitOptRepeat kicks in.

These flags are debug-only; they are intended to facilitate performing
experiments investigating optimization opportunities missed due to phase
ordering issues.
The cache created in the first iteration may not be correct in the second.
It seems there is a more general problem with failure to invalidate this
cache (GitHub issue #7844), that this change is working around for the
optRepeat case.
This works around an apparent bug in SSA construction (GitHub issue #7846),
specifically `fgPerNodeLocalVarLiveness`, where heap uses are not
considered upwards-exposed if they follow a heap def in their block (which
is incorrect because the store and load are not necessarily must-alias).
In the non-repeat configuration, these flags are always cleared coming
into SSA construction, because `TreeRenameVariables` is the only thing
that sets them.
@JosephTremoulet
Copy link
Author

Updated per feedback; @BruceForstall PTAL (and thanks for the suggestions).

@briansull
Copy link

Looks Good

@BruceForstall
Copy link
Member

LGTM

@JosephTremoulet JosephTremoulet merged commit b67ff5e into dotnet:master Nov 4, 2016
@JosephTremoulet JosephTremoulet deleted the OptRepeat branch November 4, 2016 21:54
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants