From: Heejin Ahn Date: Tue, 28 Mar 2023 08:01:21 +0000 (-0700) Subject: [WebAssembly] Select call_indirect for alloca calls X-Git-Tag: upstream/17.0.6~13281 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d91c9aef9b37924b2188b88fc1091f0926e6158d;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index 32d0b01..4fd753b 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 b88d096..8d79d93 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