]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/32586 (New VN misses FRE opportunities)
authorRichard Guenther <rguenther@suse.de>
Thu, 6 Sep 2007 16:05:32 +0000 (16:05 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 6 Sep 2007 16:05:32 +0000 (16:05 +0000)
2007-09-06  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/32586
* tree-ssa-sccvn.c (simplify_binary_expression): Avoid
folding if nothing changed.
(simplify_unary_expression): New function.  Do tree combining
on conversion like codes.
(try_to_simplify): Call it.
* builtins.c (fold_builtin_cexp): Fold the built expressions.
* fold-const.c (fold_unary): Test result of get_callee_fndecl().

* g++.dg/tree-ssa/pr27090.C: Remove XFAILs.
* gcc.dg/tree-ssa/ssa-fre-1.c: Likewise.
* gcc.dg/tree-ssa/ssa-fre-3.c: Likewise.
* gcc.dg/tree-ssa/ssa-fre-5.c: Likewise.
* gcc.dg/tree-ssa/ssa-fre-4.c: Likewise, remove scan for
now obsolete simplification.

From-SVN: r128189

gcc/ChangeLog
gcc/builtins.c
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/pr27090.C
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-1.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c
gcc/tree-ssa-sccvn.c

index bda9ea2aa6d454cdfb217bc8ddfbfdaf000dcf67..35d46e16e4db4d3e49628a0c86f51d287d5d9a26 100644 (file)
@@ -1,3 +1,14 @@
+2007-09-06  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/32586
+       * tree-ssa-sccvn.c (simplify_binary_expression): Avoid
+       folding if nothing changed.
+       (simplify_unary_expression): New function.  Do tree combining
+       on conversion like codes.
+       (try_to_simplify): Call it.
+       * builtins.c (fold_builtin_cexp): Fold the built expressions.
+       * fold-const.c (fold_unary): Test result of get_callee_fndecl().
+
 2007-09-06  Jan Hubicka  <jh@suse.cz>
 
        PR target/33318
index 566e1cc2e1b883038440f559e506b67a85af44e4..a0b1e2f441a594484abff9146949ed6daf58ea33 100644 (file)
@@ -7799,13 +7799,13 @@ fold_builtin_cexp (tree arg0, tree type)
       icall = builtin_save_expr (icall);
       rcall = build_call_expr (rfn, 1, realp);
       rcall = builtin_save_expr (rcall);
-      return build2 (COMPLEX_EXPR, type,
-                    build2 (MULT_EXPR, rtype,
-                            rcall,
-                            build1 (REALPART_EXPR, rtype, icall)),
-                    build2 (MULT_EXPR, rtype,
-                            rcall,
-                            build1 (IMAGPART_EXPR, rtype, icall)));
+      return fold_build2 (COMPLEX_EXPR, type,
+                         fold_build2 (MULT_EXPR, rtype,
+                                      rcall,
+                                      fold_build1 (REALPART_EXPR, rtype, icall)),
+                         fold_build2 (MULT_EXPR, rtype,
+                                      rcall,
+                                      fold_build1 (IMAGPART_EXPR, rtype, icall)));
     }
 
   return NULL_TREE;
index 7a90b5e8508eed1b2baf2edb62b2e63bbb4fa0ab..a6fb08b0c64908f05aaf081c90d80087622a0351 100644 (file)
@@ -8464,7 +8464,7 @@ fold_unary (enum tree_code code, tree type, tree op0)
       if (TREE_CODE (arg0) == CALL_EXPR)
        {
          tree fn = get_callee_fndecl (arg0);
-         if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
+         if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
            switch (DECL_FUNCTION_CODE (fn))
              {
              CASE_FLT_FN (BUILT_IN_CEXPI):
@@ -8506,7 +8506,7 @@ fold_unary (enum tree_code code, tree type, tree op0)
       if (TREE_CODE (arg0) == CALL_EXPR)
        {
          tree fn = get_callee_fndecl (arg0);
-         if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
+         if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
            switch (DECL_FUNCTION_CODE (fn))
              {
              CASE_FLT_FN (BUILT_IN_CEXPI):
index a2d777ef5a7f01e3d0c240ec5951683ef5a5b534..3a463461b16daefa0e3efbb2b8bea8b4047188e7 100644 (file)
@@ -1,3 +1,13 @@
+2007-09-06  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/32586
+       * g++.dg/tree-ssa/pr27090.C: Remove XFAILs.
+       * gcc.dg/tree-ssa/ssa-fre-1.c: Likewise.
+       * gcc.dg/tree-ssa/ssa-fre-3.c: Likewise.
+       * gcc.dg/tree-ssa/ssa-fre-5.c: Likewise.
+       * gcc.dg/tree-ssa/ssa-fre-4.c: Likewise, remove scan for
+       now obsolete simplification.
+
 2007-09-06  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/sse3-addsubpd.c: Add -mfpmath=sse to dg-options.
index 70ef1e09d57a3a89fab30e83bdd13ee661063e51..a56357a1b52a761e651cb6d68b3f7f2ce6fb0293 100644 (file)
@@ -17,5 +17,5 @@ int foo(Foo& f)
         return f.get();
 }
 
-/* { dg-final { scan-tree-dump "return f->x;" "optimized" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump "return f->x;" "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
index e8c57512bbdb56a86ba0acbe250db5779a4b444f..0cb63242c0e9a6f5079d0153e737b34a944596c3 100644 (file)
@@ -11,6 +11,6 @@ int f(int *a)
   return *c + t;
 }
 
-/* { dg-final { scan-tree-dump "Replaced \\\(int \\\*\\\) b_.*with a_" "fre" { xfail *-*-* } } } */
-/* { dg-final { scan-tree-dump "Replaced \\\*c_.*with t_" "fre" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump "Replaced \\\(int \\\*\\\) b_.*with a_" "fre" } } */
+/* { dg-final { scan-tree-dump "Replaced \\\*c_.*with t_" "fre" } } */
 /* { dg-final { cleanup-tree-dump "fre" } } */
index e22064624ae298886c17be02e396955da8e18348..ebc91e775183a3726a2b4d371679c3d2c894b8ad 100644 (file)
@@ -11,5 +11,5 @@ foo (int a, int b)
   return aa + bb;
 }
 
-/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) aa_.*with a_" "fre" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) aa_.*with a_" "fre" } } */
 /* { dg-final { cleanup-tree-dump "fre" } } */
