WebAssembly instruction arguments should have their arguments ordered from
the deepest to the shallowest on the stack.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
@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?
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?
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.
Feel free to merge if you think this is ready to land - I should probably ask for committers permissions at some point.
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.
Merged by @tlively as https://github.com/llvm/llvm-project/commit/cd460c4d11eeeca485353ad6a1961b543980b664
In the meantime I got committers rights. Thanks.