IT lexicon › Programming › Tail merging

Tail merging

Programming På svenska → Updated: 2026-11-05

An optimisation that folds identical instruction sequences at the end of several basic blocks that jump to the same successor.

When both the if and else arms end with the same three instructions followed by a jump to the same place, the compiler keeps one copy and has the other arm jump into it. The technique predates the name; GCC still calls it cross-jumping and controls it with -fcrossjumping. It is tail duplication run backwards, and the two passes could in principle undo each other forever if nobody kept track of the order.

The payoff is smaller code, which matters for the instruction cache and on embedded targets. The cost is an extra jump and worse debugging: when two source lines share the same machine code, the debugger can only show one of them, and the crash report points at the wrong line with complete confidence.

← Back to the lexicon