Questions: Loop Detection and Analysis

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In a control-flow graph, a back edge runs from node L to node H. What structural condition on H and L makes this a natural loop back edge?

AL must dominate H — control must always flow through L before H
BH must dominate L — control must always flow through H before L
CH and L must be in the same strongly connected component with no other entries
DL must be the only predecessor of H in the CFG
Question 2 Multiple Choice

A nested loop has an outer loop running 100 iterations and an inner loop running 10 iterations per outer iteration. Which loop should be the primary target for optimization, and why?

AThe outer loop, because it controls when the inner loop executes
BThe inner loop, because a single operation moved out of it saves 1,000 executions, not just 100
CBoth equally — nesting depth alone determines optimization priority
DNeither — compilers optimize loops based only on instruction count, not iteration count
Question 3 True / False

Nearly every loop in a well-formed program has exactly one entry point (header), making most loops natural loops.

TTrue
FFalse
Question 4 True / False

Loop-invariant code motion — moving computations whose operands don't change within a loop to just before the loop — can only be safely applied after loop detection has identified the loop's header and body.

TTrue
FFalse
Question 5 Short Answer

What makes an irreducible loop challenging for compiler optimization, and how do compilers typically handle it?

Think about your answer, then reveal below.