FR: Compile “−x − 1” as “not x”.
...Preferably even regardless of the overflow checks (at least with signed x, as in this case -x - 1 always fits into the type of x).
For example, it is occasionally useful to pack a boolean flag and an (N−1)-bit unsigned integer into one N-bit signed number x, where:
-
x >= 0representstrueflag and source numberx; -
x < 0representsfalseflag and source number-x - 1, more efficiently but less intuitively calculated asnot x.
GCC seems to do it on sight, emitting not even at -O0.