[llvm] [AggressiveInstCombine] Fold byte-reversed consecutive loads to load+bswap (PR #227517)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 21:23:53 PDT 2026


topperc wrote:

> From llvm-opt-benchmark, I think the two main regressions of interest are:
> 
> * bswap.i16 being formed, and preventing later formation of bswap.i32. Probably this transform should be able to assemble from a bswap part as well?

Looks like the bswap.i16 was formed because the `or` where the 3 of the bytes were combined had an additional user. Loop unswitch occurred sometime after that and duplicated the code. At that point one of the copies of the code didn't have an additional user anymore. In the original code SLP is able to combine the loads and form the bswap.i32 in that block.

Making this transform look through bswap won't help since we only run AggressiveInstCombine once in the pipeline.

> * 2, 1, 0, 3 shuffles not being formed, because the 1, 0 part becomes a bswap.

I'm not sure how to easily solve either issue.

It feels hacky, but I guess we could disable forming bswap.i16?

https://github.com/llvm/llvm-project/pull/227517


More information about the llvm-commits mailing list