Course: Computer Architectures
Lecture: Lecture 07 - Instruction-Level Parallelism
Dependence, hazard, and stall
| Term | What it describes |
|---|---|
| Dependence | A relationship in the program that constrains correct data flow or execution |
| Hazard | A pipeline situation that could violate that relationship |
| Stall | A delay used when the implementation cannot otherwise resolve the situation |
A dependence can exist without causing a stall. Forwarding may satisfy a producer-consumer relation at the right time. Independent instructions may still stall because of a structural resource conflict.
True data dependence
A consumer needs a value produced by an earlier instruction. Use arrows from producer to consumer; slides 23-25 contain confusing i/j wording, so identify the actual reads and writes rather than relying on that sentence’s direction.
fld f0, 0(x1)
fadd.d f4, f0, f2
fsd f4, 0(x1)The load produces f0 for the add. The add produces f4 for the store. There is also a transitive chain from the load through the add to the store.
Changing destination names does not eliminate these computations’ need for their input values. See RAW and WAW Hazards for timing examples.
Name dependencies
Instructions can reuse a register or memory name without passing a value between that particular pair.
- Antidependence: An older instruction reads a name that a younger instruction writes. Protect the older read from the new value.
- Output dependence: Two instructions write the same name. Preserve which definition is the final visible value.
Register name constraints can often be removed by Register Renaming. Memory requires address and visibility analysis; changing a memory destination casually changes the program.
RAW WAW WAR and RAR
For an older instruction i and younger instruction j:
| Category | Program relationship | Unsafe event |
|---|---|---|
| RAW: read after write | j consumes i’s produced value | j reads before the value is ready |
| WAW: write after write | i and j define the same destination | i writes after j, replacing the younger value |
| WAR: write after read | i reads the name j will overwrite | j overwrites before i has read the old value |
| RAR: read after read | Both read the same unchanged value | No data-order hazard from those reads alone |
Two reads can still compete for a port; that is a structural issue, not an RAR data hazard.
In a simple in-order pipeline with all reads early and writes late, WAR is absent under those assumptions. WAR can appear with late reads and early writes or more flexible scheduling. Slide 43’s “rare” statement describes its teaching context, not all out-of-order designs.
Worked WAW example (slide 42)
The older load spends three cycles in memory; the younger add is permitted to proceed on a shorter path.
| Instruction | C1 | C2 | C3 | C4 | C5 | C6 | C7 |
|---|---|---|---|---|---|---|---|
lw x1, 0(x2) | IF | ID | EX | MEM1 | MEM2 | MEM3 | WB |
add x1, x2, x3 | IF | ID | EX | MEM | WB |
The add writes at C6, then the older load overwrites it at C7. The final x1 is wrong: program order requires the add’s value to be final.
This is possible only under the slide’s bypass/progress assumption; a pipeline that stalls all younger work behind the load does not produce this schedule. Prevention can involve stalling conflicting writers or using distinct versions with controlled architectural visibility.
Repeated loop bodies
Slides 29-32 repeatedly use f0 and f4 for loads/adds/stores at offsets 0, -8, and -16. These are separate element computations, but shared temporary names constrain overlap.
An older add must read its f0 before the next load replaces f0: WAR. Two loads also both write f0: WAW. Similarly, a store must read its f4 before a later add overwrites it. Different temporary registers expose independence if memory accesses and final state allow it.
Memory dependencies
Registers have explicit names, while addresses may be computed at runtime. A load through one pointer and a store through another may access the same location even if their syntax differs.
Explanatory alias example:
*p = 7;
r = *q;If p and q designate the same location, the load must see the stored 7. Moving the load earlier changes the result. If they are proved disjoint, this particular data-flow constraint disappears, though other ordering and exception constraints still need checking.
Slide 27 qualification: Compilers can prove some memory relationships statically. When aliasing is unknown, they preserve conservative ordering or emit runtime checks rather than necessarily assuming every load aliases every preceding store. LLVM’s official alias-check explanation.
Related and source
Register Renaming, RAW and WAW Hazards, Hazard Detection in ID, Structural Hazards in Multicycle Pipelines, Control Dependencies and Speculation.
E. Sanchez, Instruction Level Parallelism, ASE 2026/27, slides 22-32 and 39-43. PDF: Instruction Level Parallelism.pdf. The WAW cycle table reconstructs slide 42; qualifications and alias example are explanatory additions.