[PATCH 1/2] x86: optimize XCHG to MOV for same-register forms

Jan Beulich jbeulich@suse.com
Thu Jul 2 13:24:53 GMT 2026


On 02.07.2026 14:00, Mark Wielaard wrote:
> On Thu, 2026-07-02 at 07:45 +0100, Sam James wrote:
>> Jan Beulich <jbeulich@suse.com> writes:
>>> And why is -O passed to gas there, when specific
>>> insn selection matters?
>>
>> That's just because it's one of the things I test in some runs. I'll
>> filter it out for Valgrind as I agree it makes no sense there, but
>> another problem  happens when Valgrind itself is built without it, but
>> e.g. systemd has -Wa,-O2:
> 
> Yeah, we don't control how the object files that include the inlined
> assembly in valgrind.h is compiled.
> 
> Also note that valgrind.h is often vendored into other code bases
> because it is meant to be useful standalone. Which means we cannot
> change the special instruction sequence or the inline assembly used to
> generate it.
> 
> So we need a solution that prevents this particular xchg to mov
> translation (at least for same register ones) even if the sequence is
> compiled with gas optimizations.

Use the {nooptimize} pseudo-prefix, or .insn, or (as suggested by Michael)
.byte? (Since {nooptimize} has been around for quite a bit longer than
.insn, .insn likely is the poorest of the possible options.)

Jan


More information about the Binutils mailing list