This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fixup order of ins variables for table instructions
ClosedPublic

Authored by pmatos on Apr 30 2021, 12:09 PM.

Details

Reviewers
tlively
sbc100
Summary

WebAssembly instruction arguments should have their arguments ordered from
the deepest to the shallowest on the stack.

Diff Detail

Event Timeline

pmatos created this revision.Apr 30 2021, 12:09 PM
pmatos requested review of this revision.Apr 30 2021, 12:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2021, 12:09 PM

@sbc100 Will fixing the assembly format to have the correct operand order like this break Emscripten at all? I think the incorrect order also made it into the LLVM 12 release, but I think we have few enough users that it's probably worth fixing now.

I think all of emscripten's use of the table is still via the JS API (e.g. src/runtime_functions.js) so this probably won't break emscripten. It does seem likely that nobody is using these instructions via assembly.
Is this the only change needed? Do we have no tests of these asm instructions anywhere in LLVM at all?

sbc100 accepted this revision.Apr 30 2021, 7:13 PM
sbc100 added a subscriber: sunfishcode.

I don't think there are any uses of these instructions in emscripten and I doubt there are any emscripten users using the assembly format.

@sunfishcode do you know of anyone using these assembly instructions?

This revision is now accepted and ready to land.Apr 30 2021, 7:13 PM
pmatos added a comment.May 1 2021, 5:46 AM

I think all of emscripten's use of the table is still via the JS API (e.g. src/runtime_functions.js) so this probably won't break emscripten. It does seem likely that nobody is using these instructions via assembly.
Is this the only change needed? Do we have no tests of these asm instructions anywhere in LLVM at all?

We don't have tests for the register based version of the assembly string afaiu.
It would be great to be able to run unit tests that build machine instructions and check the expected asm, however I don't think there's an infrastructure for that. If there is, I would be happy to add those tests.
Another reason we didn't notice this was broken is because we do not execute this tests, otherwise we would have seen the values and indexes for the table set and others were incorrectly ordered. I am wondering if a wasm validator would have caught this, however even if it does as far as I understand the binaryen validator does not parse LLVM assembly files.

pmatos added a comment.May 1 2021, 5:46 AM

I don't think there are any uses of these instructions in emscripten and I doubt there are any emscripten users using the assembly format.

@sunfishcode do you know of anyone using these assembly instructions?

Feel free to merge if you think this is ready to land - I should probably ask for committers permissions at some point.

sbc100 added a comment.May 1 2021, 7:05 AM

I think all of emscripten's use of the table is still via the JS API (e.g. src/runtime_functions.js) so this probably won't break emscripten. It does seem likely that nobody is using these instructions via assembly.
Is this the only change needed? Do we have no tests of these asm instructions anywhere in LLVM at all?

We don't have tests for the register based version of the assembly string afaiu.
It would be great to be able to run unit tests that build machine instructions and check the expected asm, however I don't think there's an infrastructure for that. If there is, I would be happy to add those tests.
Another reason we didn't notice this was broken is because we do not execute this tests, otherwise we would have seen the values and indexes for the table set and others were incorrectly ordered. I am wondering if a wasm validator would have caught this, however even if it does as far as I understand the binaryen validator does not parse LLVM assembly files.

Don't tests like the ones in https://github.com/llvm/llvm-project/blob/8a5e0d956396f07d2241091693f8a714a2483356/llvm/test/MC/WebAssembly/tables.s#L25 at least get both the asm output and the binary output?

Its true and we currently lack any kind of validation of execution engine in the llvm tests.. but that is also true for all other target IIUC. I guess we are different from something like x86 because we at least have the potential to validate.. Perhaps we should have least have some kind of FYI bot that attempt to validate all the test output of wasm-ld... but I don't think that lack of this has been a huge problem in the past.

Oh right, this only changes the register-based printing, which is used exclusively in llc tests. The stacky assembly that would be used in production is unaffected, so it's not surprising that none of the existing assembly tests are affected.

I'm fine merging this as-is. Presumably once we have a way to generate these instructions from LLVM IR, we will also have tests for them reflecting this change.