1 ; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
3 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
5 @funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
7 declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind
9 define %funcref @get_funcref_from_table(i32 %i) {
10 ; CHECK-LABEL: get_funcref_from_table:
11 ; CHECK-NEXT: .functype get_funcref_from_table (i32) -> (funcref)
12 ; CHECK-NEXT: local.get 0
13 ; CHECK-NEXT: table.get funcref_table
14 ; CHECK-NEXT: end_function
15 %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %i)
19 define %funcref @get_funcref_from_table_const() {
20 ; CHECK-LABEL: get_funcref_from_table_const:
21 ; CHECK-NEXT: .functype get_funcref_from_table_const () -> (funcref)
22 ; CHECK-NEXT: i32.const 0
23 ; CHECK-NEXT: table.get funcref_table
24 ; CHECK-NEXT: end_function
25 %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 0)
29 define %funcref @get_funcref_from_table_with_offset(i32 %i) {
30 ; CHECK-LABEL: get_funcref_from_table_with_offset:
31 ; CHECK-NEXT: .functype get_funcref_from_table_with_offset (i32) -> (funcref)
32 ; CHECK-NEXT: local.get 0
33 ; CHECK-NEXT: i32.const 2
35 ; CHECK-NEXT: table.get funcref_table
36 ; CHECK-NEXT: end_function
37 %off = add nsw i32 %i, 2
38 %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
43 define %funcref @get_funcref_from_table_with_var_offset(i32 %i, i32 %j) {
44 ; CHECK-LABEL: get_funcref_from_table_with_var_offset:
45 ; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset (i32, i32) -> (funcref)
46 ; CHECK-NEXT: local.get 0
47 ; CHECK-NEXT: local.get 1
49 ; CHECK-NEXT: table.get funcref_table
50 ; CHECK-NEXT: end_function
51 %off = add nsw i32 %i, %j
52 %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
56 declare i32 @get_offset()
58 define %funcref @get_funcref_from_table_with_var_offset2(i32 %i) {
59 ; CHECK-LABEL: get_funcref_from_table_with_var_offset2:
60 ; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset2 (i32) -> (funcref)
61 ; CHECK-NEXT: local.get 0
62 ; CHECK-NEXT: call get_offset
64 ; CHECK-NEXT: table.get funcref_table
65 ; CHECK-NEXT: end_function
66 %j = call i32 @get_offset()
67 %off = add nsw i32 %i, %j
68 %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off)
72 ; CHECK: .tabletype funcref_table, funcref
73 ; CHECK-LABEL: funcref_table: