[PATCH] D122010: [InstCombine] try to canonicalize logical shift after bswap

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 08:23:44 PDT 2022


spatel created this revision.
spatel added reviewers: Chenbing.Zheng, lebedev.ri, craig.topper, RKSimon, frasercrmck.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 <https://reviews.llvm.org/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


https://reviews.llvm.org/D122010

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/bswap-fold.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122010.416509.patch
Type: text/x-patch
Size: 5816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220318/ef6ac70a/attachment.bin>


More information about the llvm-commits mailing list