Data Hazards in Pipelining: Types, Solutions and Worked Examples
Follow one three-instruction trace to see exactly when a load-use pair stalls and when ALU forwarding works. Then compare the same trace without forwarding.
KnowledgeGate Team
Exam prep & CS education

Knowing the five pipeline stages is not enough when one instruction depends on another. Should it move, stall, or receive a forwarded value? Test each dependency, trace the cycle-accurate example, and distinguish RAW, WAR, and WAW. Calculate each count with a classic five-stage pipeline and stated timing rules.
Data hazards start with dependencies, not pipeline boxes
A data dependency comes from what the program must compute. A data hazard appears when the pipeline cannot yet satisfy that dependency safely.
For example:
I1: ADD R1, R2, R3
I2: SUB R4, R1, R5I2 always depends on the R1 produced by I1. Forwarding or enough instruction separation may satisfy it without a stall, so a dependency does not always cause a delay.
The model is IF -> ID -> EX -> MEM -> WB. Fetch happens in IF, register reads in ID, ALU work in EX, memory access in MEM, and register writes in WB. For a broader subject route, use the CS Fundamentals category.
Do not mix data hazards with the other two classes. Two operations competing for one memory port create a structural hazard. Waiting for a branch decision creates a control hazard.
RAW, WAR and WAW: classify by access order
Read the instructions in program order and focus on one register at a time.
Type | Access order | Meaning | Example |
|---|---|---|---|
RAW | Earlier write, later read | True dependency |
|
WAR | Earlier read, later write | Anti-dependency |
|
WAW | Earlier write, later write | Output dependency |
|
RAW carries a value from the earlier instruction to the later one, so renaming cannot remove it. In WAR, the earlier instruction must read the old value before the later write. In WAW, the final write order must match program order.
A simple single-issue, in-order five-stage pipeline normally exposes RAW hazards, not WAR or WAW hazards. Its reads and writes remain ordered. WAR and WAW become important with out-of-order execution or unequal completion times.
The solution toolbox: stall, forward, schedule or rename
A hardware interlock holds an instruction whose operand is unavailable and injects a bubble. A compiler may place an independent instruction in that gap. A literal NOP is the fallback when no useful move is safe.
Forwarding sends a result from a later pipeline register directly to EX instead of waiting for WB. Common paths are EX/MEM -> EX and MEM/WB -> EX.
Forwarding does not eliminate every stall. Here, a load produces data at the end of MEM, one cycle too late for an immediate consumer's original EX slot. Register renaming solves false WAR and WAW name conflicts, not true RAW timing.
Worked example: one load-use stall, then ALU forwarding
Lock the assumptions before drawing a timing table:
Single issue and in-order execution
Stages
IF-ID-EX-MEM-WB, one cycle eachSeparate instruction and data access
Full forwarding to EX
Load data available at the end of MEM
ALU data available at the end of EX
No cache miss
Register WB occurs early enough for an ID read in the same cycle
Use this sequence:
I1: LW R1, 0(R2) R2 = 100, Mem[100] = 7
I2: ADD R3, R1, R4 R4 = 5
I3: SUB R5, R3, R6 R6 = 2The architectural results are:
I1loadsR1 = Mem[100] = 7.I2computesR3 = R1 + R4 = 7 + 5 = 12.I3computesR5 = R3 - R6 = 12 - 2 = 10.
Pipelining in Computer Architecture explains the equal-stage baseline. For finite-batch clocks and a four-instruction load-use chain, use Pipelining Basics in Computer Architecture: Clock Cycle, Speedup and Hazard Worked Examples. Pipelining Cross-Concept Problems: CPI, Hazards and Cache Stalls combines the same dependency chain with branch and cache penalties. The three-instruction values below isolate RAW timing and compare full forwarding with no forwarding.
Instruction | C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 |
|---|---|---|---|---|---|---|---|---|
I1 | IF | ID | EX | MEM | WB | |||
I2 | IF | ID | ST | EX | MEM | WB | ||
I3 | IF | ST | ID | EX | MEM | WB |
I1 cannot deliver 7 for I2's original EX slot in C4. After one stall, I2 uses it in C5, produces 12, and forwards that result through EX/MEM -> EX to I3 in C6. No second stall is needed.

