[clang] [llvm] [WebAssembly] Change to 64-bit table indices on Wasm64 (PR #180649)

Demetrius Kanios via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 17 09:18:47 PST 2026


https://github.com/QuantumSegfault updated https://github.com/llvm/llvm-project/pull/180649

>From 4f33d6b61cc45cf60f1e89b8e752a51352011fd8 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Mon, 9 Feb 2026 15:53:40 -0800
Subject: [PATCH 1/3] Make all tables and table related operations use 64-bit
 indices on Wasm64

---
 .../CodeGen/TargetBuiltins/WebAssembly.cpp    |  30 ++-
 .../WebAssembly/builtins-table-externref.c    | 113 +++++++----
 .../WebAssembly/builtins-table-funcref.c      | 113 +++++++----
 llvm/include/llvm/IR/IntrinsicsWebAssembly.td |  36 ++--
 .../Utils/WebAssemblyTypeUtilities.cpp        |   5 +-
 .../Utils/WebAssemblyTypeUtilities.h          |   2 +-
 .../WebAssembly/WebAssemblyAsmPrinter.cpp     |   5 +-
 .../WebAssembly/WebAssemblyISelDAGToDAG.cpp   |  17 +-
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  30 ++-
 .../WebAssembly/WebAssemblyInstrTable.td      |  72 ++++---
 .../WebAssembly/WebAssemblyMCInstLower.cpp    |   5 +-
 .../WebAssembly/WebAssemblyUtilities.cpp      |  14 +-
 llvm/test/CodeGen/WebAssembly/call-wasm64.ll  | 181 ++++++++++++++++++
 .../CodeGen/WebAssembly/externref-tableget.ll |  66 ++++---
 .../CodeGen/WebAssembly/externref-tableset.ll |  75 ++++----
 llvm/test/CodeGen/WebAssembly/funcref-call.ll |  95 ++++++---
 .../CodeGen/WebAssembly/funcref-table_call.ll |  36 ++--
 .../CodeGen/WebAssembly/funcref-tableget.ll   |  80 ++++----
 .../CodeGen/WebAssembly/funcref-tableset.ll   |  82 +++++---
 .../test/CodeGen/WebAssembly/ref-test-func.ll |   9 -
 llvm/test/CodeGen/WebAssembly/table-copy.ll   |  24 ++-
 llvm/test/CodeGen/WebAssembly/table-fill.ll   |  12 +-
 llvm/test/CodeGen/WebAssembly/table-grow.ll   |  12 +-
 llvm/test/CodeGen/WebAssembly/table-size.ll   |  14 +-
 llvm/test/CodeGen/WebAssembly/table-types.ll  |   1 +
 llvm/test/MC/WebAssembly/tables.ll            |  72 +++++++
 llvm/test/MC/WebAssembly/wasm64.s             |  44 +++--
 27 files changed, 874 insertions(+), 371 deletions(-)
 create mode 100644 llvm/test/CodeGen/WebAssembly/call-wasm64.ll
 create mode 100644 llvm/test/MC/WebAssembly/tables.ll

diff --git a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
index edaba6e5998fc..079f282976d83 100644
--- a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
@@ -595,9 +595,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
     Value *Index = EmitScalarExpr(E->getArg(1));
     Function *Callee;
     if (E->getType().isWebAssemblyExternrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_get_externref);
+      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_get_externref,
+                                Index->getType());
     else if (E->getType().isWebAssemblyFuncrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_get_funcref);
+      Callee =
+          CGM.getIntrinsic(Intrinsic::wasm_table_get_funcref, Index->getType());
     else
       llvm_unreachable(
           "Unexpected reference type for __builtin_wasm_table_get");
@@ -610,9 +612,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
     Value *Val = EmitScalarExpr(E->getArg(2));
     Function *Callee;
     if (E->getArg(2)->getType().isWebAssemblyExternrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_set_externref);
+      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_set_externref,
+                                Index->getType());
     else if (E->getArg(2)->getType().isWebAssemblyFuncrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_set_funcref);
+      Callee =
+          CGM.getIntrinsic(Intrinsic::wasm_table_set_funcref, Index->getType());
     else
       llvm_unreachable(
           "Unexpected reference type for __builtin_wasm_table_set");
@@ -620,8 +624,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   }
   case WebAssembly::BI__builtin_wasm_table_size: {
     assert(E->getArg(0)->getType()->isArrayType());
+    llvm::Type *ResultType = ConvertType(E->getType());
     Value *Value = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this);
-    Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_table_size);
+    Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_table_size, ResultType);
     return Builder.CreateCall(Callee, Value);
   }
   case WebAssembly::BI__builtin_wasm_table_grow: {
@@ -632,9 +637,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 
     Function *Callee;
     if (E->getArg(1)->getType().isWebAssemblyExternrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_externref);
+      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_externref,
+                                NElems->getType());
     else if (E->getArg(1)->getType().isWebAssemblyFuncrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_funcref);
+      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_grow_funcref,
+                                NElems->getType());
     else
       llvm_unreachable(
           "Unexpected reference type for __builtin_wasm_table_grow");
@@ -650,9 +657,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 
     Function *Callee;
     if (E->getArg(2)->getType().isWebAssemblyExternrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_externref);
+      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_externref,
+                                Index->getType());
     else if (E->getArg(2)->getType().isWebAssemblyFuncrefType())
-      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_funcref);
+      Callee = CGM.getIntrinsic(Intrinsic::wasm_table_fill_funcref,
+                                Index->getType());
     else
       llvm_unreachable(
           "Unexpected reference type for __builtin_wasm_table_fill");
@@ -667,7 +676,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
     Value *SrcIdx = EmitScalarExpr(E->getArg(3));
     Value *NElems = EmitScalarExpr(E->getArg(4));
 
-    Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_table_copy);
+    Function *Callee =
+        CGM.getIntrinsic(Intrinsic::wasm_table_copy, DstIdx->getType());
 
     return Builder.CreateCall(Callee, {TableX, TableY, SrcIdx, DstIdx, NElems});
   }
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
index 74bb2442fe552..b2fe670e7f2f5 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-externref.c
@@ -1,67 +1,106 @@
 // 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];
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT:    ret ptr addrspace(10) [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT:    ret ptr addrspace(10) [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    [[TMP0:%.*]] = call ptr addrspace(10) @llvm.wasm.table.get.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
+// WASM64-NEXT:    ret ptr addrspace(10) [[TMP0]]
 //
-__externref_t test_builtin_wasm_table_get(int index) {
+__externref_t test_builtin_wasm_table_get(size_t index) {
   return __builtin_wasm_table_get(table, index);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    call void @llvm.wasm.table.set.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
-// CHECK-NEXT:    ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    call void @llvm.wasm.table.set.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
+// WASM32-NEXT:    ret void
 //
-void test_builtin_wasm_table_set(int index, __externref_t ref) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    call void @llvm.wasm.table.set.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(10) [[REF]])
+// WASM64-NEXT:    ret void
+//
+void test_builtin_wasm_table_set(size_t index, __externref_t ref) {
   return __builtin_wasm_table_set(table, index, ref);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// CHECK-SAME: () #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.size(ptr addrspace(1) @table)
-// CHECK-NEXT:    ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM32-SAME: () #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.size.i32(ptr addrspace(1) @table)
+// WASM32-NEXT:    ret i32 [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM64-SAME: () #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    [[TMP0:%.*]] = call i64 @llvm.wasm.table.size.i64(ptr addrspace(1) @table)
+// WASM64-NEXT:    ret i64 [[TMP0]]
 //
-int test_builtin_wasm_table_size() {
+size_t test_builtin_wasm_table_size() {
   return __builtin_wasm_table_size(table);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// CHECK-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT:    ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM32-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i32(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT:    ret i32 [[TMP0]]
 //
-int test_builtin_wasm_table_grow(__externref_t ref, int nelem) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM64-SAME: (ptr addrspace(10) [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref.i64(ptr addrspace(1) @table, ptr addrspace(10) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT:    ret i32 [[TMP0]]
+//
+int test_builtin_wasm_table_grow(__externref_t ref, size_t nelem) {
   return __builtin_wasm_table_grow(table, ref, nelem);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT:    ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    call void @llvm.wasm.table.fill.externref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT:    ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    call void @llvm.wasm.table.fill.externref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(10) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT:    ret void
 //
-void test_builtin_wasm_table_fill(int index, __externref_t ref, int nelem) {
+void test_builtin_wasm_table_fill(size_t index, __externref_t ref, size_t nelem) {
   __builtin_wasm_table_fill(table, index, ref, nelem);
 }
 
 static __externref_t other_table[0];
 
-// CHECK-LABEL: define {{[^@]+}}@test_table_copy
-// CHECK-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    call void @llvm.wasm.table.copy(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
-// CHECK-NEXT:    ret void
+// WASM32-LABEL: define {{[^@]+}}@test_table_copy
+// WASM32-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    call void @llvm.wasm.table.copy.i32(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
+// WASM32-NEXT:    ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_table_copy
+// WASM64-SAME: (i64 noundef [[DST_IDX:%.*]], i64 noundef [[SRC_IDX:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    call void @llvm.wasm.table.copy.i64(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i64 [[SRC_IDX]], i64 [[DST_IDX]], i64 [[NELEM]])
+// WASM64-NEXT:    ret void
 //
-void test_table_copy(int dst_idx, int src_idx, int nelem) {
+void test_table_copy(size_t dst_idx, size_t src_idx, size_t nelem) {
   __builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem);
 }
diff --git a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
index b4f729669a795..95a5265bd480d 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table-funcref.c
@@ -1,69 +1,108 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
-// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefix=WASM32
+// RUN: %clang_cc1 -triple wasm64 -target-feature +reference-types -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s -check-prefixes=WASM64
 // REQUIRES: webassembly-registered-target
 
+typedef __SIZE_TYPE__ size_t;
+
 typedef void (*__funcref funcref_t)();
 static funcref_t table[0];
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT:    ret ptr addrspace(20) [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]])
+// WASM32-NEXT:    ret ptr addrspace(20) [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]])
+// WASM64-NEXT:    ret ptr addrspace(20) [[TMP0]]
 //
-funcref_t test_builtin_wasm_table_get(int index) {
+funcref_t test_builtin_wasm_table_get(size_t index) {
   return __builtin_wasm_table_get(table, index);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]])
-// CHECK-NEXT:    ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    call void @llvm.wasm.table.set.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]])
+// WASM32-NEXT:    ret void
 //
-void test_builtin_wasm_table_set(int index, funcref_t ref) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    call void @llvm.wasm.table.set.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(20) [[REF]])
+// WASM64-NEXT:    ret void
+//
+void test_builtin_wasm_table_set(size_t index, funcref_t ref) {
   return __builtin_wasm_table_set(table, index, ref);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
-// CHECK-SAME: () #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.size(ptr addrspace(1) @table)
-// CHECK-NEXT:    ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM32-SAME: () #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.size.i32(ptr addrspace(1) @table)
+// WASM32-NEXT:    ret i32 [[TMP0]]
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_size
+// WASM64-SAME: () #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    [[TMP0:%.*]] = call i64 @llvm.wasm.table.size.i64(ptr addrspace(1) @table)
+// WASM64-NEXT:    ret i64 [[TMP0]]
 //
-int test_builtin_wasm_table_size() {
+size_t test_builtin_wasm_table_size() {
   return __builtin_wasm_table_size(table);
 }
 
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// CHECK-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT:    ret i32 [[TMP0]]
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM32-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i32(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT:    ret i32 [[TMP0]]
 //
-int test_builtin_wasm_table_grow(funcref_t ref, int nelem) {
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
+// WASM64-SAME: (ptr addrspace(20) noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    [[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.funcref.i64(ptr addrspace(1) @table, ptr addrspace(20) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT:    ret i32 [[TMP0]]
+//
+int test_builtin_wasm_table_grow(funcref_t ref, size_t nelem) {
   return __builtin_wasm_table_grow(table, ref, nelem);
 }
 
-// CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    call void @llvm.wasm.table.fill.funcref(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]], i32 [[NELEM]])
-// CHECK-NEXT:    ret void
+// WASM32-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM32-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    call void @llvm.wasm.table.fill.funcref.i32(ptr addrspace(1) @table, i32 [[INDEX]], ptr addrspace(20) [[REF]], i32 [[NELEM]])
+// WASM32-NEXT:    ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
+// WASM64-SAME: (i64 noundef [[INDEX:%.*]], ptr addrspace(20) noundef [[REF:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    call void @llvm.wasm.table.fill.funcref.i64(ptr addrspace(1) @table, i64 [[INDEX]], ptr addrspace(20) [[REF]], i64 [[NELEM]])
+// WASM64-NEXT:    ret void
 //
-void test_builtin_wasm_table_fill(int index, funcref_t ref, int nelem) {
+void test_builtin_wasm_table_fill(size_t index, funcref_t ref, size_t nelem) {
   __builtin_wasm_table_fill(table, index, ref, nelem);
 }
 
 static funcref_t other_table[0];
 
-// CHECK-LABEL: define {{[^@]+}}@test_table_copy
-// CHECK-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    call void @llvm.wasm.table.copy(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
-// CHECK-NEXT:    ret void
+// WASM32-LABEL: define {{[^@]+}}@test_table_copy
+// WASM32-SAME: (i32 noundef [[DST_IDX:%.*]], i32 noundef [[SRC_IDX:%.*]], i32 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM32-NEXT:  entry:
+// WASM32-NEXT:    call void @llvm.wasm.table.copy.i32(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i32 [[SRC_IDX]], i32 [[DST_IDX]], i32 [[NELEM]])
+// WASM32-NEXT:    ret void
+//
+// WASM64-LABEL: define {{[^@]+}}@test_table_copy
+// WASM64-SAME: (i64 noundef [[DST_IDX:%.*]], i64 noundef [[SRC_IDX:%.*]], i64 noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// WASM64-NEXT:  entry:
+// WASM64-NEXT:    call void @llvm.wasm.table.copy.i64(ptr addrspace(1) @table, ptr addrspace(1) @other_table, i64 [[SRC_IDX]], i64 [[DST_IDX]], i64 [[NELEM]])
+// WASM64-NEXT:    ret void
 //
-void test_table_copy(int dst_idx, int src_idx, int nelem) {
+void test_table_copy(size_t dst_idx, size_t src_idx, size_t nelem) {
   __builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem);
 }
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index c1e4b97e96bc8..6272099059ea9 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -51,53 +51,53 @@ def int_wasm_ref_test_func
 // Table intrinsics
 //===----------------------------------------------------------------------===//
 def int_wasm_table_set_externref :
-  DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_i32_ty, llvm_externref_ty],
+  DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_anyint_ty, llvm_externref_ty],
                         [IntrWriteMem]>;
 def int_wasm_table_set_funcref :
-  DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_i32_ty, llvm_funcref_ty],
+  DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_anyint_ty, llvm_funcref_ty],
                         [IntrWriteMem]>;
 def int_wasm_table_set_exnref :
-  DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_i32_ty, llvm_exnref_ty],
+  DefaultAttrsIntrinsic<[], [llvm_table_ty, llvm_anyint_ty, llvm_exnref_ty],
                         [IntrWriteMem]>;
 
 def int_wasm_table_get_externref :
-  DefaultAttrsIntrinsic<[llvm_externref_ty], [llvm_table_ty, llvm_i32_ty],
+  DefaultAttrsIntrinsic<[llvm_externref_ty], [llvm_table_ty, llvm_anyint_ty],
                         [IntrReadMem]>;
 def int_wasm_table_get_funcref :
-  DefaultAttrsIntrinsic<[llvm_funcref_ty], [llvm_table_ty, llvm_i32_ty],
+  DefaultAttrsIntrinsic<[llvm_funcref_ty], [llvm_table_ty, llvm_anyint_ty],
                         [IntrReadMem]>;
 def int_wasm_table_get_exnref :
-  DefaultAttrsIntrinsic<[llvm_exnref_ty], [llvm_table_ty, llvm_i32_ty],
+  DefaultAttrsIntrinsic<[llvm_exnref_ty], [llvm_table_ty, llvm_anyint_ty],
                         [IntrReadMem]>;
 
 // Query the current table size, and increase the current table size.
 def int_wasm_table_size :
-  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_table_ty], [IntrReadMem]>;
+  DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_table_ty], [IntrReadMem]>;
 def int_wasm_table_copy :
   DefaultAttrsIntrinsic<[],
-                        [llvm_table_ty, llvm_table_ty, llvm_i32_ty, llvm_i32_ty,
-                         llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_table_ty, llvm_anyint_ty, LLVMMatchType<0>,
+                         LLVMMatchType<0>], []>;
 def int_wasm_table_grow_externref :
   DefaultAttrsIntrinsic<[llvm_i32_ty],
-                        [llvm_table_ty, llvm_externref_ty, llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_externref_ty, llvm_anyint_ty], []>;
 def int_wasm_table_grow_funcref :
   DefaultAttrsIntrinsic<[llvm_i32_ty],
-                        [llvm_table_ty, llvm_funcref_ty, llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_funcref_ty, llvm_anyint_ty], []>;
 def int_wasm_table_grow_exnref :
   DefaultAttrsIntrinsic<[llvm_i32_ty],
-                        [llvm_table_ty, llvm_exnref_ty, llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_exnref_ty, llvm_anyint_ty], []>;
 def int_wasm_table_fill_externref :
   DefaultAttrsIntrinsic<[],
-                        [llvm_table_ty, llvm_i32_ty, llvm_externref_ty,
-                         llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_anyint_ty, llvm_externref_ty,
+                         LLVMMatchType<0>], []>;
 def int_wasm_table_fill_funcref :
   DefaultAttrsIntrinsic<[],
-                        [llvm_table_ty, llvm_i32_ty, llvm_funcref_ty,
-                         llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_anyint_ty, llvm_funcref_ty,
+                         LLVMMatchType<0>], []>;
 def int_wasm_table_fill_exnref :
   DefaultAttrsIntrinsic<[],
-                        [llvm_table_ty, llvm_i32_ty, llvm_exnref_ty,
-                         llvm_i32_ty], []>;
+                        [llvm_table_ty, llvm_anyint_ty, llvm_exnref_ty,
+                         LLVMMatchType<0>], []>;
 
 //===----------------------------------------------------------------------===//
 // Trapping float-to-int conversions
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
index f9293460e701a..41d2be90b8ec0 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
@@ -67,7 +67,7 @@ wasm::ValType WebAssembly::toValType(MVT Type) {
 }
 
 void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
-                                    ArrayRef<MVT> VTs) {
+                                    ArrayRef<MVT> VTs, bool Is64) {
   assert(!Sym->getType());
 
   // Tables are represented as Arrays in LLVM IR therefore
@@ -91,7 +91,8 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
 
   if (IsTable) {
     Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
-    Sym->setTableType(ValTy);
+    Sym->setTableType(ValTy, Is64 ? wasm::WASM_LIMITS_FLAG_IS_64
+                                  : wasm::WASM_LIMITS_FLAG_NONE);
   } else {
     Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
     Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(ValTy), /*Mutable=*/true});
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
index 87660947e7de1..cc3c1ea3e5999 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -60,7 +60,7 @@ wasm::ValType toValType(MVT Type);
 
 /// Sets a Wasm Symbol Type.
 void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
-                       ArrayRef<MVT> VTs);
+                       ArrayRef<MVT> VTs, bool Addr64);
 
 } // end namespace WebAssembly
 } // end namespace llvm
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 1cacdb04fa74d..fb4dfbffc914a 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -207,7 +207,10 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
       computeLegalValueVTs(TLI, GV->getParent()->getContext(),
                            GV->getDataLayout(), GlobalVT, VTs);
     }
