Module 18: Loop Optimizations
  Lecture 35: Amdahl’s Law
 


Loop Unrolling

  • Change the loop stride (most common)
  • Peel of one or more iterations at the beginning or at the end
for j = 1, n, k
for I = j, min(j+k, n)
A[i] = B[i] + C[i]
endfor
endfor

 

N1 = trunc(N/K)
N2 = N1 * K
N3 = N –N2
For j = 1, N2, K
for I = j, j+k
A[i] = B[i] + C[i]
endfor
Endfor
For I = N3+1, N
A[i] = B[i] + C[i]
endfor

Constant Propagation And Expression Evaluation

  • Most common optimization
for I = 1,n
pi = 3.14
pd = 2*pi
D[i] = pd*R[i]
endfor

pi = 3.14
pd = 6.28
for I = 1, n
D[i] = 6.28*R[i]
endfor

  • Replace constant in array index expressions with their values