Patchwork [SH] PR 54236 - Add another addc case

login
register
mail settings
Submitter Oleg Endo
Date Sept. 18, 2012, 6:56 p.m.
Message ID <1347994583.2136.21.camel@yam-132-YW-E178-FTW>
Download mbox | patch
Permalink /patch/184803/
State New
Headers show

Comments

Oleg Endo - Sept. 18, 2012, 6:56 p.m.
Hello,

There is another opportunity where SH's addc insn can be used.
Tested on rev 191342 with 
make -k check RUNTESTFLAGS="--target_board=sh-sim
\{-m2/-ml,-m2/-mb,-m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}"

and no new failures.
OK to install?

Cheers,
Oleg

gcc/ChangeLog:

	PR target/54236
	* config/sh/sh.md (*addc): Add pattern to handle one bit left 
	shifts.
	
testsuite/ChangeLog:

	PR target/54236
	* gcc.target/sh/pr54236-1.c (test_08): Add one bit left shift 
	case.
Kaz Kojima - Sept. 19, 2012, 11:56 a.m.
Oleg Endo <oleg.endo@t-online.de> wrote:
> There is another opportunity where SH's addc insn can be used.
> Tested on rev 191342 with 
> make -k check RUNTESTFLAGS="--target_board=sh-sim
> \{-m2/-ml,-m2/-mb,-m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}"
> 
> and no new failures.
> OK to install?

OK.

Regards,
	kaz

Patch

Index: gcc/testsuite/gcc.target/sh/pr54236-1.c
===================================================================
--- gcc/testsuite/gcc.target/sh/pr54236-1.c	(revision 191342)
+++ gcc/testsuite/gcc.target/sh/pr54236-1.c	(working copy)
@@ -4,9 +4,9 @@ 
 /* { dg-do compile { target "sh*-*-*" } } */
 /* { dg-options "-O1" } */
 /* { dg-skip-if "" { "sh*-*-*" } { "-m5*"} { "" } } */
-/* { dg-final { scan-assembler-times "addc" 3 } } */
+/* { dg-final { scan-assembler-times "addc" 4 } } */
 /* { dg-final { scan-assembler-times "subc" 3 } } */
-/* { dg-final { scan-assembler-times "sett" 4 } } */
+/* { dg-final { scan-assembler-times "sett" 5 } } */
 /* { dg-final { scan-assembler-times "negc" 1 } } */
 /* { dg-final { scan-assembler-not "movt" } } */
 
@@ -74,3 +74,10 @@ 
 
   return vi;
 }
+
+int
+test_08 (int a)
+{
+  /* 1x addc, 1x sett  */
+  return (a << 1) + 1;
+}
Index: gcc/config/sh/sh.md
===================================================================
--- gcc/config/sh/sh.md	(revision 191342)
+++ gcc/config/sh/sh.md	(working copy)
@@ -1787,6 +1787,22 @@ 
 				          (reg:SI T_REG)))
 	      (clobber (reg:SI T_REG))])])
 
+;; Left shifts by one are usually done with an add insn to avoid T_REG
+;; clobbers.  Thus addc can also be used to do something like '(x << 1) + 1'.
+(define_insn_and_split "*addc"
+  [(set (match_operand:SI 0 "arith_reg_dest")
+	(plus:SI (mult:SI (match_operand:SI 1 "arith_reg_operand")
+			  (const_int 2))
+		 (const_int 1)))
+   (clobber (reg:SI T_REG))]
+  "TARGET_SH1"
+  "#"
+  "&& 1"
+  [(set (reg:SI T_REG) (const_int 1))
+   (parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (match_dup 1))
+				          (reg:SI T_REG)))
+	      (clobber (reg:SI T_REG))])])
+
 ;; Sometimes combine will try to do 'reg + (0-reg) + 1' if the *addc pattern
 ;; matched.  Split this up into a simple sub add sequence, as this will save
 ;; us one sett insn.