Following a debate that aroused here, a new canonical form to a masked shl is introduced. The canonical form will now be:
define i8 @andshl(i8 %x) { %and = and i8 %x, 1 %shl = shl nuw nsw i8 %and, 3 ret i8 %shl }
instead of:
define i8 @andshl(i8 %x) { %and = shl i8 %x, 3 %shl = and i8 %and, 8 ret i8 %shl }
Which will result, first and foremost, in smaller constants used by the 'and' instructions.
Some complementary changes are also introduced:
- InstCombiner::MatchBSwap (under lib/Transforms/InstCombine/InstCombineAndOrXor.cpp) was changed to recognize both the old and new patterns (tests will fail if only one the new pattern is recognized).
- New features and fine tuning were introduced to InstructionSimplify in order to continue supporting existing test cases as well as enhancing other similar test cases. Those are specified in test/Transforms/InstCombine/select-bitext-bitwise-ops.ll
This transform is very similar to the one above, but the binop here is conditional. Should we be avoid pulling shifts above a conditional and?