Count cycles and compare forwarding with no forwarding
For n = 3 instructions and k = 5 stages, the ideal short-trace count is:
n + k - 1 = 3 + 5 - 1 = 7 cycles
The load-use bubble raises the total to 8 cycles. Trace CPI is 8/3 = 2.666..., approximately 2.67. This includes fill and drain, not steady-state operation.
Without forwarding, each consumer waits until its producer writes the register. Under the same-cycle WB-to-ID convention, the schedule is:
Instruction | C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10 | C11 |
|---|---|---|---|---|---|---|---|---|---|---|---|
I1 | IF | ID | EX | MEM | WB | ||||||
I2 | IF | ID | ST | ST | EX | MEM | WB | ||||
I3 | IF | ST | ST | ID | ST | ST | EX | MEM | WB |
I2 reads R1 when I1 writes it in C5 and enters EX in C6. I3 reaches ID in C6, waits for the R3 write in C8, enters EX in C9, and completes in C11.
No-forwarding trace CPI is 11/3 = 3.666..., approximately 3.67. The speedup is 11/8 = 1.375x. If same-cycle WB and ID are forbidden, the schedule changes, so state the convention first.

Traps that cause wrong hazard answers
Do not label every repeated register as RAW. Check whether the earlier access is a read or write and whether the later access is a read or write.
Do not assume full forwarding means zero stalls. The immediate load-use pair above still needs one bubble.
Do not add a second stall between
I2andI3. The ALU result is ready for the next EX cycle.Do not count only bubbles when total cycles are requested. Include fill and drain.
Keep the held instruction separate from the bubble injected into EX.
Mark when each producer makes its value available and when each consumer needs it. Compare those cycles instead of memorising a stall count.
How exam questions test data hazards
Practice usually takes four useful shapes: identify dependency pairs, choose a forwarding path, complete a cycle table, or calculate stalls, cycles, CPI, and speedup under the timing rules a question states.
Try this compact classification drill:
I1: ADD R7, R2, R3
I2: MUL R8, R7, R4
I3: SUB R7, R5, R6I1 -> I2is RAW onR7:I1writes it, thenI2reads it.I2 -> I3is WAR onR7:I2reads it, thenI3writes it.I1 -> I3is WAW onR7: both instructions write it.
In the simple in-order pipeline, only the RAW pair can require a runtime wait. An out-of-order design must also preserve program meaning around the WAR and WAW name dependencies, often through register renaming.
The short version and the next study step
RAW carries a value that a later instruction truly needs.
WAR and WAW are ordering constraints caused by reused register names.
Forwarding reduces waiting, but an immediate load-use pair can still stall.
A cycle count is valid only under its stated timing rules.
If your goal is GATE preparation, GATE Guidance by Sanchit Sir provides the structured route. Redraw both schedules above without looking at the tables, then change one timing assumption and trace the consequences.
Keep learning
Data Hazards and Solutions MCQs: 12 Solved Questions with Explanations
Test yourself on 12 published data-hazard questions, then check concise explanations for dependencies, forwarding, renaming and variable-latency pipeline timing.
Structural and Control Hazards in Pipelining: Worked Cycle Tables and CPI
Learn to recognise resource conflicts and wrong-path fetches, then count their cycles correctly through two complete five-stage pipeline examples.
Pipelining Cross-Concept Problems: CPI, Hazards and Cache Stalls
Build one reliable cycle ledger for a five-stage pipeline, then use it to combine load-use stalls, branch penalties and cache misses without mixing units.
Pipelining in COA: Speedup, Hazards, and Worked GATE Examples
Build a clear mental model of pipelining, then use it to solve clock-period, speedup, throughput, efficiency, and hazard questions step by step.





