I read a paper called UDP: Utility-Driven Fetch Directed Instruction Prefetching, and decided to learn about FDIP (Fetch Directed Instruction Prefetching).
What is FDIP (Fetch Directed Instruction Prefetching)?
FDIP is a technique for improving the fetch efficiency of the CPU frontend. As the "Prefetching" at the end of its name suggests, it is a technique for prefetching instructions in the frontend.
As a premise of FDIP, a technique called "Frontend Decoupling", which separates the frontend operation of "predicting instruction addresses" from "fetching instructions", is often explained together with it. The two are separated and connected to each other by an FTQ (Fetch Target Queue). The characteristic of this structure is that "instruction address prediction" (the front end of instruction fetch) can run ahead of "the actual instruction fetch" (the back end of instruction fetch); the purpose is to give the front end of instruction fetch additional time margin "for looking ahead", without being affected by the back end of instruction fetch.
Conversely, if address generation and the actual fetch operation are not separated, a stall in instruction fetch also affects address generation (for example, it stops predicting the instruction at the next address). To prevent that, the Decoupled Frontend places an FTQ with some slack in between, so that fetch address prediction does not stop.
With a Decoupled Frontend, the instruction fetch frontend can run ahead of the instruction fetch backend. Typically, the throughput of the actual fetch side has an upper limit, whereas the prediction side can generate a sequence of fetch blocks further ahead. An instruction fetch block here is a "fixed-size byte sequence of instructions (such as 32B)" whose "end of the block is the first predicted-taken branch".
The instruction fetch frontend (the branch predictor side) successively enqueues the fetch blocks it generates by prediction at the tail of the FTQ. Meanwhile, the actual instruction fetch consumes entries in order from the head of the FTQ.
FDIP scans the future entries of the FTQ and probes whether the corresponding fetch block is present in the I$ (or is already being fetched). If it is not present, it issues a prefetch. If it is not present, it issues a prefetch. By issuing the prefetch before the address is actually needed, the latency of instruction fetch can be hidden.

The FTQ depth changes timeliness
Here, there is a point that the timeliness of prefetching changes with the depth of the FTQ. In the extreme, a deeper FTQ can find and prefetch blocks that will be accessed further in the future.
On the other hand, a deeper FTQ is also a mixed blessing. Even if the FTQ gets deeper and can hold more instruction addresses, that is a separate matter from whether they are accurate. That is, by predicting inaccurate addresses and prefetching instructions, we may pollute the instruction cache.
There are several factors behind this.
- In the case of a BTB miss, "where in this block the branch is / where to cut the block" becomes invisible. As a result, we cannot stop where we should stop at a branch, and instead go straight in the fall-through direction, behaving like a "huge basic block".
- In the case of a branch misprediction, i.e. the case where the instruction is recognized as a branch but the branch is mispredicted. In practice, whether a branch was mispredicted cannot be determined until the instruction reaches the backend of the CPU pipeline, and until then incorrect prefetches based on the prediction may continue to be issued.
Here you might think, "then why not just reduce the aggressiveness of FDIP on a BTB miss?", but this is also difficult. The point is that "the off-path traffic created by making the FTQ deeper can pollute the instruction cache, but it is not all bad". In particular, even after a misprediction, if the control flow rejoins at a merge point, the instructions fetched on the off-path side may be reused later on the on-path side, and as a result become timely prefetches.
- useful: an on-path demand hits that prefetch (in the I$ or in the fill-buffer/MSHR)
- unuseful: evicted from the I$ without being used by a demand (close to pollution)
It is known that these off-path situations differ extremely depending on the workload.
- verilator: even with about 90% off-path, the utility ratio is 0.6 (= 60% is useful)
- xgboost: the utility ratio is 0.1 (= mostly pollution)
So adjusting the aggressiveness of FDIP is not necessarily the optimal solution in every case.
This is an English translation of the original Japanese post: UDP: Utility-Driven Fetch Directed Instruction Prefetching の論文を読む (1. FDIPについて)