← 🚰 Instruction Pipelining & Hazards
Subtopic 5 of 8

2.5Control hazard

The idea

A control hazard arises because a branch changes which instruction comes next, but the pipeline has already fetched the ones after it.

Think of it like this: Driving past a junction before you find out you should have turned.

Why it exists

Branches are about 15–20% of instructions, so their penalty adds up quickly.

How it works

  1. A branch is only resolved late (EX or MEM).
  2. Meanwhile the next instructions are fetched on a guess (usually "not taken").
  3. If the guess was wrong, those instructions are flushed: the lost cycles are the branch penalty.
  4. Reduce it with branch prediction, early resolution or delayed branches.

Worked example: Branch resolved after EX (cycle 3)

Two wrong-path instructions were fetched, so the penalty is 2 cycles. If the prediction was right, penalty is 0.

Now play with it

  • →Switch between "Branch taken" and "Prediction correct" and compare total cycles.
12345678
BEQIFIDEXMEMWB
I2 (wrong path)IFIDflush
I3 (wrong path)IFflush
TargetIFIDEXMEMWB

Outcome known after EX (cycle 3). Two wrongly fetched instructions are flushed: 2 cycle branch penalty.

Check yourself

Which technique directly reduces the cost of control hazards?

Remember: Wrong guess = flushed instructions = penalty cycles.
Exam notes (the dense version)

Branch outcome known late → wrong-path fetches. Fix: stall, predict (static/dynamic), delayed branch, branch target buffer.

Previous year questions: Instruction Pipelining & Hazards (15)

PYQs are grouped by topic, so this is the full set for Instruction Pipelining & Hazards; try the ones that match this subtopic. Open all 15 on the topic page.