Can you add tests for this to llvm/test/CodeGen/WebAssembly?
It would be good to write out the transformation we are doing in terms of selection dag operations and WebAssembly instructions. I don't know what PACK*SDW and PACK*SWB mean.
If you change the run line to this, you can use utils/update_llc_test_checks.py to autogenerate the test output, which will make it easier for me to understand the transformation we are doing. Also, it looks like the code is more general than it needs to be to handle this one case. Is there an opportunity to either simplify the code or test more cases here?
I'm not sure I fully understand what you mean by this. Do you want me to change the function body of @trunc16i32_16i8? Is there detailed suggestions on how to change?
For example, extractSubVector and truncateVectorWithNARROW look like they are meant to work with many different vector types. If that's correct, it would be good to add tests for more vector types. Alternatively, if we only care about a smaller set of types, it would be nice if we could simplify the code and make it less general.
Hi Thomas, you're right that the code is meant to handle more types. My initial purpose is to discuss the solution with you and Petr first so I keep the types simple and leaves a TODO here. If you're OK with the solution, I can try to cover more types and more tests.
(Actually I have little experience with LLVM types, it may take me some time to cover more, and any advice on the if conditions here is very welcome)
Nice, these tests give me a good sense of what this optimization is doing. The transformation looks good.
For both this and truncateVectorWithNARROW, it would be good to add comments about what the parameters are for and what will be returned.