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

Jan Beulich <[email protected]>
Newsgroups gmane.comp.gnu.binutils,gmane.comp.debugging.valgrind.devel
Message-ID <[email protected]>
On 02.07.2026 14:00, Mark Wielaard wrote:
> On Thu, 2026-07-02 at 07:45 +0100, Sam James wrote:
>> Jan Beulich <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.