[llvm] dd0bbae - [WebAssembly] Fix epilogue insertion for indirect tail calls
Thomas Lively via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 22 09:28:54 PDT 2023
Author: Thomas Lively
Date: 2023-03-22T09:28:48-07:00
New Revision: dd0bbae5efa4d23322eda905b2f9e11dfd3c5d36
URL: https://github.com/llvm/llvm-project/commit/dd0bbae5efa4d23322eda905b2f9e11dfd3c5d36
DIFF: https://github.com/llvm/llvm-project/commit/dd0bbae5efa4d23322eda905b2f9e11dfd3c5d36.diff
LOG: [WebAssembly] Fix epilogue insertion for indirect tail calls
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.
Differential Revision: https://reviews.llvm.org/D146569
Added:
Modified:
llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
llvm/test/CodeGen/WebAssembly/tailcall.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
index 6a123f8f4030f..ca9a5ef9dda1c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td
@@ -73,7 +73,7 @@ defm RET_CALL :
"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), [],
diff --git a/llvm/test/CodeGen/WebAssembly/tailcall.ll b/llvm/test/CodeGen/WebAssembly/tailcall.ll
index 34dd0a9a424b6..84bd142462e37 100644
--- a/llvm/test/CodeGen/WebAssembly/tailcall.ll
+++ b/llvm/test/CodeGen/WebAssembly/tailcall.ll
@@ -507,6 +507,43 @@ define i32 @stack_arg_cast(i32 %x) {
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
More information about the llvm-commits
mailing list