This patch eliminates some other UB in a slightly more tricky way than D86299: [compiler-rt][builtins] Factor out some common bit manipulations.
- Introduce a SIGN_OF(signed_int) macro (not UB-related, just to give this trick a descriptive name)
- Make the "negate if sign is -1" trick operate on corresponding unsigned types. Not factoring it out due to the "interface" of that macro would probably be quite error-prone.
This patch is expected to be NFC except for eliminating some UB identified by unit tests.