Beruflich Dokumente
Kultur Dokumente
a*b + a*c
We can use the distributive law to rewrite the expression as
a*(b + c)
Since the new expression has only two operations rather than three for the
original form, it is almost certainly cheaper, because it is both faster and
smaller.
We can also use the laws of arithmetic to further simplify expressions on
constants. Consider the following C statement:
for (i = 0; i < 8 + 1; i++)
We can simplify 8 + 1 to 9 at compile time—there is no need to perform that
arithmetic while the program is executing.
10 Dead Code Elimination
Code that will never be executed can be safely removed from the
program. The general problem of identifying code that will never be
executed is difficult, but there are some important special cases where it
can be done.
Programmers will intentionally introduce dead code in certain situations.
Consider this C code fragment:
#define DEBUG 0 ... if (DEBUG)
print_debug_stuff();
In the above case, the print_debug_stuff( ) function is never executed, but
the code allows the programmer to override the preprocessor variable
definition (perhaps with a compile-time flag) to enable the debugging
code.
11 Procedure Inlining
Array Padding – add dummy data into array. Control cache behaviour.
13 Loop Tiling
14 Register Allocation