APInt::byteSwap doesn't handle strange cases, so just give up on them.
Diff Detail
Event Timeline
I think it would make more sense to add support for this to APInt. These operations are well-defined and supported in IR, so APInt should support them as well.
I don't think this is really well defined for arbitrary odd cases. What does a bswap mean for non-byte multiples?
Sure, non-byte multiplies doesn't make sense, but byte multiples generally do. However, after checking LangRef we apparently do require the bitwidth to be a multiple of 16 for this intrinsic: https://llvm.org/docs/LangRef.html#llvm-bswap-intrinsics
Whether the intrinsic does or not, adding support to APInt is pretty trivial. Scarily we don't appear to have any unit tests at all for APInt:byteSwap
So the APInt support is there now, but we still have to do something here. I would suggest to enforce this requirement in the IR verifier (it already has a bunch of similar checks in visitIntrinsicCall), so that individual code handling bswaps doesn't have to deal with it.
I would suggest to eliminate the restriction from the langref. The GlobalISel legalizer at least handles the case just fine
Verifier check added in b76bbcc60db6cd7d42bf46f2fcdc6784250554d7