[Valgrind-developers] [PATCH 1/2] x86: optimize XCHG to MOV for same-register forms
Jan Beulich
jbeulich@suse.com
Tue Jul 14 11:37:48 GMT 2026
On 14.07.2026 13:10, H.J. Lu wrote:
> On Tue, Jul 14, 2026 at 6:33 PM Mark Wielaard <mark@klomp.org> wrote:
>>
>> 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".
>
> By "safe", I mean an optimization won't break applications. The
> most x86 assembler optimizations are for shorter encodings. They
> shouldn't make an application stop working as expected.
By repeating this you won't make it any more true. Sadly I simply don't have
time right now to demonstrate to you that the optimizations you put in
originally aren't generally "safe". It's on my todo list, but only after
higher priority stuff.
Jan
More information about the Binutils
mailing list