diff mbox series

[2/2] rs6000: Refactor genfusion.pl a bit further

Message ID 130a6f1b-9089-8cdc-8e0c-0870139df7c7@linux.ibm.com
State New
Headers show
Series [1/2] rs6000: Refactor script genfusion.pl | expand

Commit Message

Kewen.Lin Jan. 18, 2023, 9:02 a.m. UTC
Hi,

To keep the previous refactoring patch not need to
re-generate fusion.md and make the review easier,
I didn't merge this patch into the previous one.

But I think this one can help to make the subroutine
gen_logical_addsubf_scalar more clear, by separating
logical-logical and add-logical handlings into two
different loops.  It needs to regenerate fusion.md,
since add-logical type definitions would have their
own continuous area (it needs some rearrangments).

Bootstrapped and regtested on powerpc64le-linux-gnu P10.

Any comments are highly appreciated.

BR,
Kewen
-----
gcc/ChangeLog:

	* config/rs6000/fusion.md : Regenerate.
	* config/rs6000/genfusion.pl (gen_logical_addsubf_scalar): Split
	logical-logical and add-logical handlings into two loops.
---
 gcc/config/rs6000/fusion.md    | 288 ++++++++++++++++-----------------
 gcc/config/rs6000/genfusion.pl |  28 ++--
 2 files changed, 162 insertions(+), 154 deletions(-)

--
2.37.0
diff mbox series

Patch

diff --git a/gcc/config/rs6000/fusion.md b/gcc/config/rs6000/fusion.md
index d45fb138a70..0427505b7f7 100644
--- a/gcc/config/rs6000/fusion.md
+++ b/gcc/config/rs6000/fusion.md
@@ -499,42 +499,6 @@  (define_insn "*fuse_xor_and"
    (set_attr "cost" "6")
    (set_attr "length" "8")])

