Expand description
Peephole optimizations for instruction encoding. Peephole optimizations for x86/x86-64 instructions.
These optimizations transform instructions into shorter or more efficient
encodings without changing observable behavior. They are applied when
OptLevel::Size is active (the default).
§Optimizations
- Zero-idiom:
mov reg, 0→xor reg, reg(saves 3–5 bytes, faster on modern CPUs) - REX elimination:
op r64, immwhere imm fits i32 and result is zero-extended from 32-bit - NOP elimination:
mov reg, regwith same register →nopor removed - Test conversion:
and reg, reg→test reg, reg(identical flags, does not write reg) - Short AL/AX/EAX/RAX forms: Uses accumulator-specific short encodings
- Sign-extended immediate:
mov r64, immwhere imm fits i32 →mov r32, imm32
Functions§
- optimize_
instruction - Apply peephole optimizations to an instruction (mutates in place).