[PATCH] D147033: [WebAssembly] Select call_indirect for alloca calls

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 28 01:08:25 PDT 2023


aheejin created this revision.
aheejin added reviewers: tlively, HerrCai0907.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: All.
aheejin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 <https://reviews.llvm.org/D146781>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147033

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/test/CodeGen/WebAssembly/call-indirect.ll


Index: llvm/test/CodeGen/WebAssembly/call-indirect.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/call-indirect.ll
+++ llvm/test/CodeGen/WebAssembly/call-indirect.ll
@@ -18,6 +18,22 @@
   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 @@
 ; 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
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -534,11 +534,12 @@
   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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147033.508924.patch
Type: text/x-patch
Size: 2205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230328/2294069f/attachment.bin>


More information about the llvm-commits mailing list