Course: Computer Architectures

Lecture: Lecture 07 - Instruction-Level Parallelism

Control dependence

An instruction is control dependent on a branch when that branch determines whether the instruction executes. In if (p) S;, S is conditional on p.

Ordinary instruction movement must preserve that condition. Moving S before the branch may execute it on a previously skipped path; moving unconditional work inside the branch may omit it on another path.

Slides 46-50 explain why some transformations can still be correct: preserve the program’s exception behavior and data flow. This is not permission to ignore observable effects such as stores, I/O, or required live register values.

Worked examples

Example 1: A load cannot be hoisted unconditionally (slide 47)

add  x2, x3, x4
beqz x2, L1
ld   x1, 0(x2)
L1:
    # continuation

If x2 == 0, the branch skips the load. If x2 != 0, the load executes. Suppose the address is unmapped or protected.

Moving the load after the add but before the branch would perform it even on the skipped path. A program that originally avoided that access could now fault. Keeping the address dependency intact is therefore not enough: exception behavior also changes.

Hardware may execute a load speculatively while deferring architectural effects and exception delivery until the path is validated. That is an additional clarification, not the same as compiler hoisting of an ordinary faulting load. See Precise Exceptions.

Example 2: The branch selects the producer (slide 48)

add  x1, x3, x4
beqz x2, L1
sub  x1, x5, x6
L1:
or   x7, x1, x8
Branch outcomeDoes SUB execute?Value OR must receive in x1
Taken (x2 == 0)NoResult of ADD
Not takenYesResult of SUB

Hoisting SUB unconditionally overwrites ADD’s value on the taken path. The arithmetic might not trap, but the final result still changes. Correctness requires preserving the path-dependent producer, not merely keeping an instruction that writes the same register before OR.

Example 3: A dead result permits safe speculation (slides 49-50)

Original slide code:

add  x1, x2, x3
beqz x12, L
sub  x4, x5, x6
add  x5, x4, x9
L:
or   x7, x8, x9

The lecture assumes x4 is not used after L and SUB cannot generate an exception in this example. Moving SUB before the branch gives:

add  x1, x2, x3
sub  x4, x5, x6
beqz x12, L
add  x5, x4, x9
L:
or   x7, x8, x9

Path-by-path reasoning:

  1. Not taken: SUB still computes x5 - x6, and the following ADD consumes that result. The same data flow reaches the same visible computation.
  2. Taken: SUB now executes unnecessarily, but its x4 result is dead after L. It changes no value used on that path and creates no exception under the stated assumption.
  3. Branch decision: It reads x12, which SUB does not change.

Only SUB is hoisted. Hoisting the following ADD would also change x5 on the taken path; the slide supplies no proof that this is safe.

The compiler speculates by performing a computation before it knows whether it is needed. Safety comes from the explicit nontrapping/dead-result conditions, not from guessing that the branch is usually not taken. Performance benefit depends on the resulting schedule and processor.

A practical check for a proposed move

For each branch path, trace which inputs the moved instruction reads, which outputs remain observable, and which new faults could occur. Preserve every live value and every required producer-consumer relationship. Use Instruction Dependencies and Register Renaming to distinguish real data flow from reused names.

Branches, Instruction-Level Parallelism, Instruction Dependencies, Register Renaming, Exceptions and Interrupts, Precise Exceptions.

E. Sanchez, Instruction Level Parallelism, ASE 2026/27, slides 44-50. PDF: Instruction Level Parallelism.pdf. Code matches the slide sequences; moved-code blocks and path tables are explanatory reconstructions. Hardware speculation is a separately labeled clarification.

Branch prediction uses past behavior to choose a speculative path; recovery preserves correct architectural effects when that guess is wrong. Branch Prediction Fundamentals