re PR target/87079 (nios2 optimization for size - case of regression relatively to...
authorSandra Loosemore <sandra@codesourcery.com>
Sat, 3 Nov 2018 18:12:44 +0000 (14:12 -0400)
committerSandra Loosemore <sandra@gcc.gnu.org>
Sat, 3 Nov 2018 18:12:44 +0000 (14:12 -0400)
2018-11-03  Sandra Loosemore  <sandra@codesourcery.com>

PR target/87079

gcc/
* config/nios2/nios2.c (nios2_rtx_costs): Recognize <mul>sidi3
pattern.

gcc/testsuite/
* gcc.target/nios2/pr87079-1.c: New.
* gcc.target/nios2/pr87079-2.c: New.

From-SVN: r265770

gcc/ChangeLog
gcc/config/nios2/nios2.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/nios2/pr87079-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nios2/pr87079-2.c [new file with mode: 0644]

index 5cf291d..d10c488 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-03  Sandra Loosemore  <sandra@codesourcery.com>
+
+       PR target/87079
+
+       * config/nios2/nios2.c (nios2_rtx_costs): Recognize <mul>sidi3
+       pattern.
+
 2018-11-02  Aaron Sawdey  <acsawdey@linux.ibm.com>
 
        * config/rs6000/rs6000-string.c (expand_strncmp_gpr_sequence): Pay
index 78d5858..e266924 100644 (file)
@@ -1539,6 +1539,19 @@ nios2_rtx_costs (rtx x, machine_mode mode,
            *total = COSTS_N_INSNS (2);  /* Latency adjustment.  */
          else 
            *total = COSTS_N_INSNS (1);
+         if (TARGET_HAS_MULX && GET_MODE (x) == DImode)
+           {
+             enum rtx_code c0 = GET_CODE (XEXP (x, 0));
+             enum rtx_code c1 = GET_CODE (XEXP (x, 1));
+             if ((c0 == SIGN_EXTEND && c1 == SIGN_EXTEND)
+                 || (c0 == ZERO_EXTEND && c1 == ZERO_EXTEND))
+               /* This is the <mul>sidi3 pattern, which expands into 4 insns,
+                  2 multiplies and 2 moves.  */
+               {
+                 *total = *total * 2 + COSTS_N_INSNS (2);
+                 return true;
+               }
+           }
           return false;
         }
 
index a4d5061..e728c1f 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-03  Sandra Loosemore  <sandra@codesourcery.com>
+
+       PR target/87079
+
+       * gcc.target/nios2/pr87079-1.c: New.    
+       * gcc.target/nios2/pr87079-2.c: New.    
+
 2018-11-02  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * gcc.dg/compat/pr83487-1_y.c: Move dg-skip-if ...
diff --git a/gcc/testsuite/gcc.target/nios2/pr87079-1.c b/gcc/testsuite/gcc.target/nios2/pr87079-1.c
new file mode 100644 (file)
index 0000000..67d5caa
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -mhw-div -mhw-mul -mhw-mulx" } */
+
+#include <stdint.h>
+#include <stddef.h>
+
+void foo(const uint8_t* str, uint32_t* res)
+{
+  uint32_t rdVal0, rdVal1, rdVal2;
+  rdVal0 = rdVal1 = rdVal2 = 0;
+  unsigned c;
+  for (;;) {
+    c = *str++;
+    unsigned dig = c - '0';
+    if (dig > 9)
+      break; // non-digit
+    uint64_t x10;
+
+    x10 = (uint64_t)rdVal0*10 + dig;
+    rdVal0 = (uint32_t)x10;
+    dig = (uint32_t)(x10 >> 32);
+
+    x10 = (uint64_t)rdVal1*10 + dig;
+    rdVal1 = (uint32_t)x10;
+    dig = (uint32_t)(x10 >> 32);
+
+    rdVal2 = rdVal2*10 + dig;
+  }
+  res[0] = rdVal0;
+  res[1] = rdVal1;
+  res[2] = rdVal2;
+}
+
+/* { dg-final { scan-assembler-times "mulxuu\t" 2 } } */
diff --git a/gcc/testsuite/gcc.target/nios2/pr87079-2.c b/gcc/testsuite/gcc.target/nios2/pr87079-2.c
new file mode 100644 (file)
index 0000000..db2100a
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mhw-div -mhw-mul -mhw-mulx" } */
+
+#include <stdint.h>
+#include <stddef.h>
+
+void foo(const uint8_t* str, uint32_t* res)
+{
+  uint32_t rdVal0, rdVal1, rdVal2;
+  rdVal0 = rdVal1 = rdVal2 = 0;
+  unsigned c;
+  for (;;) {
+    c = *str++;
+    unsigned dig = c - '0';
+    if (dig > 9)
+      break; // non-digit
+    uint64_t x10;
+
+    x10 = (uint64_t)rdVal0*10 + dig;
+    rdVal0 = (uint32_t)x10;
+    dig = (uint32_t)(x10 >> 32);
+
+    x10 = (uint64_t)rdVal1*10 + dig;
+    rdVal1 = (uint32_t)x10;
+    dig = (uint32_t)(x10 >> 32);
+
+    rdVal2 = rdVal2*10 + dig;
+  }
+  res[0] = rdVal0;
+  res[1] = rdVal1;
+  res[2] = rdVal2;
+}
+
+/* { dg-final { scan-assembler-times "mulxuu\t" 2 } } */