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]
Other format: [Raw text]

Avoid non-canonical RTL in splitter for adding a large constant to register on the PA



The PA has a splitter to optimize the addition of certain constants to a register. One of the cases the splitter handles is when the constant requires 2 insns to generate, is divisible by 2, 4, or 8 and if divided by 2, 4 or 8 it only needs a single insn to generate the constant.

Obviously the splitter reduces the constant by a scaling factor and loads that value, then uses a shift-add insn to scale it back up for the addition to the other operand. That saves us one insn.

That splitter generates the non-canonical MULT form of a shadd. This patch changes it to use ASHIFT form instead. This fixes all the regressions seen in my testcase of 300+ files when I remove the non-canonical shift-add using MULT patterns.

We still have other places that can produce the non-canonical form, they're just not triggering in that suite of 300+ files. So I'm not removing the non-canonical shift-add using MULT patterns just yet.

Tested on hppa.exp and the 300 files noted above.  Installed on the trunk.
commit 147771b2a45499d118e4c68a7953881f182e1b97
Author: Jeff Law <law@redhat.com>
Date:   Thu May 21 11:01:59 2015 -0600

    	* config/pa/pa.md (add-with-constant splitter): Use ASHIFT rather
    	than MULT for shadd sequences.
    
    	* gcc.target/hppa/shadd-4.c: New test.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3ec7255..48472bc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2015-05-21  Jeff Law  <law@redhat.com>
+
+	* config/pa/pa.md (add-with-constant splitter): Use ASHIFT rather
+	than MULT for shadd sequences.
+
 2015-05-08  Jan Hubicka  <hubicka@ucw.cz>
 
 	* alias.c (alias_stats): New static var.	
diff --git a/gcc/config/pa/pa.md b/gcc/config/pa/pa.md
index 73c8f6b..aaec27d 100644
--- a/gcc/config/pa/pa.md
+++ b/gcc/config/pa/pa.md
@@ -5132,7 +5132,7 @@
    (clobber (match_operand:SI 4 "register_operand" ""))]
   "! pa_cint_ok_for_move (INTVAL (operands[2]))"
   [(set (match_dup 4) (match_dup 2))
-   (set (match_dup 0) (plus:SI (mult:SI (match_dup 4) (match_dup 3))
+   (set (match_dup 0) (plus:SI (ashift:SI (match_dup 4) (match_dup 3))
 			       (match_dup 1)))]
   "
 {
@@ -5147,17 +5147,17 @@
   if (intval % 2 == 0 && pa_cint_ok_for_move (intval / 2))
     {
       operands[2] = GEN_INT (intval / 2);
-      operands[3] = const2_rtx;
+      operands[3] = const1_rtx;
     }
   else if (intval % 4 == 0 && pa_cint_ok_for_move (intval / 4))
     {
       operands[2] = GEN_INT (intval / 4);
-      operands[3] = GEN_INT (4);
+      operands[3] = const2_rtx;
     }
   else if (intval % 8 == 0 && pa_cint_ok_for_move (intval / 8))
     {
       operands[2] = GEN_INT (intval / 8);
-      operands[3] = GEN_INT (8);
+      operands[3] = GEN_INT (3);
     }
   else if (pa_cint_ok_for_move (-intval))
     {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 46a6bb7..20a4379 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2015-05-21  Jeff Law  <law@redhat.com>
+
+	* gcc.target/hppa/shadd-4.c: New test.
+
 2015-05-08  Michael Matz  <matz@suse.de>
 
 	* gcc.dg/vect/vect-strided-store.c: New test.
diff --git a/gcc/testsuite/gcc.target/hppa/shadd-4.c b/gcc/testsuite/gcc.target/hppa/shadd-4.c
new file mode 100644
index 0000000..e25d148
--- /dev/null
+++ b/gcc/testsuite/gcc.target/hppa/shadd-4.c
@@ -0,0 +1,8 @@
+/* { dg-do compile }  */
+/* { dg-options "-O2" }  */
+/* { dg-final { scan-assembler-times "sh.add" 1 } }  */
+unsigned int
+oof (int uid)
+{
+  return (174 << 7) + uid;
+}

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