[PATCH] D145339: [InstCombine] Add transform `(icmp eq/ne bitreverse(x), C)` -> `(icmp eq/ne x, bitreverse(C))`

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 07:48:29 PST 2023


reames added a comment.

Just to note, the basic idea in this patch is generalizable.  For any function F for which we can compute the inverse function F' such that F'(F(x)) == x, replacing F(x) == C with x == F'(C) is legal.  Bitreverse (and the existing bswap) just happen to be cases where F == F'.

Not saying you have to implement the generalization, but might be worth some thought.

You applied this to the case where RHS is a constant, but we could also do it when F'(RHS) folds (e.g. InstSimpliy) or RHS is loop invariant when LHS isn't.

See also getInvertibleOperands from ValueTracking.cpp.  It implements basically the same idea, just with a different application.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145339/new/

https://reviews.llvm.org/D145339



More information about the llvm-commits mailing list