Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Nov 21, 2025

In pattern B there, we handle stuff like

if (..) { .. }
return x;

We split out the if body if it is large-enough, which allows inlining the if
condition + the return (efficient if the condition rarely happens). This did
not handle local effects: imagine that the if body contains x = 42, then
after splitting it out to another function, that value is not picked up in
the return of x. Fix that by checking local dependencies.

More detailed example:

function foo(x) {
  if (..) {
    work();
    x = 42;
  }
  return x;
}

function caller() {
  foo(1);
}

=> the incorrect optimization before =>

function caller() {
  // inlined call, but split: just the condition + return.
  var x = 1; // inlined value sent in call
  if (..) {
    outlinedCode();
  }
  x = x;
}

function outlinedCode() {
  // The setting of x to 42 is done here, and not picked up
  // in the caller.
  var x;
  work();
  x = 42;
}

After this PR, we do not do such split inlining.

@kripken kripken requested a review from tlively November 21, 2025 16:37
@kripken
Copy link
Member Author

kripken commented Nov 21, 2025

Unfortunately fuzzing did not find this, as these split-inlining patterns are intricate... any fuzzer change usually breaks the pattern entirely.

@kripken kripken merged commit 95b2cf0 into WebAssembly:main Nov 21, 2025
16 checks passed
@kripken kripken deleted the inlining.split.localdep branch November 21, 2025 21:15
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