]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Split MOVBE alternatives out of *bswaphi2_movbe to drop flags clobber
authorUros Bizjak <ubizjak@gmail.com>
Mon, 10 Aug 2026 07:58:11 +0000 (09:58 +0200)
committerUros Bizjak <ubizjak@gmail.com>
Mon, 10 Aug 2026 18:02:57 +0000 (20:02 +0200)
The MOVBE alternatives in *bswaphi2_movbe carry a
(clobber (reg:CC FLAGS_REG)) that only the ROL alternative
sharing the pattern actually needs. MOVBE does not touch
EFLAGS, so once reload has picked an alternative, split the
MOVBE cases out into a new clobber-free *movbehi2 pattern.

gcc/ChangeLog:

* config/i386/i386.md (*movbehi2): New insn, split from the
movbe alternatives of *bswaphi2_movbe.
(*bswaphi2_movbe): Convert to define_insn_and_split.  Split
the MOVBE alternatives (mem<->reg) post-reload into *movbehi2
to drop the now-unneeded flags clobber.

gcc/config/i386/i386.md

index 3b0f8b2cccd3f86cfee1044674b9d8c9a1fbc5f0..73d005ef5ed570469eb39421f8b63aea7de34716 100644 (file)
     operands[1] = force_reg (HImode, operands[1]);
 })
 
-(define_insn "*bswaphi2_movbe"
+(define_insn "*movbehi2"
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
+       (bswap:HI (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
+  "TARGET_MOVBE
+   && MEM_P (operands[0]) != MEM_P (operands[1])
+   && reload_completed"
+  "movbe{w}\t{%1, %0|%0, %1}"
+  [(set_attr "type" "imov")
+   (set_attr "modrm" "1")
+   (set_attr "prefix_0f" "1")
+   (set_attr "prefix_extra" "1")
+   (set_attr "mode" "HI")])
+
+;; Convert movbe to avoid flags dependency.
+(define_insn_and_split "*bswaphi2_movbe"
   [(set (match_operand:HI 0 "nonimmediate_operand" "=Q,r,r,m")
        (bswap:HI (match_operand:HI 1 "nonimmediate_operand" "0,0,m,r")))
    (clobber (reg:CC FLAGS_REG))]
   "@
     xchg{b}\t{%h0, %b0|%b0, %h0}
     rol{w}\t{$8, %0|%0, 8}
-    movbe{w}\t{%1, %0|%0, %1}
-    movbe{w}\t{%1, %0|%0, %1}"
+    #
+    #"
+  "&& MEM_P (operands[0]) != MEM_P (operands[1])
+   && reload_completed"
+  [(set (match_dup 0)
+       (bswap:HI (match_dup 1)))]
+  ""
   [(set_attr "type" "imov,rotate1,imov,imov")
    (set_attr "modrm" "*,*,1,1")
    (set_attr "prefix_0f" "*,*,1,1")