






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























^ 2. Implement 2 optimizations of your choice – tryto pick ones that you think will yield the largestperformance gains^ » You are given a baseline compiler that performs dead
BB1 b < 0 b >= 0^ BB3c <= 0^ BB c > 0
b <= 13
c <= 25^
c > 25 e < 34 d++ b++^
c++
b > 13
e >= 34 a++
e++^ BB
BB1 b < 0 b >= 0^ BB3c <= 0^ BB c > 0 b <= 13
c > 25c <= 25
b++^
c++
b > 13
e < 34
d++^ a++^ e >= 34
e++
bb1 bb2 bb
Non-reducible!
Loop:r1 = MEM[r2 + 0]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6r2 = r2 + 1blt r2 100 Loop
Remainder loop executes the “leftover” iterations
Unrolled loop same as Type 1, and is guaranteed to execute a multiple of N times
tc = final – initialtc = tc / incrementrem = tc % Nfin = rem * increment^ RemLoop:r1 = MEM[r2 + 0]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6r2 = r2 + Xblt r2 fin RemLoop
Loop:r1 = MEM[r2 + 0]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6 r1 = MEM[r2 + X]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6r2 = r2 + (N*X)blt r2 Y Loop
Loop:r1 = MEM[r2 + 0]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6r2 = MEM[r2 + 0]beq r2 0 Exit r1 = MEM[r2 + 0]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6r2 = MEM[r2 + 0]bne r2 0 LoopExit:
Just duplicate the body, none of the loop branches can be removed. Instead they are converted into conditional breaks^ Can apply this^ to any loop!
» All intermediate branches removed » Remainder loop is required since trip count not known atcompile time » Need to make sure don’t spend much time in rem loop Type 3 can be effective » No branches eliminated » But iteration overlap still possible » Always applicable (most loops fall into this category!) » Use average trip count to guide unroll amount