Let Ck,j denote the completion time of instruction k in stage j, and Dk,j its duration. The pipeline uses the following recurrence: Ck,j=max(Ck,j−1,Ck−1,j)+Dk,j, where Ck,0=0 and C0,j=0.
For the first iteration (I1, I2, I3, I4), we calculate the completion times for each stage:
C1,1=2,C1,2=3,C1,3=4,C1,4=5
C2,1=3,C2,2=6,C2,3=8,C2,4=10
C3,1=5,C3,2=7,C3,3=9,C3,4=13
C4,1=6,C4,2=9,C4,3=11,C4,4=15 (I4 of 1st iteration completes at cycle 15).
For the second iteration (I1, I2, I3, I4), we continue the sequence as I5,I6,I7,I8.
For I5 (which is I1):
C5,1=max(C5,0,C4,1)+D5,1=max(0,6)+2=8
C5,2=max(C5,1,C4,2)+D5,2=max(8,9)+1=10
C5,3=max(C5,2,C4,3)+D5,3=max(10,11)+1=12
C5,4=max(C5,3,C4,4)+D5,4=max(12,15)+1=16
For I6 (which is I2):
C6,1=max(0,C5,1)+D6,1=max(0,8)+1=9
C6,2=max(C6,1,C5,2)+D6,2=max(9,10)+3=13
C6,3=max(C6,2,C5,3)+D6,3=max(13,12)+2=15
C6,4=max(C6,3,C5,4)+D6,4=max(15,16)+2=18
For I7 (which is I3):
C7,1=max(0,C6,1)+D7,1=max(0,9)+2=11
C7,2=max(C7,1,C6,2)+D7,2=max(11,13)+1=14
C7,3=max(C7,2,C6,3)+D7,3=max(14,15)+1=16
C7,4=max(C7,3,C6,4)+D7,4=max(16,18)+3=21
For I8 (which is I4):
C8,1=max(0,C7,1)+D8,1=max(0,11)+1=12
C8,2=max(C8,1,C7,2)+D8,2=max(12,14)+2=16
C8,3=max(C8,2,C7,3)+D8,3=max(16,16)+2=18
C8,4=max(C8,3,C7,4)+D8,4=max(18,21)+2=23
The last instruction (I8) completes its final stage (S4) at cycle 23.
The final answer is 23.