Optimization and Data Flow questions

Q42

GATE CS 2026 CS-1Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the control flow graph shown in the figure.

Which one of the following options correctly lists the set of redundant expressions (common subexpressions) in the basic blocks B4 and B5?

Note: All the variables are integers.
Question figure
Show answer without attempting

Answer: D

Q45

GATE CS 2026 CS-2Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the control flow graph given below.

Which one of the following options is the set of live variables at the exit point of each basic block?
Question figure
Show answer without attempting

Answer: A

Q13

GATE CS 2025 CS-1Optimization and Data FlowMCQ1 mark−1/3 if wrong
Which ONE of the following techniques used in compiler code optimization uses live variable analysis?
Show answer without attempting

Answer: B

Q37

GATE CS 2023 CSOptimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the control flow graph shown.

Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?
Question figure
Show answer without attempting

Answer: D

Q30

GATE CS 2021 CS-2Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the following ANSI C code segment:
z = x + 3 + y->f1 + y->f2;
for (i = 0; i < 200; i = i + 2){
    if (z > i) {
        p = p + x + 3;
        q = q + y->f1;
    } else {
        p = p + y->f2;
        q = q + x + 3;
    }
}
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->f1 or y->f2) in the optimized code, respectively, are:
Show answer without attempting

Answer: D

Q38

GATE CS 2021 CS-2Optimization and Data FlowMCQ2 marks−2/3 if wrong
For a statement SS in a program, in the context of liveness analysis, the following sets are defined:

<br>USE(S):the set of variables used in S<br>IN(S):the set of variables that are live at the entry of S<br>OUT(S):the set of variables that are live at the exit of S<br>\begin{array}{rll}<br>\text{USE}(S) & : & \text{the set of variables used in } S \\<br>\text{IN}(S) & : & \text{the set of variables that are live at the entry of } S \\<br>\text{OUT}(S) & : & \text{the set of variables that are live at the exit of } S<br>\end{array}

Consider a basic block that consists of two statements, S1S_1 followed by S2S_2.
Which one of the following statements is correct?
Show answer without attempting

Answer: A

Q58

GATE CS 2015 CS-3Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown below

Program-X:
sumcal(int maxint, int value)
{
    int result=0, i=0;
    if (value < 0)
    {
        value = -value;
    }
    while((i<value) AND (result <= maxint))
    {
        i=i+1;
        result = result + 1;
    }
    if (result <= maxint)
    {
        printf(result);
    }
    else
    {
        printf("large");
    }
    printf("end of program");
}
Control Flow Diagram of Program-Y: shown in the figure.

Control Flow Diagram of Program-Z: the Control Flow Diagram of Program-X followed by (with an arrow into) the Control Flow Diagram of Program-Y.

The values of McCabe's Cyclomatic complexity of Program-X, Program-Y, and Program-Z respectively are
Question figure
Show answer without attempting

Answer: A

Q38

GATE CS 2015 CS-1Optimization and Data FlowNAT2 marks
Consider the following C program segment.
while (first <= last)
{
    if (array[middle] < search)
        first = middle + 1;
    else if (array[middle] == search)
        found = TRUE;
    else last = middle - 1;
    middle = (first + last)/2;
}
if (first > last) notPresent = TRUE;
The cyclomatic complexity of the program segment is ________.
Show answer without attempting

Answer: 5

Q46

GATE CS 2015 CS-1Optimization and Data FlowMCQ2 marks−2/3 if wrong
A variable xx is said to be live at a statement SiS_i in a program if the following three conditions hold simultaneously:

i. There exists a statement SjS_j that uses xx
ii. There is a path from SiS_i to SjS_j in the flow graph corresponding to the program
iii. The path has no intervening assignment to xx including at SiS_i and SjS_j

(Control flow graph: block 1: p=q+rp = q + r, s=p+qs = p + q, u=s∗vu = s * v; block 2: v=r+uv = r + u; block 3: q=s∗uq = s * u; block 4: q=v+rq = v + r; edges 1→2, 1→3, 2→4, 3→4, 4→1.)

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
Question figure
Show answer without attempting

Answer: C

Q34

GATE CS 2014 CS-3Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the basic block given below.

a = b + c
c = a + d
d = b + c
e = d - b
a = e + b

The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are
Show answer without attempting

Answer: A

Q17

GATE CS 2014 CS-1Optimization and Data FlowMCQ1 mark−1/3 if wrong
Which one of the following is FALSE?
Show answer without attempting

Answer: D

Q48

GATE CS 2013 CSOptimization and Data FlowMCQ2 marks−2/3 if wrong
Suppose the instruction set architecture of the processor has only two registers. The only allowed compiler optimization is code motion, which moves statements from one place to another while preserving correctness. What is the minimum number of spills to memory in the compiled code?
Show answer without attempting

Answer: B

Q49

GATE CS 2013 CSOptimization and Data FlowMCQ2 marks−2/3 if wrong
What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocation.
Show answer without attempting

Answer: B

0/130 correct0 marks

Related topics in Compiler Design