16d0c7bc1SPaulo Matos; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s 26d0c7bc1SPaulo Matos 380fb7823SAlex Bradbury%funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral 46d0c7bc1SPaulo Matos 56d0c7bc1SPaulo Matos@funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef 66d0c7bc1SPaulo Matos 7*1bd1a440SPaulo Matosdeclare %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1), i32) nounwind 8*1bd1a440SPaulo Matos 96d0c7bc1SPaulo Matosdefine %funcref @get_funcref_from_table(i32 %i) { 106d0c7bc1SPaulo Matos; CHECK-LABEL: get_funcref_from_table: 116d0c7bc1SPaulo Matos; CHECK-NEXT: .functype get_funcref_from_table (i32) -> (funcref) 126d0c7bc1SPaulo Matos; CHECK-NEXT: local.get 0 136d0c7bc1SPaulo Matos; CHECK-NEXT: table.get funcref_table 146d0c7bc1SPaulo Matos; CHECK-NEXT: end_function 15*1bd1a440SPaulo Matos %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %i) 166d0c7bc1SPaulo Matos ret %funcref %ref 176d0c7bc1SPaulo Matos} 186d0c7bc1SPaulo Matos 196d0c7bc1SPaulo Matosdefine %funcref @get_funcref_from_table_const() { 206d0c7bc1SPaulo Matos; CHECK-LABEL: get_funcref_from_table_const: 216d0c7bc1SPaulo Matos; CHECK-NEXT: .functype get_funcref_from_table_const () -> (funcref) 226d0c7bc1SPaulo Matos; CHECK-NEXT: i32.const 0 236d0c7bc1SPaulo Matos; CHECK-NEXT: table.get funcref_table 246d0c7bc1SPaulo Matos; CHECK-NEXT: end_function 25*1bd1a440SPaulo Matos %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 0) 266d0c7bc1SPaulo Matos ret %funcref %ref 276d0c7bc1SPaulo Matos} 286d0c7bc1SPaulo Matos 296d0c7bc1SPaulo Matosdefine %funcref @get_funcref_from_table_with_offset(i32 %i) { 306d0c7bc1SPaulo Matos; CHECK-LABEL: get_funcref_from_table_with_offset: 316d0c7bc1SPaulo Matos; CHECK-NEXT: .functype get_funcref_from_table_with_offset (i32) -> (funcref) 326d0c7bc1SPaulo Matos; CHECK-NEXT: local.get 0 336d0c7bc1SPaulo Matos; CHECK-NEXT: i32.const 2 346d0c7bc1SPaulo Matos; CHECK-NEXT: i32.add 356d0c7bc1SPaulo Matos; CHECK-NEXT: table.get funcref_table 366d0c7bc1SPaulo Matos; CHECK-NEXT: end_function 376d0c7bc1SPaulo Matos %off = add nsw i32 %i, 2 38*1bd1a440SPaulo Matos %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off) 396d0c7bc1SPaulo Matos ret %funcref %ref 406d0c7bc1SPaulo Matos} 416d0c7bc1SPaulo Matos 426d0c7bc1SPaulo Matos 436d0c7bc1SPaulo Matosdefine %funcref @get_funcref_from_table_with_var_offset(i32 %i, i32 %j) { 446d0c7bc1SPaulo Matos; CHECK-LABEL: get_funcref_from_table_with_var_offset: 456d0c7bc1SPaulo Matos; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset (i32, i32) -> (funcref) 466d0c7bc1SPaulo Matos; CHECK-NEXT: local.get 0 476d0c7bc1SPaulo Matos; CHECK-NEXT: local.get 1 486d0c7bc1SPaulo Matos; CHECK-NEXT: i32.add 496d0c7bc1SPaulo Matos; CHECK-NEXT: table.get funcref_table 506d0c7bc1SPaulo Matos; CHECK-NEXT: end_function 516d0c7bc1SPaulo Matos %off = add nsw i32 %i, %j 52*1bd1a440SPaulo Matos %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off) 536d0c7bc1SPaulo Matos ret %funcref %ref 546d0c7bc1SPaulo Matos} 556d0c7bc1SPaulo Matos 566d0c7bc1SPaulo Matosdeclare i32 @get_offset() 576d0c7bc1SPaulo Matos 586d0c7bc1SPaulo Matosdefine %funcref @get_funcref_from_table_with_var_offset2(i32 %i) { 596d0c7bc1SPaulo Matos; CHECK-LABEL: get_funcref_from_table_with_var_offset2: 606d0c7bc1SPaulo Matos; CHECK-NEXT: .functype get_funcref_from_table_with_var_offset2 (i32) -> (funcref) 616d0c7bc1SPaulo Matos; CHECK-NEXT: local.get 0 626d0c7bc1SPaulo Matos; CHECK-NEXT: call get_offset 636d0c7bc1SPaulo Matos; CHECK-NEXT: i32.add 646d0c7bc1SPaulo Matos; CHECK-NEXT: table.get funcref_table 656d0c7bc1SPaulo Matos; CHECK-NEXT: end_function 666d0c7bc1SPaulo Matos %j = call i32 @get_offset() 676d0c7bc1SPaulo Matos %off = add nsw i32 %i, %j 68*1bd1a440SPaulo Matos %ref = call %funcref @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 %off) 696d0c7bc1SPaulo Matos ret %funcref %ref 706d0c7bc1SPaulo Matos} 716d0c7bc1SPaulo Matos 72b5b5f0acSPaulo Matos; CHECK: .tabletype funcref_table, funcref 73c67c9cfeSPaulo Matos; CHECK-LABEL: funcref_table: 74