Skip to content
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

lowering: Optimize lowering of tryfinally with trivial finally block #52593

Merged
merged 1 commit into from
Dec 23, 2023

Conversation

Keno
Copy link
Member

@Keno Keno commented Dec 20, 2023

This optimizes the lowering of a tryfinally block with empty finally block to instead use the try/catch lowering, where the catch block is given as simply rethrow(). This is equivalent semantically to try/finally in this case, but the code structure is a lot simpler with fewer basic blocks and without the auxiliary slot for tracking the finally slot. The motivation here is to help the compiler optimize better when using the @with macro, which has an empty finally block (but uses the scope argument of 'tryfinally). The only problem with this is that it violates the lowering assumptions I made in #52527, so we'll probably need to fix that first.

Keno added a commit that referenced this pull request Dec 22, 2023
Third time's the charm hopefully. This builds on #52527 and addresses
the TODO left there by keeping track of the appropriate :scope in sroa
as we go along in order to ensure correct current_scope folding, even
when the try body is nothrow (which was left as a todo). As a result,
we also no longer result on lowering assumptions for this transformation,
which enables us to enable the lowering optimization in #52593.
Keno added a commit that referenced this pull request Dec 23, 2023
Third time's the charm hopefully. This builds on #52527 and addresses
the TODO left there by keeping track of the appropriate :scope in sroa
as we go along in order to ensure correct current_scope folding, even
when the try body is nothrow (which was left as a todo). As a result, we
also no longer result on lowering assumptions for this transformation,
which enables us to enable the lowering optimization in #52593.
This optimizes the lowering of a tryfinally block with empty finally
block to instead use the try/catch lowering, where the catch block
is given as simply `rethrow()`. This is equivalent semantically to
try/finally in this case, but the code structure is a lot simpler
with fewer basic blocks and without the auxiliary slot for tracking
the finally slot. The motivation here is to help the compiler optimize
better when using the `@with` macro, which has an empty `finally` block
(but uses the scope argument of 'tryfinally).
@Keno Keno merged commit 0b5cf42 into master Dec 23, 2023
5 of 7 checks passed
@Keno Keno deleted the kf/tryfinallylowering branch December 23, 2023 12:35
function with_macro_slot_cross()
a = 1
@with sval=>1 begin
a = sval_float[]
Copy link
Member

Choose a reason for hiding this comment

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

This is intended to be a = sval[]? It's a minor issue, so I believe it can be addressed alongside other upcoming changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is as intended, the test is for the value of the slot a across the @with region and I didn't want it to fold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants