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 Mon, Jul 13, 2026 at 06:05:56PM +0800, H.J. Lu wrote:
> -On/-Os I added to assembler which should be 100% safe.  If you can't
> or won't make it 100% safe, you can add another option to perform unsafe
> optimization.

It looks like you need a clear definition of "safe" and "unsafe". And
there are probably multiple different ones depending on context.
e.g. you could provide an option that makes it "safe" for the user to
rely on the instruction length. Or a guarantee that the code will
always use the shortest encoding. Another for not trying to optimize
away "redundent" encoding prefixes. Or removing "nop" sequences. Or
one that explicitly changes any nop sequences to the most efficient
one (for a particular length), etc.

Just make sure you agree on what "safe" and "unsafe" mean for
particular optimization levels/switches. And document them so the user
knows what they can expect when enabling the "optimization".

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.