-    WebAssembly::wasmSymbolSetType(Sym, GlobalVT, VTs);
+    WebAssembly::wasmSymbolSetType(
+        Sym, GlobalVT, VTs,
+        Subtarget ? Subtarget->hasAddr64()
+                  : GV->getDataLayout().getPointerSizeInBits() == 64);
   }
 
   emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration());
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
index 2541b0433ab59..92ab3ac5c99f3 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
@@ -254,17 +254,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 2799b0ee0c804..bc5180657758d 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -827,10 +827,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);
@@ -881,10 +886,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 =
@@ -894,7 +904,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);
@@ -1517,7 +1530,8 @@ WebAssemblyTargetLowering::LowerCall(CallLoweringInfo &CLI,
     MCSymbolWasm *Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(
         MF.getContext(), Subtarget);
     SDValue Sym = DAG.getMCSymbol(Table, PtrVT);
-    SDValue TableSlot = DAG.getConstant(0, DL, MVT::i32);
+    SDValue TableSlot =
+        DAG.getConstant(0, DL, Subtarget->hasAddr64() ? MVT::i64 : MVT::i32);
     SDValue TableSetOps[] = {Chain, Sym, TableSlot, Callee};
     SDValue TableSet = DAG.getMemIntrinsicNode(
         WebAssemblyISD::TABLE_SET, DL, DAG.getVTList(MVT::Other), TableSetOps,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
index 02f0ab8577c3d..5722e3edc3433 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
@@ -20,67 +20,83 @@ def WebAssemblyTableGet : SDNode<"WebAssemblyISD::TABLE_GET", WebAssemblyTableGe
                                  [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
 
 
-multiclass TABLE<WebAssemblyRegClass rc, string suffix> {
+multiclass TABLE<WebAssemblyRegClass rc, string suffix, WebAssemblyRegClass index_rc, ValueType index_vt, string addrmodesuffix> {
   let mayLoad = 1 in
-  defm TABLE_GET_#rc : I<(outs rc:$res), (ins table32_op:$table, I32:$i),
+  defm TABLE_GET_#rc#addrmodesuffix : I<(outs rc:$res), (ins table32_op:$table, index_rc:$i),
                          (outs), (ins table32_op:$table),
-                         [(set rc:$res, (!cast<Intrinsic>("int_wasm_table_get_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i))],
+                         [(set rc:$res, (!cast<Intrinsic>("int_wasm_table_get_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), index_rc:$i))],
                          "table.get\t$res, $table, $i",
                          "table.get\t$table",
                          0x25>;
 
   let mayStore = 1 in
-  defm TABLE_SET_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val),
+  defm TABLE_SET_#rc#addrmodesuffix : I<(outs), (ins table32_op:$table, index_rc:$i, rc:$val),
                          (outs), (ins table32_op:$table),
-                         [(!cast<Intrinsic>("int_wasm_table_set_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val)],
+                         [(!cast<Intrinsic>("int_wasm_table_set_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), index_rc:$i, rc:$val)],
                          "table.set\t$table, $i, $val",
                          "table.set\t$table",
                          0x26>;
 
-  defm TABLE_GROW_#rc : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, I32:$n),
+  defm TABLE_GROW_#rc#addrmodesuffix : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, index_rc:$n),
                           (outs), (ins table32_op:$table),
-                          [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, I32:$n))],
+                          [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, index_rc:$n))],
                           "table.grow\t$sz, $table, $val, $n",
                           "table.grow\t$table",
                           0xfc0f>;
 
-  defm TABLE_FILL_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val, I32:$n),
+  defm TABLE_FILL_#rc#addrmodesuffix : I<(outs), (ins table32_op:$table, index_rc:$i, rc:$val, index_rc:$n),
                           (outs), (ins table32_op:$table),
-                          [(!cast<Intrinsic>("int_wasm_table_fill_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val, I32:$n)],
+                          [(!cast<Intrinsic>("int_wasm_table_fill_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), index_rc:$i, rc:$val, index_rc:$n)],
                           "table.fill\t$table, $i, $val, $n",
                           "table.fill\t$table",
                           0xfc11>;
 
   foreach vt = rc.RegTypes in {
-    def : Pat<(vt (WebAssemblyTableGet (WebAssemblyWrapper tglobaladdr:$table), i32:$idx)),
-              (!cast<NI>("TABLE_GET_" # rc) tglobaladdr:$table, i32:$idx)>;
+    def : Pat<(vt (WebAssemblyTableGet (WebAssemblyWrapper tglobaladdr:$table), index_vt:$idx)),
+              (!cast<NI>("TABLE_GET_" # rc # addrmodesuffix) tglobaladdr:$table, index_vt:$idx)>;
     def : Pat<(WebAssemblyTableSet
                (WebAssemblyWrapper tglobaladdr:$table),
-               i32:$idx,
+               index_vt:$idx,
                vt:$src),
-              (!cast<NI>("TABLE_SET_" # rc) tglobaladdr:$table, i32:$idx, vt:$src)>;
+              (!cast<NI>("TABLE_SET_" # rc # addrmodesuffix) tglobaladdr:$table, index_vt:$idx, vt:$src)>;
   }
 }
 
-defm "" : TABLE<FUNCREF, "funcref">, Requires<[HasReferenceTypes]>;
-defm "" : TABLE<EXTERNREF, "externref">, Requires<[HasReferenceTypes]>;
-defm "" : TABLE<EXNREF, "exnref">,
-          Requires<[HasReferenceTypes, HasExceptionHandling]>;
+defm "" : TABLE<FUNCREF, "funcref", I32, i32, "_A32">, Requires<[HasReferenceTypes, HasAddr32]>;
+defm "" : TABLE<EXTERNREF, "externref", I32, i32, "_A32">, Requires<[HasReferenceTypes, HasAddr32]>;
+defm "" : TABLE<EXNREF, "exnref", I32, i32, "_A32">,
+          Requires<[HasReferenceTypes, HasExceptionHandling, HasAddr32]>;
+
+defm "" : TABLE<FUNCREF, "funcref", I64, i64, "_A64">, Requires<[HasReferenceTypes, HasAddr64]>;
+defm "" : TABLE<EXTERNREF, "externref", I64, i64, "_A64">, Requires<[HasReferenceTypes, HasAddr64]>;
+defm "" : TABLE<EXNREF, "exnref", I64, i64, "_A64">,
+          Requires<[HasReferenceTypes, HasExceptionHandling, HasAddr64]>;
 
 def : Pat<(WebAssemblyTableSet mcsym:$table, i32:$idx, funcref:$r),
-          (TABLE_SET_FUNCREF mcsym:$table, i32:$idx, funcref:$r)>,
-          Requires<[HasReferenceTypes]>;
+          (TABLE_SET_FUNCREF_A32 mcsym:$table, i32:$idx, funcref:$r)>,
+          Requires<[HasReferenceTypes, HasAddr32]>;
+
+def : Pat<(WebAssemblyTableSet mcsym:$table, i64:$idx, funcref:$r),
+          (TABLE_SET_FUNCREF_A64 mcsym:$table, i64:$idx, funcref:$r)>,
+          Requires<[HasReferenceTypes, HasAddr64]>;
 
-defm TABLE_SIZE : I<(outs I32:$sz), (ins table32_op:$table),
+defm TABLE_SIZE_A32 : I<(outs I32:$sz), (ins table32_op:$table),
                     (outs), (ins table32_op:$table),
                     [(set I32:$sz, (int_wasm_table_size (WebAssemblyWrapper tglobaladdr:$table)))],
                     "table.size\t$sz, $table",
                     "table.size\t$table",
                     0xfc10>,
-                    Requires<[HasReferenceTypes]>;
+                    Requires<[HasReferenceTypes, HasAddr32]>;
 
+defm TABLE_SIZE_A64 : I<(outs I64:$sz), (ins table32_op:$table),
+                    (outs), (ins table32_op:$table),
+                    [(set I64:$sz, (int_wasm_table_size (WebAssemblyWrapper tglobaladdr:$table)))],
+                    "table.size\t$sz, $table",
+                    "table.size\t$table",
+                    0xfc10>,
+                    Requires<[HasReferenceTypes, HasAddr64]>;
 
-defm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n),
+defm TABLE_COPY_A32 : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n),
                     (outs), (ins table32_op:$table1, table32_op:$table2),
                     [(int_wasm_table_copy (WebAssemblyWrapper tglobaladdr:$table1),
                                           (WebAssemblyWrapper tglobaladdr:$table2),
@@ -88,4 +104,14 @@ defm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d,
                     "table.copy\t$table1, $table2, $d, $s, $n",
                     "table.copy\t$table1, $table2",
                     0xfc0e>,
-                    Requires<[HasReferenceTypes]>;
+                    Requires<[HasReferenceTypes, HasAddr32]>;
+
+defm TABLE_COPY_A64 : I<(outs), (ins table32_op:$table1, table32_op:$table2, I64:$d, I64:$s, I64:$n),
+                    (outs), (ins table32_op:$table1, table32_op:$table2),
+                    [(int_wasm_table_copy (WebAssemblyWrapper tglobaladdr:$table1),
+                                          (WebAssemblyWrapper tglobaladdr:$table2),
+                                          I64:$d, I64:$s, I64:$n)],
+                    "table.copy\t$table1, $table2, $d, $s, $n",
+                    "table.copy\t$table1, $table2",
+                    0xfc0e>,
+                    Requires<[HasReferenceTypes, HasAddr64]>;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index e48283aadb437..8aa51ed5accb2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -20,6 +20,7 @@
 #include "Utils/WebAssemblyTypeUtilities.h"
 #include "WebAssemblyAsmPrinter.h"
 #include "WebAssemblyMachineFunctionInfo.h"
+#include "WebAssemblySubtarget.h"
 #include "WebAssemblyUtilities.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -65,7 +66,9 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
       SmallVector<MVT, 1> VTs;
       computeLegalValueVTs(CurrentFunc, TM, GlobalVT, VTs);
 
-      WebAssembly::wasmSymbolSetType(WasmSym, GlobalVT, VTs);
+      WebAssembly::wasmSymbolSetType(
+          WasmSym, GlobalVT, VTs,
+          TM.getSubtarget<WebAssemblySubtarget>(CurrentFunc).hasAddr64());
     }
     return WasmSym;
   }
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
index 890486778e700..8dac20472a4a8 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
@@ -14,6 +14,7 @@
 #include "WebAssemblyUtilities.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetMachine.h"
+#include "llvm/BinaryFormat/Wasm.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/IR/Function.h"
 #include "llvm/MC/MCContext.h"
@@ -109,9 +110,10 @@ MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol(
     if (!Sym->isFunctionTable())
       Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
   } else {
-    bool is64 = Subtarget && Subtarget->getTargetTriple().isArch64Bit();
+    bool Is64 = Subtarget ? Subtarget->hasAddr64()
+                          : Ctx.getTargetTriple().isArch64Bit();
     Sym = static_cast<MCSymbolWasm *>(Ctx.getOrCreateSymbol(Name));
-    Sym->setFunctionTable(is64);
+    Sym->setFunctionTable(Is64);
     // The default function table is synthesized by the linker.
   }
   // MVP object files can't have symtab entries for tables.
@@ -134,7 +136,13 @@ MCSymbolWasm *WebAssembly::getOrCreateFuncrefCallTableSymbol(
     // modules define the table.
     Sym->setWeak(true);
 
-    wasm::WasmLimits Limits = {0, 1, 1, 0};
+    bool Is64 = Subtarget ? Subtarget->hasAddr64()
+                          : Ctx.getTargetTriple().isArch64Bit();
+
+    wasm::WasmLimits Limits = {(uint8_t)(Is64 ? wasm::WASM_LIMITS_FLAG_IS_64
+                                              : wasm::WASM_LIMITS_FLAG_NONE),
+                               1, 1, 0};
+
     wasm::WasmTableType TableType = {wasm::ValType::FUNCREF, Limits};
     Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
     Sym->setTableType(TableType);
diff --git a/llvm/test/CodeGen/WebAssembly/call-wasm64.ll b/llvm/test/CodeGen/WebAssembly/call-wasm64.ll
new file mode 100644
index 0000000000000..bd393e8e2a835
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/call-wasm64.ll
@@ -0,0 +1,181 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -mattr=+sign-ext,+simd128 | FileCheck --check-prefixes=CHECK,SLOW %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -fast-isel -fast-isel-abort=1 -mattr=+sign-ext,+simd128 | FileCheck --check-prefixes=CHECK,FAST %s
+;
+; Test that the relavent (differing) subsets of `call.ll` function correctly under Wasm64
+
+target triple = "wasm64-unknown-unknown"
+
+declare void @void_nullary()
+
+; CHECK-LABEL: call_void_nullary:
+; CHECK-NEXT: .functype call_void_nullary () -> (){{$}}
+; CHECK-NEXT: {{^}} call void_nullary{{$}}
+; CHECK-NEXT: return{{$}}
+define void @call_void_nullary() {
+  call void @void_nullary()
+  ret void
+}
+
+; CHECK-LABEL: call_indirect_void:
+; CHECK-NEXT: .functype call_indirect_void (i64) -> (){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $pop[[L0]]{{$}}
+; CHECK-NEXT: return{{$}}
+define void @call_indirect_void(ptr %callee) {
+  call void %callee()
+  ret void
+}
+
+; CHECK-LABEL: call_indirect_i32:
+; CHECK-NEXT: .functype call_indirect_i32 (i64) -> (i32){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
+; CHECK-NEXT: return $pop[[NUM]]{{$}}
+define i32 @call_indirect_i32(ptr %callee) {
+  %t = call i32 %callee()
+  ret i32 %t
+}
+
+; CHECK-LABEL: call_indirect_i64:
+; CHECK-NEXT: .functype call_indirect_i64 (i64) -> (i64){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
+; CHECK-NEXT: return $pop[[NUM]]{{$}}
+define i64 @call_indirect_i64(ptr %callee) {
+  %t = call i64 %callee()
+  ret i64 %t
+}
+
+; CHECK-LABEL: call_indirect_float:
+; CHECK-NEXT: .functype call_indirect_float (i64) -> (f32){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
+; CHECK-NEXT: return $pop[[NUM]]{{$}}
+define float @call_indirect_float(ptr %callee) {
+  %t = call float %callee()
+  ret float %t
+}
+
+; CHECK-LABEL: call_indirect_double:
+; CHECK-NEXT: .functype call_indirect_double (i64) -> (f64){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
+; CHECK-NEXT: return $pop[[NUM]]{{$}}
+define double @call_indirect_double(ptr %callee) {
+  %t = call double %callee()
+  ret double %t
+}
+
+; CHECK-LABEL: call_indirect_v128:
+; CHECK-NEXT: .functype call_indirect_v128 (i64) -> (v128){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
+; CHECK-NEXT: return $pop[[NUM]]{{$}}
+define <16 x i8> @call_indirect_v128(ptr %callee) {
+  %t = call <16 x i8> %callee()
+  ret <16 x i8> %t
+}
+
+; CHECK-LABEL: call_indirect_arg:
+; CHECK-NEXT: .functype call_indirect_arg (i64, i32) -> (){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 1{{$}}
+; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $pop[[L0]], $pop[[L1]]{{$}}
+; CHECK-NEXT: return{{$}}
+define void @call_indirect_arg(ptr %callee, i32 %arg) {
+  call void %callee(i32 %arg)
+  ret void
+}
+
+; CHECK-LABEL: call_indirect_arg_2:
+; CHECK-NEXT: .functype call_indirect_arg_2 (i64, i32, i32) -> (){{$}}
+; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 1{{$}}
+; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 2{{$}}
+; CHECK-NEXT: local.get $push[[L2:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: {{^}} call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $pop[[L2]]{{$}}
+; CHECK-NEXT: drop $pop[[NUM]]{{$}}
+; CHECK-NEXT: return{{$}}
+define void @call_indirect_arg_2(ptr %callee, i32 %arg, i32 %arg2) {
+  call i32 %callee(i32 %arg, i32 %arg2)
+  ret void
+}
+
+; CHECK-LABEL: call_constexpr:
+; CHECK-NEXT: .functype call_constexpr () -> (){{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 2{{$}}
+; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 3{{$}}
+; CHECK-NEXT: call .Lvararg_func_bitcast, $pop[[L0]], $pop[[L1]]{{$}}
+; CHECK-NEXT: i64.const	$push[[L3:[0-9]+]]=, void_nullary{{$}}
+; CHECK-NEXT: i64.const	$push[[L2:[0-9]+]]=, other_void_nullary{{$}}
+; CHECK-NEXT: i64.add 	$push[[L4:[0-9]+]]=, $pop[[L3]], $pop[[L2]]{{$}}
+; CHECK-NEXT: call_indirect	$pop[[L4]]{{$}}
+; CHECK-NEXT: call void_nullary{{$}}
+; CHECK-NEXT: return{{$}}
+declare void @vararg_func(...)
+declare void @other_void_nullary()
+define void @call_constexpr() {
+bb0:
+  call void @vararg_func(i32 2, i32 3)
+  br label %bb1
+bb1:
+  call void getelementptr (i8, ptr @void_nullary, i64 ptrtoint (ptr @other_void_nullary to i64))()
+  br label %bb2
+bb2:
+  call void inttoptr (i64 ptrtoint (ptr @void_nullary to i64) to ptr)()
+  ret void
+}
+
+; Allocas should be lowered to call_indirects.
+; CHECK-LABEL: call_indirect_alloca:
+; CHECK:      local.tee  $push{{.*}}=, [[L0:[0-9]+]]
+; CHECK-NEXT: global.set  __stack_pointer
+; CHECK-NEXT: local.get  $push{{.*}}=, [[L0]]
+; CHECK-NEXT: i64.const  $push{{.*}}=, 12
+; CHECK-NEXT: i64.add
+; CHECK-NEXT: call_indirect  $pop{{.*}}
+define void @call_indirect_alloca() {
+entry:
+  %ptr = alloca i32, align 4
+  call void %ptr()
+  ret void
+}
+
+; Calling non-functional globals should be lowered to call_indirects.
+; CHECK-LABEL: call_indirect_int:
+; CHECK:      i64.const  $push[[L0:[0-9]+]]=, global_i8
+; CHECK-NEXT: call_indirect  $pop[[L0]]
+; CHECK-NEXT: i64.const  $push[[L1:[0-9]+]]=, global_i32
+; CHECK-NEXT: call_indirect  $pop[[L1]]
+ at global_i8 = global i8 0
+ at global_i32 = global i32 0
+define void @call_indirect_int() {
+  call void @global_i8()
+  call void @global_i32()
+  ret void
+}
+
+; Calling aliases of non-functional globals should be lowered to call_indirects.
+; CHECK-LABEL: call_indirect_int_alias:
+; CHECK:      i64.const  $push[[L0:[0-9]+]]=, global_i8_alias
+; CHECK-NEXT: call_indirect  $pop[[L0]]
+; CHECK-NEXT: i64.const  $push[[L1:[0-9]+]]=, global_i32_alias
+; CHECK-NEXT: call_indirect  $pop[[L1]]
+ at global_i8_alias = alias i8, ptr @global_i8
+ at global_i32_alias = alias i32, ptr @global_i32
+define void @call_indirect_int_alias() {
+  call void @global_i8_alias()
+  call void @global_i32_alias()
+  ret void
+}
+
+; Ideally calling aliases of functions should be lowered to direct calls. We
+; support this in the normal (=slow) isel.
+; CHECK-LABEL: call_func_alias:
+; SLOW:      call  func_alias
+; FAST:      i64.const  $push[[L0:[0-9]+]]=, func_alias
+; FAST-NEXT: call_indirect  $pop[[L0]]
+ at func_alias = alias void (), ptr @call_void_nullary
+define void @call_func_alias() {
+  call void @func_alias()
+  ret void
+}
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
index d9ae7c8f6c9b1..506e1dd694461 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
@@ -1,71 +1,81 @@
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
 @externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 
-declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), i32) nounwind
+declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), iX) nounwind
 
-define %externref @get_externref_from_table(i32 %i) {
+define %externref @get_externref_from_table(iX %i) {
 ; CHECK-LABEL: get_externref_from_table:
-; CHECK-NEXT: .functype       get_externref_from_table (i32) -> (externref)
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.get externref_table
-; CHECK-NEXT: end_function
-  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %i)
+; WASM32-NEXT: .functype       get_externref_from_table (i32) -> (externref)
+; WASM64-NEXT: .functype       get_externref_from_table (i64) -> (externref)
+; CHECK-NEXT:  local.get 0
+; CHECK-NEXT:  table.get externref_table
+; CHECK-NEXT:  end_function
+  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %i)
   ret %externref %ref
 }
 
 define %externref @get_externref_from_table_const() {
 ; CHECK-LABEL: get_externref_from_table_const:
 ; CHECK-NEXT:  .functype      get_externref_from_table_const () -> (externref)
-; CHECK-NEXT:  i32.const      0
+; WASM32-NEXT: i32.const      0
+; WASM64-NEXT: i64.const      0
 ; CHECK-NEXT:  table.get      externref_table
 ; CHECK-NEXT:  end_function
-  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 0)
+  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX 0)
   ret %externref %ref
 }
 
-define %externref @get_externref_from_table_with_offset(i32 %i) {
+define %externref @get_externref_from_table_with_offset(iX %i) {
 ; CHECK-LABEL: get_externref_from_table_with_offset:
-; CHECK-NEXT:  .functype       get_externref_from_table_with_offset (i32) -> (externref)
+; WASM32-NEXT: .functype       get_externref_from_table_with_offset (i32) -> (externref)
+; WASM64-NEXT: .functype       get_externref_from_table_with_offset (i64) -> (externref)
 ; CHECK-NEXT:  local.get       0
-; CHECK-NEXT:  i32.const       2
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.const       2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const       2
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  table.get       externref_table
 ; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, 2
-  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %off)
+  %off = add nsw iX %i, 2
+  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %off)
   ret %externref %ref
 }
 
 
-define %externref @get_externref_from_table_with_var_offset(i32 %i, i32 %j) {
+define %externref @get_externref_from_table_with_var_offset(iX %i, iX %j) {
 ; CHECK-LABEL: get_externref_from_table_with_var_offset:
-; CHECK-NEXT:  .functype       get_externref_from_table_with_var_offset (i32, i32) -> (externref)
+; WASM32-NEXT: .functype       get_externref_from_table_with_var_offset (i32, i32) -> (externref)
+; WASM64-NEXT: .functype       get_externref_from_table_with_var_offset (i64, i64) -> (externref)
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  local.get       1
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  table.get       externref_table
 ; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, %j
-  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %off)
+  %off = add nsw iX %i, %j
+  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %off)
   ret %externref %ref
 }
 
-declare i32 @get_offset()
+declare iX @get_offset()
 
-define %externref @get_externref_from_table_with_var_offset2(i32 %i) {
+define %externref @get_externref_from_table_with_var_offset2(iX %i) {
 ; CHECK-LABEL: get_externref_from_table_with_var_offset2:
-; CHECK-NEXT:  .functype       get_externref_from_table_with_var_offset2 (i32) -> (externref)
+; WASM32-NEXT: .functype       get_externref_from_table_with_var_offset2 (i32) -> (externref)
+; WASM64-NEXT: .functype       get_externref_from_table_with_var_offset2 (i64) -> (externref)
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  call    get_offset
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  table.get       externref_table
 ; CHECK-NEXT:  end_function
-  %j = call i32 @get_offset()
-  %off = add nsw i32 %i, %j
-  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, i32 %off)
+  %j = call iX @get_offset()
+  %off = add nsw iX %i, %j
+  %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX %off)
   ret %externref %ref
 }
 
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
index 37c663869428e..9a1b29bbab28e 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
@@ -1,81 +1,92 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
 @externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 
-declare void @llvm.wasm.table.set.externref(ptr addrspace(1), i32, %externref) nounwind
+declare void @llvm.wasm.table.set.externref(ptr addrspace(1), iX, %externref) nounwind
 
-define void @set_externref_table(%externref %g, i32 %i) {
+define void @set_externref_table(%externref %g, iX %i) {
 ; CHECK-LABEL: set_externref_table:
-; CHECK-NEXT: .functype       set_externref_table (externref, i32) -> ()
-; CHECK-NEXT: local.get      1
-; CHECK-NEXT: local.get      0
-; CHECK-NEXT: table.set     externref_table
-; CHECK-NEXT: end_function
+; WASM32-NEXT: .functype       set_externref_table (externref, i32) -> ()
+; WASM64-NEXT: .functype       set_externref_table (externref, i64) -> ()
+; CHECK-NEXT:  local.get      1
+; CHECK-NEXT:  local.get      0
+; CHECK-NEXT:  table.set     externref_table
+; CHECK-NEXT:  end_function
 
 ;; this generates a table.set of @externref_table
-  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %i, %externref %g)
+  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %i, %externref %g)
   ret void
 }
 
 define void @set_externref_table_const(%externref %g) {
 ; CHECK-LABEL: set_externref_table_const:
 ; CHECK-NEXT:  .functype      set_externref_table_const (externref) -> ()
-; CHECK-NEXT:  i32.const      0
+; WASM32-NEXT: i32.const      0
+; WASM64-NEXT: i64.const      0
 ; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  table.set      externref_table
 ; CHECK-NEXT:  end_function
-  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 0, %externref %g)
+  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX 0, %externref %g)
   ret void
 }
 
-define void @set_externref_table_with_offset(%externref %g, i32 %i) {
+define void @set_externref_table_with_offset(%externref %g, iX %i) {
 ; CHECK-LABEL: set_externref_table_with_offset:
-; CHECK-NEXT:  .functype       set_externref_table_with_offset (externref, i32) -> ()
+; WASM32-NEXT: .functype       set_externref_table_with_offset (externref, i32) -> ()
+; WASM64-NEXT: .functype       set_externref_table_with_offset (externref, i64) -> ()
 ; CHECK-NEXT:  local.get       1
-; CHECK-NEXT:  i32.const       2
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.const       2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const       2
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, 2
-  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
+  %off = add nsw iX %i, 2
+  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %off, %externref %g)
   ret void
 }
 
-define void @set_externref_table_with_var_offset(%externref %g, i32 %i, i32 %j) {
+define void @set_externref_table_with_var_offset(%externref %g, iX %i, iX %j) {
 ; CHECK-LABEL: set_externref_table_with_var_offset:
-; CHECK-NEXT:  .functype       set_externref_table_with_var_offset (externref, i32, i32) -> ()
+; WASM32-NEXT: .functype       set_externref_table_with_var_offset (externref, i32, i32) -> ()
+; WASM64-NEXT: .functype       set_externref_table_with_var_offset (externref, i64, i64) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  local.get       2
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, %j
-  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
+  %off = add nsw iX %i, %j
+  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %off, %externref %g)
   ret void
 }
 
-declare i32 @set_offset()
+declare iX @set_offset()
 
-define void @set_externref_table_with_var_offset2(%externref %g, i32 %i) {
+define void @set_externref_table_with_var_offset2(%externref %g, iX %i) {
 ; CHECK-LABEL: set_externref_table_with_var_offset2:
-; CHECK-NEXT:  .functype       set_externref_table_with_var_offset2 (externref, i32) -> ()
+; WASM32-NEXT: .functype       set_externref_table_with_var_offset2 (externref, i32) -> ()
+; WASM64-NEXT: .functype       set_externref_table_with_var_offset2 (externref, i64) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  call    set_offset
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
-  %j = call i32 @set_offset()
-  %off = add nsw i32 %i, %j
-  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
+  %j = call iX @set_offset()
+  %off = add nsw iX %i, %j
+  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %off, %externref %g)
   ret void
 }
 
-declare i32 @get_table_slot() local_unnamed_addr
+declare iX @get_table_slot() local_unnamed_addr
 
 define void @set_externref_table_with_id_from_call(%externref %g) {
 ; CHECK-LABEL: set_externref_table_with_id_from_call:
@@ -84,8 +95,8 @@ define void @set_externref_table_with_id_from_call(%externref %g) {
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
-  %id = call i32 @get_table_slot()
-  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %id, %externref %g)
+  %id = call iX @get_table_slot()
+  call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, iX %id, %externref %g)
   ret void
 }
 
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-call.ll b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
index 9904df2280e81..3fdbcdc491a76 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,46 +1,79 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM32
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM32
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM64
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s --check-prefixes=WASM64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
 ; CHECK: .tabletype __funcref_call_table, funcref, 1
 
 define void @call_funcref(%funcref %ref) {
-; CHECK-LABEL: call_funcref:
-; CHECK:         .functype call_funcref (funcref) -> ()
-; CHECK-NEXT:  # %bb.0:
-; CHECK-NEXT:    i32.const 0
-; CHECK-NEXT:    local.get 0
-; CHECK-NEXT:    table.set __funcref_call_table
-; CHECK-NEXT:    i32.const 0
-; CHECK-NEXT:    call_indirect __funcref_call_table, () -> ()
-; CHECK-NEXT:    i32.const 0
-; CHECK-NEXT:    ref.null_func
-; CHECK-NEXT:    table.set __funcref_call_table
-; CHECK-NEXT:    # fallthrough-return
+; WASM32-LABEL: call_funcref:
+; WASM32:         .functype call_funcref (funcref) -> ()
+; WASM32-NEXT:  # %bb.0:
+; WASM32-NEXT:    i32.const 0
+; WASM32-NEXT:    local.get 0
+; WASM32-NEXT:    table.set __funcref_call_table
+; WASM32-NEXT:    i32.const 0
+; WASM32-NEXT:    call_indirect __funcref_call_table, () -> ()
+; WASM32-NEXT:    i32.const 0
+; WASM32-NEXT:    ref.null_func
+; WASM32-NEXT:    table.set __funcref_call_table
+; WASM32-NEXT:    # fallthrough-return
+;
+; WASM64-LABEL: call_funcref:
+; WASM64:         .functype call_funcref (funcref) -> ()
+; WASM64-NEXT:  # %bb.0:
+; WASM64-NEXT:    i64.const 0
+; WASM64-NEXT:    local.get 0
+; WASM64-NEXT:    table.set __funcref_call_table
+; WASM64-NEXT:    i64.const 0
+; WASM64-NEXT:    call_indirect __funcref_call_table, () -> ()
+; WASM64-NEXT:    i64.const 0
+; WASM64-NEXT:    ref.null_func
+; WASM64-NEXT:    table.set __funcref_call_table
+; WASM64-NEXT:    # fallthrough-return
   call addrspace(20) void %ref()
   ret void
 }
 
 define float @call_funcref_with_args(%funcref %ref) {
-; CHECK-LABEL: call_funcref_with_args:
-; CHECK:         .functype call_funcref_with_args (funcref) -> (f32)
-; CHECK-NEXT:    .local f32
-; CHECK-NEXT:  # %bb.0:
-; CHECK-NEXT:    i32.const 0
-; CHECK-NEXT:    local.get 0
-; CHECK-NEXT:    table.set __funcref_call_table
-; CHECK-NEXT:    f64.const 0x1p0
-; CHECK-NEXT:    i32.const 2
-; CHECK-NEXT:    i32.const 0
-; CHECK-NEXT:    call_indirect __funcref_call_table, (f64, i32) -> (f32)
-; CHECK-NEXT:    local.set 1
-; CHECK-NEXT:    i32.const 0
-; CHECK-NEXT:    ref.null_func
-; CHECK-NEXT:    table.set __funcref_call_table
-; CHECK-NEXT:    local.get 1
-; CHECK-NEXT:    # fallthrough-return
+; WASM32-LABEL: call_funcref_with_args:
+; WASM32:         .functype call_funcref_with_args (funcref) -> (f32)
+; WASM32-NEXT:    .local f32
+; WASM32-NEXT:  # %bb.0:
+; WASM32-NEXT:    i32.const 0
+; WASM32-NEXT:    local.get 0
+; WASM32-NEXT:    table.set __funcref_call_table
+; WASM32-NEXT:    f64.const 0x1p0
+; WASM32-NEXT:    i32.const 2
+; WASM32-NEXT:    i32.const 0
+; WASM32-NEXT:    call_indirect __funcref_call_table, (f64, i32) -> (f32)
+; WASM32-NEXT:    local.set 1
+; WASM32-NEXT:    i32.const 0
+; WASM32-NEXT:    ref.null_func
+; WASM32-NEXT:    table.set __funcref_call_table
+; WASM32-NEXT:    local.get 1
+; WASM32-NEXT:    # fallthrough-return
+;
+; WASM64-LABEL: call_funcref_with_args:
+; WASM64:         .functype call_funcref_with_args (funcref) -> (f32)
+; WASM64-NEXT:    .local f32
+; WASM64-NEXT:  # %bb.0:
+; WASM64-NEXT:    i64.const 0
+; WASM64-NEXT:    local.get 0
+; WASM64-NEXT:    table.set __funcref_call_table
+; WASM64-NEXT:    f64.const 0x1p0
+; WASM64-NEXT:    i32.const 2
+; WASM64-NEXT:    i64.const 0
+; WASM64-NEXT:    call_indirect __funcref_call_table, (f64, i32) -> (f32)
+; WASM64-NEXT:    local.set 1
+; WASM64-NEXT:    i64.const 0
+; WASM64-NEXT:    ref.null_func
+; WASM64-NEXT:    table.set __funcref_call_table
+; WASM64-NEXT:    local.get 1
+; WASM64-NEXT:    # fallthrough-return
   %ret = call addrspace(20) float %ref(double 1.0, i32 2)
   ret float %ret
 }
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index 74bbc802ac077..a2421c1c6ff3a 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
@@ -1,4 +1,5 @@
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
@@ -6,26 +7,29 @@
 
 ;  CHECK: .tabletype  __funcref_call_table, funcref, 1
 
-declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind
+declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
 
-define void @call_funcref_from_table(i32 %i) {
+define void @call_funcref_from_table(iX %i) {
 ; CHECK-LABEL: call_funcref_from_table:
-; CHECK-NEXT: .functype       call_funcref_from_table (i32) -> ()
-; CHECK-NEXT: i32.const       0
-; CHECK-NEXT: local.get       0
-; CHECK-NEXT: table.get       funcref_table
-; CHECK-NEXT: table.set       __funcref_call_table
-; CHECK-NEXT: i32.const       0
-; CHECK-NEXT: call_indirect    __funcref_call_table, () -> ()
-; CHECK-NEXT: i32.const       0
-; CHECK-NEXT: ref.null_func
-; CHECK-NEXT: table.set       __funcref_call_table
-; CHECK-NEXT: end_function
-  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %i)
+; WASM32-NEXT: .functype       call_funcref_from_table (i32) -> ()
+; WASM64-NEXT: .functype       call_funcref_from_table (i64) -> ()
+; WASM32-NEXT: i32.const       0
+; WASM64-NEXT: i64.const       0
+; CHECK-NEXT:  local.get       0
+; CHECK-NEXT:  table.get       funcref_table
+; CHECK-NEXT:  table.set       __funcref_call_table
+; WASM32-NEXT: i32.const       0
+; WASM64-NEXT: i64.const       0
+; CHECK-NEXT:  call_indirect    __funcref_call_table, () -> ()
+; WASM32-NEXT: i32.const       0
+; WASM64-NEXT: i64.const       0
+; CHECK-NEXT:  ref.null_func
+; CHECK-NEXT:  table.set       __funcref_call_table
+; CHECK-NEXT:  end_function
+  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %i)
   call addrspace(20) void %ref()
   ret void
 }
 
 ;       CHECK: .tabletype funcref_table, funcref
 ; CHECK-LABEL: funcref_table:
-
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
index 3df308c5ddf80..8c8e4fdc4d5f2 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
@@ -1,71 +1,81 @@
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
 @funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
 
-declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind
+declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
 
-define %funcref @get_funcref_from_table(i32 %i) {
+define %funcref @get_funcref_from_table(iX %i) {
 ; CHECK-LABEL: get_funcref_from_table:
-; CHECK-NEXT: .functype       get_funcref_from_table (i32) -> (funcref)
-; CHECK-NEXT: local.get 0
-; CHECK-NEXT: table.get funcref_table
-; CHECK-NEXT: end_function
-  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %i)
+; WASM32-NEXT: .functype       get_funcref_from_table (i32) -> (funcref)
+; WASM64-NEXT: .functype       get_funcref_from_table (i64) -> (funcref)
+; CHECK-NEXT:  local.get 0
+; CHECK-NEXT:  table.get funcref_table
+; CHECK-NEXT:  end_function
+  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %i)
   ret %funcref %ref
 }
 
 define %funcref @get_funcref_from_table_const() {
 ; CHECK-LABEL: get_funcref_from_table_const:
 ; CHECK-NEXT:  .functype      get_funcref_from_table_const () -> (funcref)
-; CHECK-NEXT:  i32.const      0
+; WASM32-NEXT: i32.const      0
+; WASM64-NEXT: i64.const      0
 ; CHECK-NEXT:  table.get      funcref_table
 ; CHECK-NEXT:  end_function
-  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 0)
+  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX 0)
   ret %funcref %ref
 }
 
-define %funcref @get_funcref_from_table_with_offset(i32 %i) {
+define %funcref @get_funcref_from_table_with_offset(iX %i) {
 ; CHECK-LABEL: get_funcref_from_table_with_offset:
-; CHECK-NEXT:  .functype       get_funcref_from_table_with_offset (i32) -> (funcref)
-; CHECK-NEXT:  local.get       0
-; CHECK-NEXT:  i32.const       2
-; CHECK-NEXT:  i32.add
-; CHECK-NEXT:  table.get       funcref_table
-; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, 2
-  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
+; WASM32-NEXT:  .functype       get_funcref_from_table_with_offset (i32) -> (funcref)
+; WASM64-NEXT:  .functype       get_funcref_from_table_with_offset (i64) -> (funcref)
+; CHECK-NEXT:   local.get       0
+; WASM32-NEXT:  i32.const       2
+; WASM32-NEXT:  i32.add
+; WASM64-NEXT:  i64.const       2
+; WASM64-NEXT:  i64.add
+; CHECK-NEXT:   table.get       funcref_table
+; CHECK-NEXT:   end_function
+  %off = add nsw iX %i, 2
+  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %off)
   ret %funcref %ref
 }
 
 
-define %funcref @get_funcref_from_table_with_var_offset(i32 %i, i32 %j) {
+define %funcref @get_funcref_from_table_with_var_offset(iX %i, iX %j) {
 ; CHECK-LABEL: get_funcref_from_table_with_var_offset:
-; CHECK-NEXT:  .functype       get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
-; CHECK-NEXT:  local.get       0
-; CHECK-NEXT:  local.get       1
-; CHECK-NEXT:  i32.add
-; CHECK-NEXT:  table.get       funcref_table
-; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, %j
-  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
+; WASM32-NEXT:  .functype       get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
+; WASM64-NEXT:  .functype       get_funcref_from_table_with_var_offset (i64, i64) -> (funcref)
+; CHECK-NEXT:   local.get       0
+; CHECK-NEXT:   local.get       1
+; WASM32-NEXT:  i32.add
+; WASM64-NEXT:  i64.add
+; CHECK-NEXT:   table.get       funcref_table
+; CHECK-NEXT:   end_function
+  %off = add nsw iX %i, %j
+  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %off)
   ret %funcref %ref
 }
 
-declare i32 @get_offset()
+declare iX @get_offset()
 
-define %funcref @get_funcref_from_table_with_var_offset2(i32 %i) {
+define %funcref @get_funcref_from_table_with_var_offset2(iX %i) {
 ; CHECK-LABEL: get_funcref_from_table_with_var_offset2:
-; CHECK-NEXT:  .functype       get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
+; WASM32-NEXT: .functype       get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
+; WASM64-NEXT: .functype       get_funcref_from_table_with_var_offset2 (i64) -> (funcref)
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  call    get_offset
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  table.get       funcref_table
 ; CHECK-NEXT:  end_function
-  %j = call i32 @get_offset()
-  %off = add nsw i32 %i, %j
-  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
+  %j = call iX @get_offset()
+  %off = add nsw iX %i, %j
+  %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX %off)
   ret %funcref %ref
 }
 
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
index 98e1b55613d7d..897d1b704e28b 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -1,77 +1,101 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
 @funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
 
-declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), i32, %funcref) nounwind
+declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), iX, %funcref) nounwind
 
-define void @set_funcref_table(%funcref %g, i32 %i) {
+define void @set_funcref_table(%funcref %g, iX %i) {
 ; CHECK-LABEL: set_funcref_table:
-; CHECK-NEXT: .functype       set_funcref_table (funcref, i32) -> ()
-; CHECK-NEXT: local.get      1
-; CHECK-NEXT: local.get      0
-; CHECK-NEXT: table.set     funcref_table
-; CHECK-NEXT: end_function
+; WASM32-NEXT: .functype       set_funcref_table (funcref, i32) -> ()
+; WASM64-NEXT: .functype       set_funcref_table (funcref, i64) -> ()
+; CHECK-NEXT:  local.get      1
+; CHECK-NEXT:  local.get      0
+; CHECK-NEXT:  table.set     funcref_table
+; CHECK-NEXT:  end_function
 
 ;; this generates a table.set of @funcref_table
-  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %i, %funcref %g)
+  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %i, %funcref %g)
   ret void
 }
 
 define void @set_funcref_table_const(%funcref %g) {
 ; CHECK-LABEL: set_funcref_table_const:
 ; CHECK-NEXT:  .functype      set_funcref_table_const (funcref) -> ()
-; CHECK-NEXT:  i32.const      0
+; WASM32-NEXT: i32.const      0
+; WASM64-NEXT: i64.const      0
 ; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  table.set      funcref_table
 ; CHECK-NEXT:  end_function
-  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 0, %funcref %g)
+  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX 0, %funcref %g)
   ret void
 }
 
-define void @set_funcref_table_with_offset(%funcref %g, i32 %i) {
+define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
 ; CHECK-LABEL: set_funcref_table_with_offset:
-; CHECK-NEXT:  .functype       set_funcref_table_with_offset (funcref, i32) -> ()
+; WASM32-NEXT: .functype       set_funcref_table_with_offset (funcref, i32) -> ()
+; WASM64-NEXT: .functype       set_funcref_table_with_offset (funcref, i64) -> ()
 ; CHECK-NEXT:  local.get       1
-; CHECK-NEXT:  i32.const       2
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.const       2
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.const       2
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       funcref_table
 ; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, 2
-  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
+  %off = add nsw iX %i, 2
+  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %off, %funcref %g)
   ret void
 }
 
-define void @set_funcref_table_with_var_offset(%funcref %g, i32 %i, i32 %j) {
+define void @set_funcref_table_with_var_offset(%funcref %g, iX %i, iX %j) {
 ; CHECK-LABEL: set_funcref_table_with_var_offset:
-; CHECK-NEXT:  .functype       set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
+; WASM32-NEXT: .functype       set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
+; WASM64-NEXT: .functype       set_funcref_table_with_var_offset (funcref, i64, i64) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  local.get       2
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       funcref_table
 ; CHECK-NEXT:  end_function
-  %off = add nsw i32 %i, %j
-  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
+  %off = add nsw iX %i, %j
+  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %off, %funcref %g)
   ret void
 }
 
-declare i32 @set_offset()
+declare iX @set_offset()
 
-define void @set_funcref_table_with_var_offset2(%funcref %g, i32 %i) {
+define void @set_funcref_table_with_var_offset2(%funcref %g, iX %i) {
 ; CHECK-LABEL: set_funcref_table_with_var_offset2:
-; CHECK-NEXT:  .functype       set_funcref_table_with_var_offset2 (funcref, i32) -> ()
+; WASM32-NEXT: .functype       set_funcref_table_with_var_offset2 (funcref, i32) -> ()
+; WASM64-NEXT: .functype       set_funcref_table_with_var_offset2 (funcref, i64) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  call    set_offset
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
+; CHECK-NEXT:  local.get       0
+; CHECK-NEXT:  table.set       funcref_table
+; CHECK-NEXT:  end_function
+  %j = call iX @set_offset()
+  %off = add nsw iX %i, %j
+  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %off, %funcref %g)
+  ret void
+}
+
+declare iX @get_table_slot() local_unnamed_addr
+
+define void @set_funcref_table_with_id_from_call(%funcref %g) {
+; CHECK-LABEL: set_funcref_table_with_id_from_call:
+; CHECK-NEXT:  .functype       set_funcref_table_with_id_from_call (funcref) -> ()
+; CHECK-NEXT:  call    get_table_slot
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       funcref_table
 ; CHECK-NEXT:  end_function
-  %j = call i32 @set_offset()
-  %off = add nsw i32 %i, %j
-  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
+  %id = call iX @get_table_slot()
+  call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, iX %id, %funcref %g)
   ret void
 }
 
diff --git a/llvm/test/CodeGen/WebAssembly/ref-test-func.ll b/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
index 4fda253d39fe3..db100736a3423 100644
--- a/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
+++ b/llvm/test/CodeGen/WebAssembly/ref-test-func.ll
@@ -8,7 +8,6 @@ define void @test_fpsig_void_void(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_void_void (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test () -> ()
 ; CHECK-NEXT:    call use
@@ -25,7 +24,6 @@ define void @test_fpsig_return_i32(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_return_i32 (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test () -> (i32)
 ; CHECK-NEXT:    call use
@@ -42,7 +40,6 @@ define void @test_fpsig_return_i64(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_return_i64 (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test () -> (i64)
 ; CHECK-NEXT:    call use
@@ -59,7 +56,6 @@ define void @test_fpsig_return_f32(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_return_f32 (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test () -> (f32)
 ; CHECK-NEXT:    call use
@@ -76,7 +72,6 @@ define void @test_fpsig_return_f64(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_return_f64 (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test () -> (f64)
 ; CHECK-NEXT:    call use
@@ -94,7 +89,6 @@ define void @test_fpsig_param_i32(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_param_i32 (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test (f64) -> ()
 ; CHECK-NEXT:    call use
@@ -112,7 +106,6 @@ define void @test_fpsig_multiple_params_and_returns(ptr noundef %func) local_unn
 ; CHK64:         .functype test_fpsig_multiple_params_and_returns (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test (i64, f32, i64) -> (i32, i64, f32, f64)
 ; CHECK-NEXT:    call use
@@ -130,7 +123,6 @@ define void @test_fpsig_ptrs(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_fpsig_ptrs (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHK32-NEXT:    ref.test (i32, i32) -> (i32)
 ; CHK64-NEXT:    ref.test (i64, i64) -> (i64)
@@ -148,7 +140,6 @@ define void @test_reference_types(ptr noundef %func) local_unnamed_addr #0 {
 ; CHK64:         .functype test_reference_types (i64) -> ()
 ; CHECK-NEXT:  # %bb.0: # %entry
 ; CHECK-NEXT:    local.get 0
-; CHK64-NEXT:    i32.wrap_i64
 ; CHECK-NEXT:    table.get __indirect_function_table
 ; CHECK-NEXT:    ref.test (funcref, externref) -> (externref)
 ; CHECK-NEXT:    call use
diff --git a/llvm/test/CodeGen/WebAssembly/table-copy.ll b/llvm/test/CodeGen/WebAssembly/table-copy.ll
index 5c0647ada4ab0..fee5cfb9da3ac 100644
--- a/llvm/test/CodeGen/WebAssembly/table-copy.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-copy.ll
@@ -1,37 +1,41 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
 @externref_table1 = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 @externref_table2 = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 
-declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), i32, i32, i32) nounwind readonly
+declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), iX, iX, iX) nounwind readonly
 
-define void @table_copy(i32 %dst, i32 %src, i32 %len) {
+define void @table_copy(iX %dst, iX %src, iX %len) {
 ; CHECK-LABEL: table_copy:
-; CHECK-NEXT:  .functype	table_copy (i32, i32, i32) -> ()
+; WASM32-NEXT: .functype	table_copy (i32, i32, i32) -> ()
+; WASM64-NEXT: .functype	table_copy (i64, i64, i64) -> ()
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    1
 ; CHECK-NEXT:  local.get    2
 ; CHECK-NEXT:  table.copy	externref_table1, externref_table2
 ; CHECK-NEXT:  end_function
-  call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table2, i32 %dst, i32 %src, i32 %len)
+  call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table2, iX %dst, iX %src, iX %len)
   ret void
 }
 
 ; Testing copying from a table to itself at different offsets
 ; Copies len items from table1 at src to table1 at src+off
-define void @self_table_copy(i32 %src, i32 %off, i32 %len) {
+define void @self_table_copy(iX %src, iX %off, iX %len) {
 ; CHECK-LABEL: self_table_copy:
-; CHECK-NEXT:  .functype	self_table_copy (i32, i32, i32) -> ()
+; WASM32-NEXT: .functype	self_table_copy (i32, i32, i32) -> ()
+; WASM64-NEXT: .functype	self_table_copy (i64, i64, i64) -> ()
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    1
-; CHECK-NEXT:  i32.add
+; WASM32-NEXT: i32.add
+; WASM64-NEXT: i64.add
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    2
 ; CHECK-NEXT:  table.copy	externref_table1, externref_table1
 ; CHECK-NEXT:  end_function
-  %dst = add nsw i32 %src, %off
-  call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table1, i32 %dst, i32 %src, i32 %len)
+  %dst = add nsw iX %src, %off
+  call void @llvm.wasm.table.copy(ptr addrspace(1) @externref_table1, ptr addrspace(1) @externref_table1, iX %dst, iX %src, iX %len)
   ret void
 }
diff --git a/llvm/test/CodeGen/WebAssembly/table-fill.ll b/llvm/test/CodeGen/WebAssembly/table-fill.ll
index 0b78124f038b1..3fdf315bede68 100644
--- a/llvm/test/CodeGen/WebAssembly/table-fill.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-fill.ll
@@ -1,19 +1,21 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
 @externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 
-declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), i32, %externref, i32) nounwind readonly
+declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), iX, %externref, iX) nounwind readonly
 
-define void @table_fill(i32 %start, i32 %len, %externref %val) {
+define void @table_fill(iX %start, iX %len, %externref %val) {
 ; CHECK-LABEL: table_fill:
-; CHECK-NEXT:  .functype	table_fill (i32, i32, externref) -> ()
+; WASM32-NEXT: .functype	table_fill (i32, i32, externref) -> ()
+; WASM64-NEXT: .functype	table_fill (i64, i64, externref) -> ()
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    2
 ; CHECK-NEXT:  local.get    1
 ; CHECK-NEXT:  table.fill	externref_table
 ; CHECK-NEXT:  end_function
-  call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @externref_table, i32 %start, %externref %val, i32 %len)
+  call void @llvm.wasm.table.fill.externref(ptr addrspace(1) @externref_table, iX %start, %externref %val, iX %len)
   ret void
 }
diff --git a/llvm/test/CodeGen/WebAssembly/table-grow.ll b/llvm/test/CodeGen/WebAssembly/table-grow.ll
index 614c3400a782b..7ddc1d84e6dba 100644
--- a/llvm/test/CodeGen/WebAssembly/table-grow.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-grow.ll
@@ -1,20 +1,22 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
 @externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 
-declare i32 @llvm.wasm.table.grow.externref(ptr addrspace(1), %externref, i32) nounwind readonly
+declare i32 @llvm.wasm.table.grow.externref(ptr addrspace(1), %externref, iX) nounwind readonly
 declare %externref @llvm.wasm.ref.null.extern() nounwind readonly
 
-define i32 @table_grow(i32 %sz) {
+define i32 @table_grow(iX %sz) {
 ; CHECK-LABEL: table_grow:
-; CHECK-NEXT:  .functype	table_grow (i32) -> (i32)
+; WASM32-NEXT: .functype	table_grow (i32) -> (i32)
+; WASM64-NEXT: .functype	table_grow (i64) -> (i32)
 ; CHECK-NEXT:  ref.null_extern
 ; CHECK-NEXT:  local.get	0
 ; CHECK-NEXT:  table.grow	externref_table
 ; CHECK-NEXT:  end_function
   %null = call %externref @llvm.wasm.ref.null.extern()
-  %newsz = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @externref_table, %externref %null, i32 %sz)
+  %newsz = call i32 @llvm.wasm.table.grow.externref(ptr addrspace(1) @externref_table, %externref %null, iX %sz)
   ret i32 %newsz
 }
diff --git a/llvm/test/CodeGen/WebAssembly/table-size.ll b/llvm/test/CodeGen/WebAssembly/table-size.ll
index 42cd2e8a909d7..3b0722a73bb57 100644
--- a/llvm/test/CodeGen/WebAssembly/table-size.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-size.ll
@@ -1,16 +1,18 @@
-; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
 @externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
 
-declare i32 @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
+declare iX @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
 
-define i32 @table_size() {
+define iX @table_size() {
 ; CHECK-LABEL: table_size:
-; CHECK-NEXT:  .functype       table_size () -> (i32)
+; WASM32-NEXT: .functype       table_size () -> (i32)
+; WASM64-NEXT: .functype       table_size () -> (i64)
 ; CHECK-NEXT:  table.size      externref_table
 ; CHECK-NEXT:  end_function
-  %sz = call i32 @llvm.wasm.table.size(ptr addrspace(1) @externref_table)
-  ret i32 %sz
+  %sz = call iX @llvm.wasm.table.size(ptr addrspace(1) @externref_table)
+  ret iX %sz
 }
diff --git a/llvm/test/CodeGen/WebAssembly/table-types.ll b/llvm/test/CodeGen/WebAssembly/table-types.ll
index cb5e54e2af230..209d822af9fa2 100644
--- a/llvm/test/CodeGen/WebAssembly/table-types.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-types.ll
@@ -1,4 +1,5 @@
 ; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 %funcref = type ptr addrspace(20)   ;; addrspace 20 is nonintegral
diff --git a/llvm/test/MC/WebAssembly/tables.ll b/llvm/test/MC/WebAssembly/tables.ll
new file mode 100644
index 0000000000000..3ba345f96259c
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/tables.ll
@@ -0,0 +1,72 @@
+; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | obj2yaml | FileCheck --check-prefixes CHECK %s
+; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o - | obj2yaml | FileCheck --check-prefixes CHECK,WASM64 %s
+
+; Ensure that tables generated through `llc` are in the correct address mode
+
+
+%externref = type ptr addrspace(10)
+ at externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
+
+%funcref = type ptr addrspace(20)
+ at funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
+
+; CHECK:      --- !WASM
+; CHECK-NEXT: FileHeader:
+; CHECK-NEXT:   Version:         0x1
+; CHECK-NEXT: Sections:
+; CHECK-NEXT:   - Type:            IMPORT
+; CHECK-NEXT:     Imports:
+; CHECK-NEXT:       - Module:          env
+; CHECK-NEXT:         Field:           __linear_memory
+; CHECK-NEXT:         Kind:            MEMORY
+; CHECK-NEXT:         Memory:
+; WASM64-NEXT:          Flags:           [ IS_64 ]
+; CHECK-NEXT:           Minimum:         0x0
+; CHECK-NEXT:   - Type:            TABLE
+; CHECK-NEXT:     Tables:
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         ElemType:        EXTERNREF
+; CHECK-NEXT:         Limits:
+; WASM64-NEXT:          Flags:           [ IS_64 ]
+; CHECK-NEXT:           Minimum:         0x0
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         ElemType:        FUNCREF
+; CHECK-NEXT:         Limits:
+; WASM64-NEXT:          Flags:           [ IS_64 ]
+; CHECK-NEXT:           Minimum:         0x0
+; CHECK-NEXT:   - Type:            CUSTOM
+; CHECK-NEXT:     Name:            linking
+; CHECK-NEXT:     Version:         2
+; CHECK-NEXT:     SymbolTable:
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         Kind:            TABLE
+; CHECK-NEXT:         Name:            externref_table
+; CHECK-NEXT:        Flags:           [  ]
+; CHECK-NEXT:         Table:           0
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         Kind:            TABLE
+; CHECK-NEXT:         Name:            funcref_table
+; CHECK-NEXT:        Flags:           [  ]
+; CHECK-NEXT:         Table:           1
+; CHECK-NEXT:   - Type:            CUSTOM
+; CHECK-NEXT:     Name:            target_features
+; CHECK-NEXT:     Features:
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            bulk-memory
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            bulk-memory-opt
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            call-indirect-overlong
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            multivalue
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            mutable-globals
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            nontrapping-fptoint
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            reference-types
+; CHECK-NEXT:       - Prefix:          USED
+; CHECK-NEXT:         Name:            sign-ext
+; WASM64-NEXT:      - Prefix:          USED
+; WASM64-NEXT:        Name:            memory64
+; CHECK-NEXT: ...
diff --git a/llvm/test/MC/WebAssembly/wasm64.s b/llvm/test/MC/WebAssembly/wasm64.s
index 0c939b47db4f2..237f5a22dd766 100644
--- a/llvm/test/MC/WebAssembly/wasm64.s
+++ b/llvm/test/MC/WebAssembly/wasm64.s
@@ -6,6 +6,9 @@
 .globaltype myglob64, i64
 .globaltype __stack_pointer, i64
 
+    .tabletype externref_table, externref
+externref_table:
+
 test:
     .functype   test (i64) -> ()
     .local      i64
@@ -72,6 +75,9 @@ test:
 
 # CHECK:              .globaltype     myglob64, i64
 
+# CHECK:         .tabletype externref_table, externref
+# CHECK: externref_table:
+
 # CHECK:              .functype       test (i64) -> ()
 # CHECK-NEXT:         .local          i64
 
@@ -159,31 +165,38 @@ test:
 # BIN-NEXT:         GlobalMutable:   true
 # BIN-NEXT:   - Type:            FUNCTION
 # BIN-NEXT:     FunctionTypes:   [ 0 ]
+# BIN-NEXT:   - Type:            TABLE
+# BIN-NEXT:      Tables:
+# BIN-NEXT:        - Index:           0
+# BIN-NEXT:          ElemType:        EXTERNREF
+# BIN-NEXT:          Limits:
+# BIN-NEXT:            Flags:           [ IS_64 ]
+# BIN-NEXT:            Minimum:         0x0
 # BIN-NEXT:   - Type:            DATACOUNT
 # BIN-NEXT:     Count:           1
 # BIN-NEXT:   - Type:            CODE
 # BIN-NEXT:     Relocations:
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
-# BIN-NEXT:         Index:           1
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x13
 # BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           3
 # BIN-NEXT:         Offset:          0x22
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
-# BIN-NEXT:         Index:           1
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x2F
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
-# BIN-NEXT:         Index:           1
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x4F
 # BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           3
 # BIN-NEXT:         Offset:          0x62
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
-# BIN-NEXT:         Index:           1
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x78
-# BIN-NEXT:       - Type: R_WASM_GLOBAL_INDEX_LEB
-# BIN-NEXT:         Index: 3
-# BIN-NEXT:         Offset: 0x83
+# BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
+# BIN-NEXT:         Index:           4
+# BIN-NEXT:         Offset:          0x83
 # BIN-NEXT:     Functions:
 # BIN-NEXT:       - Index:           0
 # BIN-NEXT:         Locals:
@@ -193,7 +206,7 @@ test:
 # BIN-NEXT:   - Type:            DATA
 # BIN-NEXT:     Relocations:
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I64
-# BIN-NEXT:         Index:           1
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x16
 # BIN-NEXT:     Segments:
 # BIN-NEXT:       - SectionOffset:   6
@@ -207,22 +220,27 @@ test:
 # BIN-NEXT:     Version:         2
 # BIN-NEXT:     SymbolTable:
 # BIN-NEXT:       - Index:           0
+# BIN-NEXT:         Kind:            TABLE
+# BIN-NEXT:         Name:            externref_table
+# BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
+# BIN-NEXT:         Table:           0
+# BIN-NEXT:       - Index:           1
 # BIN-NEXT:         Kind:            FUNCTION
 # BIN-NEXT:         Name:            test
 # BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
 # BIN-NEXT:         Function:        0
-# BIN-NEXT:       - Index:           1
+# BIN-NEXT:       - Index:           2
 # BIN-NEXT:         Kind:            DATA
 # BIN-NEXT:         Name:            .L.str
 # BIN-NEXT:         Flags:           [ BINDING_LOCAL, VISIBILITY_HIDDEN ]
 # BIN-NEXT:         Segment:         0
 # BIN-NEXT:         Size:            24
-# BIN-NEXT:       - Index:           2
+# BIN-NEXT:       - Index:           3
 # BIN-NEXT:         Kind:            GLOBAL
 # BIN-NEXT:         Name:            myglob64
 # BIN-NEXT:         Flags:           [ UNDEFINED ]
 # BIN-NEXT:         Global:          0
-# BIN-NEXT:       - Index:           3
+# BIN-NEXT:       - Index:           4
 # BIN-NEXT:         Kind:            GLOBAL
 # BIN-NEXT:         Name:            __stack_pointer
 # BIN-NEXT:         Flags:           [ UNDEFINED ]

>From adf4471f0c735faa7d9e654ceaaf7caaae1acfac 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/3] Use FileCheck defines instead in manually written tests

---
 .../CodeGen/WebAssembly/externref-tableget.ll | 33 +++++++------------
 .../CodeGen/WebAssembly/externref-tableset.ll | 31 +++++++----------
 .../CodeGen/WebAssembly/funcref-table_call.ll | 16 ++++-----
 .../CodeGen/WebAssembly/funcref-tableget.ll   | 31 +++++++----------
 .../CodeGen/WebAssembly/funcref-tableset.ll   | 31 +++++++----------
 llvm/test/CodeGen/WebAssembly/table-copy.ll   | 13 +++-----
 llvm/test/CodeGen/WebAssembly/table-fill.ll   |  7 ++--
 llvm/test/CodeGen/WebAssembly/table-grow.ll   |  7 ++--
 llvm/test/CodeGen/WebAssembly/table-size.ll   |  7 ++--
 9 files changed, 65 insertions(+), 111 deletions(-)

diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
index 506e1dd694461..03cb1f4b7fd06 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
@@ -9,8 +9,7 @@ declare %externref @llvm.wasm.table.get.externref(ptr addrspace(1), iX) nounwind
 
 define %externref @get_externref_from_table(iX %i) {
 ; CHECK-LABEL: get_externref_from_table:
-; WASM32-NEXT: .functype       get_externref_from_table (i32) -> (externref)
-; WASM64-NEXT: .functype       get_externref_from_table (i64) -> (externref)
+; CHECK-NEXT:  .functype       get_externref_from_table ([[iPTR]]) -> (externref)
 ; CHECK-NEXT:  local.get 0
 ; CHECK-NEXT:  table.get externref_table
 ; CHECK-NEXT:  end_function
@@ -21,8 +20,7 @@ define %externref @get_externref_from_table(iX %i) {
 define %externref @get_externref_from_table_const() {
 ; CHECK-LABEL: get_externref_from_table_const:
 ; CHECK-NEXT:  .functype      get_externref_from_table_const () -> (externref)
-; WASM32-NEXT: i32.const      0
-; WASM64-NEXT: i64.const      0
+; CHECK-NEXT:  [[iPTR]].const 0
 ; CHECK-NEXT:  table.get      externref_table
 ; CHECK-NEXT:  end_function
   %ref = call %externref @llvm.wasm.table.get.externref(ptr addrspace(1) @externref_table, iX 0)
@@ -31,13 +29,10 @@ define %externref @get_externref_from_table_const() {
 
 define %externref @get_externref_from_table_with_offset(iX %i) {
 ; CHECK-LABEL: get_externref_from_table_with_offset:
-; WASM32-NEXT: .functype       get_externref_from_table_with_offset (i32) -> (externref)
-; WASM64-NEXT: .functype       get_externref_from_table_with_offset (i64) -> (externref)
+; CHECK-NEXT:  .functype       get_externref_from_table_with_offset ([[iPTR]]) -> (externref)
 ; CHECK-NEXT:  local.get       0
-; WASM32-NEXT: i32.const       2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const       2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].const  2
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  table.get       externref_table
 ; CHECK-NEXT:  end_function
   %off = add nsw iX %i, 2
@@ -48,12 +43,10 @@ define %externref @get_externref_from_table_with_offset(iX %i) {
 
 define %externref @get_externref_from_table_with_var_offset(iX %i, iX %j) {
 ; CHECK-LABEL: get_externref_from_table_with_var_offset:
-; WASM32-NEXT: .functype       get_externref_from_table_with_var_offset (i32, i32) -> (externref)
-; WASM64-NEXT: .functype       get_externref_from_table_with_var_offset (i64, i64) -> (externref)
+; CHECK-NEXT:  .functype       get_externref_from_table_with_var_offset ([[iPTR]], [[iPTR]]) -> (externref)
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  local.get       1
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  table.get       externref_table
 ; CHECK-NEXT:  end_function
   %off = add nsw iX %i, %j
@@ -65,12 +58,10 @@ declare iX @get_offset()
 
 define %externref @get_externref_from_table_with_var_offset2(iX %i) {
 ; CHECK-LABEL: get_externref_from_table_with_var_offset2:
-; WASM32-NEXT: .functype       get_externref_from_table_with_var_offset2 (i32) -> (externref)
-; WASM64-NEXT: .functype       get_externref_from_table_with_var_offset2 (i64) -> (externref)
-; CHECK-NEXT:  local.get       0
+; CHECK-NEXT: .functype       get_externref_from_table_with_var_offset2 ([[iPTR]]) -> (externref)
+; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  call    get_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  table.get       externref_table
 ; CHECK-NEXT:  end_function
   %j = call iX @get_offset()
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
index 9a1b29bbab28e..05a844a19d55d 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s  -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s  -DiPTR=i64
 
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
@@ -10,8 +10,7 @@ declare void @llvm.wasm.table.set.externref(ptr addrspace(1), iX, %externref) no
 
 define void @set_externref_table(%externref %g, iX %i) {
 ; CHECK-LABEL: set_externref_table:
-; WASM32-NEXT: .functype       set_externref_table (externref, i32) -> ()
-; WASM64-NEXT: .functype       set_externref_table (externref, i64) -> ()
+; CHECK-NEXT:  .functype       set_externref_table (externref, [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get      1
 ; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  table.set     externref_table
@@ -25,8 +24,7 @@ define void @set_externref_table(%externref %g, iX %i) {
 define void @set_externref_table_const(%externref %g) {
 ; CHECK-LABEL: set_externref_table_const:
 ; CHECK-NEXT:  .functype      set_externref_table_const (externref) -> ()
-; WASM32-NEXT: i32.const      0
-; WASM64-NEXT: i64.const      0
+; CHECK-NEXT:  [[iPTR]].const      0
 ; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  table.set      externref_table
 ; CHECK-NEXT:  end_function
@@ -36,13 +34,10 @@ define void @set_externref_table_const(%externref %g) {
 
 define void @set_externref_table_with_offset(%externref %g, iX %i) {
 ; CHECK-LABEL: set_externref_table_with_offset:
-; WASM32-NEXT: .functype       set_externref_table_with_offset (externref, i32) -> ()
-; WASM64-NEXT: .functype       set_externref_table_with_offset (externref, i64) -> ()
+; CHECK-NEXT:  .functype       set_externref_table_with_offset (externref, [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get       1
-; WASM32-NEXT: i32.const       2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const       2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].const  2
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
@@ -53,12 +48,10 @@ define void @set_externref_table_with_offset(%externref %g, iX %i) {
 
 define void @set_externref_table_with_var_offset(%externref %g, iX %i, iX %j) {
 ; CHECK-LABEL: set_externref_table_with_var_offset:
-; WASM32-NEXT: .functype       set_externref_table_with_var_offset (externref, i32, i32) -> ()
-; WASM64-NEXT: .functype       set_externref_table_with_var_offset (externref, i64, i64) -> ()
+; CHECK-NEXT:  .functype       set_externref_table_with_var_offset (externref, [[iPTR]], [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  local.get       2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
@@ -71,12 +64,10 @@ declare iX @set_offset()
 
 define void @set_externref_table_with_var_offset2(%externref %g, iX %i) {
 ; CHECK-LABEL: set_externref_table_with_var_offset2:
-; WASM32-NEXT: .functype       set_externref_table_with_var_offset2 (externref, i32) -> ()
-; WASM64-NEXT: .functype       set_externref_table_with_var_offset2 (externref, i64) -> ()
+; CHECK-NEXT:  .functype       set_externref_table_with_var_offset2 (externref, [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  call    set_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       externref_table
 ; CHECK-NEXT:  end_function
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index a2421c1c6ff3a..d50bd27c338af 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
@@ -11,18 +11,14 @@ declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
 
 define void @call_funcref_from_table(iX %i) {
 ; CHECK-LABEL: call_funcref_from_table:
-; WASM32-NEXT: .functype       call_funcref_from_table (i32) -> ()
-; WASM64-NEXT: .functype       call_funcref_from_table (i64) -> ()
-; WASM32-NEXT: i32.const       0
-; WASM64-NEXT: i64.const       0
+; CHECK-NEXT:  .functype       call_funcref_from_table ([[iPTR]]) -> ()
+; CHECK-NEXT:  [[iPTR]].const  0
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.get       funcref_table
 ; CHECK-NEXT:  table.set       __funcref_call_table
-; WASM32-NEXT: i32.const       0
-; WASM64-NEXT: i64.const       0
+; CHECK-NEXT:  [[iPTR]].const  0
 ; CHECK-NEXT:  call_indirect    __funcref_call_table, () -> ()
-; WASM32-NEXT: i32.const       0
-; WASM64-NEXT: i64.const       0
+; CHECK-NEXT:  [[iPTR]].const  0
 ; CHECK-NEXT:  ref.null_func
 ; CHECK-NEXT:  table.set       __funcref_call_table
 ; CHECK-NEXT:  end_function
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
index 8c8e4fdc4d5f2..1b86e79b13646 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
@@ -9,8 +9,7 @@ declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), iX) nounwind
 
 define %funcref @get_funcref_from_table(iX %i) {
 ; CHECK-LABEL: get_funcref_from_table:
-; WASM32-NEXT: .functype       get_funcref_from_table (i32) -> (funcref)
-; WASM64-NEXT: .functype       get_funcref_from_table (i64) -> (funcref)
+; CHECK-NEXT:  .functype       get_funcref_from_table ([[iPTR]]) -> (funcref)
 ; CHECK-NEXT:  local.get 0
 ; CHECK-NEXT:  table.get funcref_table
 ; CHECK-NEXT:  end_function
@@ -21,8 +20,7 @@ define %funcref @get_funcref_from_table(iX %i) {
 define %funcref @get_funcref_from_table_const() {
 ; CHECK-LABEL: get_funcref_from_table_const:
 ; CHECK-NEXT:  .functype      get_funcref_from_table_const () -> (funcref)
-; WASM32-NEXT: i32.const      0
-; WASM64-NEXT: i64.const      0
+; CHECK-NEXT:  [[iPTR]].const 0
 ; CHECK-NEXT:  table.get      funcref_table
 ; CHECK-NEXT:  end_function
   %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, iX 0)
@@ -31,13 +29,10 @@ define %funcref @get_funcref_from_table_const() {
 
 define %funcref @get_funcref_from_table_with_offset(iX %i) {
 ; CHECK-LABEL: get_funcref_from_table_with_offset:
-; WASM32-NEXT:  .functype       get_funcref_from_table_with_offset (i32) -> (funcref)
-; WASM64-NEXT:  .functype       get_funcref_from_table_with_offset (i64) -> (funcref)
+; CHECK-NEXT:   .functype       get_funcref_from_table_with_offset ([[iPTR]]) -> (funcref)
 ; CHECK-NEXT:   local.get       0
-; WASM32-NEXT:  i32.const       2
-; WASM32-NEXT:  i32.add
-; WASM64-NEXT:  i64.const       2
-; WASM64-NEXT:  i64.add
+; CHECK-NEXT:   [[iPTR]].const  2
+; CHECK-NEXT:   [[iPTR]].add
 ; CHECK-NEXT:   table.get       funcref_table
 ; CHECK-NEXT:   end_function
   %off = add nsw iX %i, 2
@@ -48,12 +43,10 @@ define %funcref @get_funcref_from_table_with_offset(iX %i) {
 
 define %funcref @get_funcref_from_table_with_var_offset(iX %i, iX %j) {
 ; CHECK-LABEL: get_funcref_from_table_with_var_offset:
-; WASM32-NEXT:  .functype       get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
-; WASM64-NEXT:  .functype       get_funcref_from_table_with_var_offset (i64, i64) -> (funcref)
+; CHECK-NEXT:   .functype       get_funcref_from_table_with_var_offset ([[iPTR]], [[iPTR]]) -> (funcref)
 ; CHECK-NEXT:   local.get       0
 ; CHECK-NEXT:   local.get       1
-; WASM32-NEXT:  i32.add
-; WASM64-NEXT:  i64.add
+; CHECK-NEXT:   [[iPTR]].add
 ; CHECK-NEXT:   table.get       funcref_table
 ; CHECK-NEXT:   end_function
   %off = add nsw iX %i, %j
@@ -65,12 +58,10 @@ declare iX @get_offset()
 
 define %funcref @get_funcref_from_table_with_var_offset2(iX %i) {
 ; CHECK-LABEL: get_funcref_from_table_with_var_offset2:
-; WASM32-NEXT: .functype       get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
-; WASM64-NEXT: .functype       get_funcref_from_table_with_var_offset2 (i64) -> (funcref)
+; CHECK-NEXT:  .functype       get_funcref_from_table_with_var_offset2 ([[iPTR]]) -> (funcref)
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  call    get_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  table.get       funcref_table
 ; CHECK-NEXT:  end_function
   %j = call iX @get_offset()
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
index 897d1b704e28b..dd440a5b1c1d6 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 
@@ -9,8 +9,7 @@ declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), iX, %funcref) nounwi
 
 define void @set_funcref_table(%funcref %g, iX %i) {
 ; CHECK-LABEL: set_funcref_table:
-; WASM32-NEXT: .functype       set_funcref_table (funcref, i32) -> ()
-; WASM64-NEXT: .functype       set_funcref_table (funcref, i64) -> ()
+; CHECK-NEXT:  .functype       set_funcref_table (funcref, [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get      1
 ; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  table.set     funcref_table
@@ -24,8 +23,7 @@ define void @set_funcref_table(%funcref %g, iX %i) {
 define void @set_funcref_table_const(%funcref %g) {
 ; CHECK-LABEL: set_funcref_table_const:
 ; CHECK-NEXT:  .functype      set_funcref_table_const (funcref) -> ()
-; WASM32-NEXT: i32.const      0
-; WASM64-NEXT: i64.const      0
+; CHECK-NEXT:  [[iPTR]].const 0
 ; CHECK-NEXT:  local.get      0
 ; CHECK-NEXT:  table.set      funcref_table
 ; CHECK-NEXT:  end_function
@@ -35,13 +33,10 @@ define void @set_funcref_table_const(%funcref %g) {
 
 define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
 ; CHECK-LABEL: set_funcref_table_with_offset:
-; WASM32-NEXT: .functype       set_funcref_table_with_offset (funcref, i32) -> ()
-; WASM64-NEXT: .functype       set_funcref_table_with_offset (funcref, i64) -> ()
+; CHECK-NEXT:  .functype       set_funcref_table_with_offset (funcref, [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get       1
-; WASM32-NEXT: i32.const       2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.const       2
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].const  2
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       funcref_table
 ; CHECK-NEXT:  end_function
@@ -52,12 +47,10 @@ define void @set_funcref_table_with_offset(%funcref %g, iX %i) {
 
 define void @set_funcref_table_with_var_offset(%funcref %g, iX %i, iX %j) {
 ; CHECK-LABEL: set_funcref_table_with_var_offset:
-; WASM32-NEXT: .functype       set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
-; WASM64-NEXT: .functype       set_funcref_table_with_var_offset (funcref, i64, i64) -> ()
+; CHECK-NEXT:  .functype       set_funcref_table_with_var_offset (funcref, [[iPTR]], [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  local.get       2
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       funcref_table
 ; CHECK-NEXT:  end_function
@@ -70,12 +63,10 @@ declare iX @set_offset()
 
 define void @set_funcref_table_with_var_offset2(%funcref %g, iX %i) {
 ; CHECK-LABEL: set_funcref_table_with_var_offset2:
-; WASM32-NEXT: .functype       set_funcref_table_with_var_offset2 (funcref, i32) -> ()
-; WASM64-NEXT: .functype       set_funcref_table_with_var_offset2 (funcref, i64) -> ()
+; CHECK-NEXT:  .functype       set_funcref_table_with_var_offset2 (funcref, [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get       1
 ; CHECK-NEXT:  call    set_offset
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get       0
 ; CHECK-NEXT:  table.set       funcref_table
 ; CHECK-NEXT:  end_function
diff --git a/llvm/test/CodeGen/WebAssembly/table-copy.ll b/llvm/test/CodeGen/WebAssembly/table-copy.ll
index fee5cfb9da3ac..dce33eaa7b367 100644
--- a/llvm/test/CodeGen/WebAssembly/table-copy.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-copy.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
@@ -10,8 +10,7 @@ declare void @llvm.wasm.table.copy(ptr addrspace(1), ptr addrspace(1), iX, iX, i
 
 define void @table_copy(iX %dst, iX %src, iX %len) {
 ; CHECK-LABEL: table_copy:
-; WASM32-NEXT: .functype	table_copy (i32, i32, i32) -> ()
-; WASM64-NEXT: .functype	table_copy (i64, i64, i64) -> ()
+; CHECK-NEXT:  .functype	table_copy ([[iPTR]], [[iPTR]], [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    1
 ; CHECK-NEXT:  local.get    2
@@ -25,12 +24,10 @@ define void @table_copy(iX %dst, iX %src, iX %len) {
 ; Copies len items from table1 at src to table1 at src+off
 define void @self_table_copy(iX %src, iX %off, iX %len) {
 ; CHECK-LABEL: self_table_copy:
-; WASM32-NEXT: .functype	self_table_copy (i32, i32, i32) -> ()
-; WASM64-NEXT: .functype	self_table_copy (i64, i64, i64) -> ()
+; CHECK-NEXT:  .functype	self_table_copy ([[iPTR]], [[iPTR]], [[iPTR]]) -> ()
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    1
-; WASM32-NEXT: i32.add
-; WASM64-NEXT: i64.add
+; CHECK-NEXT:  [[iPTR]].add
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    2
 ; CHECK-NEXT:  table.copy	externref_table1, externref_table1
diff --git a/llvm/test/CodeGen/WebAssembly/table-fill.ll b/llvm/test/CodeGen/WebAssembly/table-fill.ll
index 3fdf315bede68..2b9f0feb7301f 100644
--- a/llvm/test/CodeGen/WebAssembly/table-fill.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-fill.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
@@ -9,8 +9,7 @@ declare void @llvm.wasm.table.fill.externref(ptr addrspace(1), iX, %externref, i
 
 define void @table_fill(iX %start, iX %len, %externref %val) {
 ; CHECK-LABEL: table_fill:
-; WASM32-NEXT: .functype	table_fill (i32, i32, externref) -> ()
-; WASM64-NEXT: .functype	table_fill (i64, i64, externref) -> ()
+; CHECK-NEXT:  .functype	table_fill ([[iPTR]], [[iPTR]], externref) -> ()
 ; CHECK-NEXT:  local.get    0
 ; CHECK-NEXT:  local.get    2
 ; CHECK-NEXT:  local.get    1
diff --git a/llvm/test/CodeGen/WebAssembly/table-grow.ll b/llvm/test/CodeGen/WebAssembly/table-grow.ll
index 7ddc1d84e6dba..7a043462d247f 100644
--- a/llvm/test/CodeGen/WebAssembly/table-grow.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-grow.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
@@ -10,8 +10,7 @@ declare %externref @llvm.wasm.ref.null.extern() nounwind readonly
 
 define i32 @table_grow(iX %sz) {
 ; CHECK-LABEL: table_grow:
-; WASM32-NEXT: .functype	table_grow (i32) -> (i32)
-; WASM64-NEXT: .functype	table_grow (i64) -> (i32)
+; CHECK-NEXT:  .functype	table_grow ([[iPTR]]) -> (i32)
 ; CHECK-NEXT:  ref.null_extern
 ; CHECK-NEXT:  local.get	0
 ; CHECK-NEXT:  table.grow	externref_table
diff --git a/llvm/test/CodeGen/WebAssembly/table-size.ll b/llvm/test/CodeGen/WebAssembly/table-size.ll
index 3b0722a73bb57..e24f451a7596d 100644
--- a/llvm/test/CodeGen/WebAssembly/table-size.ll
+++ b/llvm/test/CodeGen/WebAssembly/table-size.ll
@@ -1,5 +1,5 @@
-; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM32
-; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s --check-prefixes=CHECK,WASM64
+; RUN: sed 's/iX/i32/g' < %s | llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i32
+; RUN: sed 's/iX/i64/g' < %s | llc --mtriple=wasm64-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s -DiPTR=i64
 
 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
 
@@ -9,8 +9,7 @@ declare iX @llvm.wasm.table.size(ptr addrspace(1)) nounwind readonly
 
 define iX @table_size() {
 ; CHECK-LABEL: table_size:
-; WASM32-NEXT: .functype       table_size () -> (i32)
-; WASM64-NEXT: .functype       table_size () -> (i64)
+; CHECK-NEXT: .functype       table_size () -> ([[iPTR]])
 ; CHECK-NEXT:  table.size      externref_table
 ; CHECK-NEXT:  end_function
   %sz = call iX @llvm.wasm.table.size(ptr addrspace(1) @externref_table)

>From 7f8e58f89b224890e73c78c793de8bbec96252af Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Tue, 17 Feb 2026 09:18:32 -0800
Subject: [PATCH 3/3] Remove table from wasm64.s (moved to #180861)

---
 llvm/test/MC/WebAssembly/wasm64.s | 44 +++++++++----------------------
 1 file changed, 13 insertions(+), 31 deletions(-)

diff --git a/llvm/test/MC/WebAssembly/wasm64.s b/llvm/test/MC/WebAssembly/wasm64.s
index 237f5a22dd766..0c939b47db4f2 100644
--- a/llvm/test/MC/WebAssembly/wasm64.s
+++ b/llvm/test/MC/WebAssembly/wasm64.s
@@ -6,9 +6,6 @@
 .globaltype myglob64, i64
 .globaltype __stack_pointer, i64
 
-    .tabletype externref_table, externref
-externref_table:
-
 test:
     .functype   test (i64) -> ()
     .local      i64
@@ -75,9 +72,6 @@ test:
 
 # CHECK:              .globaltype     myglob64, i64
 
-# CHECK:         .tabletype externref_table, externref
-# CHECK: externref_table:
-
 # CHECK:              .functype       test (i64) -> ()
 # CHECK-NEXT:         .local          i64
 
@@ -165,38 +159,31 @@ test:
 # BIN-NEXT:         GlobalMutable:   true
 # BIN-NEXT:   - Type:            FUNCTION
 # BIN-NEXT:     FunctionTypes:   [ 0 ]
-# BIN-NEXT:   - Type:            TABLE
-# BIN-NEXT:      Tables:
-# BIN-NEXT:        - Index:           0
-# BIN-NEXT:          ElemType:        EXTERNREF
-# BIN-NEXT:          Limits:
-# BIN-NEXT:            Flags:           [ IS_64 ]
-# BIN-NEXT:            Minimum:         0x0
 # BIN-NEXT:   - Type:            DATACOUNT
 # BIN-NEXT:     Count:           1
 # BIN-NEXT:   - Type:            CODE
 # BIN-NEXT:     Relocations:
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           1
 # BIN-NEXT:         Offset:          0x13
 # BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
-# BIN-NEXT:         Index:           3
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x22
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           1
 # BIN-NEXT:         Offset:          0x2F
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           1
 # BIN-NEXT:         Offset:          0x4F
 # BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
-# BIN-NEXT:         Index:           3
+# BIN-NEXT:         Index:           2
 # BIN-NEXT:         Offset:          0x62
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           1
 # BIN-NEXT:         Offset:          0x78
-# BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
-# BIN-NEXT:         Index:           4
-# BIN-NEXT:         Offset:          0x83
+# BIN-NEXT:       - Type: R_WASM_GLOBAL_INDEX_LEB
+# BIN-NEXT:         Index: 3
+# BIN-NEXT:         Offset: 0x83
 # BIN-NEXT:     Functions:
 # BIN-NEXT:       - Index:           0
 # BIN-NEXT:         Locals:
@@ -206,7 +193,7 @@ test:
 # BIN-NEXT:   - Type:            DATA
 # BIN-NEXT:     Relocations:
 # BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I64
-# BIN-NEXT:         Index:           2
+# BIN-NEXT:         Index:           1
 # BIN-NEXT:         Offset:          0x16
 # BIN-NEXT:     Segments:
 # BIN-NEXT:       - SectionOffset:   6
@@ -220,27 +207,22 @@ test:
 # BIN-NEXT:     Version:         2
 # BIN-NEXT:     SymbolTable:
 # BIN-NEXT:       - Index:           0
-# BIN-NEXT:         Kind:            TABLE
-# BIN-NEXT:         Name:            externref_table
-# BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
-# BIN-NEXT:         Table:           0
-# BIN-NEXT:       - Index:           1
 # BIN-NEXT:         Kind:            FUNCTION
 # BIN-NEXT:         Name:            test
 # BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
 # BIN-NEXT:         Function:        0
-# BIN-NEXT:       - Index:           2
+# BIN-NEXT:       - Index:           1
 # BIN-NEXT:         Kind:            DATA
 # BIN-NEXT:         Name:            .L.str
 # BIN-NEXT:         Flags:           [ BINDING_LOCAL, VISIBILITY_HIDDEN ]
 # BIN-NEXT:         Segment:         0
 # BIN-NEXT:         Size:            24
-# BIN-NEXT:       - Index:           3
+# BIN-NEXT:       - Index:           2
 # BIN-NEXT:         Kind:            GLOBAL
 # BIN-NEXT:         Name:            myglob64
 # BIN-NEXT:         Flags:           [ UNDEFINED ]
 # BIN-NEXT:         Global:          0
-# BIN-NEXT:       - Index:           4
+# BIN-NEXT:       - Index:           3
 # BIN-NEXT:         Kind:            GLOBAL
 # BIN-NEXT:         Name:            __stack_pointer
 # BIN-NEXT:         Flags:           [ UNDEFINED ]



More information about the cfe-commits mailing list