[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 08:44:25 PST 2022
spatel added reviewers: lebedev.ri, craig.topper.
spatel added a comment.
This is one of several related patterns where we mask/shift a single byte from an end of the input:
https://alive2.llvm.org/ce/z/dtHMVr
define i32 @bs_shl32(i32 %0) {
%2 = shl i32 %0, 24
%3 = call i32 @llvm.bswap.i32(i32 %2)
ret i32 %3
}
define i32 @bs_lshr32(i32 %0) {
%2 = lshr i32 %0, 24
%3 = call i32 @llvm.bswap.i32(i32 %2)
ret i32 %3
}
define i32 @bs_and32_000000ff(i32 %x) {
%m = and i32 %x, 255
%b = call i32 @llvm.bswap.i32(i32 %m)
ret i32 %b
}
define i32 @bs_and32_ff000000(i32 %x) {
%m = and i32 %x, -16777216
%b = call i32 @llvm.bswap.i32(i32 %m)
ret i32 %b
}
It might help to see a larger, motivating example in source or IR, so we know what a potentially more general solution would look like.
The backend also misses these patterns, so we may want to mimic whatever we do in IR for codegen. I recently added a similar fold with D117508 <https://reviews.llvm.org/D117508>.
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