[PATCH] D146569: [WebAssembly] Fix epilogue insertion for indirect tail calls

Thomas Lively via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 09:28:57 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd0bbae5efa4: [WebAssembly] Fix epilogue insertion for indirect tail calls (authored by tlively).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146569/new/

https://reviews.llvm.org/D146569

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
  llvm/test/CodeGen/WebAssembly/tailcall.ll


Index: llvm/test/CodeGen/WebAssembly/tailcall.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/tailcall.ll
+++ llvm/test/CodeGen/WebAssembly/tailcall.ll
@@ -507,6 +507,43 @@
   ret i32 %v
 }
 
+; Checks that epilogues are inserted after return calls.
+define i32 @direct_epilogue() {
+; CHECK-LABEL: direct_epilogue:
+; CHECK:         .functype direct_epilogue () -> (i32)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:    global.get $push0=, __stack_pointer
+; CHECK-NEXT:    i32.const $push1=, 256
+; CHECK-NEXT:    i32.sub $push5=, $pop0, $pop1
+; CHECK-NEXT:    local.tee $push4=, $0=, $pop5
+; CHECK-NEXT:    global.set __stack_pointer, $pop4
+; CHECK-NEXT:    i32.const $push2=, 256
+; CHECK-NEXT:    i32.add $push3=, $0, $pop2
+; CHECK-NEXT:    global.set __stack_pointer, $pop3
+; CHECK-NEXT:    return_call direct_epilogue
+  %a = alloca [64 x i32]
+  %v = musttail call i32 @direct_epilogue()
+  ret i32 %v
+}
+
+define i32 @indirect_epilogue(ptr %p) {
+; CHECK-LABEL: indirect_epilogue:
+; CHECK:         .functype indirect_epilogue (i32) -> (i32)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:    global.get $push0=, __stack_pointer
+; CHECK-NEXT:    i32.const $push1=, 256
+; CHECK-NEXT:    i32.sub $push5=, $pop0, $pop1
+; CHECK-NEXT:    local.tee $push4=, $1=, $pop5
+; CHECK-NEXT:    global.set __stack_pointer, $pop4
+; CHECK-NEXT:    i32.const $push2=, 256
+; CHECK-NEXT:    i32.add $push3=, $1, $pop2
+; CHECK-NEXT:    global.set __stack_pointer, $pop3
+; CHECK-NEXT:    return_call_indirect , $0, $0
+  %a = alloca [64 x i32]
+  %v = musttail call i32 %p(ptr %p)
+  ret i32 %v
+}
+
 ; Check that the signatures generated for external indirectly
 ; return-called functions include the proper return types
 
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
@@ -73,7 +73,7 @@
     "return_call    \t$callee", "return_call\t$callee", 0x12>,
   Requires<[HasTailCall]>;
 
-let isReturn = 1 in
+let isReturn = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in
 defm RET_CALL_INDIRECT :
   I<(outs), (ins TypeIndex:$type, table32_op:$table, variable_ops),
     (outs), (ins TypeIndex:$type, table32_op:$table), [],


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146569.507396.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230322/845686b9/attachment.bin>


More information about the llvm-commits mailing list