[WebAssembly] Add a test for wasm-store-results pass
authorDerek Schuff <dschuff@google.com>
Thu, 3 Dec 2015 00:50:30 +0000 (00:50 +0000)
committerDerek Schuff <dschuff@google.com>
Thu, 3 Dec 2015 00:50:30 +0000 (00:50 +0000)
Differential Revision: http://reviews.llvm.org/D15167

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254570 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
test/CodeGen/WebAssembly/store-results.ll [new file with mode: 0644]

index d0735b84de6016393640aeff54f1e708ec167f5e..3a7f50e3b1425c0b08bb594d14d1f8ab4be03569 100644 (file)
@@ -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/test/CodeGen/WebAssembly/store-results.ll b/test/CodeGen/WebAssembly/store-results.ll
new file mode 100644 (file)
index 0000000..1bcee5d
--- /dev/null
@@ -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
+}