Module 18: Loop Optimizations
  Lecture 36: Cycle Shrinking
 
For I = 1,n
A[i] = A[i] + B[i-1]
B[i] = C[i-1]*x + y
C[i] = 1/B[i]
D[i] = sqrt(C[i])
endfor
For ib = 0,n-1
B[ib+1] = C[ib]*x + y
C[ib+1] = 1/B[ib+1]
Endfor
For ib = 0,n-1
A[ib+1] = A[ib+1] + B[ib]
Endfor
For ib = 0,n-1
D[ib+1] = sqrt(C[i])
Endfor
I = n+1

Loop Reversal

  • Compiler can decide to run a loop backward
  • Always legal for parallel loops
  • Illegal for sequential loop if it has loop carried dependence
  • Allows loop fusion to proceed where it might otherwise fail
for I = 1,n
A[i]=B[i]+1
C[i]=A[i]/2
endfor
for i=1,n
D[i]=1/C[i+1]
endfor
for i=n downto 1
A[i]=B[i]+1
C[i]=A[i]/2
D[i]=1/C[i+1]
endfor