-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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\opt\OSR\tailrecursetry\tailrecursetry.cmd fails with COMPlus_FastTailCalls=0 #35687
Comments
@dotnet/jit-contrib @AndyAyersMS |
Pre-SSA liveness deletes the assignment to the catch variable, and things go downhill from there.
|
Actually that part is OK, the issue is that upstream we're not getting the expected dominance frontier for the catch block. |
Looks like a similar issue to what I saw over with #34522 -- there are more places in the jit where we assume the try region entry is the first try. In this test case we normally change the recursive tail call into a jump. In order to make that work with OSR we import the method entry block and mark it as must keep, since it will otherwise be unreferenced until morph does the call -> jump transformation. Importing this block may pull in other blocks that OSR normally wouldn't import. We don't do that transformation when Just before building SSA we have we have a try region BB03-BB04 where BB03 is empty and unreachable and the try entry is BB04.
This breaks an assumption in Fixing that in a manner similar to the fix in #34522 (search the try region for the entry) gets us a bit further as we insert the PHI, but we then hit another assert as the PHI is degenerate and has only one input. Now the issue is that when building SSA we hit a similar assumption in So it looks like there are now at least 3 places where the jit assumes that the first block of the try is the try entry. Instead of trying to fix these (and possibly more) I'm going to see if we can prune away the unreachable blocks so that the OSR cases continue to follow the expected form for trys. |
Have part of this fixed -- the jit is now is able to get rid of BB02 in the above; instead of protecting it with a bbflag I can protect it by manipulating reference counts. This approach is needed because once you set Getting rid of BB03 is going to be a bit harder; there is a lot of bias in the code expecting that try region entry blocks are are untouchable and come first in the region. Likely what we'll need is to do something akin to the region entry trimming I added when OSR was first introduced, but this version of try region trimming must run later, and is only needed if we imported the original method entry, and then morph decides not to introduce branches to the original entry. The logic should be something like: check to see if the entry block successor is in a try region, and if so, if that block is not the first block of the try, move it so it is the first block in the try. Need to ensure this is workable when the entry block successor is in multiple trys. |
May also need to watch out for #6892. |
Well, figuring out the right thing here is looking more complex than I'd like; we may need to support the idea that a try region entry is not always the first block in the try. Since this case seemingly only happens if:
I think I should to just disable the tail recursion to loop opt in the above case for now, so things are at least correct, and defer further work. We can still tail call. |
I'm confused. The test fails with "set COMPlus_FastTailCalls=0", which also disables tail recursion to loop opt. What am I missing? |
To support tail recursion->loop in OSR we over-import; if the optimization doesn't happen, we're left with unreachable code that is hard to properly clean up when it involves try regions. The unreachable code leads to confusion when enumerating EH preds and building SSA.
|
I think I understand now. Your proposal is to both disable tail recursion to loop opt and to stop over-importing if the two bullets above are true. That makes sense. |
Yep. |
Hmm, that's not sufficient either -- if we have multiple levels of nested loops and trys we still get into trouble as we have try regions whose first block is reachable but is not the try entry.
Here BB02 is the try start but can only be reached from inside the try. The entry is BB04 as it's the only block in the try that can be reached from the outside. Looking more and more like teaching the jit that try start and try entry may not be the same block is the only way to properly address all of this. That means yet another link in the eh table that needs careful treatment. |
Found a related issue with trying to support the recursive tail call -> loop optimization with OSR. If the tail call site is introduced by an inlinee, the root method won't have done the necessary anticipatory importation. Seems like there are two issues to sort through here:
|
This is an OSR-only issue; since that's an experimental feature in 5.0 and the fix looks to be somewhat disruptive and would impact more than OSR, I'm going to mark this as future. |
This change adds control flow to ensure that an OSR method for a patchpoint nested in try regions enters those regions try from the first block of each try rather than mid-try. This lets these OSR methods conform to the data flow expectations that the only way control flow can enter a try is via its first block. See #33658 for more details on the approach taken here. Fixes #35687.
This change adds control flow to ensure that an OSR method for a patchpoint nested in try regions enters those regions try from the first block of each try rather than mid-try. This lets these OSR methods conform to the data flow expectations that the only way control flow can enter a try is via its first block. See #33658 for more details on the approach taken here. Fixes #35687.
COMPlus_FastTailCalls
is a new environment variable added in #341. When it's set to 0, all tail-prefixed calls are dispatched via helpers.JIT\opt\OSR\tailrecursetry\tailrecursetry.cmd is a test that turns on on-stack replacement, it sets
If additionally we set
the test fails with
category:correctness
theme:osr
skill-level:expert
cost:medium
The text was updated successfully, but these errors were encountered: