f7.docx - LOOP OPTIMIZATIONS Loops are very important place for optimizations where programs tend to spend the bulk of their time rf we decrease the

f7.docx - LOOP OPTIMIZATIONS Loops are very important place...

This preview shows page 1 - 2 out of 5 pages.

LOOP OPTIMIZATIONS Loops are very important place for optimizations where programs tend to spend the bulk of their time. rf we decrease the number of instructions in an inner loop, even if we increase the amount of code outside that loop, the running time of a program may be improved considerably. Three important techniques for loop optimization are - code motion, which moves code outside a loop; induction-variable elimination, which we apply to eliminate loop indices from the inner loops; and reduction in strength, which replaces an expensive operation by a cheaper one, such as a multiplication by an addition. Some of the loop optimization techniques are discussed below: Code Motion Code motion is an important modification that decreases the amount of code in a loop. It takes an expression and transforms it yielding the same result independent of the number of times a loop is executed (i.e. a loop-invariant computation) and places the expression before the loop. The assumption made here is that an entry for the loop exists. For instance, evaluation of aaa is a loop-invariant computation in the following while-statement: While (i < = aaa) Code motion will transform it into the following equivalent statements: ttt = aaa; While (i < = ttt) Clearly the code motion technique has reduced the number of computations in this form. Induction Variables and Reduction In Strength Code motion may not be applicable to all the situations. Loops are usually processed from inside to outside. For example, consider the following loops: Note that the values of j and t2 remain in lock step; every time the value of j decreases by 1, that of t2 decreases by 5 because 5* j is assigned to t2. Such identifiers are called induction variables.
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 5 pages?

  • '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors