A profile-based loop optimizer generates an execution frequency table for each
loop that gives more detailed profile data that allows making a more intelligent
decision regarding if and how to optimize each loop in the computer program. The
execution frequency table contains entries that correlate a number of times a loop
is executed each time the loop is entered with a count of the occurrences of each
number during the execution of an instrumented instruction stream. The execution
frequency table is used to determine whether there is one dominant mode that appears
in the profile data, and if so, optimizes the loop according to the dominant mode.
The optimizer may perform optimizations by peeling a loop, by unrolling a loop,
and by performing both peeling and unrolling on a loop according to the profile
data in the execution frequency table for the loop. In this manner the execution
time of the resulting code is minimized according to the detailed profile data
in the execution frequency tables, resulting in a computer program with loops that
are more fully optimized.