We avoid this fold in the more general cases where we use FoldOpIntoSelect. That's because -- unlike most binary opcodes -- 'rem' can't usually be speculated with a variable divisor since it can have immediate UB. But in the case where both arms of the select are constants, we can safely evaluate both sides and eliminate 'rem' completely.
This should fix:
https://llvm.org/PR52102
I think we have the same optimization gap for 'div', but I need to add/run tests to make sure, so I'll do that as a follow-up if this is ok. We already handle the case where the dividend is a select and the divisor is constant - that's just above the diff in this patch.