If we're bswap'ing some bytes and zero'ing the remainder we can perform this as a bswap+mask which helps us match 'partial' bswaps as a first step towards folding into a more complex bswap pattern.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/Transforms/InstCombine/bswap.ll | ||
---|---|---|
398 | We would have reduced this to bswap+mask but InstCombinerImpl::matchBSwap is too harsh at filtering out or(A,B) patterns where A and B have different opcodes. |
llvm/test/Transforms/InstCombine/bswap.ll | ||
---|---|---|
398 | Add test(s) that already have a partial bswap, so we can see the most basic transform enabled by this patch? Something like this: define i32 @partial_bswap(i32 %x) { %x3 = shl i32 %x, 24 %a2 = shl i32 %x, 8 %x2 = and i32 %a2, 16711680 %x32 = or i32 %x3, %x2 %t1 = and i32 %x, -65536 %t2 = call i32 @llvm.bswap.i32(i32 %t1) %r = or i32 %x32, %t2 ret i32 %r } |
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
2953–2954 | I misread that the first time because I wasn't expecting the +=8 for something named ByteIndex. Coder pref, but might be better to multiply by 8 in the index calc and use normal increment in the for-loop. |
Addressed @spatel's comments, I've relaxed the requirements in InstCombinerImpl::matchBSwap as I'd mentioned it was necessary for an existing test and also the new partial_bswap test
LGTM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | ||
---|---|---|
2052–2057 | The comments are now more specific than the logic now. Adjust to be more like the OrWithOrs? // (A >> B) | C or A | (B >> C) // (A & B) | C or A | (B & C) Presumably, recognizeBSwapOrBitReverseIdiom() can deal with the more general patterns. |
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
3082 | some clangs stage2 builds fail in this call when building lib/Object/CMakeFiles/LLVMObject.dir/ELF.cpp.o for some reason |
The comments are now more specific than the logic now. Adjust to be more like the OrWithOrs?
Presumably, recognizeBSwapOrBitReverseIdiom() can deal with the more general patterns.