GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386 Performance Win

i386: Avoid false dependency for BSR instruction

Optimizes the BSR instruction on x86 to avoid performance penalties from false dependencies.

This commit addresses a performance issue on i386 architectures where the BSR (Bit Scan Reverse) instruction can incur a false dependency on its destination register. A new tuning option, X86_TUNE_AVOID_FALSE_DEP_FOR_BSR, is introduced to clear the destination register before BSR when it’s not used by the source operand. This prevents unnecessary stalls and improves performance, especially on processors where BSR is a single micro-operation.

In Details

Introduces TARGET_AVOID_FALSE_DEP_FOR_BSR and the X86_TUNE_AVOID_FALSE_DEP_FOR_BSR tuning parameter. The bsr and related instruction patterns in i386.md are converted to define_insn_and_split to conditionally emit a split version that clears the destination operand, mitigating a WAW (Write-After-Write) hazard that causes out-of-order execution stalls when the destination is not input to the BSR operation itself.

For Context
BSR
Bit Scan Reverse is an x86 instruction that finds the position of the most significant bit set in a given operand. It can be a performance bottleneck if not handled correctly due to microarchitectural dependencies.
false dependency
In CPU pipelining, a false dependency occurs when the processor incorrectly assumes a dependency between instructions, leading to unnecessary stalls. This often happens when an instruction's output is used by a subsequent instruction, but the instruction itself doesn't actually modify its output based on its previous state.
uop
Micro-operation. Complex machine instructions are broken down into simpler micro-operations by the CPU's front-end for execution by its various execution units.
WAW hazard
Write-After-Write hazard. A type of data hazard in pipelined processors where an instruction writes to a destination that has already been written to by a previous instruction that has not yet completed its write stage. This requires mechanisms to ensure correct program behavior, often by stalling the pipeline.
Filed Under: i386optimizationperformance