diff options
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp | 6 | ||||
-rw-r--r-- | llvm/test/CodeGen/WebAssembly/store-results.ll | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp index d0735b84de6..3a7f50e3b14 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp @@ -69,7 +69,8 @@ bool WebAssemblyStoreResults::runOnMachineFunction(MachineFunction &MF) { const MachineRegisterInfo &MRI = MF.getRegInfo(); MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>(); - 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 @@ bool WebAssemblyStoreResults::runOnMachineFunction(MachineFunction &MF) { ->getFirstTerminator(); if (&MI == Where || !MDT.dominates(&MI, Where)) continue; + DEBUG(dbgs() << "Setting operand " << O << " in " << *Where << + " from " << MI <<"\n"); O.setReg(ToReg); } } + } return true; } diff --git a/llvm/test/CodeGen/WebAssembly/store-results.ll b/llvm/test/CodeGen/WebAssembly/store-results.ll new file mode 100644 index 00000000000..1bcee5d31fb --- /dev/null +++ b/llvm/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 +} |