tree-ssa-math-opts.c (is_widening_mult_rhs_p): Handle constants beyond conversions.
authorAndrew Stubbs <ams@codesourcery.com>
Fri, 19 Aug 2011 15:05:22 +0000 (15:05 +0000)
committerAndrew Stubbs <ams@gcc.gnu.org>
Fri, 19 Aug 2011 15:05:22 +0000 (15:05 +0000)
2011-08-19  Andrew Stubbs  <ams@codesourcery.com>

gcc/
* tree-ssa-math-opts.c (is_widening_mult_rhs_p): Handle constants
beyond conversions.
(convert_mult_to_widen): Convert constant inputs to the right type.
(convert_plusminus_to_widen): Don't automatically reject inputs that
are not an SSA_NAME.
Convert constant inputs to the right type.

gcc/testsuite/
* gcc.target/arm/wmul-11.c: New file.
* gcc.target/arm/wmul-12.c: New file.
* gcc.target/arm/wmul-13.c: New file.

From-SVN: r177910

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/wmul-11.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/wmul-12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/wmul-13.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index ed79f12c910fe25421c5dcbd28f152edd25c564c..f1b85a428f2377cf48cfb7af4b582dad1228cb46 100644 (file)
@@ -1,3 +1,12 @@
+2011-08-19  Andrew Stubbs  <ams@codesourcery.com>
+
+       * tree-ssa-math-opts.c (is_widening_mult_rhs_p): Handle constants
+       beyond conversions.
+       (convert_mult_to_widen): Convert constant inputs to the right type.
+       (convert_plusminus_to_widen): Don't automatically reject inputs that
+       are not an SSA_NAME.
+       Convert constant inputs to the right type.
+
 2011-08-19  Andrew Stubbs  <ams@codesourcery.com>
 
        * tree-ssa-math-opts.c (convert_plusminus_to_widen): Convert add_rhs
index a711cc355a41cb7a771ccd632c3d49c04580ca48..ced6263db50d22d5bff33ca399e7b2e956d2a29a 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-19  Andrew Stubbs  <ams@codesourcery.com>
+
+       * gcc.target/arm/wmul-11.c: New file.
+       * gcc.target/arm/wmul-12.c: New file.
+       * gcc.target/arm/wmul-13.c: New file.
+
 2011-08-19  Andrew Stubbs  <ams@codesourcery.com>
 
        * gcc.target/arm/wmul-10.c: New file.
diff --git a/gcc/testsuite/gcc.target/arm/wmul-11.c b/gcc/testsuite/gcc.target/arm/wmul-11.c
new file mode 100644 (file)
index 0000000..904f015
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target arm_dsp } */
+
+long long
+foo (int *b)
+{
+  return 10 * (long long)*b;
+}
+
+/* { dg-final { scan-assembler "smull" } } */
diff --git a/gcc/testsuite/gcc.target/arm/wmul-12.c b/gcc/testsuite/gcc.target/arm/wmul-12.c
new file mode 100644 (file)
index 0000000..556e53f
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target arm_dsp } */
+
+long long
+foo (int *b, int *c)
+{
+  int tmp = *b * *c;
+  return 10 + (long long)tmp;
+}
+
+/* { dg-final { scan-assembler "smlal" } } */
diff --git a/gcc/testsuite/gcc.target/arm/wmul-13.c b/gcc/testsuite/gcc.target/arm/wmul-13.c
new file mode 100644 (file)
index 0000000..a73d80f
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target arm_dsp } */
+
+long long
+foo (int *a, int *b)
+{
+  return *a + (long long)*b * 10;
+}
+
+/* { dg-final { scan-assembler "smlal" } } */
index 73206adceba31e63bd7b7ea2101b8494ee1db64f..63506477a3990db22a6c2ab0a6bf9bb791110fa6 100644 (file)
@@ -1995,7 +1995,16 @@ is_widening_mult_rhs_p (tree type, tree rhs, tree *type_out,
              : rhs_code != FIXED_CONVERT_EXPR)
            rhs1 = rhs;
          else
-           rhs1 = gimple_assign_rhs1 (stmt);
+           {
+             rhs1 = gimple_assign_rhs1 (stmt);
+
+             if (TREE_CODE (rhs1) == INTEGER_CST)
+               {
+                 *new_rhs_out = rhs1;
+                 *type_out = NULL;
+                 return true;
+               }
+           }
        }
       else
        rhs1 = rhs;
@@ -2164,6 +2173,12 @@ convert_mult_to_widen (gimple stmt, gimple_stmt_iterator *gsi)
       rhs2 = build_and_insert_cast (gsi, loc, tmp, rhs2);
     }
 
+  /* Handle constants.  */
+  if (TREE_CODE (rhs1) == INTEGER_CST)
+    rhs1 = fold_convert (type1, rhs1);
+  if (TREE_CODE (rhs2) == INTEGER_CST)
+    rhs2 = fold_convert (type2, rhs2);
+
   gimple_assign_set_rhs1 (stmt, rhs1);
   gimple_assign_set_rhs2 (stmt, rhs2);
   gimple_assign_set_rhs_code (stmt, WIDEN_MULT_EXPR);
@@ -2215,8 +2230,6 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt,
       if (is_gimple_assign (rhs1_stmt))
        rhs1_code = gimple_assign_rhs_code (rhs1_stmt);
     }
-  else
-    return false;
 
   if (TREE_CODE (rhs2) == SSA_NAME)
     {
@@ -2224,8 +2237,6 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt,
       if (is_gimple_assign (rhs2_stmt))
        rhs2_code = gimple_assign_rhs_code (rhs2_stmt);
     }
-  else
-    return false;
 
   /* Allow for one conversion statement between the multiply
      and addition/subtraction statement.  If there are more than
@@ -2373,6 +2384,12 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt,
     add_rhs = build_and_insert_cast (gsi, loc, create_tmp_var (type, NULL),
                                     add_rhs);
 
+  /* Handle constants.  */
+  if (TREE_CODE (mult_rhs1) == INTEGER_CST)
+    rhs1 = fold_convert (type1, mult_rhs1);
+  if (TREE_CODE (mult_rhs2) == INTEGER_CST)
+    rhs2 = fold_convert (type2, mult_rhs2);
+
   gimple_assign_set_rhs_with_ops_1 (gsi, wmult_code, mult_rhs1, mult_rhs2,
                                    add_rhs);
   update_stmt (gsi_stmt (*gsi));