[pushed] i386: Split MOVBE alternatives out of *bswaphi2_movbe to drop flags clobber

Uros Bizjak <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <CAFULd4Zgg6rc7Ky-xKt3xdzAJ+cDvLPeXFLaE-SnFj9EdO=dqQ@mail.gmail.com>
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.

Bootstrapped and regression tested on x86_64-pc-linux-gnu.

Uros.
p.diff.txt (text/plain, 1.4 KB)
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 3b0f8b2cccd..73d005ef5ed 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -23658,7 +23658,21 @@ (define_expand "bswaphi2"
     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))]
@@ -23667,8 +23681,13 @@ (define_insn "*bswaphi2_movbe"
   "@
     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")
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.