ARM's RBIT instruction can be used to implement bit-reversal. This patch uses a similar approach to finding bit reversal patterns as instcombine does to find byteswaps - it expects a sequence of test-and-set operations linked together by ORs:
bitreverse(a) = (test(X, 0) ? set(Y, 31) : 0) | (test(X, 1) ? set(Y, 30) : 0) | ...;
This sequence can be in any order.
We can recognize an entire 32-bit RBIT or any partial bitreverse. Partial bitreverses can be masked together with the original value to take avantage of the RBIT instruction.