binutils Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
x86

Disable XCHG to MOV optimization in assembler

Assembler optimization for XCHG to MOV instruction is disabled on x86.

This commit disables a specific optimization in the x86 assembler that rewrites XCHG instructions into MOV instructions when certain conditions are met. This optimization, enabled by -O, -O2, and -Os flags, was intended to shorten instruction encodings but has now been disabled to address potential issues. The change affects assembly code generation for x86 architectures.

In Details

The x86 assembler's optimization to replace XCHG with MOV instructions, previously enabled by -O[2|s], is disabled. This optimization leveraged the zero-extension behavior of 32-bit immediate MOVs into 64-bit registers. The change potentially addresses correctness issues or unintended consequences of this specific encoding shortcut.

For Context
XCHG
An x86 assembly instruction that exchanges the contents of two operands (e.g., registers or memory locations).
MOV
An x86 assembly instruction that copies data from a source operand to a destination operand.
assembler
A program that translates assembly language code into machine code that a computer's CPU can execute.
optimization flags
Compiler or assembler options (like -O, -O2, -Os) that enable various techniques to improve program performance or reduce code size.
REX.W bit
A prefix byte in x86-64 architecture instruction encoding that extends operations to 64-bit operands.
Filed Under: x86assembleroptimization