[PATCH] D16554: [WebAssembly] Omit no-op adds for non-mem uses of FrameIndex

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 12:57:52 PST 2016


dschuff created this revision.
dschuff added reviewers: jfb, sunfish.
dschuff added a subscriber: llvm-commits.
Herald added subscribers: dschuff, jfb.

http://reviews.llvm.org/D16554

Files:
  lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
  lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
  test/CodeGen/WebAssembly/userstack.ll

Index: test/CodeGen/WebAssembly/userstack.ll
===================================================================
--- test/CodeGen/WebAssembly/userstack.ll
+++ test/CodeGen/WebAssembly/userstack.ll
@@ -76,6 +76,24 @@
  ret void
 }
 
+declare void @ext_func(i64* %ptr)
+; CHECK-LABEL: non_mem_use
+define void @non_mem_use() {
+ ; CHECK: i32.const [[L2:.+]]=, 16
+ ; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, [[L2]]
+ %r = alloca i64
+ %r2 = alloca i64
+ ; %r is at SP+8
+ ; CHECK: i32.const [[OFF:.+]]=, 8
+ ; CHECK-NEXT: i32.add [[ARG1:.+]]=, [[SP]], [[OFF]]
+ ; CHECK-NEXT: call ext_func at FUNCTION, [[ARG1]]
+ call void @ext_func(i64* %r)
+ ; %r2 is at SP+0, no add needed
+ ; CHECK-NEXT: call ext_func at FUNCTION, [[SP]]
+ call void @ext_func(i64* %r2)
+ ret void
+}
+
 ; CHECK-LABEL: allocarray_inbounds:
 ; CHECK: .local i32, i32, i32, i32{{$}}
 define void @allocarray_inbounds() {
Index: lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
+++ lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
@@ -81,15 +81,18 @@
     auto &MRI = MF.getRegInfo();
     const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
 
-    unsigned OffsetReg = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
-    BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(WebAssembly::CONST_I32),
-            OffsetReg)
-        .addImm(FrameOffset);
-    BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(WebAssembly::ADD_I32),
-            OffsetReg)
-        .addReg(WebAssembly::SP32)
-        .addReg(OffsetReg);
-    MI.getOperand(FIOperandNum).ChangeToRegister(OffsetReg, /*IsDef=*/false);
+    unsigned FIRegOperand = WebAssembly::SP32;
+    if (FrameOffset) {
+      FIRegOperand = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
+      BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(WebAssembly::CONST_I32),
+              FIRegOperand)
+          .addImm(FrameOffset);
+      BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(WebAssembly::ADD_I32),
+              FIRegOperand)
+          .addReg(WebAssembly::SP32)
+          .addReg(FIRegOperand);
+    }
+    MI.getOperand(FIOperandNum).ChangeToRegister(FIRegOperand, /*IsDef=*/false);
   }
 }
 
Index: lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
+++ lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
@@ -158,6 +158,7 @@
   BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::CONST_I32), OffsetReg)
       .addImm(StackSize);
   auto *SPSymbol = MF.createExternalSymbolName("__stack_pointer");
+  // TODO: Fold this add into the const offset field of the store.
   BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::ADD_I32), WebAssembly::SP32)
       .addReg(WebAssembly::SP32)
       .addReg(OffsetReg);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16554.45904.patch
Type: text/x-patch
Size: 2901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160125/853f343d/attachment.bin>


More information about the llvm-commits mailing list