Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp @@ -69,7 +69,8 @@ const MachineRegisterInfo &MRI = MF.getRegInfo(); MachineDominatorTree &MDT = getAnalysis(); - for (auto &MBB : MF) + for (auto &MBB : MF) { + DEBUG(dbgs() << "Basic Block: " << MBB.getName() << '\n'); for (auto &MI : MBB) switch (MI.getOpcode()) { default: @@ -94,9 +95,12 @@ ->getFirstTerminator(); if (&MI == Where || !MDT.dominates(&MI, Where)) continue; + DEBUG(dbgs() << "Setting operand " << O << " in " << *Where << + " from " << MI <<"\n"); O.setReg(ToReg); } } + } return true; } Index: llvm/trunk/test/CodeGen/WebAssembly/store-results.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/store-results.ll +++ llvm/trunk/test/CodeGen/WebAssembly/store-results.ll @@ -0,0 +1,18 @@ +; RUN: llc < %s -asm-verbose=false | FileCheck %s + +; Test that the wasm-store-results pass makes users of stored values use the +; result of store expressions to reduce get_local/set_local traffic. + +target datalayout = "e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +; CHECK-LABEL: single_block: +; CHECK-NOT: .local +; CHECK: i32.const $push{{[0-9]+}}=, 0 +; CHECK: i32.store $push[[STORE:[0-9]+]]=, $0, $pop{{[0-9]+}} +; CHECK: return $pop[[STORE]]{{$}} +define i32 @single_block(i32* %p) { +entry: + store i32 0, i32* %p + ret i32 0 +}