301 views
1 1 vote

Consider the following $C$ code segment:
 

A[i] = A[i] + 1; // Line 1
j = i + 1;       // Line 2
A[j] = A[i] * 2; // Line 3
k = i;           // Line 4
A[k] = A[k] + 1; // Line 5


In the context of data-flow analysis for code optimization, we are interested in Write-After-Read (WAR) dependencies.

Ignoring all loops and function calls, the number of distinct Write-After-Read (WAR) data dependencies in this code segment is $\_\_\_\_$

1 Answer

2 2 votes

Dependency $L_3 \rightarrow L_5$ (The potential WAR):
 

  • $L_3$ : Reads $\mathbf{A}[\mathbf{i}]$ (The location at index $i$)
     
  • $L_5$ : Writes $\mathbf{A}[\mathbf{k}]$ (The location at index $k$)
     


Since $L_4$ sets $\mathbf{k}=\mathbf{i}$, the locations are guaranteed to be the same: $\mathbf{A}[\mathbf{i}]$ is the same memory cell as $\mathbf{A}[\mathbf{k}]$.

  • $L_3$ reads $\mathbf{A}[\mathbf{i}]$.
     
  • $L_5$ writes $\mathbf{A}[\mathbf{i}]$.
     
  • Therefore, a WAR dependency $\mathbf{L}_3 \rightarrow \mathbf{L}_5$ exists.
     

Hence the correct answer is 1

Answer:
Position:
Show:

Related questions

1 1 vote
2 2 answers
338
338 views
GO Classes asked Dec 11, 2025
338 views
Consider the following $C$ code segment: x = y + 1; // Line 1 y = x - 2; // Line 2 z = x + y; // Line 3 x = 5; // Line 4 y =z * 2; // Line 5In the context of instruction-...
3 3 votes
5 5 answers
573
573 views
GO Classes asked Dec 11, 2025
573 views
Consider a language that defines valid identifiers and valid integers. The tokens are defined by the following regular expressions:1. IDENTIFIER (ID): Must start with a l...
1 1 vote
2 2 answers
448
448 views
GO Classes asked Dec 11, 2025
448 views
Consider the following $C$ code segment, where $S_1$ and $S_2$ are mutually exclusive basic blocks (they are within an $\verb|if-else|$ structure): // Preceding Block B0 ...
3 3 votes
1 1 answer
310
310 views
GO Classes asked Dec 11, 2025
310 views
Consider the following $C$ code segment:x = y * z; p = q + 5; r = y * z; s = x + r; t = p + 1;In a compiler, this code segment is represented internally as a directed acy...