A method, apparatus, and computer instructions for local program
reorganization using branch count per instruction hardware. In a
preferred embodiment, a hardware counter is used in the present invention
to count the number of times a branch is taken when branch instructions
are executed. Branch count statistics generated from the hardware
counters are available to a program in order to analyze whether code
reorganization is necessary. If reorganization is necessary, the program
autonomically reorganizes instructions locally at run time to allow more
instructions to be executed prior to taking a branch, so that the number
of branches taken is minimized without modifying underlying program code.