1; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s 2 3%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral 4 5@funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef 6 7declare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind 8 9define %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) 16 ret %funcref %ref 17} 18 19define %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) 26 ret %funcref %ref 27} 28 29define %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 34; CHECK-NEXT: i32.add 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) 39 ret %funcref %ref 40} 41 42 43define %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 48; CHECK-NEXT: i32.add 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) 53 ret %funcref %ref 54} 55 56declare i32 @get_offset() 57 58define %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 63; CHECK-NEXT: i32.add 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) 69 ret %funcref %ref 70} 71 72; CHECK: .tabletype funcref_table, funcref 73; CHECK-LABEL: funcref_table: 74