diff --git a/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp b/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp index 88c50a098dc..a76cb81b34f 100644 --- a/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp @@ -92,6 +92,9 @@ bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) { unsigned CurReg = MFI.getParams().size(); for (unsigned VRegIdx = 0; VRegIdx < NumVRegs; ++VRegIdx) { unsigned VReg = TargetRegisterInfo::index2VirtReg(VRegIdx); + // Skip unused registers. + if (MRI.use_empty(VReg)) + continue; // Handle stackified registers. if (MFI.isVRegStackified(VReg)) { DEBUG(dbgs() << "VReg " << VReg << " -> WAReg " @@ -99,9 +102,6 @@ bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) { MFI.setWAReg(VReg, INT32_MIN | NumStackRegs++); continue; } - // Skip unused registers. - if (MRI.use_empty(VReg)) - continue; if (MFI.getWAReg(VReg) == WebAssemblyFunctionInfo::UnusedReg) { DEBUG(dbgs() << "VReg " << VReg << " -> WAReg " << CurReg << "\n"); MFI.setWAReg(VReg, CurReg++); diff --git a/test/CodeGen/WebAssembly/cfg-stackify.ll b/test/CodeGen/WebAssembly/cfg-stackify.ll index f5b4b77c3d7..a1ff4ee30e0 100644 --- a/test/CodeGen/WebAssembly/cfg-stackify.ll +++ b/test/CodeGen/WebAssembly/cfg-stackify.ll @@ -1176,9 +1176,9 @@ bb5: ; CHECK-NEXT: .LBB23_2:{{$}} ; CHECK-NEXT: end_loop{{$}} ; CHECK-NEXT: loop{{$}} +; CHECK-NEXT: i32.const $discard=, 0{{$}} ; CHECK-NEXT: i32.const $push1=, 0{{$}} -; CHECK-NEXT: i32.const $push2=, 0{{$}} -; CHECK-NEXT: br_if $pop2, 0{{$}} +; CHECK-NEXT: br_if $pop1, 0{{$}} ; CHECK-NEXT: end_loop{{$}} ; CHECK-NEXT: return{{$}} define void @test14() {