index 2b2353f33633dca851523019b987804e53c214f2..04208a2290d6309e85e51f3f4ca27a96d3290f06 100644 (file)
@@ -9,6 +9,5 @@ char bar(char f)
         return wrap(f);
 }
 
-/* { dg-final { scan-tree-dump "Replaced \\\(char\\\) .*with " "fre" { xfail *-*-* } } } */
-/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) .*with " "fre" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump "Replaced \\\(char\\\) .*with " "fre" } } */
 /* { dg-final { cleanup-tree-dump "fre" } } */
index db6346cc2e77c927d3353fa16a6d7b16e5af4f2d..7ef20c2214d01fa54e029832936fde372d221138 100644 (file)
@@ -10,5 +10,5 @@ bar (unsigned int t)
   return a == t;
 }
 
-/* { dg-final { scan-tree-dump "Replaced \\\(unsigned int\\\) a_.*with t_" "fre" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump "Replaced \\\(unsigned int\\\) a_.*with t_" "fre" } } */
 /* { dg-final { cleanup-tree-dump "fre" } } */
index 855f42af9952e8a3cbad732259d7d96c5b980e1e..bca0e8473aeb347cb0624ff23b23d8d0f2cf1f1d 100644 (file)
@@ -1411,6 +1411,11 @@ simplify_binary_expression (tree rhs)
        op1 = SSA_VAL (op1);
     }
 
+  /* Avoid folding if nothing changed.  */
+  if (op0 == TREE_OPERAND (rhs, 0)
+      && op1 == TREE_OPERAND (rhs, 1))
+    return NULL_TREE;
+
   result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1);
 
   /* Make sure result is not a complex expression consisting
@@ -1423,6 +1428,50 @@ simplify_binary_expression (tree rhs)
   return NULL_TREE;
 }
 
+/* Simplify the unary expression RHS, and return the result if
+   simplified. */
+
+static tree
+simplify_unary_expression (tree rhs)
+{
+  tree result = NULL_TREE;
+  tree op0 = TREE_OPERAND (rhs, 0);
+
+  if (TREE_CODE (op0) != SSA_NAME)
+    return NULL_TREE;
+
+  if (VN_INFO (op0)->has_constants)
+    op0 = valueize_expr (VN_INFO (op0)->expr);
+  else if (TREE_CODE (rhs) == NOP_EXPR
+          || TREE_CODE (rhs) == CONVERT_EXPR
+          || TREE_CODE (rhs) == REALPART_EXPR
+          || TREE_CODE (rhs) == IMAGPART_EXPR)
+    {
+      /* We want to do tree-combining on conversion-like expressions.
+         Make sure we feed only SSA_NAMEs or constants to fold though.  */
+      tree tem = valueize_expr (VN_INFO (op0)->expr);
+      if (UNARY_CLASS_P (tem)
+         || BINARY_CLASS_P (tem)
+         || TREE_CODE (tem) == SSA_NAME
+         || is_gimple_min_invariant (tem))
+       op0 = tem;
+    }
+
+  /* Avoid folding if nothing changed, but remember the expression.  */
+  if (op0 == TREE_OPERAND (rhs, 0))
+    return rhs;
+
+  result = fold_unary (TREE_CODE (rhs), TREE_TYPE (rhs), op0);
+  if (result)
+    {
+      STRIP_USELESS_TYPE_CONVERSION (result);
+      if (valid_gimple_expression_p (result))
+        return result;
+    }
+
+  return rhs;
+}
+
 /* Try to simplify RHS using equivalences and constant folding.  */
 
 static tree
@@ -1457,21 +1506,14 @@ try_to_simplify (tree stmt, tree rhs)
            if (result)
              return result;
          }
-         break;
+         /* Fallthrough for some codes.  */
+         if (!(TREE_CODE (rhs) == REALPART_EXPR
+               || TREE_CODE (rhs) == IMAGPART_EXPR))
+           break;
          /* We could do a little more with unary ops, if they expand
             into binary ops, but it's debatable whether it is worth it. */
        case tcc_unary:
-         {
-           tree result = NULL_TREE;
-           tree op0 = TREE_OPERAND (rhs, 0);
-           if (TREE_CODE (op0) == SSA_NAME && VN_INFO (op0)->has_constants)
-             op0 = VN_INFO (op0)->expr;
-           else if (TREE_CODE (op0) == SSA_NAME && SSA_VAL (op0) != op0)
-             op0 = SSA_VAL (op0);
-           result = fold_unary (TREE_CODE (rhs), TREE_TYPE (rhs), op0);
-           if (result)
-             return result;
-         }
+         return simplify_unary_expression (rhs);
          break;
        case tcc_comparison:
        case tcc_binary: