-
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 does not elide empty try/catch blocks #107191
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
in-pr
There is an active PR which will close this issue when it is merged
tenet-performance
Performance related issue
Milestone
Comments
dotnet-issue-labeler
bot
added
the
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
label
Aug 30, 2024
dotnet-policy-service
bot
added
the
untriaged
New issue has not been triaged by the area owner
label
Aug 30, 2024
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This comment was marked as outdated.
This comment was marked as outdated.
colejohnson66
changed the title
JIT does not elide empty try/catch blocks
JIT does not elide conditionally empty try/catch blocks
Aug 30, 2024
We added try-finally opts because there were quite a few cases where we'd see either empty trys or empty finallys. I haven't seen the same for (empty)try-catch but perhaps it's worth a look, it would be relatively "easy" to do. |
AndyAyersMS
removed
the
untriaged
New issue has not been triaged by the area owner
label
Aug 30, 2024
colejohnson66
changed the title
JIT does not elide conditionally empty try/catch blocks
JIT does not elide empty try/catch blocks
Aug 30, 2024
AndyAyersMS
added a commit
to AndyAyersMS/runtime
that referenced
this issue
Nov 29, 2024
If no tree in the try region of a try/catch can throw, then we can remove the try and delete the catch. If no tree in the try region of a try/finally can throw, we can remove the try and inline the finally. This slightly generalizes the empty-try/finally opt we have been doing for a long time. (We should do something similar for try/fault, but don't, yet). Since these optimization passes are cheap, and opportunities for them arise after other optimizations and unblock subsequent optimizations, run them early, middle, and late. Resolves dotnet#107191. I expect we'll see more of these cases in the future, say if we unblock cloning of loops with EH.
dotnet-policy-service
bot
added
the
in-pr
There is an active PR which will close this issue when it is merged
label
Nov 29, 2024
eduardo-vp
pushed a commit
to eduardo-vp/runtime
that referenced
this issue
Dec 5, 2024
If no tree in the try region of a try/catch can throw, then we can remove the try and delete the catch. If no tree in the try region of a try/finally can throw, we can remove the try and inline the finally. This slightly generalizes the empty-try/finally opt we have been doing for a long time. (We should do something similar for try/fault, but don't, yet). Since these optimization passes are cheap, and opportunities for them arise after other optimizations and unblock subsequent optimizations, run them early, middle, and late. Resolves dotnet#107191. I expect we'll see more of these cases in the future, say if we unblock cloning of loops with EH.
mikelle-rogers
pushed a commit
to mikelle-rogers/runtime
that referenced
this issue
Dec 10, 2024
If no tree in the try region of a try/catch can throw, then we can remove the try and delete the catch. If no tree in the try region of a try/finally can throw, we can remove the try and inline the finally. This slightly generalizes the empty-try/finally opt we have been doing for a long time. (We should do something similar for try/fault, but don't, yet). Since these optimization passes are cheap, and opportunities for them arise after other optimizations and unblock subsequent optimizations, run them early, middle, and late. Resolves dotnet#107191. I expect we'll see more of these cases in the future, say if we unblock cloning of loops with EH.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
in-pr
There is an active PR which will close this issue when it is merged
tenet-performance
Performance related issue
Description
If we want to format some runtime values for a
Debug.WriteLine
invocation, it's possible for the formatting method to throw. So, I figured I'd wrap a try/catch around theDebug.WriteLine
call. However, the JIT does not elide the block in release mode.https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABABgAJiBGAOgBEBLbAcwDsJcMGxcBuAWABQZSrQBKAV1Zd8MGgGEI+AA4MANjCgBlTQDduMPkJHUaAFRgIMAwcYDMlAEzl5avLiEBvIeV/kA2gCyMBgAFhAAJgCSKmoAFMFhkTHKagDyylwQrLg0AILMzLC4uAy6MBkyDABe2FmsAJQAuj5+xA7EKOSJ4RFxwACeGDD+TeQRddgNrb7egn4L5BhQAzOLc4ub5HQwwBLMNADqUAzDADIMrDBxAKKskBGXBwCqZgBiABw0AOIhWstPOITDBTBo2LbkAC+awWYDqYFCML8Gwhfh2ewOx1OMAuVziACJgNgImoBuQAGbQfB1YYRcaTfFgpG+aHzPysyFAA===
C# / IL / JIT ASM
Configuration
8.0.724.31311 on x64
Analysis
The assembly appears to set up a stack frame, immediately tear it down, then return. Curiously, there are unreachable instructions after the
ret
onL0013
.Alternatively, the JIT will elide an empty try/finally block, reducing
Class.Method
to a simpleret
.https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABABgAJiBGAOgBEBLbAcwDsJcMGxcBuAWABQZSrQAqMBBgGChxAMyUATOQDCAGzy4hAbyHkDlRcRTkAsjAwALCABMAFMACeGGAG0AuuVvYM2AJT6hnqChmHkGFBOQeHkIbGxdDDAAK7MNADqUAyuADIMrDD2AKKskLYF6QCqYgBiABw0AOKWAMqRlfY+fv7+MgnkAL4x4QBmBdjq6tGhCfEDhkmp6Vk5MPmF9gBEW30jYcOzBoeDQA
C# / IL / JIT ASM
The text was updated successfully, but these errors were encountered: