• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Code Generation and Optimization

Question 21

Consider the following source code :

c = a + b
d = c
c = c – e
a = d – e
b = b * e
b = d/b

Which of the following is correct optimization of given code?

  • c = a + b
          t = b * e
          a = d – e
          b = d/t
          c = a
  • c = a + b
          d = c
          c = c – e
          a = d – e
          b = d/b
  • d = c
         c = c – e
         a = d – e
         b = b * e
         b = d/b
  • None of the above

Question 22

Consider the code segment

int i, j, x, y, m, n;
 n=20;
 for (i = 0, i < n; i++)
  {
    for (j = 0; j < n; j++)
     {
        if (i % 2)
        {
         x + = ((4*j) + 5*i);
         y += (7 + 4*j);
        }
     }
  }
  m = x + y;

Which one of the following is false

  • The code contains loop invariant computation

  • There is scope of common sub-expression elimination in this code

  • There is scope of strength reduction in this code

  • There is scope of dead code elimination in this code

Question 23

Peephole optimization is form of
  • Loop optimization
  • Local optimization
  • Constant folding
  • Data flow analysis

Question 24

Which of the following is NOT represented in a subroutine\'s activation record frame for a stack-based programming language?
  • Values of local variables
  • Return address
  • Heap area
  • Information needed to access non local variables

Question 25

In compiler terminology reduction in strength means
  • Replacing run time computation by compile time computation
  • Removing loop invariant computation
  • Removing common subexpressions
  • replacing a costly operation by a relatively cheaper one

Question 26

Which of the following statements about peephole optimization is False?
  • It is applied to a small part of the code
  • It can be used to optimize intermediate code
  • To get the best out of this, it has to be applied repeatedly
  • It can be applied to the portion of the code that is not contiguous

Question 27

The use of multiple register windows with overlap causes a reduction in the number of memory accesses for I. Function locals and parameters II. Register saves and restores III. Instruction fetches
  • I only
  • II only
  • III only
  • I, II and III

Question 28

Substitution of values for names (whose values are constants) is done in
  • Local optimization
  • Loop optimization
  • Constant folding
  • Strength reduction

Question 29

Relative to the program translated by a compiler, the same program when interpreted runs
  • Faster
  • Slower
  • At the same speed
  • May be faster or slower

Question 30

In a resident – OS computer, which of the following systems must reside in the main memory under all situations?
  • Assembler
  • Linker
  • Loader
  • Compiler

There are 38 questions to complete.

Last Updated :
Take a part in the ongoing discussion