This is a partial port of the same optimization from AArch64ISelLowering, although the original handles more cases when generating regular compares instead of this one which just does it when selecting G_SELECTs.
For more detailed comments see the original comments for emitConditionalComparison() in AArch64ISelLowering.
Gives minor code size improvements.
clang-format: please reformat the code