A processor permits register operands only, at most two sources and one destination per instruction. All variables are dead after this segment. Only correctness-preserving code motion is allowed. With two registers, find the minimum memory spills.
Move d=c*a and e=c+a into the else branch, immediately before their respective squarings, because only that branch uses them. At the branch test a,c,x would otherwise require three values, so spill c once and use its register for x. After the branch reload c as needed while producing and squaring d and e in place. Thus one spill suffices and zero cannot preserve all three needed values. Answer B; dead-code elimination is excluded.
More Code Optimization and Data Flow Analysis questions
GATE 2013 CS (CS1) Q59– For the same register-only architecture and complete segment below, apply register…
GATE 2010 CS (CS1) Q47– Without spilling values to memory, what is the minimum number of registers needed for this…