This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: SH: cmpeqdi splitter messes up the CFG


On Aug 30, 2000, Richard Henderson <rth@cygnus.com> wrote:

> On Wed, Aug 30, 2000 at 04:17:01PM -0300, Alexandre Oliva wrote:
>> * config/sh/sh.md (cmpeqsi_ior_t, cmpeqsi_and_t): New insns.
>> (cmpeqdi_t splitter): Use cmpeqsi_and_t instead of emitting jumps
>> and labels.

> Seems fine.

Yes.  Kind of.  We're generating pretty stupid code with it (not that
it would be any better before).  Things like jumps to jumps with the
same condition.

Here's an additional patch that simplifies the original split a little
bit, and introduces two new splits, only applied when optimizing code
(that's the key to avoid the problem in machine-dependent reorg).
This considerably improves the quality of the generated code.  No
regressions in the testsuite.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/sh/sh.md (cmpeqsi_ior_t, cmpeqsi_and_t): Split when
	optimizing.
	(cmpeqdi_t splitter): Simplify, using subreg where appropriate.
	Apply even before reload.

Index: gcc/config/sh/sh.md
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/config/sh/sh.md,v
retrieving revision 1.166
diff -u -p -r1.166 sh.md
--- gcc/config/sh/sh.md	2000/08/30 22:55:06	1.166
+++ gcc/config/sh/sh.md	2000/08/31 03:20:16
@@ -570,6 +570,23 @@
 	bt .+4\;cmp/eq	%1,%0"
   [(set_attr "length" "4")])
 
+(define_split
+  [(set (reg:SI 18)
+	(ior:SI (reg:SI 18)
+		(eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
+		       (match_operand:SI 1 "arith_operand" "N,rI,r"))))]
+  ;; If we apply this split when not optimizing, it will only be
+  ;; applied during the machine-dependent reorg, when it is already
+  ;; too late for any jump or flow optimization to be applied.
+  "optimize > 0"
+  [(set (pc) (if_then_else (ne (reg:SI 18) (const_int 0))
+			   (label_ref (match_dup 2))
+			   (pc)))
+  (set (reg:SI 18)
+       (eq:SI (match_dup 0) (match_dup 1)))
+  (match_dup 2)]
+  "operands[2] = gen_label_rtx ();")
+
 (define_insn "cmpeqsi_and_t"
   [(set (reg:SI 18)
 	(and:SI (reg:SI 18)
@@ -582,6 +599,20 @@
 	bf .+4\;cmp/eq	%1,%0"
   [(set_attr "length" "4")])
 
+(define_split
+  [(set (reg:SI 18)
+	(and:SI (reg:SI 18)
+		(eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
+		       (match_operand:SI 1 "arith_operand" "N,rI,r"))))]
+  "optimize > 0"
+  [(set (pc) (if_then_else (eq (reg:SI 18) (const_int 0))
+			   (label_ref (match_dup 2))
+			   (pc)))
+  (set (reg:SI 18)
+       (eq:SI (match_dup 0) (match_dup 1)))
+  (match_dup 2)]
+  "operands[2] = gen_label_rtx ();")
+
 (define_insn "cmpgtsi_t"
   [(set (reg:SI 18) (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
 			   (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
@@ -658,24 +689,22 @@
 (define_split
   [(set (reg:SI 18) (eq:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
 			   (match_operand:DI 1 "arith_reg_or_0_operand" "N,r")))]
-  "reload_completed"
-  [(set (reg:SI 18) (eq:SI (match_dup 2) (match_dup 3)))
+  ""
+  [(set (reg:SI 18) (eq:SI (subreg:SI (match_dup 0) 0)
+			   (match_dup 1)))
    (set (reg:SI 18)
 	(and:SI (reg:SI 18)
-		(eq:SI (match_dup 4) (match_dup 5))))]
+		(eq:SI (subreg:SI (match_dup 0) 1)
+		       (match_dup 2))))]
   "
 {
-  operands[2]
-    = gen_rtx_REG (SImode,
-		   true_regnum (operands[0]) + (TARGET_LITTLE_ENDIAN ? 1 : 0));
-  operands[3]
-    = (operands[1] == const0_rtx
-       ? const0_rtx
-       : gen_rtx_REG (SImode,
-		      true_regnum (operands[1])
-		      + (TARGET_LITTLE_ENDIAN ? 1 : 0)));
-  operands[4] = gen_lowpart (SImode, operands[0]);
-  operands[5] = gen_lowpart (SImode, operands[1]);
+  if (operands[1] == const0_rtx)
+    operands[2] = operands[1];
+  else
+    {
+      operands[2] = gen_rtx_SUBREG (SImode, operands[1], 1);
+      operands[1] = gen_rtx_SUBREG (SImode, operands[1], 0);
+    }
 }")
 
 (define_insn "cmpgtdi_t"

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]