commit c44b5bd19efb029b8bbd4e3c7e2d631bdc482b7c
Author: Xingxing Pan <xxingpan@marvell.com>
Date:   Sun Apr 19 15:54:43 2015 +0800

    Fix widen-sum pattern in neon.md.
    
    gcc/
    
    2015-04-19  Xingxing Pan  <xxingpan@marvell.com>
    
        * config/arm/iterators.md (VWSD): New.
          (V_widen_sum_d): New.
        * config/arm/neon.md (widen_ssum<mode>3): Redefined.
        (widen_usum<mode>3): Ditto.
        (neon_svaddw<mode>3): New anonymous define_insn.
        (neon_uvaddw<mode>3): Ditto.
    
    gcc/testsuite/
    
    2015-04-19  Xingxing Pan  <xxingpan@marvell.com>
    
        * gcc.target/arm/neon/vect-widen-sum-char2short-s-d.c: New.
        * gcc.target/arm/neon/vect-widen-sum-char2short-s.c: New.
        * gcc.target/arm/neon/vect-widen-sum-char2short-u-d.c: New.
        * gcc.target/arm/neon/vect-widen-sum-char2short-u.c: New.
        * gcc.target/arm/neon/vect-widen-sum-short2int-s-d.c: New.
        * gcc.target/arm/neon/vect-widen-sum-short2int-s.c: New.
        * gcc.target/arm/neon/vect-widen-sum-short2int-u-d.c: New.
        * gcc.target/arm/neon/vect-widen-sum-short2int-u.c: New.
        * lib/target-supports.exp
        (check_effective_target_vect_widen_sum_hi_to_si_pattern): Return 1 for ARM NEON.
        (check_effective_target_vect_widen_sum_hi_to_si): Ditto.
        (check_effective_target_vect_widen_sum_qi_to_hi): Ditto.

diff --git a/gcc/config/arm/iterators.md b/gcc/config/arm/iterators.md
index f7f8ab7..f73278d 100644
--- a/gcc/config/arm/iterators.md
+++ b/gcc/config/arm/iterators.md
@@ -95,6 +95,9 @@
 ;; Widenable modes.
 (define_mode_iterator VW [V8QI V4HI V2SI])
 
+;; Widenable modes.  Used by widen sum.
+(define_mode_iterator VWSD [V8QI V4HI V16QI V8HI])
+
 ;; Narrowable modes.
 (define_mode_iterator VN [V8HI V4SI V2DI])
 
@@ -555,9 +558,14 @@
 ;; Same as V_widen, but lower-case.
 (define_mode_attr V_widen_l [(V8QI "v8hi") (V4HI "v4si") ( V2SI "v2di")])
 
-;; Widen. Result is half the number of elements, but widened to double-width.
+;; Widen.  Result is half the number of elements, but widened to double-width.
 (define_mode_attr V_unpack   [(V16QI "V8HI") (V8HI "V4SI") (V4SI "V2DI")])
 
