Loop Transformations: Merging Two Loop Bodies (Loop Rolling vs Loop Jamming)
When a compiler applies loop fusion (often also called loop jamming in many optimization discussions), it merges the bodies of two (or more) loops that iterate over compatible iteration spaces. In contrast, loop rolling is a different transformation that changes the loop structure (e.g., unrolling/combining iterations differently), and constant folding is compile-time simplification of constant expressions—not a loop-structure transformation.
A concise way to decide the multiple-choice question is:
- “Merges the bodies of two loops” Loop Jamming (loop fusion).
- “Changes loop structure by rearranging iterations” Loop Rolling (not body merging).
- “Evaluates constant expressions at compile time” Constant Folding.
This corresponds to the standard meaning of Loop Fusion / Loop Jamming, and differs from Loop Rolling and Constant Folding.
Loop Fusion (Loop Jamming) vs Other Loop Optimizations
How to identify the correct loop transformation from a prompt
- 1Step 1
“Merges the bodies of two loops” directly describes fusion/jamming rather than structural rearrangements.
- 2Step 2
Body merging Loop Jamming. Iteration restructuring (e.g., rolling/unrolling) Loop Rolling.
- 3Step 3
Constant folding targets expressions, not loop structure—so it cannot “merge loop bodies.”
- 4Step 4
Therefore the correct option is (ii) Loop Jamming.
Rule of thumb
If the question says merge bodies (or combine loops), think loop fusion / loop jamming.
Common confusion
Students often confuse loop fusion/jamming (combines loops) with loop rolling (changes loop structure/number of iterations). Only the fusion/jamming family literally merges the loop bodies.
Typical optimization intent (conceptual)
Separate loops exist
Step AProgram has Loop 1 and Loop 2 that may be fusible."
Apply Loop Jamming / Fusion
Step BCombine both loop bodies into one loop to reduce loop overhead and improve locality."
Alternative: Loop Rolling
Step CRe-express the loop structure/iterations without necessarily merging bodies."
Alternative: Constant Folding
Step DSimplify constant computations; no loop-body merging."
Answer and concept check
Matching prompt phrases to transformations
Quick diagnostic based on what part of the program changes.
Knowledge Check
The method which merges the bodies of two loops is