-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
JIT: run a late pass of empty try/finally/fault removal #108003
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
@BruceForstall PTAL Expect modest diffs (including some regressions where LSRA has made different choices). |
src/coreclr/jit/fgopt.cpp
Outdated
@@ -3306,8 +3306,6 @@ bool Compiler::fgReorderBlocks(bool useProfile) | |||
{ | |||
noway_assert(opts.compDbgCode == false); | |||
|
|||
assert(UsesFunclets() == fgFuncletsCreated); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume by the time useProfile
is true
this assert should be always true? not sure it makes sense to keep, though
Looks like there's a widespread issue. The |
Seems like fixing this is not so simple. There are several issues here. I'll use ACD as a shorthand for
This latter problem exists even without a late EH opts pass, but things work today because To avoid the stale block references it probably makes sense for the ACD entries to record the try and handler indices (which they sort of do now, encoded in data) and simply rely on those, then adjust those as needed if EH regions are removed later, and use them to direct the throw block placement. That seems like a preqrequisite change, so I may work on it first and come back to this. |
fyi, I've wondered whether we can stop setting |
Should PHASE_EMPTY_TRY also be run again? I'm surprised that moving funclet creation didn't cause any problems (or maybe the problems are hidden behind the ACD failures)? |
Yeah it might be worth rerunning that too. I don't have a complete fix for the ACD issues yet so can't tell if there are other problems. Going to refactor how ACD works first so it is more amenable to EH region removal. |
The JIT can sometimes optimize away all the code in a finally or fault, so rerun and generalize the empty try-finally removal to cover faults and run it again after the main optimization passes.
2b8d631
to
a8c2e70
Compare
I have finally got a version that seems to properly update the ACDs and builds upon the other recent refactorings. SPMI diffs show modest improvements. I experimented with running this just after morph as well, and it doesn't add much. I have not yet looked into re-running empty try removal. That seems less likely to kick in? Though perhaps if we go by lack of GTF_EXCEPT, we can remove trys even for non-empty cases. Will add this to my things to look into some day. I could probably be talked into adding index -> eh region number translation goo for ACDs like we have on basic blocks. |
Looks like some issues on x86 still. |
Forgot that non-funclet EH only ever uses KD_NONE or KD_TRY (which encode to the same key bits). |
@BruceForstall ping -- if you're tied up with other work, let me know. |
// compiler - current compiler instance | ||
// | ||
// Returns: | ||
// true if the key desinator changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// true if the key desinator changes | |
// true if the key designator changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix subsequently.
Will other flow graph modifications want to do ACD modifications, warranting creating an "API" for doing so (and extracting some of the code here to helper functions)? |
I'm not aware of any other cases. The ACD's act like virtual blocks that are tied to their EH regions; the only time we change the EH regions of blocks are when we remove (or I suppose add) EH regions, and removal always goes down this path, and adding only happens today for very limited cases before we've ever created any ACDs. |
The JIT can sometimes optimize away all the code in a finally or fault, so rerun and generalize the empty try-finally removal to cover faults and run it again after the main optimization passes.