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

wasmtime: Remove redundant epoch check on function entry #8853

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

jameysharp
Copy link
Contributor

The epoch interruption implementation caches the current deadline in a register, and avoids reloading that cache until the cached deadline has passed.

However, the first epoch check happens immediately after the cache has been populated on function entry, so there's never a reason to reload the cache at that point. It only needs to be reloaded in loops. So this commit eliminates the double-check on function entry.

When Cranelift optimizations are enabled, the alias analysis pass correctly detected that this load was redundant, and the egraph pass optimized away the icmp as well. However, since we don't do conditional constant propagation, the branch couldn't be optimized away. On x86 this lowered to a redundant cmp/jae pair of instructions in every function entry, which this commit eliminates.

To keep track of what code we're generating for epoch interruptions, I've also added disas tests with a trivial infinite loop.

The epoch interruption implementation caches the current deadline in a
register, and avoids reloading that cache until the cached deadline has
passed.

However, the first epoch check happens immediately after the cache has
been populated on function entry, so there's never a reason to reload
the cache at that point. It only needs to be reloaded in loops. So this
commit eliminates the double-check on function entry.

When Cranelift optimizations are enabled, the alias analysis pass
correctly detected that this load was redundant, and the egraph pass
optimized away the `icmp` as well. However, since we don't do
conditional constant propagation, the branch couldn't be optimized away.
On x86 this lowered to a redundant `cmp`/`jae` pair of instructions in
every function entry, which this commit eliminates.

To keep track of what code we're generating for epoch interruptions,
I've also added disas tests with a trivial infinite loop.
@jameysharp jameysharp requested a review from cfallin June 20, 2024 20:51
@jameysharp jameysharp requested a review from a team as a code owner June 20, 2024 20:51
@jameysharp jameysharp requested review from pchickey and removed request for a team June 20, 2024 20:51
@alexcrichton alexcrichton added this pull request to the merge queue Jun 20, 2024
Merged via the queue into bytecodealliance:main with commit e29d56e Jun 20, 2024
36 checks passed
@jameysharp jameysharp deleted the epoch-entry branch June 20, 2024 21:26
@cfallin
Copy link
Member

cfallin commented Jun 20, 2024

Ah, I've wondered where that stray branch came from but never tracked it down -- thanks for finding this!

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.

3 participants