[PATCH] D117680: [InstCombine] Fold bswap(shl(x, C)) -> and(x, 255)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 10:36:08 PST 2022


spatel added a comment.

In D117680#3255184 <https://reviews.llvm.org/D117680#3255184>, @chfast wrote:

> My motivation is rather boring. I have a generic data -> integer loader. The data is in big-endian order. For i32 example the data can be from 1 to 4 bytes in size. Here is the generic template which handles all 4 cases:
> https://godbolt.org/z/dPcGjvb94

Thanks! I guessed there was more than just this one potential optimization, but that makes it clearer.
Pushing a logical shift after the bswap (and reversing direction) might get us most of what we need:
https://alive2.llvm.org/ce/z/2zveR6
That should allow the existing demanded bits fold to trigger in the simplest cases if I'm seeing it correctly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117680/new/

https://reviews.llvm.org/D117680



More information about the llvm-commits mailing list