Available expressions at a control-flow merge
Code Optimization & Data-Flow Analysis

Answer & solution
Official answer: D
Givens and goal
The flow is Entry→B1→either B2 or B3→B4→B5→Exit. B1: a=b+i. B2: a=g*k; f=d−f; a=c*4. B3: t=g*k; b=c+m. B4: x=g*k; y=b+i. B5: z=c+m. All variables are integers. Find the redundant expression sets in B4 and B5.
Approach
An expression is available only if it has already been computed on every incoming path and neither operand has been reassigned since.
Step-by-step solution
1. The control-flow shape is a diamond followed by a tail:
B1 ──→ B2 ──┐
└──→ B3 ──┴──→ B4 ──→ B5At the B4 merge, availability uses the intersection of the incoming expression sets, not their union.
2. B1 computes b+i. Along B2 neither b nor i is assigned, so this expression remains available there. Along B3, however, b is overwritten by c+m. That kills the old b+i value. Hence b+i is not available on every path to B4 and y=b+i is not globally redundant.
3. Both B2 and B3 compute g*k, and neither subsequently changes g or k. Thus g*k is available along both incoming paths. Its evaluation in x=g*k is redundant. B2 later overwrites a, but that changes the destination holding a previous result, not the operands g and k; a transformation may preserve the value in a temporary.
4. B3 computes c+m, but B2 does not. B4 computes neither c+m nor anything proving its value was previously computed on the B2 path. Therefore z=c+m in B5 is not redundant on all paths.
5. The required sets are B4:{g*k}, B5:empty, option D. Option A wrongly keeps b+i; B wrongly treats a computation on only one branch as universally available; C also incorrectly keeps b+i.
In particular a=c*4 assigns a, not c; the target variable matters when deciding whether an expression is killed.

![Question 52, GATE 2025: Partition this three-address code into maximal basic blocks. 1001 i=1; 1002 j=1; 1003 t1=10*i; 1004 t2=t1+j; 1005 t3=8*t2; 1006 t4=t3−88; 1007 a[t4]=0.0; 1008 j=j+1; 1009 if j≤10 goto 1003; 1010 i=i+1; 1011 if i≤10 goto 1002; 1012 i=1; 1013 t5=i−1; 1014 t6=88*t5; 1015 a[t6]=1.0; 1016 i=i+1; 1017 if i≤10 goto 1013. How many blocks?](../../../assets/questions/CS-2025-S1-Q52-1.webp)
![Question 39, GATE 2024: The code is L1 t1=−1; L2 t2=0; L3 t3=0; L4 t4=4*t3; L5 t5=4*t2; L6 t6=t5*M; L7 t7=t4+t6; L8 t8=a[t7]; L9 if t8<=max goto L11; L10 t1=t8; L11 t3=t3+1; L12 if t3<M goto L4; L13 t2=t2+1; L14 if t2<N goto L3; L15 max=t1. Find (number of basic blocks, instructions in largest block). A (6,6); B (6,7); C (7,7); D (7,6).](../../../assets/questions/CS-2024-S1-Q39-1.webp)









![Question 55, GATE 2006: Consider C functions:
int work 1(int *a,int i,int j) {
int x=a[i+2]; a[j]=x+1; return a[i+2]-3;
}
int work 2(int *a,int i,int j) {
int t1=i+2; int t2=a[t1]; a[j]=t2+1; return t2-3;
}
S1: work 2 always gives the same output and effect on state as work 1.
S2: the transformations always reduce CPU time.
Which truth values apply?
Options:
(A) S1 false, S2 false
(B) S1 false, S2 true
(C) S1 true, S2 false
(D) S1 true, S2 true](../../../assets/questions/CS-2006-Q55-1.webp)
