Instruction Combining
At the source code level, combine two statements into one statement. At the IL (Intermediate Language) level, combine two instructions into one instruction.
Example:
In the code fragment below, the two post-increment statements can be combined into one statement.
int i; void f (void) { i++; i++; }
The code fragment below shows the function after the two post-increment statements have been combined into one statement.
int i; void f (void) { i += 2; }
Notes:
Many operators are candidates for instruction combining, including addition, subtraction, multiplication, left and right shift, boolean operations, and others. Some compilers perform instruction combining for some operators; few compilers perform instruction combining for a wide variety of operators. For example, some compilers will combine two post-increment statements, but will not combine two pre-increment statements, or two post-decrement statements.
Instruction combining can be performed within basic blocks and across basic blocks. Some compilers perform this optimization within basic blocks; few compilers perform this optimization across basic blocks.
Loop unrolling can provide additional opportunities for instruction combining.