GATE CS 2021 (Afternoon) — Question 40

Compiler DesignIntermediate Code Generation & Local Code OptimizationMCQ2 marks · −2/3 if wrongHard

Consider the following ANSI C code segment:
c
1z = x + 3 + y -> f1 + y -> f2;
2for (i = 0; i < 200; i = i + 2) {
3    if (z > i) {
4        p = p + x + 3;
5        q = q + y -> f1;
6    } else {
7        p = p + y -> f2;
8        q = q + x + 3;
9    }
10}
11
Assume that the variable \(y\) points to a struct (allocated on the heap) containing two fields \(f1\) and \(f2\), and the local variables \(x\), \(y\), \(z\), \(p\), \(q\), and \(i\) are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and dereference operations (of the form \(y \rightarrow f1\) or \(y \rightarrow f2\)) in the optimized code, respectively, are :
  1. A
    403 and 102
  2. B
    203 and 2
  3. C
    303 and 102
  4. D
    303 and 2
Practise the full 2021-AN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkCompilers: Principles, Techniques & ToolsThe "Dragon Book" for parsing, syntax-directed translation and code generation.
Practise more on Intermediate Code Generation & Local Code OptimizationTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group