[PATCH] D120192: [DAG] Attempt to fold bswap(shl(x,c)) -> zext(bswap(trunc(shl(x,c-bw/2))))

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 19 11:35:31 PST 2022


RKSimon created this revision.
RKSimon added reviewers: spatel, craig.topper, nikic, lebedev.ri, dmgreen.
Herald added subscribers: ecnelises, pengfei, hiraditya.
RKSimon requested review of this revision.
Herald added a project: LLVM.

If the shl is at least half the bitwidth (i.e. the lower half of the bswap source is zero), then we can reduce the shift and perform the bswap at half the bitwidth and just zero extend.

I've currently allowed any shift value >= bw/2, but we could limit this to modulo16 so that the shl is always folded away? I'll probably enforce that limit for the InstCombine variant of this fold for PR53867, but I was wondering whether we should be more relaxed in DAG.

Based off PR51391 + PR53867


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120192

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AArch64/load-combine-big-endian.ll
  llvm/test/CodeGen/AArch64/load-combine.ll
  llvm/test/CodeGen/X86/combine-bswap.ll
  llvm/test/CodeGen/X86/load-combine.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120192.410095.patch
Type: text/x-patch
Size: 7851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220219/666aa9cd/attachment.bin>


More information about the llvm-commits mailing list