Skip to content

Compute effects for indirect calls in GlobalEffects#8609

Open
stevenfontanella wants to merge 10 commits intomainfrom
indirect-effects-scc
Open

Compute effects for indirect calls in GlobalEffects#8609
stevenfontanella wants to merge 10 commits intomainfrom
indirect-effects-scc

Conversation

@stevenfontanella
Copy link
Copy Markdown
Member

@stevenfontanella stevenfontanella commented Apr 15, 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 for indirect calls.

Yields a very small byte count reduction in calcworker (3799354 - 3799297 = 57 bytes). Also shows no significant difference in 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
  • 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.

@stevenfontanella stevenfontanella changed the base branch from main to effects-scc April 16, 2026 16:28
@stevenfontanella stevenfontanella force-pushed the indirect-effects-scc branch 8 times, most recently from b7ce0b6 to 9fcf76b Compare April 16, 2026 20:59
@stevenfontanella stevenfontanella changed the title Indirect effects scc Compute effects for indirect calls in GlobalEffects Apr 16, 2026
@stevenfontanella stevenfontanella marked this pull request as ready for review April 16, 2026 21:43
@stevenfontanella stevenfontanella requested a review from a team as a code owner April 16, 2026 21:43
@stevenfontanella stevenfontanella requested review from kripken and removed request for a team April 16, 2026 21:43
Base automatically changed from effects-scc to main April 16, 2026 22:36
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp
Comment thread src/passes/GlobalEffects.cpp
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp
Comment thread src/passes/GlobalEffects.cpp
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread test/lit/passes/global-effects-closed-world.wast Outdated
Comment thread test/lit/passes/global-effects-closed-world.wast
Comment thread test/lit/passes/global-effects-closed-world.wast
Comment thread src/passes/GlobalEffects.cpp Outdated
Comment thread src/passes/GlobalEffects.cpp Outdated
}
};

// Explicit deduction guide to resolve -Wctad-maybe-unsupported
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.

Using ranges turned out to be much more complicated than I thought 😢

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.

I am not that impressed with the clarity of the Ranges code... but I don't feel strongly if you two like it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Totally agreed, this is my first time trying ranges. Disabling -Wctad-maybe-unsupported is an option which would let us remove this but Gemini suggested that the auto-generated deduction guides go wrong sometimes: https://gist.github.com/stevenfontanella/819251700a408d6243f7833acebdad20

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.

The bigger problem is that google uses that option when compiling this internally.

Comment thread src/passes/GlobalEffects.cpp
Comment thread test/lit/passes/global-effects-closed-world.wast Outdated
Comment thread test/lit/passes/global-effects-closed-world.wast
Comment thread out.txt Outdated
Comment on lines +160 to +163
(type $func-with-sub-param (sub (func (param (ref $sub)))))
;; Subtype
;; CHECK: (type $func-with-super-param (sub $func-with-sub-param (func (param (ref $super)))))
(type $func-with-super-param (sub $func-with-sub-param (func (param (ref $super)))))
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.

You could simplify these tests by getting rid of the struct types and parameters entirely, and just have (type $super (sub (func))) and (type $sub (sub $super (func))).

Comment on lines +57 to +59
;; Similar to $f, but we may still trap here because the ref is null, so we
;; don't optimize.
(call $calls-nop-via-nullable-ref (local.get $ref))
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 would be interesting to test --traps-never-happen mode as well so show that this will be optimized in that case.

Comment thread src/passes/GlobalEffects.cpp Outdated
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