diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index 38ed4c73fb93..5a505ddfc112 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -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); diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll index 025fb037328e..bd5ad6942fcd 100644 --- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll +++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll @@ -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