























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the university of michigan covers control flow analysis, specifically loop detection and unrolling in the context of the eecs 483 course. It explains the concepts of natural loops, backedges, loop detection, and loop unrolling. The document also includes examples and class problems to help students understand these concepts.
Typology: Study notes
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























Cycle suitable for optimization » Discuss opti later
2 properties: » Single entry point called the header
» Must be one way to iterate the loop (ie at least 1 path back to the header from within theloop) called a backedge
Backedge detection » Edge, x Æ y where the target (y) dominates the source (x)
Y Identify all backedges using dominance info Y Each backedge (x Æ y) defines a loop
Y Merge loops with the same header
Y Important property
Entry Exit
Y Header, LoopBB Y Backedges, BackedgeBB Y Exitedges, ExitBB
Y Preheader (Preloop)
Y Postheader (Postloop) - analogous
Note, preheader for blue loop is contained in yellow loop BB2 BB
Entry Exit BB BB Pre1 Pre BB2 BB
Entry BB1 BB6^ Exit
900 60 1240 200 BB
Entry BB1^ Exit 20
700 1100 40 80
20
Y Induction variables are variables such that everytime they changes value, they areincremented/decremented by some constant Y Basic induction variable – induction variablewhose only assignments within a loop are of theform j = j +/- C, where C is a constant Y Primary induction variable – basic inductionvariable that controls the loop execution (for i=0;i<100; i++), i (virtual register holding i) is theprimary induction variable Y Derived induction variable – variable that is alinear function of a basic induction variable
Y A flow graph is reducible if and only if we can partition the edges into 2 disjoint groups oftencalled forward and back edges with the followingproperties
Y More simply – Take a CFG, remove all thebackedges (x Æ y where y dominates x), you should have a connected, acyclic graph
bb Non-reducible! bb bb
r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 1 blt r2 100 Loop Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 1 blt r2 100 Loop r2 is the loop variable, Increment is 1 Initial value is 0 Final value is 100 Trip count is 100 Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 1 Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r1 = MEM[r2 + 1] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 2 blt r2 100 Loop
Remove r2 increments from first N-1 iterations and update last increment Remove branch from first N-1 iterations
Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + X blt r2 Y Loop r2 is the loop variable, Increment is? Initial value is? Final value is? Trip count is? 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 * r5^ r6 = r4 << 2^ MEM[r3 + 0] = r6^ r2 = r2 + X^ blt r2 fin RemLoop Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r1 = MEM[r2 + X] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + (N*X) blt r2 Y Loop
Y Goals
Y Type 1 is the most effective
Y Type 2 is almost as effective
Y Type 3 can be effective