tree-ssa-math-opts.c (convert_plusminus_to_widen): Call has_single_use () and not...
authorYufeng Zhang <yufeng.zhang@arm.com>
Fri, 25 Oct 2013 17:25:08 +0000 (17:25 +0000)
committerYufeng Zhang <yufeng@gcc.gnu.org>
Fri, 25 Oct 2013 17:25:08 +0000 (17:25 +0000)
gcc/

* tree-ssa-math-opts.c (convert_plusminus_to_widen): Call
has_single_use () and not do the conversion if has_single_use ()
returns false for the multiplication result.

gcc/testsuite/

* gcc.dg/wmul-1.c: New test.

From-SVN: r204072

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/wmul-1.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index dccf076f223f36b5ed0be5dc048a62f6ccbf8617..8b5eec842be22d934230537fc157fb80d02d4d94 100644 (file)
@@ -1,3 +1,9 @@
+2013-10-25  Yufeng Zhang  <yufeng.zhang@arm.com>
+
+       * tree-ssa-math-opts.c (convert_plusminus_to_widen): Call
+       has_single_use () and not do the conversion if has_single_use ()
+       returns false for the multiplication result.
+
 2013-10-25  David Malcolm  <dmalcolm@redhat.com>
 
        * tree.h (EXCEPTIONAL_CLASS_P): Rename parameter from "CODE"
index ac5ab6d06488398bea3497fe1bff7955460d71ee..3c27fcc371dee39ec1ee7d2f1c13653d13501687 100644 (file)
@@ -1,3 +1,7 @@
+2013-10-25  Yufeng Zhang  <yufeng.zhang@arm.com>
+
+       * gcc.dg/wmul-1.c: New test.
+
 2013-10-25  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/58878
diff --git a/gcc/testsuite/gcc.dg/wmul-1.c b/gcc/testsuite/gcc.dg/wmul-1.c
new file mode 100644 (file)
index 0000000..3e762f4
--- /dev/null
@@ -0,0 +1,19 @@
+/* Not to fuse widening multiply with accumulate if the multiply has more than
+   one uses.
+   Note that for targets where pointer and int are of the same size or
+   widening multiply-and-accumulate is not available, this test just passes.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-widening_mul" } */
+
+typedef int ArrT [10][10];
+
+void
+foo (ArrT Arr, int Idx)
+{
+  Arr[Idx][Idx] = 1;
+  Arr[Idx + 10][Idx] = 2;
+}
+
+/* { dg-final { scan-tree-dump-not "WIDEN_MULT_PLUS_EXPR" "widening_mul" } } */
+/* { dg-final { cleanup-tree-dump "widening_mul" } } */
index 1817c20772c0c58642897168060b72dc2ee462d6..9a2941119458621408aa1e6a7d40fbed14a7e97c 100644 (file)
@@ -2432,20 +2432,25 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt,
 
      It might also appear that it would be sufficient to use the existing
      operands of the widening multiply, but that would limit the choice of
-     multiply-and-accumulate instructions.  */
+     multiply-and-accumulate instructions.
+
+     If the widened-multiplication result has more than one uses, it is
+     probably wiser not to do the conversion.  */
   if (code == PLUS_EXPR
       && (rhs1_code == MULT_EXPR || rhs1_code == WIDEN_MULT_EXPR))
     {
-      if (!is_widening_mult_p (rhs1_stmt, &type1, &mult_rhs1,
-                              &type2, &mult_rhs2))
+      if (!has_single_use (rhs1)
+         || !is_widening_mult_p (rhs1_stmt, &type1, &mult_rhs1,
+                                 &type2, &mult_rhs2))
        return false;
       add_rhs = rhs2;
       conv_stmt = conv1_stmt;
     }
   else if (rhs2_code == MULT_EXPR || rhs2_code == WIDEN_MULT_EXPR)
     {
-      if (!is_widening_mult_p (rhs2_stmt, &type1, &mult_rhs1,
-                              &type2, &mult_rhs2))
+      if (!has_single_use (rhs2)
+         || !is_widening_mult_p (rhs2_stmt, &type1, &mult_rhs1,
+                                 &type2, &mult_rhs2))
        return false;
       add_rhs = rhs1;
       conv_stmt = conv2_stmt;