Currently when translating the call_indirect instruction Wasmtime will insert a null-check to ensure that we're not calling a null function pointer. Because our representation of a null function pointer is literally a null pointer, however, I think we can actually skip this check entirely due to the next instruction being guaranteed to segfault if it's actually a null pointer.
I don't think this is necessarily as easy as simply removing the null pointer check, however, since I think the load needs to at least somehow be annotated with the proper trap code and probably "this can segfault", which I'm not precisely sure how to do. This could be a nice way to clean up the generated code for call_indirect slightly thought which is already somewhat large I believe.
Currently when translating the
call_indirectinstruction Wasmtime will insert a null-check to ensure that we're not calling a null function pointer. Because our representation of a null function pointer is literally a null pointer, however, I think we can actually skip this check entirely due to the next instruction being guaranteed to segfault if it's actually a null pointer.I don't think this is necessarily as easy as simply removing the null pointer check, however, since I think the
loadneeds to at least somehow be annotated with the proper trap code and probably "this can segfault", which I'm not precisely sure how to do. This could be a nice way to clean up the generated code forcall_indirectslightly thought which is already somewhat large I believe.