Our default behavior is to use sign_extend for signed comparisons and zero_extend for everything. But for equality we have the freedom to use either extension. If we can prove the input has been truncated from something with enough sign bits, we can use sign_extend instead and let DAG combine optimize it out. A similar rule is used by type legalization in LegalizeIntegerTypes.
This gets rid of the movzx in PR42189. The immediate will still take 4 bytes instead of the 2 bytes plus 0x66 prefix a cmp di, 32767 would get, but it avoids a length changing prefix.
I refactored this code to handle floating point first to remove one level indentation in the integer path. I can pre-commit some of the refactoring if reviewers want.