-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar add -> and
-(define_insn "*fuse_add_and"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (and:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
-                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   add %3,%1,%0\;and %3,%3,%2
-   add %3,%1,%0\;and %3,%3,%2
-   add %3,%1,%0\;and %3,%3,%2
-   add %4,%1,%0\;and %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar subf -> and
-(define_insn "*fuse_subf_and"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (and:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
-                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   subf %3,%1,%0\;and %3,%3,%2
-   subf %3,%1,%0\;and %3,%3,%2
-   subf %3,%1,%0\;and %3,%3,%2
-   subf %4,%1,%0\;and %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar and -> andc
 (define_insn "*fuse_and_andc"
@@ -967,42 +931,6 @@  (define_insn "*fuse_xor_nand"
    (set_attr "cost" "6")
    (set_attr "length" "8")])

-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar add -> nand
-(define_insn "*fuse_add_nand"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (ior:GPR (not:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
-                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   add %3,%1,%0\;nand %3,%3,%2
-   add %3,%1,%0\;nand %3,%3,%2
-   add %3,%1,%0\;nand %3,%3,%2
-   add %4,%1,%0\;nand %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar subf -> nand
-(define_insn "*fuse_subf_nand"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (ior:GPR (not:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
-                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   subf %3,%1,%0\;nand %3,%3,%2
-   subf %3,%1,%0\;nand %3,%3,%2
-   subf %3,%1,%0\;nand %3,%3,%2
-   subf %4,%1,%0\;nand %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar and -> nor
 (define_insn "*fuse_and_nor"
@@ -1147,42 +1075,6 @@  (define_insn "*fuse_xor_nor"
    (set_attr "cost" "6")
    (set_attr "length" "8")])

-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar add -> nor
-(define_insn "*fuse_add_nor"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (and:GPR (not:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
-                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   add %3,%1,%0\;nor %3,%3,%2
-   add %3,%1,%0\;nor %3,%3,%2
-   add %3,%1,%0\;nor %3,%3,%2
-   add %4,%1,%0\;nor %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar subf -> nor
-(define_insn "*fuse_subf_nor"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (and:GPR (not:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
-                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   subf %3,%1,%0\;nor %3,%3,%2
-   subf %3,%1,%0\;nor %3,%3,%2
-   subf %3,%1,%0\;nor %3,%3,%2
-   subf %4,%1,%0\;nor %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar and -> or
 (define_insn "*fuse_and_or"
@@ -1327,42 +1219,6 @@  (define_insn "*fuse_xor_or"
    (set_attr "cost" "6")
    (set_attr "length" "8")])

-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar add -> or
-(define_insn "*fuse_add_or"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (ior:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
-                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   add %3,%1,%0\;or %3,%3,%2
-   add %3,%1,%0\;or %3,%3,%2
-   add %3,%1,%0\;or %3,%3,%2
-   add %4,%1,%0\;or %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
-;; add-logical fusion pattern generated by gen_logical_addsubf
-;; scalar subf -> or
-(define_insn "*fuse_subf_or"
-  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
-        (ior:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
-                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
-                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
-   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
-  "(TARGET_P10_FUSION)"
-  "@
-   subf %3,%1,%0\;or %3,%3,%2
-   subf %3,%1,%0\;or %3,%3,%2
-   subf %3,%1,%0\;or %3,%3,%2
-   subf %4,%1,%0\;or %3,%4,%2"
-  [(set_attr "type" "fused_arith_logical")
-   (set_attr "cost" "6")
-   (set_attr "length" "8")])
-
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar and -> orc
 (define_insn "*fuse_and_orc"
@@ -1651,6 +1507,150 @@  (define_insn "*fuse_xor_xor"
    (set_attr "cost" "6")
    (set_attr "length" "8")])

+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar add -> and
+(define_insn "*fuse_add_and"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (and:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
+                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   add %3,%1,%0\;and %3,%3,%2
+   add %3,%1,%0\;and %3,%3,%2
+   add %3,%1,%0\;and %3,%3,%2
+   add %4,%1,%0\;and %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar subf -> and
+(define_insn "*fuse_subf_and"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (and:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
+                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   subf %3,%1,%0\;and %3,%3,%2
+   subf %3,%1,%0\;and %3,%3,%2
+   subf %3,%1,%0\;and %3,%3,%2
+   subf %4,%1,%0\;and %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar add -> nand
+(define_insn "*fuse_add_nand"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (ior:GPR (not:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
+                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   add %3,%1,%0\;nand %3,%3,%2
+   add %3,%1,%0\;nand %3,%3,%2
+   add %3,%1,%0\;nand %3,%3,%2
+   add %4,%1,%0\;nand %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar subf -> nand
+(define_insn "*fuse_subf_nand"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (ior:GPR (not:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
+                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   subf %3,%1,%0\;nand %3,%3,%2
+   subf %3,%1,%0\;nand %3,%3,%2
+   subf %3,%1,%0\;nand %3,%3,%2
+   subf %4,%1,%0\;nand %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar add -> nor
+(define_insn "*fuse_add_nor"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (and:GPR (not:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
+                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   add %3,%1,%0\;nor %3,%3,%2
+   add %3,%1,%0\;nor %3,%3,%2
+   add %3,%1,%0\;nor %3,%3,%2
+   add %4,%1,%0\;nor %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar subf -> nor
+(define_insn "*fuse_subf_nor"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (and:GPR (not:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
+                 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r"))))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   subf %3,%1,%0\;nor %3,%3,%2
+   subf %3,%1,%0\;nor %3,%3,%2
+   subf %3,%1,%0\;nor %3,%3,%2
+   subf %4,%1,%0\;nor %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar add -> or
+(define_insn "*fuse_add_or"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (ior:GPR (plus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
+                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   add %3,%1,%0\;or %3,%3,%2
+   add %3,%1,%0\;or %3,%3,%2
+   add %3,%1,%0\;or %3,%3,%2
+   add %4,%1,%0\;or %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
+;; add-logical fusion pattern generated by gen_logical_addsubf
+;; scalar subf -> or
+(define_insn "*fuse_subf_or"
+  [(set (match_operand:GPR 3 "gpc_reg_operand" "=&0,&1,&r,r")
+        (ior:GPR (minus:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
+                          (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
+                 (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
+   (clobber (match_scratch:GPR 4 "=X,X,X,&r"))]
+  "(TARGET_P10_FUSION)"
+  "@
+   subf %3,%1,%0\;or %3,%3,%2
+   subf %3,%1,%0\;or %3,%3,%2
+   subf %3,%1,%0\;or %3,%3,%2
+   subf %4,%1,%0\;or %3,%4,%2"
+  [(set_attr "type" "fused_arith_logical")
+   (set_attr "cost" "6")
+   (set_attr "length" "8")])
+
 ;; logical-add fusion pattern generated by gen_logical_addsubf
 ;; scalar and -> add
 (define_insn "*fuse_and_add"
diff --git a/gcc/config/rs6000/genfusion.pl b/gcc/config/rs6000/genfusion.pl
index 487e662ce05..6002a3af578 100755
--- a/gcc/config/rs6000/genfusion.pl
+++ b/gcc/config/rs6000/genfusion.pl
@@ -335,22 +335,30 @@  sub gen_logical_addsubf_scalar
   my $constraint = 'r';

   my @logicals = ( 'and', 'andc', 'eqv', 'nand', 'nor', 'or', 'orc', 'xor' );
+
+  # logical-logical
+  foreach my $outer_op ( @logicals ) {
+    foreach my $inner_op ( @logicals ) {
+      my $exp = logical_addsubf_make_exp ($outer_op, $inner_op, $mode,
+                                          $pred, $constraint);
+      logical_addsubf_emit_define ('logical-logical', 'scalar', $outer_op,
+                                   $inner_op, $mode, $pred, $constraint,
+                                   $exp, $fuse_type);
+    }
+  }
+
   # logical ops which can fuse with add/subf/rsubf
   my @logicals2 = ( 'and', 'nand', 'nor', 'or' );
   my @add_subf = ( 'add', 'subf' );

-  # {logical, add}-logical
-  foreach my $outer_op ( @logicals ) {
-    foreach my $inner_op ( @logicals, @add_subf ) {
-      my $ftype = 'logical-logical';
-      if (grep (/^$inner_op$/, @add_subf)) {
-         next unless grep (/^$outer_op$/, @logicals2);
-         $ftype = 'add-logical';
-      }
+  # add-logical
+  foreach my $outer_op ( @logicals2 ) {
+    foreach my $inner_op ( @add_subf ) {
       my $exp = logical_addsubf_make_exp ($outer_op, $inner_op, $mode,
                                           $pred, $constraint);
-      logical_addsubf_emit_define ($ftype, 'scalar', $outer_op, $inner_op,
-                                   $mode, $pred, $constraint, $exp, $fuse_type);
+      logical_addsubf_emit_define ('add-logical', 'scalar', $outer_op,
+                                   $inner_op, $mode, $pred, $constraint,
+                                   $exp, $fuse_type);
     }
   }