[InstCombine] try to canonicalize logical shift after bswap
authorSanjay Patel <spatel@rotateright.com>
Tue, 22 Mar 2022 13:02:28 +0000 (09:02 -0400)
committerSanjay Patel <spatel@rotateright.com>
Tue, 22 Mar 2022 13:10:55 +0000 (09:10 -0400)
commit60820e53ec9d3be028ce315f9b630b55c670b32e
tree43b29264e6e9eb6da85f4e417cd31c1e312b797b
parent91ea247039dbcc756107616d39baecbb3a4bfb7e
[InstCombine] try to canonicalize logical shift after bswap

When shifting by a byte-multiple:
bswap (shl X, C) --> lshr (bswap X), C
bswap (lshr X, C) --> shl (bswap X), C

This is an IR implementation of a transform suggested in D120648.
The "swaps cancel" test models the motivating optimization from
that proposal.

Alive2 checks (as noted in the other review, we could use
knownbits to handle shift-by-variable-amount, but that can be an
enhancement patch):
https://alive2.llvm.org/ce/z/pXUaRf
https://alive2.llvm.org/ce/z/ZnaMLf

Differential Revision: https://reviews.llvm.org/D122010
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/bswap-fold.ll