+;; Widen.  Result is half the number of elements, but widened to double-width.
+;; Used by widen sum.
+(define_mode_attr V_widen_sum_d [(V8QI "V4HI") (V4HI "V2SI")
+                                 (V16QI "V8HI") (V8HI "V4SI")])
+
 ;; Conditions to be used in extend<mode>di patterns.
 (define_mode_attr qhs_zextenddi_cond [(SI "") (HI "&& arm_arch6") (QI "")])
 (define_mode_attr qhs_sextenddi_cond [(SI "") (HI "&& arm_arch6")
diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
index 63c327e..839883f 100644
--- a/gcc/config/arm/neon.md
+++ b/gcc/config/arm/neon.md
@@ -1174,7 +1174,29 @@
 
 ;; Widening operations
 
-(define_insn "widen_ssum<mode>3"
+(define_expand "widen_usum<mode>3"
+ [(match_operand:<V_widen_sum_d> 0 "s_register_operand" "")
+  (match_operand:VWSD 1 "s_register_operand" "")
+  (match_operand:<V_widen_sum_d> 2 "s_register_operand" "")]
+  "TARGET_NEON"
+  {
+    emit_insn (gen_neon_vpadalu<mode> (operands[0], operands[2], operands[1]));
+    DONE;
+  }
+)
+
+(define_expand "widen_ssum<mode>3"
+ [(match_operand:<V_widen_sum_d> 0 "s_register_operand" "")
+  (match_operand:VWSD 1 "s_register_operand" "")
+  (match_operand:<V_widen_sum_d> 2 "s_register_operand" "")]
+  "TARGET_NEON"
+  {
+    emit_insn (gen_neon_vpadals<mode> (operands[0], operands[2], operands[1]));
+    DONE;
+  }
+)
+
+(define_insn "*neon_svaddw<mode>3"
   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
 	(plus:<V_widen> (sign_extend:<V_widen>
 			  (match_operand:VW 1 "s_register_operand" "%w"))
@@ -1184,7 +1206,7 @@
   [(set_attr "type" "neon_add_widen")]
 )
 
-(define_insn "widen_usum<mode>3"
+(define_insn "*neon_uvaddw<mode>3"
   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
 	(plus:<V_widen> (zero_extend:<V_widen>
 			  (match_operand:VW 1 "s_register_operand" "%w"))
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-s-d.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-s-d.c
new file mode 100644
index 0000000..8d0278c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-s-d.c
@@ -0,0 +1,63 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -mvectorize-with-neon-double -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { xfail *-*-* } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { xfail *-*-* } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef signed char STYPE1;
+typedef signed short STYPE2;
+extern void abort (void);
+
+#define N 128
+STYPE1 sdata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+ssum ()
+{
+  int i;
+  STYPE2 sum = 0;
+  STYPE2 check_sum = 0;
+
+  /* widenning sum: sum chars into short.
+
+     Like gcc.dg/vect/vect-reduc-pattern-2c.c, the widening-summation pattern
+     is currently not detected because of this patch:
+
+     2005-12-26  Kazu Hirata  <kazu@codesourcery.com>
+        PR tree-optimization/25125
+   */
+
+  for (i = 0; i < N; i++)
+    {
+      sdata[i] = i*2;
+      check_sum += sdata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += sdata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  ssum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-s.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-s.c
new file mode 100644
index 0000000..f7384c3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-s.c
@@ -0,0 +1,63 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { xfail *-*-* } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { xfail *-*-* } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef signed char STYPE1;
+typedef signed short STYPE2;
+extern void abort (void);
+
+#define N 128
+STYPE1 sdata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+ssum ()
+{
+  int i;
+  STYPE2 sum = 0;
+  STYPE2 check_sum = 0;
+
+  /* widenning sum: sum chars into short.
+
+     Like gcc.dg/vect/vect-reduc-pattern-2c.c, the widening-summation pattern
+     is currently not detected because of this patch:
+
+     2005-12-26  Kazu Hirata  <kazu@codesourcery.com>
+        PR tree-optimization/25125
+   */
+
+  for (i = 0; i < N; i++)
+    {
+      sdata[i] = i*2;
+      check_sum += sdata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += sdata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  ssum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-u-d.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-u-d.c
new file mode 100644
index 0000000..35f8fa7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-u-d.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -mvectorize-with-neon-double -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { target { arm_neon } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { target { arm_neon } } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef unsigned char UTYPE1;
+typedef unsigned short UTYPE2;
+extern void abort (void);
+
+#define N 128
+UTYPE1 udata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+usum ()
+{
+  int i;
+  UTYPE2 sum = 0;
+  UTYPE2 check_sum = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      udata[i] = i*2;
+      check_sum += udata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += udata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  usum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-u.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-u.c
new file mode 100644
index 0000000..38af5f0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-char2short-u.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { target { arm_neon } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { target { arm_neon } } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef unsigned char UTYPE1;
+typedef unsigned short UTYPE2;
+extern void abort (void);
+
+#define N 128
+UTYPE1 udata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+usum ()
+{
+  int i;
+  UTYPE2 sum = 0;
+  UTYPE2 check_sum = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      udata[i] = i*2;
+      check_sum += udata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += udata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  usum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-s-d.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-s-d.c
new file mode 100644
index 0000000..ef765de
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-s-d.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -mvectorize-with-neon-double -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { target { arm_neon } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { target arm_neon } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef signed short STYPE1;
+typedef signed int STYPE2;
+extern void abort (void);
+
+#define N 128
+STYPE1 sdata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+ssum ()
+{
+  int i;
+  STYPE2 sum = 0;
+  STYPE2 check_sum = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      sdata[i] = i*2;
+      check_sum += sdata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += sdata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  ssum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-s.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-s.c
new file mode 100644
index 0000000..fb38d56
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-s.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { target { arm_neon } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { target { arm_neon } } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef signed short STYPE1;
+typedef signed int STYPE2;
+extern void abort (void);
+
+#define N 128
+STYPE1 sdata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+ssum ()
+{
+  int i;
+  STYPE2 sum = 0;
+  STYPE2 check_sum = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      sdata[i] = i*2;
+      check_sum += sdata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += sdata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  ssum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-u-d.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-u-d.c
new file mode 100644
index 0000000..5a3dfd6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-u-d.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -mvectorize-with-neon-double -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { target { arm_neon } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { target { arm_neon } } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef unsigned short UTYPE1;
+typedef unsigned int UTYPE2;
+extern void abort (void);
+
+#define N 128
+UTYPE1 udata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+usum ()
+{
+  int i;
+  UTYPE2 sum = 0;
+  UTYPE2 check_sum = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      udata[i] = i*2;
+      check_sum += udata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += udata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  usum ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-u.c b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-u.c
new file mode 100644
index 0000000..770b08d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/neon/vect-widen-sum-short2int-u.c
@@ -0,0 +1,54 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -fdump-tree-vect-details -fdump-rtl-expand" } */
+/* { dg-add-options arm_neon } */
+
+/* { dg-final { scan-tree-dump-times "pattern recognized.*w\\\+" 1 "vect" { target { arm_neon } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+/* { dg-final { scan-rtl-dump-times "UNSPEC_VPADAL" 1 "expand" { target { arm_neon } } } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
+
+typedef unsigned short UTYPE1;
+typedef unsigned int UTYPE2;
+extern void abort (void);
+
+#define N 128
+UTYPE1 udata[N];
+
+volatile int y = 0;
+
+__attribute__ ((noinline)) int
+usum ()
+{
+  int i;
+  UTYPE2 sum = 0;
+  UTYPE2 check_sum = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      udata[i] = i*2;
+      check_sum += udata[i];
+      /* Avoid vectorization.  */
+      if (y)
+        abort ();
+    }
+
+  /* widenning sum: sum chars into int.  */
+  for (i = 0; i < N; i++)
+    {
+      sum += udata[i];
+    }
+
+  /* check results:  */
+  if (sum != check_sum)
+    abort ();
+
+  return 0;
+}
+
+int
+main (void)
+{
+  usum ();
+  return 0;
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index f632d00..477ab53 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -3795,6 +3795,7 @@ proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
     } else {
         set et_vect_widen_sum_hi_to_si_pattern_saved 0
         if { [istarget powerpc*-*-*]
+             || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok])
              || [istarget ia64-*-*] } {
             set et_vect_widen_sum_hi_to_si_pattern_saved 1
         }
@@ -3818,7 +3819,8 @@ proc check_effective_target_vect_widen_sum_hi_to_si { } {
     } else {
         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
         if { [istarget powerpc*-*-*] 
-	     || [istarget ia64-*-*] } {
+             || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok])
+             || [istarget ia64-*-*] } {
             set et_vect_widen_sum_hi_to_si_saved 1
         }
     }
@@ -3841,7 +3843,7 @@ proc check_effective_target_vect_widen_sum_qi_to_hi { } {
     } else {
         set et_vect_widen_sum_qi_to_hi_saved 0
 	if { [check_effective_target_vect_unpack] 
-	     || [check_effective_target_arm_neon_ok]
+	     || ([istarget arm*-*-*] && [check_effective_target_arm_neon_ok])
 	     || [istarget ia64-*-*] } {
             set et_vect_widen_sum_qi_to_hi_saved 1
 	}
