[llvm] 95ac931 - [WebAssembly] Prevent FastISel from trying to select funcref calls (#178742)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 30 12:05:20 PST 2026
Author: Demetrius Kanios
Date: 2026-01-30T12:05:15-08:00
New Revision: 95ac9314dfa5bf3c8281848184648fbb7bd052f7
URL: https://github.com/llvm/llvm-project/commit/95ac9314dfa5bf3c8281848184648fbb7bd052f7
DIFF: https://github.com/llvm/llvm-project/commit/95ac9314dfa5bf3c8281848184648fbb7bd052f7.diff
LOG: [WebAssembly] Prevent FastISel from trying to select funcref calls (#178742)
Before, Wasm FastISel treated all indirect calls the same, causing
miscompilations at O0 when trying to call a funcref (`call ptr
addrspace(20)`), as it would treat the funcref as a normal `ptr`
This adds a check so it falls back to ISelDAG when encountering calls
outside addrspace 0 (which covers direct calls and indirect calls
through normal function pointers).
Related: #140933
Added:
Modified:
llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/test/CodeGen/WebAssembly/funcref-call.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 2aef3217f5e19..f4860e21e310e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
+#include "Utils/WasmAddressSpaces.h"
#include "Utils/WebAssemblyTypeUtilities.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySubtarget.h"
@@ -772,6 +773,11 @@ bool WebAssemblyFastISel::fastLowerArguments() {
bool WebAssemblyFastISel::selectCall(const Instruction *I) {
const auto *Call = cast<CallInst>(I);
+ // FastISel does not support calls through funcref
+ if (Call->getCalledOperand()->getType()->getPointerAddressSpace() !=
+ WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_DEFAULT)
+ return false;
+
// TODO: Support tail calls in FastISel
if (Call->isMustTailCall() || Call->isInlineAsm() ||
Call->getFunctionType()->isVarArg())
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-call.ll b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
index c4eb425244450..9904df2280e81 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
More information about the llvm-commits
mailing list