Skip to content

[StackIR] Optimize the simple case of a multivalue tee and extracts#8623

Merged
kripken merged 18 commits intoWebAssembly:mainfrom
kripken:stackir.tuple.unsplat
Apr 20, 2026
Merged

[StackIR] Optimize the simple case of a multivalue tee and extracts#8623
kripken merged 18 commits intoWebAssembly:mainfrom
kripken:stackir.tuple.unsplat

Conversation

@kripken
Copy link
Copy Markdown
Member

@kripken kripken commented Apr 17, 2026

When getting a multivalue from e.g. a call and then consuming it immediately,
we get this pattern:

      (tuple.extract 3 0
        (local.tee $temp
          (call $multivalue-return)
        )
      )
      (tuple.extract 3 1
        (local.get $temp)
      )
      (tuple.extract 3 2
        (local.get $temp)
      )

We save the entire tuple to a local, then read index by index. In StackIR
we can just remove all the tuple operations, as the value is on the stack
and ready to be used.

Fixes #8618

@kripken kripken requested a review from tlively April 17, 2026 18:16
@kripken kripken requested a review from a team as a code owner April 17, 2026 18:16
@kripken kripken mentioned this pull request Apr 17, 2026
)
)

;; CHECK: (func $multivalue-return-too-short (type $3) (result i32 f64)
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.

Might be interesting to add round trip output, too, to make sure the binary writer still does the right thing.

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.

Already done 😉 see the command above

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.

Oh, I see. It's too bad we can't get a text output that matches the written binary exactly (i.e. with the tuple pseudoinstructions lowered away).

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.

We can get close without the roundtrip - the StackIR is printed right before binary emitting. I pushed a change now to include both outputs (with a different lit prefix).

@kripken kripken merged commit 604f547 into WebAssembly:main Apr 20, 2026
16 checks passed
@kripken kripken deleted the stackir.tuple.unsplat branch April 20, 2026 18:06
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.

Unnecessary pop & push

2 participants