[clang] [llvm] [WebAssembly] Change to 64-bit table indices on Wasm64 (PR #180649)
Demetrius Kanios via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 14:47:21 PDT 2026
https://github.com/QuantumSegfault updated https://github.com/llvm/llvm-project/pull/180649
>From f7e6d2bd9660dd8ca513269d0027aea7c0228147 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Mon, 9 Feb 2026 15:53:40 -0800
Subject: [PATCH 1/5] Make all tables and table related operations use 64-bit
indices on Wasm64
---
.../CodeGen/TargetBuiltins/WebAssembly.cpp | 30 +++--
.../WebAssembly/builtins-table-externref.c | 111 ++++++++++++-----
.../WebAssembly/builtins-table-funcref.c | 113 ++++++++++++------
llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 36 +++---
.../Utils/WebAssemblyTypeUtilities.cpp | 5 +-
.../Utils/WebAssemblyTypeUtilities.h | 2 +-
.../WebAssembly/WebAssemblyAsmPrinter.cpp | 2 +-
.../WebAssembly/WebAssemblyISelDAGToDAG.cpp | 17 +--
.../WebAssembly/WebAssemblyISelLowering.cpp | 30 +++--
.../WebAssembly/WebAssemblyInstrTable.td | 72 +++++++----
.../WebAssembly/WebAssemblyMCInstLower.cpp | 5 +-
.../WebAssembly/WebAssemblyUtilities.cpp | 14 ++-
.../CodeGen/WebAssembly/externref-tableget.ll | 66 +++++-----
.../CodeGen/WebAssembly/externref-tableset.ll | 75 +++++++-----
llvm/test/CodeGen/WebAssembly/funcref-call.ll | 95 ++++++++++-----
.../CodeGen/WebAssembly/funcref-table_call.ll | 36 +++---
.../CodeGen/WebAssembly/funcref-tableget.ll | 80 +++++++------
.../CodeGen/WebAssembly/funcref-tableset.ll | 82 ++++++++-----
.../test/CodeGen/WebAssembly/ref-test-func.ll | 9 --
llvm/test/CodeGen/WebAssembly/table-copy.ll | 24 ++--
llvm/test/CodeGen/WebAssembly/table-fill.ll | 12 +-
llvm/test/CodeGen/WebAssembly/table-grow.ll | 12 +-
llvm/test/CodeGen/WebAssembly/table-size.ll | 14 ++-
llvm/test/CodeGen/WebAssembly/table-types.ll | 1 +
llvm/test/MC/WebAssembly/tables.ll | 72 +++++++++++
25 files changed, 663 insertions(+), 352 deletions(-)
create mode 100644 llvm/test/MC/WebAssembly/tables.ll
diff --git a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
index edaba6e5998fc..079f282976d83 100644
--- a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
@@ -595,9 +595,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Value *Index = EmitScalarExpr(E->getArg(1));
Function *Callee;
if (E->getType().isWebAssemblyExternrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_get_externref);
+ Callee = CGM.getIntrinsic(Intrinsic::wasm_table_get_externref,
+ Index->getType());
else if (E->getType().isWebAssemblyFuncrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_get_funcref);
+ Callee =
+ CGM.getIntrinsic(Intrinsic::wasm_table_get_funcref, Index->getType());
else
llvm_unreachable(
"Unexpected reference type for __builtin_wasm_table_get");
@@ -610,9 +612,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Value *Val = EmitScalarExpr(E->getArg(2));
Function *Callee;
if (E->getArg(2)->getType().isWebAssemblyExternrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_set_externref);
+ Callee = CGM.getIntrinsic(Intrinsic::wasm_table_set_externref,
+ Index->getType());
else if (E->getArg(2)->getType().isWebAssemblyFuncrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_set_funcref);
+ Callee =
+ CGM.getIntrinsic(Intrinsic::wasm_table_set_funcref, Index->getType());
else
llvm_unreachable(
"Unexpected reference type for __builtin_wasm_table_set");
@@ -620,8 +624,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
}
case WebAssembly::BI__builtin_wasm_table_size: {
assert(E->getArg(0)->getType()->isArrayType());
+ llvm::Type *ResultType = ConvertType(E->getType());
Value *Value = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this);
- Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_table_size);
+ Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_table_size, ResultType);
return Builder.CreateCall(Callee, Value);
}
case WebAssembly::BI__builtin_wasm_table_grow: {
@@ -632,9 +637,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Function *Callee;
if (E->getArg(1)->getType().isWebAssemblyExternrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_externref);
+ Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_externref,
+ NElems->getType());
else if (E->getArg(1)->getType().isWebAssemblyFuncrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_funcref);
+ Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_funcref,
+ NElems->getType());
else
llvm_unreachable(
"Unexpected reference type for __builtin_wasm_table_grow");
@@ -650,9 +657,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Function *Callee;
if (E->getArg(2)->getType().isWebAssemblyExternrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_externref);
+ Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_externref,
+ Index->getType());
else if (E->getArg(2)->getType().isWebAssemblyFuncrefType())
- Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_funcref);
+ Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_funcref,
+ Index->getType());
else
llvm_unreachable(
"Unexpected reference type for __builtin_wasm_table_fill");
@@ -667,7 +676,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Value *SrcIdx = EmitScalarExpr(E->getArg(3));
Value *NElems = EmitScalarExpr(E->getArg(4));
- Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_table_copy);
+ Function *Callee =
+ CGM.getIntrinsic(Intrinsic::wasm_table_copy, DstIdx->getType());
return Builder.CreateCall(Callee, {TableX, TableY, SrcIdx, DstIdx, NElems});
}
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
index 7600a53ba3aa2..80856ea1c410c 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -1,17 +1,26 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
-// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM32
+// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM64
// REQUIRES: webassembly-registered-target
+typedef __SIZE_TYPE__ size_t;
+
static __externref_t table[0];
static const __externref_t const_table[0];
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT: ret ptr addrspace(10) [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT: ret ptr addrspace(10) [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
+// WASM64-NEXT: ret ptr addrspace(10) [[TMP0]]
//
-__externref_t test_builtin_wasm_table_get(int index) {
+__externref_t test_builtin_wasm_table_get(size_t index) {
return __builtin_wasm_table_get(table, index);
}
@@ -37,6 +46,22 @@ void test_builtin_wasm_table_set(const int index, __externref_t ref) {
return __builtin_wasm_table_set(table, index, ref);
}
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(10) [[REF]])
+// WASM64-NEXT: ret void
+//
+void test_builtin_wasm_table_set(size_t index, __externref_t ref) {
+ return __builtin_wasm_table_set(table, index, ref);
+}
+
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
@@ -49,44 +74,68 @@ void test_builtin_wasm_table_set_const(const int index, const __externref_t ref)
return __builtin_wasm_table_set(const_table, index, ref);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// CHECK-SAME: () #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.size(ptr addrspace(1) @table)
-// CHECK-NEXT: ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM32-SAME: () #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.size.i32(ptr addrspace(1) @table)
+// WASM32-NEXT: ret i32 [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM64-SAME: () #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call i64 @llvm.wasm.table.size.i64(ptr addrspace(1) @table)
+// WASM64-NEXT: ret i64 [[TMP0]]
//
-int test_builtin_wasm_table_size() {
+size_t test_builtin_wasm_table_size() {
return __builtin_wasm_table_size(table);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// CHECK-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM32-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i32(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret i32 [[TMP0]]
//
-int test_builtin_wasm_table_grow(__externref_t ref, int nelem) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM64-SAME: (ptr addrspace(10) [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i64(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT: ret i32 [[TMP0]]
+//
+int test_builtin_wasm_table_grow(__externref_t ref, size_t nelem) {
return __builtin_wasm_table_grow(table, ref, nelem);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.fill.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.fill.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(10) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT: ret void
//
-void test_builtin_wasm_table_fill(int index, __externref_t ref, int nelem) {
+void test_builtin_wasm_table_fill(size_t index, __externref_t ref, size_t nelem) {
__builtin_wasm_table_fill(table, index, ref, nelem);
}
static __externref_t other_table[0];
-// CHECK-LABEL: define {{[^@]+}}@test_table_copy
-// CHECK-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.copy(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_table_copy
+// WASM32-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.copy.i32(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_table_copy
+// WASM64-SAME: (i64 noundef [[DST_IDX:%.*]], i64 noundef [[SRC_IDX:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.copy.i64(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i64 [[SRC_IDX]], i64 [[DST_IDX]], i64 [[NELEM]])
+// WASM64-NEXT: ret void
//
-void test_table_copy(int dst_idx, int src_idx, int nelem) {
+void test_table_copy(size_t dst_idx, size_t src_idx, size_t nelem) {
__builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem);
}
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
index b4f729669a795..95a5265bd480d 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
@@ -1,69 +1,108 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
-// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM32
+// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefixes=WASM64
// REQUIRES: webassembly-registered-target
+typedef __SIZE_TYPE__ size_t;
+
typedef void (*__funcref funcref_t)();
static funcref_t table[0];
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT: ret ptr addrspace(20) [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
+// WASM64-NEXT: ret ptr addrspace(20) [[TMP0]]
//
-funcref_t test_builtin_wasm_table_get(int index) {
+funcref_t test_builtin_wasm_table_get(size_t index) {
return __builtin_wasm_table_get(table, index);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.set.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]])
+// WASM32-NEXT: ret void
//
-void test_builtin_wasm_table_set(int index, funcref_t ref) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.set.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(20) [[REF]])
+// WASM64-NEXT: ret void
+//
+void test_builtin_wasm_table_set(size_t index, funcref_t ref) {
return __builtin_wasm_table_set(table, index, ref);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// CHECK-SAME: () #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.size(ptr addrspace(1) @table)
-// CHECK-NEXT: ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM32-SAME: () #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.size.i32(ptr addrspace(1) @table)
+// WASM32-NEXT: ret i32 [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM64-SAME: () #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call i64 @llvm.wasm.table.size.i64(ptr addrspace(1) @table)
+// WASM64-NEXT: ret i64 [[TMP0]]
//
-int test_builtin_wasm_table_size() {
+size_t test_builtin_wasm_table_size() {
return __builtin_wasm_table_size(table);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// CHECK-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM32-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i32(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret i32 [[TMP0]]
//
-int test_builtin_wasm_table_grow(funcref_t ref, int nelem) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM64-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i64(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT: ret i32 [[TMP0]]
+//
+int test_builtin_wasm_table_grow(funcref_t ref, size_t nelem) {
return __builtin_wasm_table_grow(table, ref, nelem);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.fill.funcref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.fill.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.fill.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(20) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT: ret void
//
-void test_builtin_wasm_table_fill(int index, funcref_t ref, int nelem) {
+void test_builtin_wasm_table_fill(size_t index, funcref_t ref, size_t nelem) {
__builtin_wasm_table_fill(table, index, ref, nelem);
}
static funcref_t other_table[0];
-// CHECK-LABEL: define {{[^@]+}}@test_table_copy
-// CHECK-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.copy(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_table_copy
+// WASM32-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.copy.i32(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_table_copy
+// WASM64-SAME: (i64 noundef [[DST_IDX:%.*]], i64 noundef [[SRC_IDX:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.copy.i64(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i64 [[SRC_IDX]], i64 [[DST_IDX]], i64 [[NELEM]])
+// WASM64-NEXT: ret void
//
-void test_table_copy(int dst_idx, int src_idx, int nelem) {
+void test_table_copy(size_t dst_idx, size_t src_idx, size_t nelem) {
__builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem);
}
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index c1e4b97e96bc8..6272099059ea9 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -51,53 +51,53 @@ def int_wasm_ref_test_func
// Table intrinsics
//===----------------------------------------------------------------------===//
def int_wasm_table_set_externref :
- DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_i32_ty, llvm_externref_ty],
+ DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_anyint_ty, llvm_externref_ty],
[IntrWriteMem]>;
def int_wasm_table_set_funcref :
- DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_i32_ty, llvm_funcref_ty],
+ DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_anyint_ty, llvm_funcref_ty],
[IntrWriteMem]>;
def int_wasm_table_set_exnref :
- DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_i32_ty, llvm_exnref_ty],
+ DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_anyint_ty, llvm_exnref_ty],
[IntrWriteMem]>;
def int_wasm_table_get_externref :
- DefaultAttrsIntrinsic<[llvm_externref_ty], [llvm_table_ty, llvm_i32_ty],
+ DefaultAttrsIntrinsic<[llvm_externref_ty], [llvm_table_ty, llvm_anyint_ty],
[IntrReadMem]>;
def int_wasm_table_get_funcref :
- DefaultAttrsIntrinsic<[llvm_funcref_ty], [llvm_table_ty, llvm_i32_ty],
+ DefaultAttrsIntrinsic<[llvm_funcref_ty], [llvm_table_ty, llvm_anyint_ty],
[IntrReadMem]>;
def int_wasm_table_get_exnref :
- DefaultAttrsIntrinsic<[llvm_exnref_ty], [llvm_table_ty, llvm_i32_ty],
+ DefaultAttrsIntrinsic<[llvm_exnref_ty], [llvm_table_ty, llvm_anyint_ty],
[IntrReadMem]>;
// Query the current table size, and increase the current table size.
def int_wasm_table_size :
- DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_table_ty], [IntrReadMem]>;
+ DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_table_ty], [IntrReadMem]>;
def int_wasm_table_copy :
DefaultAttrsIntrinsic<[],
- [llvm_table_ty, llvm_table_ty, llvm_i32_ty, llvm_i32_ty,
- llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_table_ty, llvm_anyint_ty, LLVMMatchType<0>,
+ LLVMMatchType<0>], []>;
def int_wasm_table_grow_externref :
DefaultAttrsIntrinsic<[llvm_i32_ty],
- [llvm_table_ty, llvm_externref_ty, llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_externref_ty, llvm_anyint_ty], []>;
def int_wasm_table_grow_funcref :
DefaultAttrsIntrinsic<[llvm_i32_ty],
- [llvm_table_ty, llvm_funcref_ty, llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_funcref_ty, llvm_anyint_ty], []>;
def int_wasm_table_grow_exnref :
DefaultAttrsIntrinsic<[llvm_i32_ty],
- [llvm_table_ty, llvm_exnref_ty, llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_exnref_ty, llvm_anyint_ty], []>;
def int_wasm_table_fill_externref :
DefaultAttrsIntrinsic<[],
- [llvm_table_ty, llvm_i32_ty, llvm_externref_ty,
- llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_anyint_ty, llvm_externref_ty,
+ LLVMMatchType<0>], []>;
def int_wasm_table_fill_funcref :
DefaultAttrsIntrinsic<[],
- [llvm_table_ty, llvm_i32_ty, llvm_funcref_ty,
- llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_anyint_ty, llvm_funcref_ty,
+ LLVMMatchType<0>], []>;
def int_wasm_table_fill_exnref :
DefaultAttrsIntrinsic<[],
- [llvm_table_ty, llvm_i32_ty, llvm_exnref_ty,
- llvm_i32_ty], []>;
+ [llvm_table_ty, llvm_anyint_ty, llvm_exnref_ty,
+ LLVMMatchType<0>], []>;
//===----------------------------------------------------------------------===//
// Trapping float-to-int conversions
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
index f9293460e701a..41d2be90b8ec0 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
@@ -67,7 +67,7 @@ wasm::ValType WebAssembly::toValType(MVT Type) {
}
void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
- ArrayRef<MVT> VTs) {
+ ArrayRef<MVT> VTs, bool Is64) {
assert(!Sym->getType());
// Tables are represented as Arrays in LLVM IR therefore
@@ -91,7 +91,8 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
if (IsTable) {
Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
- Sym->setTableType(ValTy);
+ Sym->setTableType(ValTy, Is64 ? wasm::WASM_LIMITS_FLAG_IS_64
+ : wasm::WASM_LIMITS_FLAG_NONE);
} else {
Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(ValTy), /*Mutable=*/true});
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
index 87660947e7de1..cc3c1ea3e5999 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -60,7 +60,7 @@ wasm::ValType toValType(MVT Type);
/// Sets a Wasm Symbol Type.
void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
- ArrayRef<MVT> VTs);
+ ArrayRef<MVT> VTs, bool Addr64);
} // end namespace WebAssembly
} // end namespace llvm
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index edea99e629407..94b933ee117c4 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -206,7 +206,7 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
computeLegalValueVTs(TLI, GV->getParent()->getContext(),
GV->getDataLayout(), GlobalVT, VTs);
- WebAssembly::wasmSymbolSetType(Sym, GlobalVT, VTs);
+ WebAssembly::wasmSymbolSetType(Sym, GlobalVT, VTs, ST->hasAddr64());
}
emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration());
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
index 4a63be7ce9e34..b361c04021b6d 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
@@ -284,17 +284,12 @@ void WebAssemblyDAGToDAGISel::Select(SDNode *Node) {
MF.getContext(), Subtarget);
SDValue TableSym = CurDAG->getMCSymbol(Table, PtrVT);
SDValue FuncPtr = Node->getOperand(1);
- if (Subtarget->hasAddr64() && FuncPtr.getValueType() == MVT::i64) {
- // table.get expects an i32 but on 64 bit platforms the function pointer
- // is an i64. In that case, i32.wrap_i64 to convert.
- FuncPtr = SDValue(CurDAG->getMachineNode(WebAssembly::I32_WRAP_I64, DL,
- MVT::i32, FuncPtr),
- 0);
- }
- SDValue FuncRef =
- SDValue(CurDAG->getMachineNode(WebAssembly::TABLE_GET_FUNCREF, DL,
- MVT::funcref, TableSym, FuncPtr),
- 0);
+ SDValue FuncRef = SDValue(
+ CurDAG->getMachineNode(Subtarget->hasAddr64()
+ ? WebAssembly::TABLE_GET_FUNCREF_A64
+ : WebAssembly::TABLE_GET_FUNCREF_A32,
+ DL, MVT::funcref, TableSym, FuncPtr),
+ 0);
// Encode the signature information into the type index placeholder.
// This gets decoded and converted into the actual type signature in
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index a0c5e2f5d2639..2c931ff7731b3 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -833,10 +833,15 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
// (the index in
// __funcref_call_table is added).
if (IsFuncrefCall) {
- Register RegZero =
- MF.getRegInfo().createVirtualRegister(&WebAssembly::I32RegClass);
+ Register RegZero = MF.getRegInfo().createVirtualRegister(
+ Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
+ : &WebAssembly::I32RegClass);
MachineInstrBuilder MIBC0 =
- BuildMI(MF, DL, TII.get(WebAssembly::CONST_I32), RegZero).addImm(0);
+ BuildMI(MF, DL,
+ TII.get(Subtarget->hasAddr64() ? WebAssembly::CONST_I64
+ : WebAssembly::CONST_I32),
+ RegZero)
+ .addImm(0);
BB->insert(CallResults.getIterator(), MIBC0);
MachineInstrBuilder(MF, CallParams).addReg(RegZero);
@@ -887,10 +892,15 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
if (IsIndirect && IsFuncrefCall) {
MCSymbolWasm *Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(
MF.getContext(), Subtarget);
- Register RegZero =
- MF.getRegInfo().createVirtualRegister(&WebAssembly::I32RegClass);
+ Register RegZero = MF.getRegInfo().createVirtualRegister(
+ Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
+ : &WebAssembly::I32RegClass);
MachineInstr *Const0 =
- BuildMI(MF, DL, TII.get(WebAssembly::CONST_I32), RegZero).addImm(0);
+ BuildMI(MF, DL,
+ TII.get(Subtarget->hasAddr64() ? WebAssembly::CONST_I64
+ : WebAssembly::CONST_I32),
+ RegZero)
+ .addImm(0);
BB->insertAfter(MIB.getInstr()->getIterator(), Const0);
Register RegFuncref =
@@ -900,7 +910,10 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
BB->insertAfter(Const0->getIterator(), RefNull);
MachineInstr *TableSet =
- BuildMI(MF, DL, TII.get(WebAssembly::TABLE_SET_FUNCREF))
+ BuildMI(MF, DL,
+ TII.get(Subtarget->hasAddr64()
+ ? WebAssembly::TABLE_SET_FUNCREF_A64
+ : WebAssembly::TABLE_SET_FUNCREF_A32))
.addSym(Table)
.addReg(RegZero)
.addReg(RegFuncref);
@@ -1529,7 +1542,8 @@ WebAssemblyTargetLowering::LowerCall(CallLoweringInfo &CLI,
MCSymbolWasm *Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(
MF.getContext(), Subtarget);
SDValue Sym = DAG.getMCSymbol(Table, PtrVT);
- SDValue TableSlot = DAG.getConstant(0, DL, MVT::i32);
+ SDValue TableSlot =
+ DAG.getConstant(0, DL, Subtarget->hasAddr64() ? MVT::i64 : MVT::i32);
SDValue TableSetOps[] = {Chain, Sym, TableSlot, Callee};
SDValue TableSet = DAG.getMemIntrinsicNode(
WebAssemblyISD::TABLE_SET, DL, DAG.getVTList(MVT::Other), TableSetOps,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
index 02f0ab8577c3d..5722e3edc3433 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
@@ -20,67 +20,83 @@ def WebAssemblyTableGet : SDNode<"WebAssemblyISD::TABLE_GET", WebAssemblyTableGe
[SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
-multiclass TABLE<WebAssemblyRegClass rc, string suffix> {
+multiclass TABLE<WebAssemblyRegClass rc, string suffix, WebAssemblyRegClass index_rc, ValueType index_vt, string addrmodesuffix> {
let mayLoad = 1 in
- defm TABLE_GET_#rc : I<(outs rc:$res), (ins table32_op:$table, I32:$i),
+ defm TABLE_GET_#rc#addrmodesuffix : I<(outs rc:$res), (ins table32_op:$table, index_rc:$i),
(outs), (ins table32_op:$table),
- [(set rc:$res, (!cast<Intrinsic>("int_wasm_table_get_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i))],
+ [(set rc:$res, (!cast<Intrinsic>("int_wasm_table_get_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), index_rc:$i))],
"table.get\t$res, $table, $i",
"table.get\t$table",
0x25>;
let mayStore = 1 in
- defm TABLE_SET_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val),
+ defm TABLE_SET_#rc#addrmodesuffix : I<(outs), (ins table32_op:$table, index_rc:$i, rc:$val),
(outs), (ins table32_op:$table),
- [(!cast<Intrinsic>("int_wasm_table_set_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val)],
+ [(!cast<Intrinsic>("int_wasm_table_set_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), index_rc:$i, rc:$val)],
"table.set\t$table, $i, $val",
"table.set\t$table",
0x26>;
- defm TABLE_GROW_#rc : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, I32:$n),
+ defm TABLE_GROW_#rc#addrmodesuffix : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, index_rc:$n),
(outs), (ins table32_op:$table),
- [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, I32:$n))],
+ [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, index_rc:$n))],
"table.grow\t$sz, $table, $val, $n",
"table.grow\t$table",
0xfc0f>;
- defm TABLE_FILL_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val, I32:$n),
+ defm TABLE_FILL_#rc#addrmodesuffix : I<(outs), (ins table32_op:$table, index_rc:$i, rc:$val, index_rc:$n),
(outs), (ins table32_op:$table),
- [(!cast<Intrinsic>("int_wasm_table_fill_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val, I32:$n)],
+ [(!cast<Intrinsic>("int_wasm_table_fill_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), index_rc:$i, rc:$val, index_rc:$n)],
"table.fill\t$table, $i, $val, $n",
"table.fill\t$table",
0xfc11>;
foreach vt = rc.RegTypes in {
- def : Pat<(vt (WebAssemblyTableGet (WebAssemblyWrapper tglobaladdr:$table), i32:$idx)),
- (!cast<NI>("TABLE_GET_" # rc) tglobaladdr:$table, i32:$idx)>;
+ def : Pat<(vt (WebAssemblyTableGet (WebAssemblyWrapper tglobaladdr:$table), index_vt:$idx)),
+ (!cast<NI>("TABLE_GET_" # rc # addrmodesuffix) tglobaladdr:$table, index_vt:$idx)>;
def : Pat<(WebAssemblyTableSet
(WebAssemblyWrapper tglobaladdr:$table),
- i32:$idx,
+ index_vt:$idx,
vt:$src),
- (!cast<NI>("TABLE_SET_" # rc) tglobaladdr:$table, i32:$idx, vt:$src)>;
+ (!cast<NI>("TABLE_SET_" # rc # addrmodesuffix) tglobaladdr:$table, index_vt:$idx, vt:$src)>;
}
}
-defm "" : TABLE<FUNCREF, "funcref">, Requires<[HasReferenceTypes]>;
-defm "" : TABLE<EXTERNREF, "externref">, Requires<[HasReferenceTypes]>;
-defm "" : TABLE<EXNREF, "exnref">,
- Requires<[HasReferenceTypes, HasExceptionHandling]>;
+defm "" : TABLE<FUNCREF, "funcref", I32, i32, "_A32">, Requires<[HasReferenceTypes, HasAddr32]>;
+defm "" : TABLE<EXTERNREF, "externref", I32, i32, "_A32">, Requires<[HasReferenceTypes, HasAddr32]>;
+defm "" : TABLE<EXNREF, "exnref", I32, i32, "_A32">,
+ Requires<[HasReferenceTypes, HasExceptionHandling, HasAddr32]>;
+
+defm "" : TABLE<FUNCREF, "funcref", I64, i64, "_A64">, Requires<[HasReferenceTypes, HasAddr64]>;
+defm "" : TABLE<EXTERNREF, "externref", I64, i64, "_A64">, Requires<[HasReferenceTypes, HasAddr64]>;
+defm "" : TABLE<EXNREF, "exnref", I64, i64, "_A64">,
+ Requires<[HasReferenceTypes, HasExceptionHandling, HasAddr64]>;
def : Pat<(WebAssemblyTableSet mcsym:$table, i32:$idx, funcref:$r),
- (TABLE_SET_FUNCREF mcsym:$table, i32:$idx, funcref:$r)>,
- Requires<[HasReferenceTypes]>;
+ (TABLE_SET_FUNCREF_A32 mcsym:$table, i32:$idx, funcref:$r)>,
+ Requires<[HasReferenceTypes, HasAddr32]>;
+
+def : Pat<(WebAssemblyTableSet mcsym:$table, i64:$idx, funcref:$r),
+ (TABLE_SET_FUNCREF_A64 mcsym:$table, i64:$idx, funcref:$r)>,
+ Requires<[HasReferenceTypes, HasAddr64]>;
-defm TABLE_SIZE : I<(outs I32:$sz), (ins table32_op:$table),
+defm TABLE_SIZE_A32 : I<(outs I32:$sz), (ins table32_op:$table),
(outs), (ins table32_op:$table),
[(set I32:$sz, (int_wasm_table_size (WebAssemblyWrapper tglobaladdr:$table)))],
"table.size\t$sz, $table",
"table.size\t$table",
0xfc10>,
- Requires<[HasReferenceTypes]>;
+ Requires<[HasReferenceTypes, HasAddr32]>;
+defm TABLE_SIZE_A64 : I<(outs I64:$sz), (ins table32_op:$table),
+ (outs), (ins table32_op:$table),
+ [(set I64:$sz, (int_wasm_table_size (WebAssemblyWrapper tglobaladdr:$table)))],
+ "table.size\t$sz, $table",
+ "table.size\t$table",
+ 0xfc10>,
+ Requires<[HasReferenceTypes, HasAddr64]>;
-defm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n),
+defm TABLE_COPY_A32 : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n),
(outs), (ins table32_op:$table1, table32_op:$table2),
[(int_wasm_table_copy (WebAssemblyWrapper tglobaladdr:$table1),
(WebAssemblyWrapper tglobaladdr:$table2),
@@ -88,4 +104,14 @@ defm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d,
"table.copy\t$table1, $table2, $d, $s, $n",
"table.copy\t$table1, $table2",
0xfc0e>,
- Requires<[HasReferenceTypes]>;
+ Requires<[HasReferenceTypes, HasAddr32]>;
+
+defm TABLE_COPY_A64 : I<(outs), (ins table32_op:$table1, table32_op:$table2, I64:$d, I64:$s, I64:$n),
+ (outs), (ins table32_op:$table1, table32_op:$table2),
+ [(int_wasm_table_copy (WebAssemblyWrapper tglobaladdr:$table1),
+ (WebAssemblyWrapper tglobaladdr:$table2),
+ I64:$d, I64:$s, I64:$n)],
+ "table.copy\t$table1, $table2, $d, $s, $n",
+ "table.copy\t$table1, $table2",
+ 0xfc0e>,
+ Requires<[HasReferenceTypes, HasAddr64]>;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index e48283aadb437..8aa51ed5accb2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -20,6 +20,7 @@
#include "Utils/WebAssemblyTypeUtilities.h"
#include "WebAssemblyAsmPrinter.h"
#include "WebAssemblyMachineFunctionInfo.h"
+#include "WebAssemblySubtarget.h"
#include "WebAssemblyUtilities.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallVector.h"
@@ -65,7 +66,9 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
SmallVector<MVT, 1> VTs;
computeLegalValueVTs(CurrentFunc, TM, GlobalVT, VTs);
- WebAssembly::wasmSymbolSetType(WasmSym, GlobalVT, VTs);
+ WebAssembly::wasmSymbolSetType(
+ WasmSym, GlobalVT, VTs,
+ TM.getSubtarget<WebAssemblySubtarget>(CurrentFunc).hasAddr64());
}
return WasmSym;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
index 890486778e700..8dac20472a4a8 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
@@ -14,6 +14,7 @@
#include "WebAssemblyUtilities.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblyTargetMachine.h"
+#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IR/Function.h"
#include "llvm/MC/MCContext.h"
@@ -109,9 +110,10 @@ MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol(
if (!Sym->isFunctionTable())
Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
} else {
- bool is64 = Subtarget && Subtarget->getTargetTriple().isArch64Bit();
+ bool Is64 = Subtarget ? Subtarget->hasAddr64()
+ : Ctx.getTargetTriple().isArch64Bit();
Sym = static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(Name));
- Sym->setFunctionTable(is64);
+ Sym->setFunctionTable(Is64);
// The default function table is synthesized by the linker.
}
// MVP object files can't have symtab entries for tables.
@@ -134,7 +136,13 @@ MCSymbolWasm *WebAssembly::getOrCreateFuncrefCallTableSymbol(
// modules define the table.
Sym->setWeak(true);
- wasm::WasmLimits Limits = {0, 1, 1, 0};
+ bool Is64 = Subtarget ? Subtarget->hasAddr64()
+ : Ctx.getTargetTriple().isArch64Bit();
+
+ wasm::WasmLimits Limits = {(uint8_t)(Is64 ? wasm::WASM_LIMITS_FLAG_IS_64
+ : wasm::WASM_LIMITS_FLAG_NONE),
+ 1, 1, 0};
+
wasm::WasmTableType TableType = {wasm::ValType::FUNCREF, Limits};
Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
Sym->setTableType(TableType);
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
index d9ae7c8f6c9b1..506e1dd694461 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
@@ -1,71 +1,81 @@
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), i32) nounwind
+declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), iX) nounwind
-define %externref @get_externref_from_table(i32 %i) {
+define %externref @get_externref_from_table(iX %i) {
; CHECK-LABEL: get_externref_from_table:
-; CHECK-NEXT: .functype get_externref_from_table (i32) -> (externref)
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.get externref_table
-; CHECK-NEXT: end_function
- %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %i)
+; WASM32-NEXT: .functype get_externref_from_table (i32) -> (externref)
+; WASM64-NEXT: .functype get_externref_from_table (i64) -> (externref)
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.get externref_table
+; CHECK-NEXT: end_function
+ %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %i)
ret %externref %ref
}
define %externref @get_externref_from_table_const() {
; CHECK-LABEL: get_externref_from_table_const:
; CHECK-NEXT: .functype get_externref_from_table_const () -> (externref)
-; CHECK-NEXT: i32.const 0
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
- %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 0)
+ %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX 0)
ret %externref %ref
}
-define %externref @get_externref_from_table_with_offset(i32 %i) {
+define %externref @get_externref_from_table_with_offset(iX %i) {
; CHECK-LABEL: get_externref_from_table_with_offset:
-; CHECK-NEXT: .functype get_externref_from_table_with_offset (i32) -> (externref)
+; WASM32-NEXT: .functype get_externref_from_table_with_offset (i32) -> (externref)
+; WASM64-NEXT: .functype get_externref_from_table_with_offset (i64) -> (externref)
; CHECK-NEXT: local.get 0
-; CHECK-NEXT: i32.const 2
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.const 2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const 2
+; WASM64-NEXT: i64.add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
- %off = add nsw i32 %i, 2
- %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %off)
+ %off = add nsw iX %i, 2
+ %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %off)
ret %externref %ref
}
-define %externref @get_externref_from_table_with_var_offset(i32 %i, i32 %j) {
+define %externref @get_externref_from_table_with_var_offset(iX %i, iX %j) {
; CHECK-LABEL: get_externref_from_table_with_var_offset:
-; CHECK-NEXT: .functype get_externref_from_table_with_var_offset (i32, i32) -> (externref)
+; WASM32-NEXT: .functype get_externref_from_table_with_var_offset (i32, i32) -> (externref)
+; WASM64-NEXT: .functype get_externref_from_table_with_var_offset (i64, i64) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
- %off = add nsw i32 %i, %j
- %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %off)
+ %off = add nsw iX %i, %j
+ %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %off)
ret %externref %ref
}
-declare i32 @get_offset()
+declare iX @get_offset()
-define %externref @get_externref_from_table_with_var_offset2(i32 %i) {
+define %externref @get_externref_from_table_with_var_offset2(iX %i) {
; CHECK-LABEL: get_externref_from_table_with_var_offset2:
-; CHECK-NEXT: .functype get_externref_from_table_with_var_offset2 (i32) -> (externref)
+; WASM32-NEXT: .functype get_externref_from_table_with_var_offset2 (i32) -> (externref)
+; WASM64-NEXT: .functype get_externref_from_table_with_var_offset2 (i64) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: call get_offset
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
- %j = call i32 @get_offset()
- %off = add nsw i32 %i, %j
- %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %off)
+ %j = call iX @get_offset()
+ %off = add nsw iX %i, %j
+ %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %off)
ret %externref %ref
}
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
index 37c663869428e..9a1b29bbab28e 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
@@ -1,81 +1,92 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare void @llvm.wasm.table.set.externref(ptr addrspace(1), i32, %externref) nounwind
+declare void @llvm.wasm.table.set.externref(ptr addrspace(1), iX, %externref) nounwind
-define void @set_externref_table(%externref %g, i32 %i) {
+define void @set_externref_table(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table:
-; CHECK-NEXT: .functype set_externref_table (externref, i32) -> ()
-; CHECK-NEXT: local.get 1
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.set externref_table
-; CHECK-NEXT: end_function
+; WASM32-NEXT: .functype set_externref_table (externref, i32) -> ()
+; WASM64-NEXT: .functype set_externref_table (externref, i64) -> ()
+; CHECK-NEXT: local.get 1
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set externref_table
+; CHECK-NEXT: end_function
;; this generates a table.set of @externref_table
- call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %i, %externref %g)
+ call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %i, %externref %g)
ret void
}
define void @set_externref_table_const(%externref %g) {
; CHECK-LABEL: set_externref_table_const:
; CHECK-NEXT: .functype set_externref_table_const (externref) -> ()
-; CHECK-NEXT: i32.const 0
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
- call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 0, %externref %g)
+ call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX 0, %externref %g)
ret void
}
-define void @set_externref_table_with_offset(%externref %g, i32 %i) {
+define void @set_externref_table_with_offset(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table_with_offset:
-; CHECK-NEXT: .functype set_externref_table_with_offset (externref, i32) -> ()
+; WASM32-NEXT: .functype set_externref_table_with_offset (externref, i32) -> ()
+; WASM64-NEXT: .functype set_externref_table_with_offset (externref, i64) -> ()
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: i32.const 2
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.const 2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const 2
+; WASM64-NEXT: i64.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
- %off = add nsw i32 %i, 2
- call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
+ %off = add nsw iX %i, 2
+ call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %off, %externref %g)
ret void
}
-define void @set_externref_table_with_var_offset(%externref %g, i32 %i, i32 %j) {
+define void @set_externref_table_with_var_offset(%externref %g, iX %i, iX %j) {
; CHECK-LABEL: set_externref_table_with_var_offset:
-; CHECK-NEXT: .functype set_externref_table_with_var_offset (externref, i32, i32) -> ()
+; WASM32-NEXT: .functype set_externref_table_with_var_offset (externref, i32, i32) -> ()
+; WASM64-NEXT: .functype set_externref_table_with_var_offset (externref, i64, i64) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
- %off = add nsw i32 %i, %j
- call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
+ %off = add nsw iX %i, %j
+ call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %off, %externref %g)
ret void
}
-declare i32 @set_offset()
+declare iX @set_offset()
-define void @set_externref_table_with_var_offset2(%externref %g, i32 %i) {
+define void @set_externref_table_with_var_offset2(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table_with_var_offset2:
-; CHECK-NEXT: .functype set_externref_table_with_var_offset2 (externref, i32) -> ()
+; WASM32-NEXT: .functype set_externref_table_with_var_offset2 (externref, i32) -> ()
+; WASM64-NEXT: .functype set_externref_table_with_var_offset2 (externref, i64) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: call set_offset
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
- %j = call i32 @set_offset()
- %off = add nsw i32 %i, %j
- call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
+ %j = call iX @set_offset()
+ %off = add nsw iX %i, %j
+ call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %off, %externref %g)
ret void
}
-declare i32 @get_table_slot() local_unnamed_addr
+declare iX @get_table_slot() local_unnamed_addr
define void @set_externref_table_with_id_from_call(%externref %g) {
; CHECK-LABEL: set_externref_table_with_id_from_call:
@@ -84,8 +95,8 @@ define void @set_externref_table_with_id_from_call(%externref %g) {
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
- %id = call i32 @get_table_slot()
- call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %id, %externref %g)
+ %id = call iX @get_table_slot()
+ call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %id, %externref %g)
ret void
}
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-call.ll b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
index 9904df2280e81..3fdbcdc491a76 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,46 +1,79 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; 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
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM32
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM64
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
; CHECK: .tabletype __funcref_call_table, funcref, 1
define void @call_funcref(%funcref %ref) {
-; CHECK-LABEL: call_funcref:
-; CHECK: .functype call_funcref (funcref) -> ()
-; CHECK-NEXT: # %bb.0:
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: ref.null_func
-; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: # fallthrough-return
+; WASM32-LABEL: call_funcref:
+; WASM32: .functype call_funcref (funcref) -> ()
+; WASM32-NEXT: # %bb.0:
+; WASM32-NEXT: i32.const 0
+; WASM32-NEXT: local.get 0
+; WASM32-NEXT: table.set __funcref_call_table
+; WASM32-NEXT: i32.const 0
+; WASM32-NEXT: call_indirect __funcref_call_table, () -> ()
+; WASM32-NEXT: i32.const 0
+; WASM32-NEXT: ref.null_func
+; WASM32-NEXT: table.set __funcref_call_table
+; WASM32-NEXT: # fallthrough-return
+;
+; WASM64-LABEL: call_funcref:
+; WASM64: .functype call_funcref (funcref) -> ()
+; WASM64-NEXT: # %bb.0:
+; WASM64-NEXT: i64.const 0
+; WASM64-NEXT: local.get 0
+; WASM64-NEXT: table.set __funcref_call_table
+; WASM64-NEXT: i64.const 0
+; WASM64-NEXT: call_indirect __funcref_call_table, () -> ()
+; WASM64-NEXT: i64.const 0
+; WASM64-NEXT: ref.null_func
+; WASM64-NEXT: table.set __funcref_call_table
+; WASM64-NEXT: # fallthrough-return
call addrspace(20) void %ref()
ret void
}
define float @call_funcref_with_args(%funcref %ref) {
-; CHECK-LABEL: call_funcref_with_args:
-; CHECK: .functype call_funcref_with_args (funcref) -> (f32)
-; CHECK-NEXT: .local f32
-; CHECK-NEXT: # %bb.0:
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: f64.const 0x1p0
-; CHECK-NEXT: i32.const 2
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: call_indirect __funcref_call_table, (f64, i32) -> (f32)
-; CHECK-NEXT: local.set 1
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: ref.null_func
-; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: local.get 1
-; CHECK-NEXT: # fallthrough-return
+; WASM32-LABEL: call_funcref_with_args:
+; WASM32: .functype call_funcref_with_args (funcref) -> (f32)
+; WASM32-NEXT: .local f32
+; WASM32-NEXT: # %bb.0:
+; WASM32-NEXT: i32.const 0
+; WASM32-NEXT: local.get 0
+; WASM32-NEXT: table.set __funcref_call_table
+; WASM32-NEXT: f64.const 0x1p0
+; WASM32-NEXT: i32.const 2
+; WASM32-NEXT: i32.const 0
+; WASM32-NEXT: call_indirect __funcref_call_table, (f64, i32) -> (f32)
+; WASM32-NEXT: local.set 1
+; WASM32-NEXT: i32.const 0
+; WASM32-NEXT: ref.null_func
+; WASM32-NEXT: table.set __funcref_call_table
+; WASM32-NEXT: local.get 1
+; WASM32-NEXT: # fallthrough-return
+;
+; WASM64-LABEL: call_funcref_with_args:
+; WASM64: .functype call_funcref_with_args (funcref) -> (f32)
+; WASM64-NEXT: .local f32
+; WASM64-NEXT: # %bb.0:
+; WASM64-NEXT: i64.const 0
+; WASM64-NEXT: local.get 0
+; WASM64-NEXT: table.set __funcref_call_table
+; WASM64-NEXT: f64.const 0x1p0
+; WASM64-NEXT: i32.const 2
+; WASM64-NEXT: i64.const 0
+; WASM64-NEXT: call_indirect __funcref_call_table, (f64, i32) -> (f32)
+; WASM64-NEXT: local.set 1
+; WASM64-NEXT: i64.const 0
+; WASM64-NEXT: ref.null_func
+; WASM64-NEXT: table.set __funcref_call_table
+; WASM64-NEXT: local.get 1
+; WASM64-NEXT: # fallthrough-return
%ret = call addrspace(20) float %ref(double 1.0, i32 2)
ret float %ret
}
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index 74bbc802ac077..a2421c1c6ff3a 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
@@ -1,4 +1,5 @@
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -6,26 +7,29 @@
; CHECK: .tabletype __funcref_call_table, funcref, 1
-declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind
+declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
-define void @call_funcref_from_table(i32 %i) {
+define void @call_funcref_from_table(iX %i) {
; CHECK-LABEL: call_funcref_from_table:
-; CHECK-NEXT: .functype call_funcref_from_table (i32) -> ()
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.get funcref_table
-; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
-; CHECK-NEXT: i32.const 0
-; CHECK-NEXT: ref.null_func
-; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: end_function
- %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %i)
+; WASM32-NEXT: .functype call_funcref_from_table (i32) -> ()
+; WASM64-NEXT: .functype call_funcref_from_table (i64) -> ()
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.get funcref_table
+; CHECK-NEXT: table.set __funcref_call_table
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: ref.null_func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: end_function
+ %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %i)
call addrspace(20) void %ref()
ret void
}
; CHECK: .tabletype funcref_table, funcref
; CHECK-LABEL: funcref_table:
-
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
index 3df308c5ddf80..8c8e4fdc4d5f2 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
@@ -1,71 +1,81 @@
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
-declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind
+declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
-define %funcref @get_funcref_from_table(i32 %i) {
+define %funcref @get_funcref_from_table(iX %i) {
; CHECK-LABEL: get_funcref_from_table:
-; CHECK-NEXT: .functype get_funcref_from_table (i32) -> (funcref)
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.get funcref_table
-; CHECK-NEXT: end_function
- %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %i)
+; WASM32-NEXT: .functype get_funcref_from_table (i32) -> (funcref)
+; WASM64-NEXT: .functype get_funcref_from_table (i64) -> (funcref)
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.get funcref_table
+; CHECK-NEXT: end_function
+ %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %i)
ret %funcref %ref
}
define %funcref @get_funcref_from_table_const() {
; CHECK-LABEL: get_funcref_from_table_const:
; CHECK-NEXT: .functype get_funcref_from_table_const () -> (funcref)
-; CHECK-NEXT: i32.const 0
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
- %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 0)
+ %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX 0)
ret %funcref %ref
}
-define %funcref @get_funcref_from_table_with_offset(i32 %i) {
+define %funcref @get_funcref_from_table_with_offset(iX %i) {
; CHECK-LABEL: get_funcref_from_table_with_offset:
-; CHECK-NEXT: .functype get_funcref_from_table_with_offset (i32) -> (funcref)
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: i32.const 2
-; CHECK-NEXT: i32.add
-; CHECK-NEXT: table.get funcref_table
-; CHECK-NEXT: end_function
- %off = add nsw i32 %i, 2
- %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
+; WASM32-NEXT: .functype get_funcref_from_table_with_offset (i32) -> (funcref)
+; WASM64-NEXT: .functype get_funcref_from_table_with_offset (i64) -> (funcref)
+; CHECK-NEXT: local.get 0
+; WASM32-NEXT: i32.const 2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const 2
+; WASM64-NEXT: i64.add
+; CHECK-NEXT: table.get funcref_table
+; CHECK-NEXT: end_function
+ %off = add nsw iX %i, 2
+ %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %off)
ret %funcref %ref
}
-define %funcref @get_funcref_from_table_with_var_offset(i32 %i, i32 %j) {
+define %funcref @get_funcref_from_table_with_var_offset(iX %i, iX %j) {
; CHECK-LABEL: get_funcref_from_table_with_var_offset:
-; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: local.get 1
-; CHECK-NEXT: i32.add
-; CHECK-NEXT: table.get funcref_table
-; CHECK-NEXT: end_function
- %off = add nsw i32 %i, %j
- %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
+; WASM32-NEXT: .functype get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
+; WASM64-NEXT: .functype get_funcref_from_table_with_var_offset (i64, i64) -> (funcref)
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: local.get 1
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
+; CHECK-NEXT: table.get funcref_table
+; CHECK-NEXT: end_function
+ %off = add nsw iX %i, %j
+ %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %off)
ret %funcref %ref
}
-declare i32 @get_offset()
+declare iX @get_offset()
-define %funcref @get_funcref_from_table_with_var_offset2(i32 %i) {
+define %funcref @get_funcref_from_table_with_var_offset2(iX %i) {
; CHECK-LABEL: get_funcref_from_table_with_var_offset2:
-; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
+; WASM32-NEXT: .functype get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
+; WASM64-NEXT: .functype get_funcref_from_table_with_var_offset2 (i64) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: call get_offset
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
- %j = call i32 @get_offset()
- %off = add nsw i32 %i, %j
- %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
+ %j = call iX @get_offset()
+ %off = add nsw iX %i, %j
+ %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %off)
ret %funcref %ref
}
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
index 98e1b55613d7d..897d1b704e28b 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -1,77 +1,101 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
-declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), i32, %funcref) nounwind
+declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), iX, %funcref) nounwind
-define void @set_funcref_table(%funcref %g, i32 %i) {
+define void @set_funcref_table(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table:
-; CHECK-NEXT: .functype set_funcref_table (funcref, i32) -> ()
-; CHECK-NEXT: local.get 1
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.set funcref_table
-; CHECK-NEXT: end_function
+; WASM32-NEXT: .functype set_funcref_table (funcref, i32) -> ()
+; WASM64-NEXT: .functype set_funcref_table (funcref, i64) -> ()
+; CHECK-NEXT: local.get 1
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set funcref_table
+; CHECK-NEXT: end_function
;; this generates a table.set of @funcref_table
- call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %i, %funcref %g)
+ call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %i, %funcref %g)
ret void
}
define void @set_funcref_table_const(%funcref %g) {
; CHECK-LABEL: set_funcref_table_const:
; CHECK-NEXT: .functype set_funcref_table_const (funcref) -> ()
-; CHECK-NEXT: i32.const 0
+; WASM32-NEXT: i32.const 0
+; WASM64-NEXT: i64.const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
- call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 0, %funcref %g)
+ call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX 0, %funcref %g)
ret void
}
-define void @set_funcref_table_with_offset(%funcref %g, i32 %i) {
+define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table_with_offset:
-; CHECK-NEXT: .functype set_funcref_table_with_offset (funcref, i32) -> ()
+; WASM32-NEXT: .functype set_funcref_table_with_offset (funcref, i32) -> ()
+; WASM64-NEXT: .functype set_funcref_table_with_offset (funcref, i64) -> ()
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: i32.const 2
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.const 2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const 2
+; WASM64-NEXT: i64.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
- %off = add nsw i32 %i, 2
- call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
+ %off = add nsw iX %i, 2
+ call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %off, %funcref %g)
ret void
}
-define void @set_funcref_table_with_var_offset(%funcref %g, i32 %i, i32 %j) {
+define void @set_funcref_table_with_var_offset(%funcref %g, iX %i, iX %j) {
; CHECK-LABEL: set_funcref_table_with_var_offset:
-; CHECK-NEXT: .functype set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
+; WASM32-NEXT: .functype set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
+; WASM64-NEXT: .functype set_funcref_table_with_var_offset (funcref, i64, i64) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
- %off = add nsw i32 %i, %j
- call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
+ %off = add nsw iX %i, %j
+ call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %off, %funcref %g)
ret void
}
-declare i32 @set_offset()
+declare iX @set_offset()
-define void @set_funcref_table_with_var_offset2(%funcref %g, i32 %i) {
+define void @set_funcref_table_with_var_offset2(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table_with_var_offset2:
-; CHECK-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, i32) -> ()
+; WASM32-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, i32) -> ()
+; WASM64-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, i64) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: call set_offset
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set funcref_table
+; CHECK-NEXT: end_function
+ %j = call iX @set_offset()
+ %off = add nsw iX %i, %j
+ call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %off, %funcref %g)
+ ret void
+}
+
+declare iX @get_table_slot() local_unnamed_addr
+
+define void @set_funcref_table_with_id_from_call(%funcref %g) {
+; CHECK-LABEL: set_funcref_table_with_id_from_call:
+; CHECK-NEXT: .functype set_funcref_table_with_id_from_call (funcref) -> ()
+; CHECK-NEXT: call get_table_slot
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
- %j = call i32 @set_offset()
- %off = add nsw i32 %i, %j
- call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
+ %id = call iX @get_table_slot()
+ call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %id, %funcref %g)
ret void
}
diff --git a/llvm/test/CodeGen/WebAssembly/ref-test-func.ll b/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
index 4fda253d39fe3..db100736a3423 100644
--- a/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
+++ b/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
@@ -8,7 +8,6 @@ define void @test_fpsig_void_void(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_void_void (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test () -> ()
; CHECK-NEXT: call use
@@ -25,7 +24,6 @@ define void @test_fpsig_return_i32(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_return_i32 (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test () -> (i32)
; CHECK-NEXT: call use
@@ -42,7 +40,6 @@ define void @test_fpsig_return_i64(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_return_i64 (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test () -> (i64)
; CHECK-NEXT: call use
@@ -59,7 +56,6 @@ define void @test_fpsig_return_f32(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_return_f32 (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test () -> (f32)
; CHECK-NEXT: call use
@@ -76,7 +72,6 @@ define void @test_fpsig_return_f64(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_return_f64 (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test () -> (f64)
; CHECK-NEXT: call use
@@ -94,7 +89,6 @@ define void @test_fpsig_param_i32(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_param_i32 (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test (f64) -> ()
; CHECK-NEXT: call use
@@ -112,7 +106,6 @@ define void @test_fpsig_multiple_params_and_returns(ptr noundef %func) local_unn
; CHK64: .functype test_fpsig_multiple_params_and_returns (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test (i64, f32, i64) -> (i32, i64, f32, f64)
; CHECK-NEXT: call use
@@ -130,7 +123,6 @@ define void @test_fpsig_ptrs(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_fpsig_ptrs (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHK32-NEXT: ref.test (i32, i32) -> (i32)
; CHK64-NEXT: ref.test (i64, i64) -> (i64)
@@ -148,7 +140,6 @@ define void @test_reference_types(ptr noundef %func) local_unnamed_addr #0 {
; CHK64: .functype test_reference_types (i64) -> ()
; CHECK-NEXT: # %bb.0: # %entry
; CHECK-NEXT: local.get 0
-; CHK64-NEXT: i32.wrap_i64
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: ref.test (funcref, externref) -> (externref)
; CHECK-NEXT: call use
diff --git a/llvm/test/CodeGen/WebAssembly/table-copy.ll b/llvm/test/CodeGen/WebAssembly/table-copy.ll
index 5c0647ada4ab0..fee5cfb9da3ac 100644
--- a/llvm/test/CodeGen/WebAssembly/table-copy.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-copy.ll
@@ -1,37 +1,41 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table1 = local_unnamed_addr addrspace(1) global [0 x %externref] undef
@externref_table2 = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), i32, i32, i32) nounwind readonly
+declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), iX, iX, iX) nounwind readonly
-define void @table_copy(i32 %dst, i32 %src, i32 %len) {
+define void @table_copy(iX %dst, iX %src, iX %len) {
; CHECK-LABEL: table_copy:
-; CHECK-NEXT: .functype table_copy (i32, i32, i32) -> ()
+; WASM32-NEXT: .functype table_copy (i32, i32, i32) -> ()
+; WASM64-NEXT: .functype table_copy (i64, i64, i64) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
; CHECK-NEXT: table.copy externref_table1, externref_table2
; CHECK-NEXT: end_function
- call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table2, i32 %dst, i32 %src, i32 %len)
+ call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table2, iX %dst, iX %src, iX %len)
ret void
}
; Testing copying from a table to itself at different offsets
; Copies len items from table1 at src to table1 at src+off
-define void @self_table_copy(i32 %src, i32 %off, i32 %len) {
+define void @self_table_copy(iX %src, iX %off, iX %len) {
; CHECK-LABEL: self_table_copy:
-; CHECK-NEXT: .functype self_table_copy (i32, i32, i32) -> ()
+; WASM32-NEXT: .functype self_table_copy (i32, i32, i32) -> ()
+; WASM64-NEXT: .functype self_table_copy (i64, i64, i64) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 2
; CHECK-NEXT: table.copy externref_table1, externref_table1
; CHECK-NEXT: end_function
- %dst = add nsw i32 %src, %off
- call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table1, i32 %dst, i32 %src, i32 %len)
+ %dst = add nsw iX %src, %off
+ call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table1, iX %dst, iX %src, iX %len)
ret void
}
diff --git a/llvm/test/CodeGen/WebAssembly/table-fill.ll b/llvm/test/CodeGen/WebAssembly/table-fill.ll
index 0b78124f038b1..3fdf315bede68 100644
--- a/llvm/test/CodeGen/WebAssembly/table-fill.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-fill.ll
@@ -1,19 +1,21 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), i32, %externref, i32) nounwind readonly
+declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), iX, %externref, iX) nounwind readonly
-define void @table_fill(i32 %start, i32 %len, %externref %val) {
+define void @table_fill(iX %start, iX %len, %externref %val) {
; CHECK-LABEL: table_fill:
-; CHECK-NEXT: .functype table_fill (i32, i32, externref) -> ()
+; WASM32-NEXT: .functype table_fill (i32, i32, externref) -> ()
+; WASM64-NEXT: .functype table_fill (i64, i64, externref) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 2
; CHECK-NEXT: local.get 1
; CHECK-NEXT: table.fill externref_table
; CHECK-NEXT: end_function
- call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @externref_table, i32 %start, %externref %val, i32 %len)
+ call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @externref_table, iX %start, %externref %val, iX %len)
ret void
}
diff --git a/llvm/test/CodeGen/WebAssembly/table-grow.ll b/llvm/test/CodeGen/WebAssembly/table-grow.ll
index 614c3400a782b..7ddc1d84e6dba 100644
--- a/llvm/test/CodeGen/WebAssembly/table-grow.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-grow.ll
@@ -1,20 +1,22 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare i32 @llvm.wasm.table.grow.externref(ptr addrspace(1), %externref, i32) nounwind readonly
+declare i32 @llvm.wasm.table.grow.externref(ptr addrspace(1), %externref, iX) nounwind readonly
declare %externref @llvm.wasm.ref.null.extern() nounwind readonly
-define i32 @table_grow(i32 %sz) {
+define i32 @table_grow(iX %sz) {
; CHECK-LABEL: table_grow:
-; CHECK-NEXT: .functype table_grow (i32) -> (i32)
+; WASM32-NEXT: .functype table_grow (i32) -> (i32)
+; WASM64-NEXT: .functype table_grow (i64) -> (i32)
; CHECK-NEXT: ref.null_extern
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.grow externref_table
; CHECK-NEXT: end_function
%null = call %externref @llvm.wasm.ref.null.extern()
- %newsz = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @externref_table, %externref %null, i32 %sz)
+ %newsz = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @externref_table, %externref %null, iX %sz)
ret i32 %newsz
}
diff --git a/llvm/test/CodeGen/WebAssembly/table-size.ll b/llvm/test/CodeGen/WebAssembly/table-size.ll
index 42cd2e8a909d7..3b0722a73bb57 100644
--- a/llvm/test/CodeGen/WebAssembly/table-size.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-size.ll
@@ -1,16 +1,18 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare i32 @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
+declare iX @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
-define i32 @table_size() {
+define iX @table_size() {
; CHECK-LABEL: table_size:
-; CHECK-NEXT: .functype table_size () -> (i32)
+; WASM32-NEXT: .functype table_size () -> (i32)
+; WASM64-NEXT: .functype table_size () -> (i64)
; CHECK-NEXT: table.size externref_table
; CHECK-NEXT: end_function
- %sz = call i32 @llvm.wasm.table.size(ptr addrspace(1) @externref_table)
- ret i32 %sz
+ %sz = call iX @llvm.wasm.table.size(ptr addrspace(1) @externref_table)
+ ret iX %sz
}
diff --git a/llvm/test/CodeGen/WebAssembly/table-types.ll b/llvm/test/CodeGen/WebAssembly/table-types.ll
index cb5e54e2af230..209d822af9fa2 100644
--- a/llvm/test/CodeGen/WebAssembly/table-types.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-types.ll
@@ -1,4 +1,5 @@
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
diff --git a/llvm/test/MC/WebAssembly/tables.ll b/llvm/test/MC/WebAssembly/tables.ll
new file mode 100644
index 0000000000000..3ba345f96259c
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/tables.ll
@@ -0,0 +1,72 @@
+; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | obj2yaml | FileCheck --check-prefixes CHECK %s
+; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o - | obj2yaml | FileCheck --check-prefixes CHECK,WASM64 %s
+
+; Ensure that tables generated through `llc` are in the correct address mode
+
+
+%externref = type ptr addrspace(10)
+ at externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
+
+%funcref = type ptr addrspace(20)
+ at funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
+
+; CHECK: --- !WASM
+; CHECK-NEXT: FileHeader:
+; CHECK-NEXT: Version: 0x1
+; CHECK-NEXT: Sections:
+; CHECK-NEXT: - Type: IMPORT
+; CHECK-NEXT: Imports:
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __linear_memory
+; CHECK-NEXT: Kind: MEMORY
+; CHECK-NEXT: Memory:
+; WASM64-NEXT: Flags: [ IS_64 ]
+; CHECK-NEXT: Minimum: 0x0
+; CHECK-NEXT: - Type: TABLE
+; CHECK-NEXT: Tables:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: ElemType: EXTERNREF
+; CHECK-NEXT: Limits:
+; WASM64-NEXT: Flags: [ IS_64 ]
+; CHECK-NEXT: Minimum: 0x0
+; CHECK-NEXT: - Index: 1
+; CHECK-NEXT: ElemType: FUNCREF
+; CHECK-NEXT: Limits:
+; WASM64-NEXT: Flags: [ IS_64 ]
+; CHECK-NEXT: Minimum: 0x0
+; CHECK-NEXT: - Type: CUSTOM
+; CHECK-NEXT: Name: linking
+; CHECK-NEXT: Version: 2
+; CHECK-NEXT: SymbolTable:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Kind: TABLE
+; CHECK-NEXT: Name: externref_table
+; CHECK-NEXT: Flags: [ ]
+; CHECK-NEXT: Table: 0
+; CHECK-NEXT: - Index: 1
+; CHECK-NEXT: Kind: TABLE
+; CHECK-NEXT: Name: funcref_table
+; CHECK-NEXT: Flags: [ ]
+; CHECK-NEXT: Table: 1
+; CHECK-NEXT: - Type: CUSTOM
+; CHECK-NEXT: Name: target_features
+; CHECK-NEXT: Features:
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: bulk-memory
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: bulk-memory-opt
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: call-indirect-overlong
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: multivalue
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: mutable-globals
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: nontrapping-fptoint
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: reference-types
+; CHECK-NEXT: - Prefix: USED
+; CHECK-NEXT: Name: sign-ext
+; WASM64-NEXT: - Prefix: USED
+; WASM64-NEXT: Name: memory64
+; CHECK-NEXT: ...
>From 0e1e3a1ea279b1270fd4380611a1dca5f31cd8d6 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Tue, 10 Feb 2026 16:03:47 -0800
Subject: [PATCH 2/5] Use FileCheck defines instead in manually written tests
---
.../CodeGen/WebAssembly/externref-tableget.ll | 33 +++++++------------
.../CodeGen/WebAssembly/externref-tableset.ll | 31 +++++++----------
.../CodeGen/WebAssembly/funcref-table_call.ll | 16 ++++-----
.../CodeGen/WebAssembly/funcref-tableget.ll | 31 +++++++----------
.../CodeGen/WebAssembly/funcref-tableset.ll | 31 +++++++----------
llvm/test/CodeGen/WebAssembly/table-copy.ll | 13 +++-----
llvm/test/CodeGen/WebAssembly/table-fill.ll | 7 ++--
llvm/test/CodeGen/WebAssembly/table-grow.ll | 7 ++--
llvm/test/CodeGen/WebAssembly/table-size.ll | 7 ++--
9 files changed, 65 insertions(+), 111 deletions(-)
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
index 506e1dd694461..03cb1f4b7fd06 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -9,8 +9,7 @@ declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), iX) nounwind
define %externref @get_externref_from_table(iX %i) {
; CHECK-LABEL: get_externref_from_table:
-; WASM32-NEXT: .functype get_externref_from_table (i32) -> (externref)
-; WASM64-NEXT: .functype get_externref_from_table (i64) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table ([[iPTR]]) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
@@ -21,8 +20,7 @@ define %externref @get_externref_from_table(iX %i) {
define %externref @get_externref_from_table_const() {
; CHECK-LABEL: get_externref_from_table_const:
; CHECK-NEXT: .functype get_externref_from_table_const () -> (externref)
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX 0)
@@ -31,13 +29,10 @@ define %externref @get_externref_from_table_const() {
define %externref @get_externref_from_table_with_offset(iX %i) {
; CHECK-LABEL: get_externref_from_table_with_offset:
-; WASM32-NEXT: .functype get_externref_from_table_with_offset (i32) -> (externref)
-; WASM64-NEXT: .functype get_externref_from_table_with_offset (i64) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table_with_offset ([[iPTR]]) -> (externref)
; CHECK-NEXT: local.get 0
-; WASM32-NEXT: i32.const 2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const 2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].const 2
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, 2
@@ -48,12 +43,10 @@ define %externref @get_externref_from_table_with_offset(iX %i) {
define %externref @get_externref_from_table_with_var_offset(iX %i, iX %j) {
; CHECK-LABEL: get_externref_from_table_with_var_offset:
-; WASM32-NEXT: .functype get_externref_from_table_with_var_offset (i32, i32) -> (externref)
-; WASM64-NEXT: .functype get_externref_from_table_with_var_offset (i64, i64) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table_with_var_offset ([[iPTR]], [[iPTR]]) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, %j
@@ -65,12 +58,10 @@ declare iX @get_offset()
define %externref @get_externref_from_table_with_var_offset2(iX %i) {
; CHECK-LABEL: get_externref_from_table_with_var_offset2:
-; WASM32-NEXT: .functype get_externref_from_table_with_var_offset2 (i32) -> (externref)
-; WASM64-NEXT: .functype get_externref_from_table_with_var_offset2 (i64) -> (externref)
-; CHECK-NEXT: local.get 0
+; CHECK-NEXT: .functype get_externref_from_table_with_var_offset2 ([[iPTR]]) -> (externref)
+; CHECK-NEXT: local.get 0
; CHECK-NEXT: call get_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%j = call iX @get_offset()
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
index 9a1b29bbab28e..05a844a19d55d 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -10,8 +10,7 @@ declare void @llvm.wasm.table.set.externref(ptr addrspace(1), iX, %externref) no
define void @set_externref_table(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table:
-; WASM32-NEXT: .functype set_externref_table (externref, i32) -> ()
-; WASM64-NEXT: .functype set_externref_table (externref, i64) -> ()
+; CHECK-NEXT: .functype set_externref_table (externref, [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
@@ -25,8 +24,7 @@ define void @set_externref_table(%externref %g, iX %i) {
define void @set_externref_table_const(%externref %g) {
; CHECK-LABEL: set_externref_table_const:
; CHECK-NEXT: .functype set_externref_table_const (externref) -> ()
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
@@ -36,13 +34,10 @@ define void @set_externref_table_const(%externref %g) {
define void @set_externref_table_with_offset(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table_with_offset:
-; WASM32-NEXT: .functype set_externref_table_with_offset (externref, i32) -> ()
-; WASM64-NEXT: .functype set_externref_table_with_offset (externref, i64) -> ()
+; CHECK-NEXT: .functype set_externref_table_with_offset (externref, [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
-; WASM32-NEXT: i32.const 2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const 2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].const 2
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
@@ -53,12 +48,10 @@ define void @set_externref_table_with_offset(%externref %g, iX %i) {
define void @set_externref_table_with_var_offset(%externref %g, iX %i, iX %j) {
; CHECK-LABEL: set_externref_table_with_var_offset:
-; WASM32-NEXT: .functype set_externref_table_with_var_offset (externref, i32, i32) -> ()
-; WASM64-NEXT: .functype set_externref_table_with_var_offset (externref, i64, i64) -> ()
+; CHECK-NEXT: .functype set_externref_table_with_var_offset (externref, [[iPTR]], [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
@@ -71,12 +64,10 @@ declare iX @set_offset()
define void @set_externref_table_with_var_offset2(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table_with_var_offset2:
-; WASM32-NEXT: .functype set_externref_table_with_var_offset2 (externref, i32) -> ()
-; WASM64-NEXT: .functype set_externref_table_with_var_offset2 (externref, i64) -> ()
+; CHECK-NEXT: .functype set_externref_table_with_var_offset2 (externref, [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: call set_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index a2421c1c6ff3a..d50bd27c338af 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -11,18 +11,14 @@ declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
define void @call_funcref_from_table(iX %i) {
; CHECK-LABEL: call_funcref_from_table:
-; WASM32-NEXT: .functype call_funcref_from_table (i32) -> ()
-; WASM64-NEXT: .functype call_funcref_from_table (i64) -> ()
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: .functype call_funcref_from_table ([[iPTR]]) -> ()
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: table.set __funcref_call_table
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: ref.null_func
; CHECK-NEXT: table.set __funcref_call_table
; CHECK-NEXT: end_function
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
index 8c8e4fdc4d5f2..1b86e79b13646 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -9,8 +9,7 @@ declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
define %funcref @get_funcref_from_table(iX %i) {
; CHECK-LABEL: get_funcref_from_table:
-; WASM32-NEXT: .functype get_funcref_from_table (i32) -> (funcref)
-; WASM64-NEXT: .functype get_funcref_from_table (i64) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table ([[iPTR]]) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
@@ -21,8 +20,7 @@ define %funcref @get_funcref_from_table(iX %i) {
define %funcref @get_funcref_from_table_const() {
; CHECK-LABEL: get_funcref_from_table_const:
; CHECK-NEXT: .functype get_funcref_from_table_const () -> (funcref)
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX 0)
@@ -31,13 +29,10 @@ define %funcref @get_funcref_from_table_const() {
define %funcref @get_funcref_from_table_with_offset(iX %i) {
; CHECK-LABEL: get_funcref_from_table_with_offset:
-; WASM32-NEXT: .functype get_funcref_from_table_with_offset (i32) -> (funcref)
-; WASM64-NEXT: .functype get_funcref_from_table_with_offset (i64) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table_with_offset ([[iPTR]]) -> (funcref)
; CHECK-NEXT: local.get 0
-; WASM32-NEXT: i32.const 2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const 2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].const 2
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, 2
@@ -48,12 +43,10 @@ define %funcref @get_funcref_from_table_with_offset(iX %i) {
define %funcref @get_funcref_from_table_with_var_offset(iX %i, iX %j) {
; CHECK-LABEL: get_funcref_from_table_with_var_offset:
-; WASM32-NEXT: .functype get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
-; WASM64-NEXT: .functype get_funcref_from_table_with_var_offset (i64, i64) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset ([[iPTR]], [[iPTR]]) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, %j
@@ -65,12 +58,10 @@ declare iX @get_offset()
define %funcref @get_funcref_from_table_with_var_offset2(iX %i) {
; CHECK-LABEL: get_funcref_from_table_with_var_offset2:
-; WASM32-NEXT: .functype get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
-; WASM64-NEXT: .functype get_funcref_from_table_with_var_offset2 (i64) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset2 ([[iPTR]]) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: call get_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%j = call iX @get_offset()
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
index 897d1b704e28b..dd440a5b1c1d6 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -9,8 +9,7 @@ declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), iX, %funcref) nounwi
define void @set_funcref_table(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table:
-; WASM32-NEXT: .functype set_funcref_table (funcref, i32) -> ()
-; WASM64-NEXT: .functype set_funcref_table (funcref, i64) -> ()
+; CHECK-NEXT: .functype set_funcref_table (funcref, [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
@@ -24,8 +23,7 @@ define void @set_funcref_table(%funcref %g, iX %i) {
define void @set_funcref_table_const(%funcref %g) {
; CHECK-LABEL: set_funcref_table_const:
; CHECK-NEXT: .functype set_funcref_table_const (funcref) -> ()
-; WASM32-NEXT: i32.const 0
-; WASM64-NEXT: i64.const 0
+; CHECK-NEXT: [[iPTR]].const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
@@ -35,13 +33,10 @@ define void @set_funcref_table_const(%funcref %g) {
define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table_with_offset:
-; WASM32-NEXT: .functype set_funcref_table_with_offset (funcref, i32) -> ()
-; WASM64-NEXT: .functype set_funcref_table_with_offset (funcref, i64) -> ()
+; CHECK-NEXT: .functype set_funcref_table_with_offset (funcref, [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
-; WASM32-NEXT: i32.const 2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const 2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].const 2
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
@@ -52,12 +47,10 @@ define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
define void @set_funcref_table_with_var_offset(%funcref %g, iX %i, iX %j) {
; CHECK-LABEL: set_funcref_table_with_var_offset:
-; WASM32-NEXT: .functype set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
-; WASM64-NEXT: .functype set_funcref_table_with_var_offset (funcref, i64, i64) -> ()
+; CHECK-NEXT: .functype set_funcref_table_with_var_offset (funcref, [[iPTR]], [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
@@ -70,12 +63,10 @@ declare iX @set_offset()
define void @set_funcref_table_with_var_offset2(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table_with_var_offset2:
-; WASM32-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, i32) -> ()
-; WASM64-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, i64) -> ()
+; CHECK-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, [[iPTR]]) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: call set_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
diff --git a/llvm/test/CodeGen/WebAssembly/table-copy.ll b/llvm/test/CodeGen/WebAssembly/table-copy.ll
index fee5cfb9da3ac..dce33eaa7b367 100644
--- a/llvm/test/CodeGen/WebAssembly/table-copy.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-copy.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -10,8 +10,7 @@ declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), iX, iX, i
define void @table_copy(iX %dst, iX %src, iX %len) {
; CHECK-LABEL: table_copy:
-; WASM32-NEXT: .functype table_copy (i32, i32, i32) -> ()
-; WASM64-NEXT: .functype table_copy (i64, i64, i64) -> ()
+; CHECK-NEXT: .functype table_copy ([[iPTR]], [[iPTR]], [[iPTR]]) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
@@ -25,12 +24,10 @@ define void @table_copy(iX %dst, iX %src, iX %len) {
; Copies len items from table1 at src to table1 at src+off
define void @self_table_copy(iX %src, iX %off, iX %len) {
; CHECK-LABEL: self_table_copy:
-; WASM32-NEXT: .functype self_table_copy (i32, i32, i32) -> ()
-; WASM64-NEXT: .functype self_table_copy (i64, i64, i64) -> ()
+; CHECK-NEXT: .functype self_table_copy ([[iPTR]], [[iPTR]], [[iPTR]]) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT: [[iPTR]].add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 2
; CHECK-NEXT: table.copy externref_table1, externref_table1
diff --git a/llvm/test/CodeGen/WebAssembly/table-fill.ll b/llvm/test/CodeGen/WebAssembly/table-fill.ll
index 3fdf315bede68..2b9f0feb7301f 100644
--- a/llvm/test/CodeGen/WebAssembly/table-fill.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-fill.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -9,8 +9,7 @@ declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), iX, %externref, i
define void @table_fill(iX %start, iX %len, %externref %val) {
; CHECK-LABEL: table_fill:
-; WASM32-NEXT: .functype table_fill (i32, i32, externref) -> ()
-; WASM64-NEXT: .functype table_fill (i64, i64, externref) -> ()
+; CHECK-NEXT: .functype table_fill ([[iPTR]], [[iPTR]], externref) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 2
; CHECK-NEXT: local.get 1
diff --git a/llvm/test/CodeGen/WebAssembly/table-grow.ll b/llvm/test/CodeGen/WebAssembly/table-grow.ll
index 7ddc1d84e6dba..7a043462d247f 100644
--- a/llvm/test/CodeGen/WebAssembly/table-grow.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-grow.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -10,8 +10,7 @@ declare %externref @llvm.wasm.ref.null.extern() nounwind readonly
define i32 @table_grow(iX %sz) {
; CHECK-LABEL: table_grow:
-; WASM32-NEXT: .functype table_grow (i32) -> (i32)
-; WASM64-NEXT: .functype table_grow (i64) -> (i32)
+; CHECK-NEXT: .functype table_grow ([[iPTR]]) -> (i32)
; CHECK-NEXT: ref.null_extern
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.grow externref_table
diff --git a/llvm/test/CodeGen/WebAssembly/table-size.ll b/llvm/test/CodeGen/WebAssembly/table-size.ll
index 3b0722a73bb57..e24f451a7596d 100644
--- a/llvm/test/CodeGen/WebAssembly/table-size.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-size.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -9,8 +9,7 @@ declare iX @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
define iX @table_size() {
; CHECK-LABEL: table_size:
-; WASM32-NEXT: .functype table_size () -> (i32)
-; WASM64-NEXT: .functype table_size () -> (i64)
+; CHECK-NEXT: .functype table_size () -> ([[iPTR]])
; CHECK-NEXT: table.size externref_table
; CHECK-NEXT: end_function
%sz = call iX @llvm.wasm.table.size(ptr addrspace(1) @externref_table)
>From 79ec85dcdf95cae336c8bc2ce067842b31a3a9ef Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Thu, 26 Mar 2026 00:45:40 -0700
Subject: [PATCH 3/5] Use `-DiPTR` in Clang tests.
---
.../WebAssembly/builtins-table-externref.c | 122 ++++++-----------
.../WebAssembly/builtins-table-funcref.c | 124 ++++++++----------
2 files changed, 94 insertions(+), 152 deletions(-)
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
index 80856ea1c410c..7230272cf0cd0 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
-// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM32
-// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM64
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -DiPTR=i32
+// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -DiPTR=i64
// REQUIRES: webassembly-registered-target
typedef __SIZE_TYPE__ size_t;
@@ -8,115 +8,75 @@ typedef __SIZE_TYPE__ size_t;
static __externref_t table[0];
static const __externref_t const_table[0];
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
-// WASM32-NEXT: ret ptr addrspace(10) [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
-// WASM64-NEXT: ret ptr addrspace(10) [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret ptr addrspace(10) [[TMP0]]
//
__externref_t test_builtin_wasm_table_get(size_t index) {
return __builtin_wasm_table_get(table, index);
}
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
+// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
// CHECK-NEXT: ret ptr addrspace(10) [[TMP0]]
//
-__externref_t test_builtin_wasm_table_get_const(const int index) {
+__externref_t test_builtin_wasm_table_get_const(const size_t index) {
return __builtin_wasm_table_get(table, index);
}
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @const_table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], ptr addrspace(10) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], ptr addrspace(10) [[REF]])
// CHECK-NEXT: ret void
//
-void test_builtin_wasm_table_set(const int index, __externref_t ref) {
+void test_builtin_wasm_table_set(const size_t index, __externref_t ref) {
__builtin_wasm_table_set(const_table, index, ref);
return __builtin_wasm_table_set(table, index, ref);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(10) [[REF]])
-// WASM64-NEXT: ret void
-//
-void test_builtin_wasm_table_set(size_t index, __externref_t ref) {
- return __builtin_wasm_table_set(table, index, ref);
-}
-
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @const_table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], ptr addrspace(10) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], ptr addrspace(10) [[REF]])
// CHECK-NEXT: ret void
//
-void test_builtin_wasm_table_set_const(const int index, const __externref_t ref) {
+void test_builtin_wasm_table_set_const(const size_t index, const __externref_t ref) {
__builtin_wasm_table_set(table, index, ref);
return __builtin_wasm_table_set(const_table, index, ref);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// WASM32-SAME: () #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.size.i32(ptr addrspace(1) @table)
-// WASM32-NEXT: ret i32 [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// WASM64-SAME: () #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call i64 @llvm.wasm.table.size.i64(ptr addrspace(1) @table)
-// WASM64-NEXT: ret i64 [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call [[iPTR]] @llvm.wasm.table.size.[[iPTR]](ptr addrspace(1) @table)
+// CHECK-NEXT: ret [[iPTR]] [[TMP0]]
//
size_t test_builtin_wasm_table_size() {
return __builtin_wasm_table_size(table);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// WASM32-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i32(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret i32 [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// WASM64-SAME: (ptr addrspace(10) [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i64(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret i32 [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// CHECK-SAME: (ptr addrspace(10) [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(10) [[REF]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret i32 [[TMP0]]
//
int test_builtin_wasm_table_grow(__externref_t ref, size_t nelem) {
return __builtin_wasm_table_grow(table, ref, nelem);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.fill.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.fill.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(10) [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.fill.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], ptr addrspace(10) [[REF]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret void
//
void test_builtin_wasm_table_fill(size_t index, __externref_t ref, size_t nelem) {
__builtin_wasm_table_fill(table, index, ref, nelem);
@@ -124,17 +84,11 @@ void test_builtin_wasm_table_fill(size_t index, __externref_t ref, size_t nelem)
static __externref_t other_table[0];
-// WASM32-LABEL: define {{[^@]+}}@test_table_copy
-// WASM32-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.copy.i32(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_table_copy
-// WASM64-SAME: (i64 noundef [[DST_IDX:%.*]], i64 noundef [[SRC_IDX:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.copy.i64(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i64 [[SRC_IDX]], i64 [[DST_IDX]], i64 [[NELEM]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_table_copy
+// CHECK-SAME: ([[iPTR]] noundef [[DST_IDX:%.*]], [[iPTR]] noundef [[SRC_IDX:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.copy.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(1) @other_table, [[iPTR]] [[SRC_IDX]], [[iPTR]] [[DST_IDX]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret void
//
void test_table_copy(size_t dst_idx, size_t src_idx, size_t nelem) {
__builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem);
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
index 95a5265bd480d..67508c17caf5b 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
@@ -1,89 +1,83 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
-// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM32
-// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefixes=WASM64
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -DiPTR=i32
+// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -DiPTR=i64
// REQUIRES: webassembly-registered-target
typedef __SIZE_TYPE__ size_t;
typedef void (*__funcref funcref_t)();
static funcref_t table[0];
+static const funcref_t const_table[0];
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
-// WASM32-NEXT: ret ptr addrspace(20) [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
-// WASM64-NEXT: ret ptr addrspace(20) [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]]
//
funcref_t test_builtin_wasm_table_get(size_t index) {
return __builtin_wasm_table_get(table, index);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.set.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]])
-// WASM32-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]]
//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.set.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(20) [[REF]])
-// WASM64-NEXT: ret void
+funcref_t test_builtin_wasm_table_get_const(const size_t index) {
+ return __builtin_wasm_table_get(table, index);
+}
+
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], ptr addrspace(20) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], ptr addrspace(20) [[REF]])
+// CHECK-NEXT: ret void
//
-void test_builtin_wasm_table_set(size_t index, funcref_t ref) {
+void test_builtin_wasm_table_set(const size_t index, funcref_t ref) {
+ __builtin_wasm_table_set(const_table, index, ref);
return __builtin_wasm_table_set(table, index, ref);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// WASM32-SAME: () #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.size.i32(ptr addrspace(1) @table)
-// WASM32-NEXT: ret i32 [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], ptr addrspace(20) [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], ptr addrspace(20) [[REF]])
+// CHECK-NEXT: ret void
//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// WASM64-SAME: () #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call i64 @llvm.wasm.table.size.i64(ptr addrspace(1) @table)
-// WASM64-NEXT: ret i64 [[TMP0]]
+void test_builtin_wasm_table_set_const(const size_t index, const funcref_t ref) {
+ __builtin_wasm_table_set(table, index, ref);
+ return __builtin_wasm_table_set(const_table, index, ref);
+}
+
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call [[iPTR]] @llvm.wasm.table.size.[[iPTR]](ptr addrspace(1) @table)
+// CHECK-NEXT: ret [[iPTR]] [[TMP0]]
//
size_t test_builtin_wasm_table_size() {
return __builtin_wasm_table_size(table);
}
-
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// WASM32-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i32(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret i32 [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// WASM64-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i64(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret i32 [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// CHECK-SAME: (ptr addrspace(20) noundef [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(20) [[REF]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret i32 [[TMP0]]
//
int test_builtin_wasm_table_grow(funcref_t ref, size_t nelem) {
return __builtin_wasm_table_grow(table, ref, nelem);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.fill.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.fill.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(20) [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.fill.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], ptr addrspace(20) [[REF]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret void
//
void test_builtin_wasm_table_fill(size_t index, funcref_t ref, size_t nelem) {
__builtin_wasm_table_fill(table, index, ref, nelem);
@@ -91,17 +85,11 @@ void test_builtin_wasm_table_fill(size_t index, funcref_t ref, size_t nelem) {
static funcref_t other_table[0];
-// WASM32-LABEL: define {{[^@]+}}@test_table_copy
-// WASM32-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.copy.i32(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_table_copy
-// WASM64-SAME: (i64 noundef [[DST_IDX:%.*]], i64 noundef [[SRC_IDX:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.copy.i64(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i64 [[SRC_IDX]], i64 [[DST_IDX]], i64 [[NELEM]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_table_copy
+// CHECK-SAME: ([[iPTR]] noundef [[DST_IDX:%.*]], [[iPTR]] noundef [[SRC_IDX:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.copy.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(1) @other_table, [[iPTR]] [[SRC_IDX]], [[iPTR]] [[DST_IDX]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret void
//
void test_table_copy(size_t dst_idx, size_t src_idx, size_t nelem) {
__builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem);
>From cc9abf7ef23cd4a71259274987db1472ec5e3ef7 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Sun, 29 Mar 2026 23:53:23 -0700
Subject: [PATCH 4/5] Fix undef
---
llvm/test/MC/WebAssembly/tables.ll | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/MC/WebAssembly/tables.ll b/llvm/test/MC/WebAssembly/tables.ll
index 3ba345f96259c..a5685e096591d 100644
--- a/llvm/test/MC/WebAssembly/tables.ll
+++ b/llvm/test/MC/WebAssembly/tables.ll
@@ -5,10 +5,10 @@
%externref = type ptr addrspace(10)
- at externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
+ at externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] []
%funcref = type ptr addrspace(20)
- at funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
+ at funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] []
; CHECK: --- !WASM
; CHECK-NEXT: FileHeader:
>From 84b28657cea04ddcf09c1dc9477680fd21a34bca Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Mon, 30 Mar 2026 13:49:22 -0700
Subject: [PATCH 5/5] Use sed tmpfile for FileCheck instead of DiPTR, and fix
`wasm.grow`
---
.../WebAssembly/builtins-table-externref.c | 6 +-
.../WebAssembly/builtins-table-funcref.c | 6 +-
llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 12 +--
.../WebAssembly/WebAssemblyInstrTable.td | 4 +-
.../CodeGen/WebAssembly/externref-tableget.ll | 22 ++---
.../CodeGen/WebAssembly/externref-tableset.ll | 22 ++---
llvm/test/CodeGen/WebAssembly/funcref-call.ll | 97 +++++++------------
.../CodeGen/WebAssembly/funcref-table_call.ll | 12 +--
.../CodeGen/WebAssembly/funcref-tableget.ll | 22 ++---
.../CodeGen/WebAssembly/funcref-tableset.ll | 22 ++---
llvm/test/CodeGen/WebAssembly/table-copy.ll | 10 +-
llvm/test/CodeGen/WebAssembly/table-fill.ll | 6 +-
llvm/test/CodeGen/WebAssembly/table-grow.ll | 14 +--
llvm/test/CodeGen/WebAssembly/table-size.ll | 6 +-
14 files changed, 115 insertions(+), 146 deletions(-)
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
index 7230272cf0cd0..ac7224bb44cd7 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -65,10 +65,10 @@ size_t test_builtin_wasm_table_size() {
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
// CHECK-SAME: (ptr addrspace(10) [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(10) [[REF]], [[iPTR]] [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// CHECK-NEXT: [[TMP0:%.*]] = call [[iPTR]] @llvm.wasm.table.grow.externref.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(10) [[REF]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret [[iPTR]] [[TMP0]]
//
-int test_builtin_wasm_table_grow(__externref_t ref, size_t nelem) {
+size_t test_builtin_wasm_table_grow(__externref_t ref, size_t nelem) {
return __builtin_wasm_table_grow(table, ref, nelem);
}
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
index 67508c17caf5b..532054705bafc 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
@@ -66,10 +66,10 @@ size_t test_builtin_wasm_table_size() {
// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
// CHECK-SAME: (ptr addrspace(20) noundef [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(20) [[REF]], [[iPTR]] [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// CHECK-NEXT: [[TMP0:%.*]] = call [[iPTR]] @llvm.wasm.table.grow.funcref.[[iPTR]](ptr addrspace(1) @table, ptr addrspace(20) [[REF]], [[iPTR]] [[NELEM]])
+// CHECK-NEXT: ret [[iPTR]] [[TMP0]]
//
-int test_builtin_wasm_table_grow(funcref_t ref, size_t nelem) {
+size_t test_builtin_wasm_table_grow(funcref_t ref, size_t nelem) {
return __builtin_wasm_table_grow(table, ref, nelem);
}
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index 6272099059ea9..0e776b7f5c548 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -78,14 +78,14 @@ def int_wasm_table_copy :
[llvm_table_ty, llvm_table_ty, llvm_anyint_ty, LLVMMatchType<0>,
LLVMMatchType<0>], []>;
def int_wasm_table_grow_externref :
- DefaultAttrsIntrinsic<[llvm_i32_ty],
- [llvm_table_ty, llvm_externref_ty, llvm_anyint_ty], []>;
+ DefaultAttrsIntrinsic<[llvm_anyint_ty],
+ [llvm_table_ty, llvm_externref_ty, LLVMMatchType<0>], []>;
def int_wasm_table_grow_funcref :
- DefaultAttrsIntrinsic<[llvm_i32_ty],
- [llvm_table_ty, llvm_funcref_ty, llvm_anyint_ty], []>;
+ DefaultAttrsIntrinsic<[llvm_anyint_ty],
+ [llvm_table_ty, llvm_funcref_ty, LLVMMatchType<0>], []>;
def int_wasm_table_grow_exnref :
- DefaultAttrsIntrinsic<[llvm_i32_ty],
- [llvm_table_ty, llvm_exnref_ty, llvm_anyint_ty], []>;
+ DefaultAttrsIntrinsic<[llvm_anyint_ty],
+ [llvm_table_ty, llvm_exnref_ty, LLVMMatchType<0>], []>;
def int_wasm_table_fill_externref :
DefaultAttrsIntrinsic<[],
[llvm_table_ty, llvm_anyint_ty, llvm_externref_ty,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
index 5722e3edc3433..d93022b216b44 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
@@ -37,9 +37,9 @@ multiclass TABLE<WebAssemblyRegClass rc, string suffix, WebAssemblyRegClass inde
"table.set\t$table",
0x26>;
- defm TABLE_GROW_#rc#addrmodesuffix : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, index_rc:$n),
+ defm TABLE_GROW_#rc#addrmodesuffix : I<(outs index_rc:$sz), (ins table32_op:$table, rc:$val, index_rc:$n),
(outs), (ins table32_op:$table),
- [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, index_rc:$n))],
+ [(set index_rc:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, index_rc:$n))],
"table.grow\t$sz, $table, $val, $n",
"table.grow\t$table",
0xfc0f>;
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
index 03cb1f4b7fd06..22142aa38bdb2 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -9,7 +9,7 @@ declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), iX) nounwind
define %externref @get_externref_from_table(iX %i) {
; CHECK-LABEL: get_externref_from_table:
-; CHECK-NEXT: .functype get_externref_from_table ([[iPTR]]) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table (iX) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
@@ -20,7 +20,7 @@ define %externref @get_externref_from_table(iX %i) {
define %externref @get_externref_from_table_const() {
; CHECK-LABEL: get_externref_from_table_const:
; CHECK-NEXT: .functype get_externref_from_table_const () -> (externref)
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX 0)
@@ -29,10 +29,10 @@ define %externref @get_externref_from_table_const() {
define %externref @get_externref_from_table_with_offset(iX %i) {
; CHECK-LABEL: get_externref_from_table_with_offset:
-; CHECK-NEXT: .functype get_externref_from_table_with_offset ([[iPTR]]) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table_with_offset (iX) -> (externref)
; CHECK-NEXT: local.get 0
-; CHECK-NEXT: [[iPTR]].const 2
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.const 2
+; CHECK-NEXT: iX.add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, 2
@@ -43,10 +43,10 @@ define %externref @get_externref_from_table_with_offset(iX %i) {
define %externref @get_externref_from_table_with_var_offset(iX %i, iX %j) {
; CHECK-LABEL: get_externref_from_table_with_var_offset:
-; CHECK-NEXT: .functype get_externref_from_table_with_var_offset ([[iPTR]], [[iPTR]]) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table_with_var_offset (iX, iX) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, %j
@@ -58,10 +58,10 @@ declare iX @get_offset()
define %externref @get_externref_from_table_with_var_offset2(iX %i) {
; CHECK-LABEL: get_externref_from_table_with_var_offset2:
-; CHECK-NEXT: .functype get_externref_from_table_with_var_offset2 ([[iPTR]]) -> (externref)
+; CHECK-NEXT: .functype get_externref_from_table_with_var_offset2 (iX) -> (externref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: call get_offset
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: table.get externref_table
; CHECK-NEXT: end_function
%j = call iX @get_offset()
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
index 05a844a19d55d..31f609320a90e 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -10,7 +10,7 @@ declare void @llvm.wasm.table.set.externref(ptr addrspace(1), iX, %externref) no
define void @set_externref_table(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table:
-; CHECK-NEXT: .functype set_externref_table (externref, [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_externref_table (externref, iX) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
@@ -24,7 +24,7 @@ define void @set_externref_table(%externref %g, iX %i) {
define void @set_externref_table_const(%externref %g) {
; CHECK-LABEL: set_externref_table_const:
; CHECK-NEXT: .functype set_externref_table_const (externref) -> ()
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
@@ -34,10 +34,10 @@ define void @set_externref_table_const(%externref %g) {
define void @set_externref_table_with_offset(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table_with_offset:
-; CHECK-NEXT: .functype set_externref_table_with_offset (externref, [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_externref_table_with_offset (externref, iX) -> ()
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: [[iPTR]].const 2
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.const 2
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
@@ -48,10 +48,10 @@ define void @set_externref_table_with_offset(%externref %g, iX %i) {
define void @set_externref_table_with_var_offset(%externref %g, iX %i, iX %j) {
; CHECK-LABEL: set_externref_table_with_var_offset:
-; CHECK-NEXT: .functype set_externref_table_with_var_offset (externref, [[iPTR]], [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_externref_table_with_var_offset (externref, iX, iX) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
@@ -64,10 +64,10 @@ declare iX @set_offset()
define void @set_externref_table_with_var_offset2(%externref %g, iX %i) {
; CHECK-LABEL: set_externref_table_with_var_offset2:
-; CHECK-NEXT: .functype set_externref_table_with_var_offset2 (externref, [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_externref_table_with_var_offset2 (externref, iX) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: call set_offset
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-call.ll b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
index 3fdbcdc491a76..9c483e4b9a16f 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,79 +1,48 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM32
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM32
-; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM64
-; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM64
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s -DiPTR=i64
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
; CHECK: .tabletype __funcref_call_table, funcref, 1
define void @call_funcref(%funcref %ref) {
-; WASM32-LABEL: call_funcref:
-; WASM32: .functype call_funcref (funcref) -> ()
-; WASM32-NEXT: # %bb.0:
-; WASM32-NEXT: i32.const 0
-; WASM32-NEXT: local.get 0
-; WASM32-NEXT: table.set __funcref_call_table
-; WASM32-NEXT: i32.const 0
-; WASM32-NEXT: call_indirect __funcref_call_table, () -> ()
-; WASM32-NEXT: i32.const 0
-; WASM32-NEXT: ref.null_func
-; WASM32-NEXT: table.set __funcref_call_table
-; WASM32-NEXT: # fallthrough-return
-;
-; WASM64-LABEL: call_funcref:
-; WASM64: .functype call_funcref (funcref) -> ()
-; WASM64-NEXT: # %bb.0:
-; WASM64-NEXT: i64.const 0
-; WASM64-NEXT: local.get 0
-; WASM64-NEXT: table.set __funcref_call_table
-; WASM64-NEXT: i64.const 0
-; WASM64-NEXT: call_indirect __funcref_call_table, () -> ()
-; WASM64-NEXT: i64.const 0
-; WASM64-NEXT: ref.null_func
-; WASM64-NEXT: table.set __funcref_call_table
-; WASM64-NEXT: # fallthrough-return
+; CHECK-LABEL: call_funcref:
+; CHECK: .functype call_funcref (funcref) -> ()
+; CHECK-NEXT: # %bb.0:
+; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
+; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: ref.null_func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: # fallthrough-return
call addrspace(20) void %ref()
ret void
}
define float @call_funcref_with_args(%funcref %ref) {
-; WASM32-LABEL: call_funcref_with_args:
-; WASM32: .functype call_funcref_with_args (funcref) -> (f32)
-; WASM32-NEXT: .local f32
-; WASM32-NEXT: # %bb.0:
-; WASM32-NEXT: i32.const 0
-; WASM32-NEXT: local.get 0
-; WASM32-NEXT: table.set __funcref_call_table
-; WASM32-NEXT: f64.const 0x1p0
-; WASM32-NEXT: i32.const 2
-; WASM32-NEXT: i32.const 0
-; WASM32-NEXT: call_indirect __funcref_call_table, (f64, i32) -> (f32)
-; WASM32-NEXT: local.set 1
-; WASM32-NEXT: i32.const 0
-; WASM32-NEXT: ref.null_func
-; WASM32-NEXT: table.set __funcref_call_table
-; WASM32-NEXT: local.get 1
-; WASM32-NEXT: # fallthrough-return
-;
-; WASM64-LABEL: call_funcref_with_args:
-; WASM64: .functype call_funcref_with_args (funcref) -> (f32)
-; WASM64-NEXT: .local f32
-; WASM64-NEXT: # %bb.0:
-; WASM64-NEXT: i64.const 0
-; WASM64-NEXT: local.get 0
-; WASM64-NEXT: table.set __funcref_call_table
-; WASM64-NEXT: f64.const 0x1p0
-; WASM64-NEXT: i32.const 2
-; WASM64-NEXT: i64.const 0
-; WASM64-NEXT: call_indirect __funcref_call_table, (f64, i32) -> (f32)
-; WASM64-NEXT: local.set 1
-; WASM64-NEXT: i64.const 0
-; WASM64-NEXT: ref.null_func
-; WASM64-NEXT: table.set __funcref_call_table
-; WASM64-NEXT: local.get 1
-; WASM64-NEXT: # fallthrough-return
+; CHECK-LABEL: call_funcref_with_args:
+; CHECK: .functype call_funcref_with_args (funcref) -> (f32)
+; CHECK-NEXT: .local f32
+; CHECK-NEXT: # %bb.0:
+; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: f64.const 0x1p0
+; CHECK-NEXT: i32.const 2
+; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: call_indirect __funcref_call_table, (f64, i32) -> (f32)
+; CHECK-NEXT: local.set 1
+; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: ref.null_func
+; CHECK-NEXT: table.set __funcref_call_table
+; CHECK-NEXT: local.get 1
+; CHECK-NEXT: # fallthrough-return
%ret = call addrspace(20) float %ref(double 1.0, i32 2)
ret float %ret
}
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index d50bd27c338af..3e97a2371b89e 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -11,14 +11,14 @@ declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
define void @call_funcref_from_table(iX %i) {
; CHECK-LABEL: call_funcref_from_table:
-; CHECK-NEXT: .functype call_funcref_from_table ([[iPTR]]) -> ()
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: .functype call_funcref_from_table (iX) -> ()
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: table.set __funcref_call_table
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: call_indirect __funcref_call_table, () -> ()
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: ref.null_func
; CHECK-NEXT: table.set __funcref_call_table
; CHECK-NEXT: end_function
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
index 1b86e79b13646..94ae51620264a 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -9,7 +9,7 @@ declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
define %funcref @get_funcref_from_table(iX %i) {
; CHECK-LABEL: get_funcref_from_table:
-; CHECK-NEXT: .functype get_funcref_from_table ([[iPTR]]) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table (iX) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
@@ -20,7 +20,7 @@ define %funcref @get_funcref_from_table(iX %i) {
define %funcref @get_funcref_from_table_const() {
; CHECK-LABEL: get_funcref_from_table_const:
; CHECK-NEXT: .functype get_funcref_from_table_const () -> (funcref)
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX 0)
@@ -29,10 +29,10 @@ define %funcref @get_funcref_from_table_const() {
define %funcref @get_funcref_from_table_with_offset(iX %i) {
; CHECK-LABEL: get_funcref_from_table_with_offset:
-; CHECK-NEXT: .functype get_funcref_from_table_with_offset ([[iPTR]]) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table_with_offset (iX) -> (funcref)
; CHECK-NEXT: local.get 0
-; CHECK-NEXT: [[iPTR]].const 2
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.const 2
+; CHECK-NEXT: iX.add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, 2
@@ -43,10 +43,10 @@ define %funcref @get_funcref_from_table_with_offset(iX %i) {
define %funcref @get_funcref_from_table_with_var_offset(iX %i, iX %j) {
; CHECK-LABEL: get_funcref_from_table_with_var_offset:
-; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset ([[iPTR]], [[iPTR]]) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset (iX, iX) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%off = add nsw iX %i, %j
@@ -58,10 +58,10 @@ declare iX @get_offset()
define %funcref @get_funcref_from_table_with_var_offset2(iX %i) {
; CHECK-LABEL: get_funcref_from_table_with_var_offset2:
-; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset2 ([[iPTR]]) -> (funcref)
+; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset2 (iX) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: call get_offset
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: table.get funcref_table
; CHECK-NEXT: end_function
%j = call iX @get_offset()
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
index dd440a5b1c1d6..2aa00054e91db 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
@@ -9,7 +9,7 @@ declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), iX, %funcref) nounwi
define void @set_funcref_table(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table:
-; CHECK-NEXT: .functype set_funcref_table (funcref, [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_funcref_table (funcref, iX) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
@@ -23,7 +23,7 @@ define void @set_funcref_table(%funcref %g, iX %i) {
define void @set_funcref_table_const(%funcref %g) {
; CHECK-LABEL: set_funcref_table_const:
; CHECK-NEXT: .functype set_funcref_table_const (funcref) -> ()
-; CHECK-NEXT: [[iPTR]].const 0
+; CHECK-NEXT: iX.const 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
@@ -33,10 +33,10 @@ define void @set_funcref_table_const(%funcref %g) {
define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table_with_offset:
-; CHECK-NEXT: .functype set_funcref_table_with_offset (funcref, [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_funcref_table_with_offset (funcref, iX) -> ()
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: [[iPTR]].const 2
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.const 2
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
@@ -47,10 +47,10 @@ define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
define void @set_funcref_table_with_var_offset(%funcref %g, iX %i, iX %j) {
; CHECK-LABEL: set_funcref_table_with_var_offset:
-; CHECK-NEXT: .functype set_funcref_table_with_var_offset (funcref, [[iPTR]], [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_funcref_table_with_var_offset (funcref, iX, iX) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
@@ -63,10 +63,10 @@ declare iX @set_offset()
define void @set_funcref_table_with_var_offset2(%funcref %g, iX %i) {
; CHECK-LABEL: set_funcref_table_with_var_offset2:
-; CHECK-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, [[iPTR]]) -> ()
+; CHECK-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, iX) -> ()
; CHECK-NEXT: local.get 1
; CHECK-NEXT: call set_offset
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set funcref_table
; CHECK-NEXT: end_function
diff --git a/llvm/test/CodeGen/WebAssembly/table-copy.ll b/llvm/test/CodeGen/WebAssembly/table-copy.ll
index dce33eaa7b367..69a63c0e445c3 100644
--- a/llvm/test/CodeGen/WebAssembly/table-copy.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-copy.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -10,7 +10,7 @@ declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), iX, iX, i
define void @table_copy(iX %dst, iX %src, iX %len) {
; CHECK-LABEL: table_copy:
-; CHECK-NEXT: .functype table_copy ([[iPTR]], [[iPTR]], [[iPTR]]) -> ()
+; CHECK-NEXT: .functype table_copy (iX, iX, iX) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
; CHECK-NEXT: local.get 2
@@ -24,10 +24,10 @@ define void @table_copy(iX %dst, iX %src, iX %len) {
; Copies len items from table1 at src to table1 at src+off
define void @self_table_copy(iX %src, iX %off, iX %len) {
; CHECK-LABEL: self_table_copy:
-; CHECK-NEXT: .functype self_table_copy ([[iPTR]], [[iPTR]], [[iPTR]]) -> ()
+; CHECK-NEXT: .functype self_table_copy (iX, iX, iX) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
-; CHECK-NEXT: [[iPTR]].add
+; CHECK-NEXT: iX.add
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 2
; CHECK-NEXT: table.copy externref_table1, externref_table1
diff --git a/llvm/test/CodeGen/WebAssembly/table-fill.ll b/llvm/test/CodeGen/WebAssembly/table-fill.ll
index 2b9f0feb7301f..180eb17b7c549 100644
--- a/llvm/test/CodeGen/WebAssembly/table-fill.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-fill.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -9,7 +9,7 @@ declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), iX, %externref, i
define void @table_fill(iX %start, iX %len, %externref %val) {
; CHECK-LABEL: table_fill:
-; CHECK-NEXT: .functype table_fill ([[iPTR]], [[iPTR]], externref) -> ()
+; CHECK-NEXT: .functype table_fill (iX, iX, externref) -> ()
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 2
; CHECK-NEXT: local.get 1
diff --git a/llvm/test/CodeGen/WebAssembly/table-grow.ll b/llvm/test/CodeGen/WebAssembly/table-grow.ll
index 7a043462d247f..f8602453bc70a 100644
--- a/llvm/test/CodeGen/WebAssembly/table-grow.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-grow.ll
@@ -1,21 +1,21 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
-declare i32 @llvm.wasm.table.grow.externref(ptr addrspace(1), %externref, iX) nounwind readonly
+declare iX @llvm.wasm.table.grow.externref(ptr addrspace(1), %externref, iX) nounwind readonly
declare %externref @llvm.wasm.ref.null.extern() nounwind readonly
-define i32 @table_grow(iX %sz) {
+define iX @table_grow(iX %sz) {
; CHECK-LABEL: table_grow:
-; CHECK-NEXT: .functype table_grow ([[iPTR]]) -> (i32)
+; CHECK-NEXT: .functype table_grow (iX) -> (iX)
; CHECK-NEXT: ref.null_extern
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.grow externref_table
; CHECK-NEXT: end_function
%null = call %externref @llvm.wasm.ref.null.extern()
- %newsz = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @externref_table, %externref %null, iX %sz)
- ret i32 %newsz
+ %newsz = call iX @llvm.wasm.table.grow.externref(ptr addrspace(1) @externref_table, %externref %null, iX %sz)
+ ret iX %newsz
}
diff --git a/llvm/test/CodeGen/WebAssembly/table-size.ll b/llvm/test/CodeGen/WebAssembly/table-size.ll
index e24f451a7596d..1bf0b47aac414 100644
--- a/llvm/test/CodeGen/WebAssembly/table-size.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-size.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
+; RUN: sed 's/iX/i32/g' < %s > %t && llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
+; RUN: sed 's/iX/i64/g' < %s > %t && llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types < %t | FileCheck %t
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -9,7 +9,7 @@ declare iX @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
define iX @table_size() {
; CHECK-LABEL: table_size:
-; CHECK-NEXT: .functype table_size () -> ([[iPTR]])
+; CHECK-NEXT: .functype table_size () -> (iX)
; CHECK-NEXT: table.size externref_table
; CHECK-NEXT: end_function
%sz = call iX @llvm.wasm.table.size(ptr addrspace(1) @externref_table)
More information about the cfe-commits
mailing list