Skip to content

Fix tree threading in fgOptimizeBranch #51422

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

Merged
merged 1 commit into from
Apr 17, 2021

Conversation

BruceForstall
Copy link
Contributor

In case fgOptimizeBranch gets far enough to calculate the cost of
statements it is considering duplicating, then it calls gtPrepareCost =>
gtSetEvalOrder to compute a statement's costs. Unfortunately, that
can reverse operands (and in this case, did). fgOptimizeBranch is
called only by fgReorderBlocks which is called by fgInsertGCPolls,
late enough that the tree is already threaded with gtNext/gtPrev links.
(The test case inserted multiple GC polls for SuppressGCTransitionAttribute
code.) When the operands of the tree were swapped, nobody fixed up these links.
The only other caller of fgReorderBlocks is optOptimizeLayout, which
comes before the trees are threaded.

The solution is to simply call fgSetStmtSeq if needed.

No SPMI x86, x64 asm diffs.

Fixes #51293, a failure in JIT/Performance/CodeQuality/Burgers/Burgers/Burgers.sh
on Linux arm32 under JitStress=1. There is IBC data, and setting
COMPlus_JitDisablePgo=1 also fixes the failure.

In case `fgOptimizeBranch` gets far enough to calculate the cost of
statements it is considering duplicating, then it calls `gtPrepareCost` =>
`gtSetEvalOrder` to compute a statement's costs. Unfortunately, that
can reverse operands (and in this case, did). `fgOptimizeBranch` is
called only by `fgReorderBlocks` which is called by `fgInsertGCPolls`,
late enough that the tree is already threaded with gtNext/gtPrev links.
(The test case inserted multiple GC polls for SuppressGCTransitionAttribute
code.) When the operands of the tree were swapped, nobody fixed up these links.
The only other caller of `fgReorderBlocks` is `optOptimizeLayout`, which
comes before the trees are threaded.

The solution is to simply call `fgSetStmtSeq` if needed.

No SPMI x86, x64 asm diffs.

Fixes dotnet#51293, a failure in JIT/Performance/CodeQuality/Burgers/Burgers/Burgers.sh
on Linux arm32 under JitStress=1. There is IBC data, and setting
`COMPlus_JitDisablePgo=1` also fixes the failure.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 16, 2021
@BruceForstall
Copy link
Contributor Author

@AndyAyersMS @dotnet/jit-contrib PTAL

@BruceForstall
Copy link
Contributor Author

/azp run runtime-coreclr outerloop

@BruceForstall
Copy link
Contributor Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BruceForstall BruceForstall self-assigned this Apr 16, 2021
@BruceForstall BruceForstall added this to the 6.0.0 milestone Apr 16, 2021
Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

LGTM.

We really ought to find a way to cost trees without having this happen.

@BruceForstall
Copy link
Contributor Author

@BruceForstall BruceForstall merged commit 4d629d7 into dotnet:main Apr 17, 2021
@BruceForstall BruceForstall deleted the FixBurgers51293 branch April 17, 2021 05:05
@ghost ghost locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failure JIT/Performance/CodeQuality/Burgers/Burgers/Burgers.sh
2 participants