[PATCH] D95774: [RISCV] Optimize (srl (and X, 0xffff), C) -> (srli (slli X, 16), 16 + C).

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 31 23:08:15 PST 2021


craig.topper created this revision.
craig.topper added reviewers: asb, luismarques, frasercrmck.
Herald added subscribers: vkmr, NickHung, evandro, apazos, sameer.abuasal, pzheng, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
craig.topper requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.

Rather than materializing the 0xffff immediate for the AND, use
a shift left to remove the upper bits and then shift in zeros
from the right.

This pattern occurs when type legalizing an i16 right shift.

I've implemented this with custom selection code for a number of
reasons. I've limited this to the AND having a single use. We need
to compensate for SimplifyDemandedBits altering the AND mask. I'm
using *W opcodes on RV64. We may want to generlize this in the
future. For all these reason it seemed easiest to do it this way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95774

Files:
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/test/CodeGen/RISCV/alu16.ll
  llvm/test/CodeGen/RISCV/bswap-ctlz-cttz-ctpop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95774.320399.patch
Type: text/x-patch
Size: 3905 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210201/98dda324/attachment.bin>


More information about the llvm-commits mailing list