https://gcc.gnu.org/g:446835a07d5ba4752805ab24101b3951e31defe4

commit r16-7909-g446835a07d5ba4752805ab24101b3951e31defe4
Author: Jakub Jelinek <[email protected]>
Date:   Thu Mar 5 11:23:24 2026 +0100

    i386: Make -masm={att,intel} xchg operand order consistent
    
    While in this case it is not an assemble failure nor wrong-code,
    because say xchgl %eax, %edx and xchg eax, edx do the same thing,
    they are encoded differently, so if we want consistency between
    -masm=att and -masm=intel emitted code (my understanding is that
    is what is Zdenek testing right now, fuzzing code, compiling
    with both -masm=att and -masm=intel and making sure if the former
    assembles, the latter does too and they result in identical
    *.o files), we should use different order of the operands
    even here (and it doesn't matter which order we pick).
    
    I've grepped the *.md files with
    grep '\\t%[0-9], %[0-9]' *.md | grep -v '%0, %0'
    i386.md:  "xchg{<imodesuffix>}\t%1, %0"
    i386.md:   xchg{<imodesuffix>}\t%1, %0
    i386.md:  "wrss<mskmodesuffix>\t%0, %1"
    i386.md:  "wruss<mskmodesuffix>\t%0, %1"
    (before this and PR124366 fix) and later on also with
    grep '\\t%[a-z0-9_<>]*[0-9], %[a-z0-9_<>]*[0-9]' *.md | grep -v '%0, %0'
    and checked all the output and haven't found anything else problematic.
    
    2026-03-05  Jakub Jelinek  <[email protected]>
    
            * config/i386/i386.md (swap<mode>): Swap operand order for
            -masm=intel.

Diff:
---
 gcc/config/i386/i386.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 5533c6e92d3b..8636b0168785 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -3360,7 +3360,7 @@
    (set (match_dup 1)
        (match_dup 0))]
   ""
-  "xchg{<imodesuffix>}\t%1, %0"
+  "xchg{<imodesuffix>}\t{%1, %0|%0, %1}"
   [(set_attr "type" "imov")
    (set_attr "mode" "<MODE>")
    (set_attr "pent_pair" "np")
@@ -3375,8 +3375,8 @@
        (match_dup 0))]
   ""
   "@
-   xchg{<imodesuffix>}\t%1, %0
-   xchg{l}\t%k1, %k0"
+   xchg{<imodesuffix>}\t{%1, %0|%0, %1}
+   xchg{l}\t{%k1, %k0|%k0, %k1}"
   [(set_attr "type" "imov")
    (set_attr "mode" "<MODE>,SI")
    (set (attr "preferred_for_size")

Reply via email to