[llvm] d91c9ae - [WebAssembly] Select call_indirect for alloca calls
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 29 12:47:15 PDT 2023
Author: Heejin Ahn
Date: 2023-03-29T12:46:58-07:00
New Revision: d91c9aef9b37924b2188b88fc1091f0926e6158d
URL: https://github.com/llvm/llvm-project/commit/d91c9aef9b37924b2188b88fc1091f0926e6158d
DIFF: https://github.com/llvm/llvm-project/commit/d91c9aef9b37924b2188b88fc1091f0926e6158d.diff
LOG: [WebAssembly] Select call_indirect for alloca calls
Currently calling stack locations is selected using `CALL` in ISel,
resulting in an invalid code and crashing in AsmPrinter. FastISel
correctly selects it will `CALL_INDIRECT`.
Fixes the problem reported in D146781.
Reviewed By: tlively, HerrCai0907
Differential Revision: https://reviews.llvm.org/D147033
Added:
Modified:
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/test/CodeGen/WebAssembly/call-indirect.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 32d0b01cb90e8..4fd753b54d882 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -534,11 +534,12 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
assert(CallResults.getOpcode() == WebAssembly::CALL_RESULTS ||
CallResults.getOpcode() == WebAssembly::RET_CALL_RESULTS);
- bool IsIndirect = CallParams.getOperand(0).isReg();
+ bool IsIndirect =
+ CallParams.getOperand(0).isReg() || CallParams.getOperand(0).isFI();
bool IsRetCall = CallResults.getOpcode() == WebAssembly::RET_CALL_RESULTS;
bool IsFuncrefCall = false;
- if (IsIndirect) {
+ if (IsIndirect && CallParams.getOperand(0).isReg()) {
Register Reg = CallParams.getOperand(0).getReg();
const MachineFunction *MF = BB->getParent();
const MachineRegisterInfo &MRI = MF->getRegInfo();
diff --git a/llvm/test/CodeGen/WebAssembly/call-indirect.ll b/llvm/test/CodeGen/WebAssembly/call-indirect.ll
index b88d0965a0d53..8d79d9320b76a 100644
--- a/llvm/test/CodeGen/WebAssembly/call-indirect.ll
+++ b/llvm/test/CodeGen/WebAssembly/call-indirect.ll
@@ -18,6 +18,22 @@ define void @call_indirect_void(ptr %callee) {
ret void
}
+; CHECK-LABEL: call_indirect_alloca:
+; CHECK-NEXT: .functype call_indirect_alloca () -> ()
+; CHECK: local.tee 0
+; CHECK-NEXT: global.set __stack_pointer
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: i32.const 12
+; CHECK-NEXT: i32.add
+; REF: call_indirect __indirect_function_table, () -> ()
+; NOREF: call_indirect () -> ()
+define void @call_indirect_alloca() {
+entry:
+ %ptr = alloca i32, align 4
+ call void %ptr()
+ ret void
+}
+
; OBJ: Imports:
; OBJ-NEXT: - Module: env
; OBJ-NEXT: Field: __linear_memory
@@ -25,5 +41,10 @@ define void @call_indirect_void(ptr %callee) {
; OBJ-NEXT: Memory:
; OBJ-NEXT: Minimum: 0x0
; OBJ-NEXT: - Module: env
+; OBJ-NEXT: Field: __stack_pointer
+; OBJ-NEXT: Kind: GLOBAL
+; OBJ-NEXT: GlobalType: I32
+; OBJ-NEXT: GlobalMutable: true
+; OBJ-NEXT: - Module: env
; OBJ-NEXT: Field: __indirect_function_table
; OBJ-NEXT: Kind: TABLE
More information about the llvm-commits
mailing list