Skip to content

Optimize codegen for call_indirect of final super types with GC enabled - #13572

Merged
fitzgen merged 3 commits into
bytecodealliance:mainfrom
fitzgen:gc-call-indirect-codegen
Jun 5, 2026
Merged

fitzgen merged 3 commits into
bytecodealliance:mainfrom
fitzgen:gc-call-indirect-codegen

Conversation

@fitzgen

@fitzgen fitzgen commented Jun 5, 2026

Copy link
Copy Markdown
Member

See each commit for details.

fitzgen added 3 commits June 5, 2026 11:43
`FuncEnvironment::is_subtype` always emitted a fast-path equality check, and if
that failed would then do a slow-path `is_subtype` libcall.

However, when the super type is `final` it has no proper subtypes, so `a <: b`
holds if and only if `a == b`. That is, the slow path would only ever evaluate
to `false`, is purely code bloat, and the control-flow merge tripped up the
mid-end optimizer and and pessimized the fast path.

This commit special-cases `final` super types to emit just the equality check,
and now the codegen for `call_indirect` of `final` types with GC enabled matches
the codegen for `call_indirect` with GC disabled.
@fitzgen
fitzgen requested review from a team as code owners June 5, 2026 19:11
@fitzgen
fitzgen requested review from cfallin and removed request for a team June 5, 2026 19:11
@fitzgen fitzgen mentioned this pull request Jun 5, 2026
14 tasks done

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! Could the branches on if features.gc() be removed now in translation as well?

I'll defer to @cfallin for the middle commit on egraphs as well

@cfallin cfallin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Middle commit (and last one for good measure too) LGTM. Nice! I didn't realize we had the truthy helper already from the comparison rewrites but weren't using it for conditional branches/traps -- nice to finally tie that in.

@fitzgen

fitzgen commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

Nice! Could the branches on if features.gc() be removed now in translation as well?

I think so, will do in a follow up

@fitzgen
fitzgen added this pull request to the merge queue Jun 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 5, 2026
@fitzgen
fitzgen added this pull request to the merge queue Jun 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 5, 2026
@fitzgen
fitzgen added this pull request to the merge queue Jun 5, 2026
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language labels Jun 5, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Subscribe to Label Action

cc @cfallin, @fitzgen

Details This issue or pull request has been labeled: "cranelift", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Merged via the queue into bytecodealliance:main with commit 75f2ba8 Jun 5, 2026
51 checks passed
@fitzgen
fitzgen deleted the gc-call-indirect-codegen branch June 5, 2026 21:16
pull Bot pushed a commit to eduardomourar/wasmtime that referenced this pull request Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants