From: Uros Bizjak Date: Mon, 10 Aug 2026 07:58:11 +0000 (+0200) Subject: i386: Split MOVBE alternatives out of *bswaphi2_movbe to drop flags clobber X-Git-Url: http://git.ipfire.org/index.cgi?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fgcc.git i386: Split MOVBE alternatives out of *bswaphi2_movbe to drop flags clobber 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. --- 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 @@ 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 @@ "@ 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")