# Details

Details

# Diff Detail

Diff Detail

- Repository
- rG LLVM Github Monorepo

### Event Timeline

Comment Actions

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.