For two's complement integers it's equivalent to (a & ((-1) >>> 1)) for unsigned integers, and to (a+a) >> 1 for the signed ones. It is not equivalent to a, and should not be optimized to it (even if you're optimizing C; both GCC and Clang do it correctly by the way).
> recognizing that expressions of the form (a * b) / b are equivalent to a * (b / b) and therefore equivalent to a
None of those three are equivalent if you use two's complement arithmetic and trap division by zero. If you don't trap division by zero, then a * (b / b) is indeed equivalent to a.
Optimizing integer arithmetic correctly is hard :/
For two's complement integers it's equivalent to (a & ((-1) >>> 1)) for unsigned integers, and to (a+a) >> 1 for the signed ones. It is not equivalent to a, and should not be optimized to it (even if you're optimizing C; both GCC and Clang do it correctly by the way).
> recognizing that expressions of the form (a * b) / b are equivalent to a * (b / b) and therefore equivalent to a
None of those three are equivalent if you use two's complement arithmetic and trap division by zero. If you don't trap division by zero, then a * (b / b) is indeed equivalent to a.
Optimizing integer arithmetic correctly is hard :/