GCC Tweak Boosts Speed 12%, Slows Another Test 14%

An engineer from Intel introduced a one-liner to the set of GCC compilers change, increasing the weight of branch mispredictions on x86 processors. The change made it possible to increase the performance of the generated code when passing the test 544.nab_r by 12.7% when included in the optimizations “-O2 -mtune=graniterapids” for the Intel Granite Rapids/Xeon 6 CPU and 12.1% when “-O2 -mtune=znver5” is included in the optimizations on AMD Zen5 CPU.

Changing the weight from “COSTS_N_INSNS (2)” to “COSTS_N_INSNS (2) + 3” increases the significance of the prediction error from 2 to 5 conditional instructions, which better reflects the features of command processing pipelines (pipelines) in modern CPUs, in which branch prediction errors are more are expensive. Changing the weight causes the compiler to force the compiler to convert “if” statements into conditional instructions without branches, such as CMOV, eliminating the stalls on branch mispredictions caused by the need to reset the state of the pipeline. Previously, the weight “COSTS_N_INSNS(2) + 3” was specified in GCC only for Intel processors

/Reports, release notes, official announcements.