[PATCH] D146569: [WebAssembly] Fix epilogue insertion for indirect tail calls
Thomas Lively via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 14:47:42 PDT 2023
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, jgravelle-google, sbc100.
Herald added a project: All.
tlively requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Previously epilogues were incorrectly inserted after indirect tail calls because
they did not have the `isTerminator` property. Add that property and test that
they get correct epilogues. To be safe, also add other properties that were
defined for direct tail calls.
Repository:
rG LLVM Github Monorepo
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.507130.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230321/90175710/attachment.bin>
More information about the llvm-commits
mailing list