[clang] [llvm] [WebAssembly] Change to 64-bit table indices on Wasm64 (PR #180649)
Demetrius Kanios via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 01:01:52 PDT 2026
https://github.com/QuantumSegfault updated https://github.com/llvm/llvm-project/pull/180649
>From 04d18f8e18c268a47af15b82929c117d467b0550 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Wed, 1 Jul 2026 00:53:57 -0700
Subject: [PATCH 1/4] Make all tables and table related operations use 64-bit
indices on Wasm64
---
.../CodeGen/TargetBuiltins/WebAssembly.cpp | 30 ++--
.../WebAssembly/builtins-table-externref.c | 157 ++++++++++++------
.../WebAssembly/builtins-table-funcref.c | 113 ++++++++-----
llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 36 ++--
.../Utils/WebAssemblyTypeUtilities.cpp | 6 +-
.../Utils/WebAssemblyTypeUtilities.h | 2 +-
.../WebAssembly/WebAssemblyAsmPrinter.cpp | 3 +-
.../WebAssembly/WebAssemblyFastISel.cpp | 32 +++-
.../WebAssembly/WebAssemblyISelDAGToDAG.cpp | 28 +---
.../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 | 98 +++++++----
.../WebAssembly/funcref-ptr-conversion.ll | 15 +-
.../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 ++++++++
27 files changed, 724 insertions(+), 400 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 e7bdb91d49ce8..f05e7c46208e7 100644
--- a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
@@ -594,9 +594,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");
@@ -609,9 +611,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");
@@ -619,8 +623,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: {
@@ -631,9 +636,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");
@@ -649,9 +656,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");
@@ -666,7 +675,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 454fc31a5f53f..7aec1af779a3f 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -1,92 +1,145 @@
// 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 target("wasm.externref") @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT: ret target("wasm.externref") [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT: ret target("wasm.externref") [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
+// WASM64-NEXT: ret target("wasm.externref") [[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);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT: ret target("wasm.externref") [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT: ret target("wasm.externref") [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
+// WASM64-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM64-NEXT: ret target("wasm.externref") [[TMP0]]
//
__externref_t test_builtin_wasm_table_get_const(const int index) {
return __builtin_wasm_table_get(table, index);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @const_table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// CHECK-NEXT: ret void
-//
-void test_builtin_wasm_table_set(const int index, __externref_t ref) {
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @const_table, i32 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @const_table, i64 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM64-NEXT: ret void
+//
+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);
}
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// CHECK-NEXT: call void @llvm.wasm.table.set.externref(ptr addrspace(1) @const_table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// CHECK-NEXT: ret void
-//
-void test_builtin_wasm_table_set_const(const int index, const __externref_t ref) {
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @const_table, i32 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @const_table, i64 [[INDEX]], target("wasm.externref") [[REF]])
+// WASM64-NEXT: ret void
+//
+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);
}
-// 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: (target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @table, target("wasm.externref") [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM32-SAME: (target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i32(ptr addrspace(1) @table, target("wasm.externref") [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret i32 [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM64-SAME: (target("wasm.externref") [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i64(ptr addrspace(1) @table, target("wasm.externref") [[REF]], i64 [[NELEM]])
+// WASM64-NEXT: ret i32 [[TMP0]]
//
-int test_builtin_wasm_table_grow(__externref_t ref, int nelem) {
+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:%.*]], target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.fill.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret void
//
-void test_builtin_wasm_table_fill(int index, __externref_t ref, int nelem) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.fill.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.externref") [[REF]], i64 [[NELEM]])
+// WASM64-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);
}
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 f80e9b10c4941..72d71157d8685 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 target("wasm.funcref") @llvm.wasm.table.get.funcref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT: ret target("wasm.funcref") [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call target("wasm.funcref") @llvm.wasm.table.get.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT: ret target("wasm.funcref") [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call target("wasm.funcref") @llvm.wasm.table.get.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
+// WASM64-NEXT: ret target("wasm.funcref") [[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:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.funcref") [[REF]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: call void @llvm.wasm.table.set.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.funcref") [[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:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: call void @llvm.wasm.table.set.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.funcref") [[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: (target("wasm.funcref") noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref(ptr addrspace(1) @table, target("wasm.funcref") [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM32-SAME: (target("wasm.funcref") noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT: entry:
+// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i32(ptr addrspace(1) @table, target("wasm.funcref") [[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: (target("wasm.funcref") noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT: entry:
+// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i64(ptr addrspace(1) @table, target("wasm.funcref") [[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:%.*]], target("wasm.funcref") noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @llvm.wasm.table.fill.funcref(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.funcref") [[REF]], i32 [[NELEM]])
-// CHECK-NEXT: ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.funcref") 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]], target("wasm.funcref") [[REF]], i32 [[NELEM]])
+// WASM32-NEXT: ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.funcref") 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]], target("wasm.funcref") [[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 a0e83cee9f055..8d362958ccf02 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -62,53 +62,53 @@ def int_wasm_ptr_to_funcref :
// 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 57502c82f6c26..c1552378d87cf 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
@@ -67,7 +67,8 @@ wasm::ValType WebAssembly::toValType(MVT Type) {
}
void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
- ArrayRef<MVT> VTs, bool Mutable) {
+ ArrayRef<MVT> VTs, bool Mutable,
+ bool Is64) {
assert(!Sym->getType());
// Tables are represented as Arrays in LLVM IR therefore
@@ -91,7 +92,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});
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
index 47ba91df81161..ff2a943e9cf5b 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -58,7 +58,7 @@ wasm::ValType toValType(MVT Type);
/// Sets a Wasm Symbol Type.
void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
- ArrayRef<MVT> VTs, bool Mutable);
+ ArrayRef<MVT> VTs, bool Mutable, bool Is64);
} // end namespace WebAssembly
} // end namespace llvm
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 6142e19165fc0..ef7ba2e37e3a8 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -207,7 +207,8 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
GV->getDataLayout(), GlobalVT, VTs);
WebAssembly::wasmSymbolSetType(Sym, GlobalVT, VTs,
- /*Mutable=*/!GV->isConstant());
+ /*Mutable=*/!GV->isConstant(),
+ /*Is64=*/ST->hasAddr64());
}
emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration());
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 95f4367f76cdf..e3b4f54c1c0cb 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -966,19 +966,29 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) {
Subtarget);
CalleeReg = getRegForValue(FuncrefArg);
// Put the funcref in slot 0 of __funcref_call_table
- unsigned ZeroReg = createResultReg(&WebAssembly::I32RegClass);
+ unsigned ZeroReg =
+ createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
+ : &WebAssembly::I32RegClass);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
- TII.get(WebAssembly::CONST_I32), ZeroReg)
+ TII.get(Subtarget->hasAddr64() ? WebAssembly::CONST_I64
+ : WebAssembly::CONST_I32),
+ ZeroReg)
.addImm(0);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
- TII.get(WebAssembly::TABLE_SET_FUNCREF))
+ TII.get(Subtarget->hasAddr64()
+ ? WebAssembly::TABLE_SET_FUNCREF_A64
+ : WebAssembly::TABLE_SET_FUNCREF_A32))
.addSym(Table)
.addReg(ZeroReg)
.addReg(CalleeReg);
// Set CalleeReg to an immediate 0
- CalleeReg = createResultReg(&WebAssembly::I32RegClass);
+ CalleeReg =
+ createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
+ : &WebAssembly::I32RegClass);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
- TII.get(WebAssembly::CONST_I32), CalleeReg)
+ TII.get(Subtarget->hasAddr64() ? WebAssembly::CONST_I64
+ : WebAssembly::CONST_I32),
+ CalleeReg)
.addImm(0);
}
}
@@ -1012,15 +1022,21 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) {
if (IsFuncrefCall) {
// Clear slot 0 of the funcref call table after the call.
- unsigned ZeroReg = createResultReg(&WebAssembly::I32RegClass);
+ unsigned ZeroReg =
+ createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
+ : &WebAssembly::I32RegClass);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
- TII.get(WebAssembly::CONST_I32), ZeroReg)
+ TII.get(Subtarget->hasAddr64() ? WebAssembly::CONST_I64
+ : WebAssembly::CONST_I32),
+ ZeroReg)
.addImm(0);
unsigned NullReg = createResultReg(&WebAssembly::FUNCREFRegClass);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(WebAssembly::REF_NULL_FUNCREF), NullReg);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
- TII.get(WebAssembly::TABLE_SET_FUNCREF))
+ TII.get(Subtarget->hasAddr64()
+ ? WebAssembly::TABLE_SET_FUNCREF_A64
+ : WebAssembly::TABLE_SET_FUNCREF_A32))
.addSym(Table)
.addReg(ZeroReg)
.addReg(NullReg);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
index 69e9e6b5a9717..a545d40ae3887 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
@@ -284,15 +284,10 @@ 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);
- }
MachineSDNode *FuncRef = CurDAG->getMachineNode(
- WebAssembly::TABLE_GET_FUNCREF, DL, MVT::funcref, TableSym, FuncPtr);
+ Subtarget->hasAddr64() ? WebAssembly::TABLE_GET_FUNCREF_A64
+ : WebAssembly::TABLE_GET_FUNCREF_A32,
+ DL, MVT::funcref, TableSym, FuncPtr);
ReplaceNode(Node, FuncRef);
return;
}
@@ -305,17 +300,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 f06ab5bd0942b..d24747210ae1e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -822,10 +822,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);
@@ -876,10 +881,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 =
@@ -889,7 +899,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);
@@ -1542,7 +1555,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 fbff8bba50d3c..15d644235d6dc 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"
@@ -91,7 +92,9 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
SmallVector<MVT, 1> VTs;
computeLegalValueVTs(CurrentFunc, TM, GlobalVT, VTs);
- WebAssembly::wasmSymbolSetType(WasmSym, GlobalVT, VTs, *Mutable);
+ WebAssembly::wasmSymbolSetType(
+ WasmSym, GlobalVT, VTs, *Mutable,
+ TM.getSubtarget<WebAssemblySubtarget>(CurrentFunc).hasAddr64());
}
return WasmSym;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
index ac8df67fe7557..cff03fd56ef51 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 1189fc3571902..ec41a8025fc89 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 target("wasm.externref")
@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 f84ae4dba68eb..afec4e788dd91 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 target("wasm.externref")
@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 04089ee5a79fb..58ed1e15eb768 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,10 +1,13 @@
; 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=0 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
; RUN: llc < %s --mtriple=wasm32-unknown-unknown --filetype=obj
; Use -fast-isel-abort=3 (never fall back to SelectionDAG) to make sure that the
; funcref call is selected by FastISel
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%funcref = type target("wasm.funcref")
@@ -13,42 +16,75 @@ declare ptr @llvm.wasm.funcref.to_ptr(%funcref) nounwind
; 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
%refptr = call ptr @llvm.wasm.funcref.to_ptr(%funcref %ref)
call void %refptr()
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
%refptr = call ptr @llvm.wasm.funcref.to_ptr(%funcref %ref)
%ret = call float %refptr(double 1.0, i32 2)
ret float %ret
}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-ptr-conversion.ll b/llvm/test/CodeGen/WebAssembly/funcref-ptr-conversion.ll
index b9792b661a742..a2d5cb99ce123 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-ptr-conversion.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-ptr-conversion.ll
@@ -1,5 +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 --check-prefix=CHECK64
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
%funcref = type target("wasm.funcref")
@@ -11,18 +11,11 @@ declare %funcref @llvm.wasm.ptr.to_funcref(ptr) nounwind
; __indirect_function_table.
define %funcref @ptr_to_funcref(ptr %p) {
; CHECK-LABEL: ptr_to_funcref:
-; CHECK: .functype ptr_to_funcref (i32) -> (funcref)
+; WASM32: .functype ptr_to_funcref (i32) -> (funcref)
+; WASM64: .functype ptr_to_funcref (i64) -> (funcref)
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.get __indirect_function_table
; CHECK-NEXT: end_function
-;
-; On wasm64 the function pointer is an i64 and must be wrapped to i32 first.
-; CHECK64-LABEL: ptr_to_funcref:
-; CHECK64: .functype ptr_to_funcref (i64) -> (funcref)
-; CHECK64-NEXT: local.get 0
-; CHECK64-NEXT: i32.wrap_i64
-; CHECK64-NEXT: table.get __indirect_function_table
-; CHECK64-NEXT: end_function
%ref = call %funcref @llvm.wasm.ptr.to_funcref(ptr %p)
ret %funcref %ref
}
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index e5343fa80d846..334c16aeb1c86 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 target("wasm.funcref")
@@ -6,23 +7,27 @@
; 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
declare ptr @llvm.wasm.funcref.to_ptr(%funcref) 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)
%refptr = call ptr @llvm.wasm.funcref.to_ptr(%funcref %ref)
call void %refptr()
ret void
@@ -30,4 +35,3 @@ define void @call_funcref_from_table(i32 %i) {
; 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 2621dcde6a79b..fc4c8814b0bd9 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 target("wasm.funcref")
@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 e62eb8a6f2d20..e455fc3787b77 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 target("wasm.funcref")
@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 f74c968abdadc..fab56dc64ec3a 100644
--- a/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
+++ b/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
@@ -7,7 +7,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
@@ -24,7 +23,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
@@ -41,7 +39,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
@@ -58,7 +55,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
@@ -75,7 +71,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
@@ -93,7 +88,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
@@ -111,7 +105,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
@@ -129,7 +122,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)
@@ -147,7 +139,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 d1387428c4368..4ace77dc8656b 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 target("wasm.externref")
@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 7ed39361a1afd..c7b9d33684022 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 target("wasm.externref")
@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 2b5801ea2fa17..fd5d7753fd0ec 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 target("wasm.externref")
@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 2b8d0185bb049..4161e08810cdc 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 target("wasm.externref")
@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 da04ba35dd58e..a55db92a28e0a 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 target("wasm.externref")
%funcref = type target("wasm.funcref")
diff --git a/llvm/test/MC/WebAssembly/tables.ll b/llvm/test/MC/WebAssembly/tables.ll
new file mode 100644
index 0000000000000..857150ee09dd9
--- /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 target("wasm.externref")
+ at externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] []
+
+%funcref = type target("wasm.funcref")
+ at funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] []
+
+; 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 1fbe95955297fb3b78d732114b739316d2ec422f 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/4] 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 ec41a8025fc89..e62ef3ef6cd53 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 target("wasm.externref")
@@ -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 afec4e788dd91..e1a1b39c6e29b 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 target("wasm.externref")
@@ -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 334c16aeb1c86..85eedc89736f4 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 target("wasm.funcref")
@@ -12,18 +12,14 @@ declare ptr @llvm.wasm.funcref.to_ptr(%funcref) 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 fc4c8814b0bd9..733758c822d84 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 target("wasm.funcref")
@@ -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 e455fc3787b77..283f38abd93df 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 target("wasm.funcref")
@@ -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 4ace77dc8656b..6933b1aeb5d7a 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 target("wasm.externref")
@@ -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 c7b9d33684022..2de6e4faaa43c 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 target("wasm.externref")
@@ -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 fd5d7753fd0ec..188afb3d13d5f 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 target("wasm.externref")
@@ -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 4161e08810cdc..26cf29464c981 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 target("wasm.externref")
@@ -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 9088861525a95bf0273bb8896e0f5d8eb8d7efca 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/4] Use `-DiPTR` in Clang tests.
---
.../WebAssembly/builtins-table-externref.c | 141 ++++++------------
.../WebAssembly/builtins-table-funcref.c | 125 +++++++---------
2 files changed, 101 insertions(+), 165 deletions(-)
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
index 7aec1af779a3f..8aab5eaa1ac70 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -1,6 +1,5 @@
-// 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,119 +7,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 target("wasm.externref") @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
-// WASM32-NEXT: ret target("wasm.externref") [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
-// WASM64-NEXT: ret target("wasm.externref") [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret target("wasm.externref") [[TMP0]]
//
__externref_t test_builtin_wasm_table_get(size_t index) {
return __builtin_wasm_table_get(table, index);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
-// WASM32-NEXT: ret target("wasm.externref") [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
-// WASM64-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
-// WASM64-NEXT: ret target("wasm.externref") [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get_const
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.externref") @llvm.wasm.table.get.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret target("wasm.externref") [[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);
}
-// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @const_table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @const_table, i64 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], target("wasm.externref") [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], target("wasm.externref") [[REF]])
+// CHECK-NEXT: ret void
//
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_const
-// WASM32-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM32-NEXT: call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @const_table, i32 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM64-NEXT: call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @const_table, i64 [[INDEX]], target("wasm.externref") [[REF]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set_const
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], target("wasm.externref") [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.externref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], target("wasm.externref") [[REF]])
+// CHECK-NEXT: ret void
//
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: (target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i32(ptr addrspace(1) @table, target("wasm.externref") [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret i32 [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// WASM64-SAME: (target("wasm.externref") [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i64(ptr addrspace(1) @table, target("wasm.externref") [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret i32 [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// CHECK-SAME: (target("wasm.externref") [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.[[iPTR]](ptr addrspace(1) @table, target("wasm.externref") [[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:%.*]], target("wasm.externref") [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.fill.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.externref") [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.fill.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.externref") [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], target("wasm.externref") [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.fill.externref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], target("wasm.externref") [[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);
@@ -128,17 +83,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 72d71157d8685..6185f5d74a14e 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
@@ -1,89 +1,82 @@
-// 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 target("wasm.funcref") @llvm.wasm.table.get.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
-// WASM32-NEXT: ret target("wasm.funcref") [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call target("wasm.funcref") @llvm.wasm.table.get.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
-// WASM64-NEXT: ret target("wasm.funcref") [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call target("wasm.funcref") @llvm.wasm.table.get.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret target("wasm.funcref") [[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:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: call void @llvm.wasm.table.set.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], target("wasm.funcref") [[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 target("wasm.funcref") @llvm.wasm.table.get.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]])
+// CHECK-NEXT: ret target("wasm.funcref") [[TMP0]]
//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: call void @llvm.wasm.table.set.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], target("wasm.funcref") [[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:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], target("wasm.funcref") [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], target("wasm.funcref") [[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:%.*]], target("wasm.funcref") noundef [[REF:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @table, [[iPTR]] [[INDEX]], target("wasm.funcref") [[REF]])
+// CHECK-NEXT: call void @llvm.wasm.table.set.funcref.[[iPTR]](ptr addrspace(1) @const_table, [[iPTR]] [[INDEX]], target("wasm.funcref") [[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: (target("wasm.funcref") noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM32-NEXT: entry:
-// WASM32-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i32(ptr addrspace(1) @table, target("wasm.funcref") [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret i32 [[TMP0]]
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// WASM64-SAME: (target("wasm.funcref") noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// WASM64-NEXT: entry:
-// WASM64-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i64(ptr addrspace(1) @table, target("wasm.funcref") [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret i32 [[TMP0]]
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// CHECK-SAME: (target("wasm.funcref") noundef [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.[[iPTR]](ptr addrspace(1) @table, target("wasm.funcref") [[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:%.*]], target("wasm.funcref") 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]], target("wasm.funcref") [[REF]], i32 [[NELEM]])
-// WASM32-NEXT: ret void
-//
-// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// WASM64-SAME: (i64 noundef [[INDEX:%.*]], target("wasm.funcref") 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]], target("wasm.funcref") [[REF]], i64 [[NELEM]])
-// WASM64-NEXT: ret void
+// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// CHECK-SAME: ([[iPTR]] noundef [[INDEX:%.*]], target("wasm.funcref") 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]], target("wasm.funcref") [[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 +84,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 29ab3595bbca824ca9fa5545aeaf7a6bbf17e791 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 4/4] Use sed tmpfile for FileCheck instead of DiPTR, and fix
`wasm.grow`
---
.../WebAssembly/builtins-table-externref.c | 4 +-
.../WebAssembly/builtins-table-funcref.c | 4 +-
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, 113 insertions(+), 144 deletions(-)
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
index 8aab5eaa1ac70..caa066fa23d10 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -65,9 +65,9 @@ size_t test_builtin_wasm_table_size() {
// CHECK-SAME: (target("wasm.externref") [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.[[iPTR]](ptr addrspace(1) @table, target("wasm.externref") [[REF]], [[iPTR]] [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// 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 6185f5d74a14e..491bc6238ddb3 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
@@ -66,9 +66,9 @@ size_t test_builtin_wasm_table_size() {
// CHECK-SAME: (target("wasm.funcref") noundef [[REF:%.*]], [[iPTR]] noundef [[NELEM:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
// CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.[[iPTR]](ptr addrspace(1) @table, target("wasm.funcref") [[REF]], [[iPTR]] [[NELEM]])
-// CHECK-NEXT: ret i32 [[TMP0]]
+// 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 8d362958ccf02..374652d523dfa 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -89,14 +89,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 e62ef3ef6cd53..e399eb18e3fdc 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 target("wasm.externref")
@@ -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 e1a1b39c6e29b..548cc2f151b5a 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 target("wasm.externref")
@@ -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 58ed1e15eb768..6f953f7372ba1 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,13 +1,13 @@
; 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=CHECK,WASM32
-; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -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=wasm32-unknown-unknown --filetype=obj
; Use -fast-isel-abort=3 (never fall back to SelectionDAG) to make sure that the
; funcref call is selected by FastISel
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -fast-isel-abort=3 -mattr=+reference-types | FileCheck %s -DiPTR=i64
%funcref = type target("wasm.funcref")
@@ -16,72 +16,41 @@ declare ptr @llvm.wasm.funcref.to_ptr(%funcref) nounwind
; 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
%refptr = call ptr @llvm.wasm.funcref.to_ptr(%funcref %ref)
call void %refptr()
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
%refptr = call ptr @llvm.wasm.funcref.to_ptr(%funcref %ref)
%ret = call float %refptr(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 85eedc89736f4..1c74a70c99b50 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 target("wasm.funcref")
@@ -12,14 +12,14 @@ declare ptr @llvm.wasm.funcref.to_ptr(%funcref) 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 733758c822d84..5b884e4b86af0 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 target("wasm.funcref")
@@ -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 283f38abd93df..1b4a7561155ff 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 target("wasm.funcref")
@@ -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 6933b1aeb5d7a..7568020f99439 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 target("wasm.externref")
@@ -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 2de6e4faaa43c..e843d046fdf70 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 target("wasm.externref")
@@ -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 188afb3d13d5f..06091ff1d9a35 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 target("wasm.externref")
@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 26cf29464c981..ad16ba2afb121 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 target("wasm.externref")
@@ -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 llvm-commits
mailing list