cris.md: Post-reload, split/generate clobberless memory destination moves
authorHans-Peter Nilsson <hp@axis.com>
Mon, 27 Jan 2020 03:24:59 +0000 (04:24 +0100)
committerHans-Peter Nilsson <hp@axis.com>
Sat, 9 May 2020 01:43:51 +0000 (03:43 +0200)
In preparation for compare-elimination (for it to be obviously
useful), we have to have some common insn in-between that
doesn't clobber condition-codes.  A move to memory is an obvious
choice.  Note the FIXME: we can do this for a zero source too;
later.

gcc:
* config/cris/cris.md ("movsi"): For memory destination
post-reload, generate clobberless variant.
("*mov_tomem<mode>_split"): New split.
("*mov_tomem<mode>"): New insn.
("enabled", mov_tomem_enabled): Define and use to exclude "x" ->
"Q>m" for less-than-SImode.

gcc/ChangeLog
gcc/config/cris/cris.md

index dec4b5f..6234bd7 100644 (file)
 
        * config/cris/cris.h (REVERSIBLE_CC_MODE): Define to true.
 
+       * config/cris/cris.md ("movsi"): For memory destination
+       post-reload, generate clobberless variant.
+       ("*mov_tomem<mode>_split"): New split.
+       ("*mov_tomem<mode>"): New insn.
+       ("enabled", mov_tomem_enabled): Define and use to exclude "x" ->
+       "Q>m" for less-than-SImode.
+
 2020-05-08  Vladimir Makarov  <vmakarov@redhat.com>
 
        * ira-color.c (update_costs_from_allocno): Remove
index 0b42197..3de2f5a 100644 (file)
        (not (match_test "dead_or_set_regno_p (insn, CRIS_SRP_REGNUM)")))
    (nil) (nil)])
 
+(define_attr "enabled" "no,yes" (const_string "yes"))
 \f
 ;; Iterator definitions.
 
       && operands[1] != const0_rtx
       && can_create_pseudo_p ())
     operands[1] = force_reg (SImode, operands[1]);
+
+   /* At post-reload time, we'll get here for e.g. split multi-mode insns
+      with a memory destination.  Go directly to the clobber-less variant.
+      FIXME: Also applies to zero source.  */
+   if (MEM_P (operands[0]) && reload_completed)
+     {
+        emit_insn (gen_rtx_SET (operands[0], operands[1]));
+        DONE;
+     }
 })
 
 (define_insn "*movsi_internal"
    move %1,%0
    move %1,%0"
   [(set_attr "slottable" "yes,yes,yes,yes,yes,no,no,no,yes,yes,yes,no,yes,no")])
+
+;; Post-reload, for memory destinations, split the clobber-variant and
+;; get rid of the clobber.
+
+(define_split ;; "*mov_tomem<mode>_split"
+  [(set (match_operand:BWD 0 "memory_operand")
+       (match_operand:BWD 1 "nonmemory_operand"))
+   (clobber (reg:CC CRIS_CC0_REGNUM))]
+  "reload_completed"
+  [(set (match_dup 0) (match_dup 1))]
+  "")
+
+;; Exclude moving special-registers to memory from matching for
+;; less-than-SImode, as they are SImode only (or actually, the size of
+;; the register, but the ones free for "x" are naturally SImode; see
+;; special measures taken for reload).
+;; This might be a belt-and-suspenders thing, as a move from special
+;; register to memory in less-than-SImode should not have made it here.
+
+(define_mode_attr mov_tomem_enabled
+  [(SI "yes,yes,yes,yes,yes,yes")
+   (HI "yes,yes,no,yes,yes,no")
+   (QI "yes,yes,no,yes,yes,no")])
+
+(define_insn "*mov_tomem<mode>"
+  [(set (match_operand:BWD 0 "memory_operand"   "=Q>,Q>,Q>,m,m,m")
+       (match_operand:BWD 1 "nonmemory_operand" "M, r, x, M,r,x"))]
+  "reload_completed"
+  "@
+   clear<m> %0
+   move<m> %1,%0
+   move %1,%0
+   clear<m> %0
+   move<m> %1,%0
+   move %1,%0"
+  [(set_attr "slottable" "yes,yes,yes,no,no,no")
+   (set_attr "enabled" "<mov_tomem_enabled>")])
 \f
 ;; Movem patterns.  Primarily for use in function prologue and epilogue.
 ;; Unfortunately, movem stores R0 in the highest memory location, thus