|
|
|
|
|
by piinbinary
21 days ago
|
|
The part of this that's the most interesting to me is the fact that it is worthwhile for the compiler to expend the effort looking for this optimization opportunity. I would expect (x << 2) & -4 to be a fairly rare pattern, and even then removing the & -4 only saves one or two assembly instructions. |
|
The particular patterns were added to C2 just recently, being copied from the implementations in LLVM and GCC.
Also it's unlikely the compiler looks for this in particular, but this falls out of a set of optimizations that do matter and it collapses into the output assembly on relevant architectures.