]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Avoid XCHGB %rH, %rL in bswaphi2 on non-pentium4 targets [PR126433]
authorUros Bizjak <ubizjak@gmail.com>
Tue, 28 Jul 2026 06:41:57 +0000 (08:41 +0200)
committerUros Bizjak <ubizjak@gmail.com>
Tue, 28 Jul 2026 06:57:46 +0000 (08:57 +0200)
XCHGB has higher latency than ROLW for non-pentium4 targets, so it
should be avoided. Switch from the preferred_for_size/preferred_for_speed
attributes to the "enabled" attribute to hard-disable unwanted alternatives.

PR target/126433

gcc/ChangeLog:

* config/i386/i386.md (*bswaphi2_movbe) Use enabled attribute.
Remove preferred_for_speed and preferred_for_size attributes.
(*bswaphi2): Ditto.
(*bswaphisi2_lowpart): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/xchg-1.c: Scan for ROL instead of XCHG.
* gcc.target/i386/xchg-2.c: Use -O2 -march=pentium4 to emit XCHG.

gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/xchg-1.c
gcc/testsuite/gcc.target/i386/xchg-2.c

index f762b2ccea2d50edc5398257d569cf8f742ec2b7..230fcb576d02b7c8134fa6bcf1938a0c402940ab 100644 (file)
    (set_attr "c86_decode" "vector,*,*,*")
    (set_attr "bdver1_decode" "double,*,*,*")
    (set_attr "mode" "QI,HI,HI,HI")
-   (set (attr "preferred_for_size")
-     (cond [(eq_attr "alternative" "1")
-             (symbol_ref "false")
-          ]
-          (symbol_ref "true")))
-   (set (attr "preferred_for_speed")
-     (cond [(eq_attr "alternative" "1")
-             (symbol_ref "!TARGET_USE_XCHGB")
+   (set (attr "enabled")
+     (cond [(eq_attr "alternative" "0")
+              (symbol_ref "TARGET_USE_XCHGB")
+           (eq_attr "alternative" "1")
+              (symbol_ref "!TARGET_USE_XCHGB")
           ]
-          (symbol_ref "true")))])
+          (const_string "*")))])
 
 (define_insn "*bswaphi2"
   [(set (match_operand:HI 0 "register_operand" "=Q,r")
    (set_attr "c86_decode" "vector,*")
    (set_attr "bdver1_decode" "double,*")
    (set_attr "mode" "QI,HI")
-   (set (attr "preferred_for_size")
-     (cond [(eq_attr "alternative" "1")
-             (symbol_ref "false")
-          ]
-          (symbol_ref "true")))
-   (set (attr "preferred_for_speed")
-     (cond [(eq_attr "alternative" "1")
-             (symbol_ref "!TARGET_USE_XCHGB")
+   (set (attr "enabled")
+     (cond [(eq_attr "alternative" "0")
+              (symbol_ref "TARGET_USE_XCHGB")
+           (eq_attr "alternative" "1")
+              (symbol_ref "!TARGET_USE_XCHGB")
           ]
-          (symbol_ref "true")))])
+          (const_string "*")))])
 
 (define_insn "bswaphisi2_lowpart"
   [(set (match_operand:SI 0 "register_operand" "=Q,r")
    (set_attr "c86_decode" "vector,*")
    (set_attr "bdver1_decode" "double,*")
    (set_attr "mode" "QI,HI")
-   (set (attr "preferred_for_size")
-     (cond [(eq_attr "alternative" "1")
-             (symbol_ref "false")
-          ]
-          (symbol_ref "true")))
-   (set (attr "preferred_for_speed")
-     (cond [(eq_attr "alternative" "1")
-             (symbol_ref "!TARGET_USE_XCHGB")
+   (set (attr "enabled")
+     (cond [(eq_attr "alternative" "0")
+              (symbol_ref "TARGET_USE_XCHGB")
+           (eq_attr "alternative" "1")
+              (symbol_ref "!TARGET_USE_XCHGB")
           ]
-          (symbol_ref "true")))])
+          (const_string "*")))])
 
 (define_expand "bitreverse<mode>2"
   [(set (match_operand:SWIDWI 0 "register_operand")
index ea9fc7a8b14e9fbad96427d159a4a10f8e6b5fd7..f3e8f84ddf46a18e06045ed668a4d816d2839e29 100644 (file)
@@ -6,4 +6,4 @@ unsigned short good(unsigned short a)
        return (a >> 8 | a << 8);
 }
 
-/* { dg-final { scan-assembler "\[ \t\]xchg" } } */
+/* { dg-final { scan-assembler "\[ \t\]rol" } } */
index f00fb0f211562153e3cb9dc2c02fbe883cd81e1e..9cd02eb310b4cb32f86762d18e881d4ac2732162 100644 (file)
@@ -1,9 +1,9 @@
-/* { dg-do compile } */
-/* { dg-options "-Os" } */
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -march=pentium4" } */
 
 unsigned short good(unsigned short a)
 {
        return (a >> 8 | a << 8);
 }
 
-/* { dg-final { scan-assembler "xchgb" } } */
+/* { dg-final { scan-assembler "\[ \t\]xchg" } } */