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

Mark Wielaard <[email protected]>
Newsgroups gmane.comp.debugging.valgrind.devel,gmane.comp.gnu.binutils
Message-ID <[email protected]>
Hi,

On Fri, Jul 03, 2026 at 11:04:30AM +0100, Sam James wrote:
> Jan Beulich <jbeulich-IBi9RG/[email protected]> writes:
> > I don't expect so. In fact, my take is that -O... should not be used on
> > compiler generated code. The compiler should do whatever optimizations
> > are possible / sensible, and it should not emit code which can (easily)
> > further be optimized. (Easily because the assembler really only does
> > very simple and pretty obvious transformations.)
> 
> Yes, that's reasonable. We should document it though.

So given that we seem to expect a compiler to not invoke gas with
optimizations and this should only trigger when someone deliberately
adds something like -Wa,-O2 to their CFLAGS I think the only thing
valgrind should do is generate a better runtime message when this
"optimization" is detected. But that we don't try to mitigate in any
other way. The warning message I am proposing is:

  special instruction preamble followed by unknown instruction
  this can happen when inline valgrind.h assembly is optimized (away)

Followed by the "normal" illegal instruction error message valgrind
generates when it cannot handle a specific instruction. 

See also https://bugs.kde.org/show_bug.cgi?id=522533

Cheers,

Mark
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.