[cris-decc0,7/14] cris: Enable *movsi_internal to set condition codes.
diff mbox series

Message ID 202002120658.01C6w0rx026705@ignucius.se.axis.com
State New
Headers show
Series
  • Untitled series #158021
Related show

Commit Message

Hans-Peter Nilsson Feb. 12, 2020, 6:58 a.m. UTC
* config/cris/cris.md ("cc"): Comment on new use.
("cc_enabled"): New attribute.
("enabled"): Make default fall back to cc_enabled.
("setnz", "ccnz", "setnzvc", "ccnzvc", "setcc", "cccc"): New
default_subst_attrs.
("setnz_subst", "setnzvc_subst", "setcc_subst"): New default_subst.
("*movsi_internal<setcc><setnz><setnzvc>"): Rename from
"*movsi_internal".  Correct contents of, and rename attribute
"cc" to "cc<cccc><ccnz><ccnzvc>".

Completion of, and first use of, the CRIS-specific parts of the
condition-code-setting framework, making use of the define_subst
machinery and the cmpelim optimization pass.  This round, just
moves in SImode.  Note the re-use of the cc0 era "cc" attribute
(tweaks needed).
---
 gcc/config/cris/cris.md | 61 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/gcc/config/cris/cris.md b/gcc/config/cris/cris.md
index 362d63f6d..bee9e9735 100644
--- a/gcc/config/cris/cris.md
+++ b/gcc/config/cris/cris.md
@@ -117,10 +117,16 @@  (define_attr "slottable" "no,yes,has_slot,has_return_slot"
   (const_string "no"))
 
 ;; We also need attributes to sanely determine the condition code
-;; state.
-
+;; state.  This attribute isn't used as-is, just as a template,
+;; effectively a dummy except in a substitution setting CRIS_CC0_REGNUM
+;; to a specific value.
 (define_attr "cc" "none,clobber,normal" (const_string "normal"))
 
+;; The attribute "_enabled" is appended to "cc", forming "cc_enabled" to
+;; pick out certain alternatives when generating a useful
+;; condition-code-setting.  See the "enabled" attribute.
+(define_attr "cc_enabled" "none,clobber,normal" (const_string "normal"))
+
 ;; At the moment, this attribute is just used to help bb-reorder do its
 ;; work; the default 0 doesn't help it.  Many insns have other lengths,
 ;; though none are shorter.
@@ -147,7 +153,11 @@  (define_delay (eq_attr "slottable" "has_return_slot")
 	(not (match_test "dead_or_set_regno_p (insn, CRIS_SRP_REGNUM)")))
    (nil) (nil)])
 
-(define_attr "enabled" "no,yes" (const_string "yes"))
+(define_attr "enabled" "no,yes"
+  (if_then_else
+   (eq_attr "cc_enabled" "normal")
+   (const_string "yes")
+   (const_string "no")))
 
 ;; Iterator definitions.
 
@@ -225,6 +235,44 @@  (define_code_attr xCC [(eq "CC") (ne "CC") (gtu "CC") (ltu "CC_NZVC")
 		       (geu "CC_NZVC") (leu "CC") (lt "CC") (ge "CC")
 		       (gt "CC_NZVC") (le "CC_NZVC")])
 
+;; Substitutions to describe condition-code settings.
+
+(define_subst_attr "setnz" "setnz_subst" "" "_setnz")
+(define_subst_attr "ccnz" "setnz_subst" "" "_enabled")
+
+(define_subst "setnz_subst"
+  [(set (match_operand 0)
+	(match_operand 1))
+   (clobber (reg:CC CRIS_CC0_REGNUM))]
+  "reload_completed"
+  [(set (reg:CC_NZ CRIS_CC0_REGNUM)
+	(compare:CC_NZ (match_dup 1) (const_int 0)))
+   (set (match_operand 0) (match_operand 1))])
+
+(define_subst_attr "setnzvc" "setnzvc_subst" "" "_setnzvc")
+(define_subst_attr "ccnzvc" "setnzvc_subst" "" "_enabled")
+
+(define_subst "setnzvc_subst"
+  [(set (match_operand 0)
+	(match_operand 1))
+   (clobber (reg:CC CRIS_CC0_REGNUM))]
+  "reload_completed"
+  [(set (reg:CC_NZVC CRIS_CC0_REGNUM)
+	(compare:CC_NZVC (match_dup 1) (const_int 0)))
+   (set (match_operand 0) (match_operand 1))])
+
+(define_subst_attr "setcc" "setcc_subst" "" "_setcc")
+(define_subst_attr "cccc" "setcc_subst" "" "_enabled")
+
+(define_subst "setcc_subst"
+  [(set (match_operand 0)
+	(match_operand 1))
+   (clobber (reg:CC CRIS_CC0_REGNUM))]
+  "reload_completed"
+  [(set (reg:CC CRIS_CC0_REGNUM)
+	(compare:CC (match_dup 1) (const_int 0)))
+   (set (match_operand 0) (match_operand 1))])
+
 ;; Operand and operator predicates.
 
 (include "predicates.md")
@@ -495,7 +543,9 @@  (define_expand "movsi"
      }
 })
 
-(define_insn "*movsi_internal"
+;; We provide CC, CC_NZ and CC_NZVC variants, as moves clear V and C
+;; and the result is thus usable in a compare against 0.
+(define_insn "*movsi_internal<setcc><setnz><setnzvc>"
   [(set
     (match_operand:SI 0 "nonimmediate_operand"
 		      "=r,r, r,Q>,r,Q>,g,r,r,g,rQ>,x,  m,x")
@@ -554,7 +604,8 @@  (define_insn "*movsi_internal"
     }
 }
   [(set_attr "slottable" "yes,yes,yes,yes,yes,yes,no,no,no,no,yes,yes,no,no")
-   (set_attr "cc" "*,*,*,*,*,*,*,*,*,*,none,none,none,none")])
+   (set_attr "cc<cccc><ccnz><ccnzvc>"
+	     "*,*,none,none,*,none,none,*,*,none,none,none,none,none")])
 
 ;; FIXME: See movsi.