diff mbox series

[committed] Simplify and improve some H8 peepholes

Message ID 604c1e96c2631ffc43403df91fbebc032ebdb5ee.camel@redhat.com
State New
Headers show
Series [committed] Simplify and improve some H8 peepholes | expand

Commit Message

Li, Pan2 via Gcc-patches May 16, 2020, 4:50 a.m. UTC
A couple minor improvements to the H8 port I spotted while doing the cc0->CC_REG
transition.

First is consolidation of 3 peepholes into a single peephole using a mode
iterator.  This has zero impact on the code we generate, but means fewer patterns
that I ultimately have to convert.

Second is two conceptual improvements to peepholes that combine stack allocations
with stores into the stack by turning the store into a pre-decrement address
mode.

First, the peepholes should work just as well with SFmode as they do with SImode.
So a new iterator is introduced so that we don't need separate patterns for
SFmode.  Second we failed to optimize stack adjustments of 8 bytes.  If we use
subs the sequence would take 8 bytes, but after the peephole it's just 6 bytes.

This saves a few hundred bytes and makes it easier to compare the baseline
against the converted port for regressions.  I remove the clock counts -- they
don't look right (perhaps they were for the original H8/300).

jeff
diff mbox series

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3ae73f21560..4f48d443235 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@ 
+2020-05-15 Jeff Law  <law@redhat.com>
+
+	* config/h8300/h8300.md (SFI iterator): New iterator for
+	SFmode and SImode.
+	* config/h8300/peepholes.md (memory comparison): Use mode
+	iterator to consolidate 3 patterns into one.
+	(stack allocation and stack store): Handle SFmode.  Handle
+	8 byte allocations.
+
 2020-05-15  Segher Boessenkool  <segher@kernel.crashing.org>
 
 	* config/rs6000/rs6000-builtin.def (BU_FUTURE_MISC_2): Also require
diff --git a/gcc/config/h8300/h8300.md b/gcc/config/h8300/h8300.md
index e9b598d375a..46ab2442576 100644
--- a/gcc/config/h8300/h8300.md
+++ b/gcc/config/h8300/h8300.md
@@ -191,6 +191,8 @@ 
 
 (define_mode_iterator QHSIF [QI HI SI SF])
 
+(define_mode_iterator SFI [SF SI])
+
 (define_code_iterator shifts [ashift ashiftrt lshiftrt])
 
 (define_code_iterator ors [ior xor])
diff --git a/gcc/config/h8300/peepholes.md b/gcc/config/h8300/peepholes.md
index 9086bddcf57..a0f5af28a53 100644
--- a/gcc/config/h8300/peepholes.md
+++ b/gcc/config/h8300/peepholes.md
@@ -551,9 +551,9 @@ 
 ;; Convert a memory comparison to a move if there is a scratch register.
 
 (define_peephole2
-  [(match_scratch:QI 1 "r")
+  [(match_scratch:QHSI 1 "r")
    (set (cc0)
-	(compare (match_operand:QI 0 "memory_operand" "")
+	(compare (match_operand:QHSI 0 "memory_operand" "")
 		 (const_int 0)))]
   ""
   [(set (match_dup 1)
@@ -562,31 +562,6 @@ 
 		       (const_int 0)))]
   "")
 
-(define_peephole2
-  [(match_scratch:HI 1 "r")
-   (set (cc0)
-	(compare (match_operand:HI 0 "memory_operand" "")
-		 (const_int 0)))]
-  ""
-  [(set (match_dup 1)
-	(match_dup 0))
-   (set (cc0) (compare (match_dup 1)
-		       (const_int 0)))]
-  "")
-
-(define_peephole2
-  [(match_scratch:SI 1 "r")
-   (set (cc0)
-	(compare (match_operand:SI 0 "memory_operand" "")
-		 (const_int 0)))]
-  ""
-  [(set (match_dup 1)
-	(match_dup 0))
-   (set (cc0) (compare (match_dup 1)
-		       (const_int 0)))]
-  "")
-
-
 ;; (compare (reg:HI) (const_int)) takes 4 bytes, so we try to achieve
 ;; the equivalent with shorter sequences.  Here is the summary.  Cases
 ;; are grouped for each define_peephole2.
@@ -1418,31 +1393,48 @@ 
 
 ;; stack adjustment of -4, generate one push
 ;;
-;; before : 6 bytes, 10 clocks
-;; after  : 4 bytes, 10 clocks
+;; before : 6 bytes
+;; after  : 4 bytes
 
 (define_peephole2
   [(set (reg:SI SP_REG)
 	(plus:SI (reg:SI SP_REG)
 		 (const_int -4)))
-   (set (mem:SI (reg:SI SP_REG))
-	(match_operand:SI 0 "register_operand" ""))]
+   (set (mem:SFI (reg:SI SP_REG))
+	(match_operand:SFI 0 "register_operand" ""))]
   "!TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
-  [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
-	(match_dup 0))]
-  "")
+  [(set (mem:SFI (pre_dec:SI (reg:SI SP_REG)))
+	(match_dup 0))])
+
+;; stack adjustment of -8, generate one push
+;;
+;; before : 8 bytes
+;; after  : 6 bytes
+
+(define_peephole2
+  [(set (reg:SI SP_REG)
+	(plus:SI (reg:SI SP_REG)
+		 (const_int -8)))
+   (set (mem:SFI (reg:SI SP_REG))
+	(match_operand:SFI 0 "register_operand" ""))]
+  "!TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
+  [(set (reg:SI SP_REG)
+	(plus:SI (reg:SI SP_REG)
+		 (const_int -4)))
+   (set (mem:SFI (pre_dec:SI (reg:SI SP_REG)))
+	(match_dup 0))])
 
 ;; stack adjustment of -12, generate one push
 ;;
-;; before : 10 bytes, 14 clocks
-;; after  :  8 bytes, 14 clocks
+;; before : 10 bytes
+;; after  :  8 bytes
 
 (define_peephole2
   [(set (reg:SI SP_REG)
 	(plus:SI (reg:SI SP_REG)
 		 (const_int -12)))
-   (set (mem:SI (reg:SI SP_REG))
-	(match_operand:SI 0 "register_operand" ""))]
+   (set (mem:SFI (reg:SI SP_REG))
+	(match_operand:SFI 0 "register_operand" ""))]
   "!TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
   [(set (reg:SI SP_REG)
 	(plus:SI (reg:SI SP_REG)
@@ -1450,9 +1442,8 @@ 
    (set (reg:SI SP_REG)
 	(plus:SI (reg:SI SP_REG)
 		 (const_int -4)))
-   (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
-	(match_dup 0))]
-  "")
+   (set (mem:SFI (pre_dec:SI (reg:SI SP_REG)))
+	(match_dup 0))])
 
 ;; Transform
 ;;