[PATCH] D149577: [InstCombine] Improve bswap optimization

Austin Chang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 04:09:41 PDT 2023


austin880625 created this revision.
austin880625 added a reviewer: RKSimon.
austin880625 added a project: LLVM.
Herald added subscribers: ecnelises, hiraditya.
Herald added a project: All.
austin880625 requested review of this revision.
Herald added a subscriber: llvm-commits.

Fold the following case on IR InstCombine pass and SelectionDAG combiner

  bswap(logic_op(x, bswap(y))) -> logic_op(bswap(x), y)
  bswap(logic_op(bswap(x), y)) -> logic_op(x, bswap(y))
  bswap(bswap(x)) -> x (for duplicated bswap introduced by other optimizations)

For related optimization `logic_op(bswap(x), bswap(y)) -> bswap(logic_op(x, y))`, I also add a change which I believe to align with the same optimization in SelectionDAG on the one-use constraints.

     if (match(OldRHS, m_BSwap(m_Value(NewRHS)))) {
       // OP( BSWAP(x), BSWAP(y) ) -> BSWAP( OP(x, y) )
  -    if (!OldLHS->hasOneUse() && !OldRHS->hasOneUse())
  +    if (!OldLHS->hasOneUse() || !OldRHS->hasOneUse())
         return nullptr;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149577

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/bswap-fold.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149577.518420.patch
Type: text/x-patch
Size: 12701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230501/fb0fb960/attachment-0001.bin>


More information about the llvm-commits mailing list