Skip to content

Use effects for indirect call expressions#8625

Draft
stevenfontanella wants to merge 1 commit intomainfrom
expression-effects
Draft

Use effects for indirect call expressions#8625
stevenfontanella wants to merge 1 commit intomainfrom
expression-effects

Conversation

@stevenfontanella
Copy link
Copy Markdown
Member

No description provided.

Comment thread src/ir/effects.h
void visitCallIndirect(CallIndirect* curr) {
if (auto it = parent.module.typeEffects.find(curr->heapType);
it != parent.module.typeEffects.end()) {
parent.mergeIn(*it->second);
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.

It doesn't look like this accounts for the possible trap from a bad type check. I guess the previous code didn't need to handle it because setting calls implicitly includes trapping along with most other effects.

To make this as precise as possible, we could look at the type of the table and skip setting the trap effect if it is non-nullable and a subtype of the call_indirect expected type.

@stevenfontanella
Copy link
Copy Markdown
Member Author

Seems like JJ + Github don't play well when I'm on a branch based on another branch that had a merge commit. Will fix this after merging the other branch.

stevenfontanella added a commit that referenced this pull request Apr 24, 2026
When running in --closed-world, compute effects for indirect calls by
unioning the effects of all potential functions of that type. In
--closed-world, we assume that all references originate in our module,
so the only possible functions that we don't know about are imports.
Previously [we gave up on effects
analysis](https://github.com/WebAssembly/binaryen/blob/29b2d42e8a748fbe1095696d58a52b7bf83e2253/src/passes/GlobalEffects.cpp#L83-L87)
for indirect calls.

Yields a very small byte count reduction in calcworker (3799354 -
3799297 = 57 bytes). Also shows no significant difference in Binaryen
runtime: (0.1346069 -> 0.13375045 = <1% improvement, probably within
noise). We expect more benefits after we're able to share indirect call
effects with other passes, since currently they're only seen one layer
up for callers of functions that indirectly call functions (see the
newly-added tests for examples).

Followups:
* Share effect information per type with other passes besides just via
Function::effects (#8625)
* Exclude functions that don't have an address (i.e. functions that
aren't the target of ref.func) from effect analysis ()
* Compute effects more precisely for exact + nullable/non-nullable
references

Part of #8615.
Base automatically changed from indirect-effects-scc to main April 24, 2026 21:36
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