Patent ID: 7702856

Claim:
A method comprising: receiving a computer program to be compiled; identifying a loop included in the computer program, the loop comprising a trip-count for calculating a prefetch distance for a prefetch instruction during the performance of prefetch optimization on the computer program, wherein the trip count is not statically known; generating prefetch distance calculation code in response to identifying the loop, wherein the prefetch distance calculation code calculates the prefetch distance when executed by having the prefetch distance cover all latency associated with a memory access if the trip-count of the loop at run-time is more than three times the distance needed to cover all latency associated with a memory access, and having the prefetch distance equal to one plus one-third of the trip-count of the loop at run-time if the trip-count of the loop at run-time is less than or equal to three times the distance needed to cover all latency associated with a memory access; generating the prefetch instruction during the performance of prefetch optimization on the computer program, the prefetch instruction using the prefetch distance calculated by the prefetch distance calculation code at run-time; and inserting the prefetch distance calculation code before the loop; and inserting the prefetch instruction inside the loop.