edited by
1,561 views
12 votes
12 votes

Consider a basic block:

x:= a[i]; a[j]:= y; z:= a[j]

optimized by removing common sub expression a[i] as follows:

x:= a[i]; z:= x; a[j]:= y.

Which of the following is true?

  1. Both are equivalent.
  2. The values computed by both are exactly the same.
  3. Both give exactly the same values only if $i$ is not equal to $j$.
  4. They will be equivalent in concurrent programming languages with shared memory.
  5. None of the above.
edited by

2 Answers

Best answer
7 votes
7 votes

Correct Option: E
As in $1^{st}$ $z = a[j] =y$

whereas in $2^{nd}$ $z = x=a[i]$

So, $z$ is getting different values if $i \neq j$

(Also there's typo in question, expression $a[j]$ has been removed )

2 votes
2 votes
Both are equivalent only for y=x other than that they are not equal
Answer:

Related questions