[WebAssembly] Fix reftype load/store match with idx from call

Implement support for matching an index from a WebAssembly CALL
instruction. Add test.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D115327
This commit is contained in:
Paulo Matos 2022-01-13 10:03:59 +01:00
parent 821dd3b0e5
commit 97ef15ad76
2 changed files with 16 additions and 2 deletions

View File

@ -1491,8 +1491,7 @@ bool WebAssemblyTargetLowering::MatchTableForLowering(SelectionDAG &DAG,
if (GA) {
// We are in Case 2 above.
Idx = Base->getOperand(1);
if (!Idx || GA->getNumValues() != 1 || Idx->getNumValues() != 1)
return false;
assert(GA->getNumValues() == 1);
} else {
// This might be Case 1 above (or an error)
SDValue V = Base->getOperand(0);

View File

@ -79,4 +79,19 @@ define void @set_externref_table_with_var_offset2(%externref %g, i32 %i) {
ret void
}
declare i32 @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:
; CHECK-NEXT: .functype set_externref_table_with_id_from_call (externref) -> ()
; CHECK-NEXT: call get_table_slot
; CHECK-NEXT: local.get 0
; CHECK-NEXT: table.set externref_table
; CHECK-NEXT: end_function
%id = call i32 @get_table_slot()
%p = getelementptr [0 x %externref], [0 x %externref] addrspace (1)* @externref_table, i32 0, i32 %id
store %externref %g, %externref addrspace(1)* %p
ret void
}
; CHECK: .tabletype externref_table, externref