Skip to content

[WebAssembly] Unstackify registers with no uses in ExplicitLocals #149626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,17 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {

// Precompute the set of registers that are unused, so that we can insert
// drops to their defs.
// And unstackify any stackified registers that don't have any uses, so that
// they can be dropped later. This can happen when transformations after
// RegStackify removes instructions that use stackified registers.
BitVector UseEmpty(MRI.getNumVirtRegs());
for (unsigned I = 0, E = MRI.getNumVirtRegs(); I < E; ++I)
UseEmpty[I] = MRI.use_empty(Register::index2VirtReg(I));
for (unsigned I = 0, E = MRI.getNumVirtRegs(); I < E; ++I) {
Register Reg = Register::index2VirtReg(I);
if (MRI.use_empty(Reg)) {
UseEmpty[I] = true;
MFI.unstackifyVReg(Reg);
}
}

// Visit each instruction in the function.
for (MachineBasicBlock &MBB : MF) {
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/WebAssembly/removed-terminator.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: llc -O0 < %s

target triple = "wasm32-unknown-unknown"

define void @test(i1 %x) {
%y = xor i1 %x, true
; This br_if's operand (%y) is stackified in RegStackify. But this terminator
; will be removed in CFGSort after that. We need to make sure we unstackify %y
; so that it can be dropped in ExplicitLocals.
br i1 %y, label %exit, label %exit

exit:
ret void
}
Loading