]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): Code to simplify SWITCH_EXPR_...
authorJeff Law <law@redhat.com>
Sun, 18 Dec 2005 07:23:08 +0000 (00:23 -0700)
committerJeff Law <law@gcc.gnu.org>
Sun, 18 Dec 2005 07:23:08 +0000 (00:23 -0700)
* tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): Code
to simplify SWITCH_EXPR_CODE moved from here to ...
* tree-ssa-forwprop.c (simplify_switch_expr): Here.
(tree-ssa-forward_propagate_single_use_vars): Call
simplify_switch_expr when appropriate.

From-SVN: r108738

gcc/ChangeLog
gcc/tree-ssa-dom.c
gcc/tree-ssa-forwprop.c

index 03f63c34d1f8e008c71883006935a9ee4995074c..d30feed3cfdc8e89598fdfbb385b0a69da6d6833 100644 (file)
@@ -1,3 +1,11 @@
+2005-12-18  Jeff Law  <law@redhat.com>
+
+       * tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): Code
+       to simplify SWITCH_EXPR_CODE moved from here to ...
+       * tree-ssa-forwprop.c (simplify_switch_expr): Here.
+       (tree-ssa-forward_propagate_single_use_vars): Call
+       simplify_switch_expr when appropriate.
+
 2005-12-17  Andrew Pinski  <pinskia@physics.uc.edu>
 
        * doc/objc.texi (Type encoding): Add documentation about encoding
index 8e4a1995471728127bf3549d74fbce1586b279ae..00659f3a6709ddd6f043ac14d5af0fc38df2084e 100644 (file)
@@ -274,7 +274,6 @@ static void record_cond (tree, tree);
 static void record_const_or_copy (tree, tree);
 static void record_equality (tree, tree);
 static tree simplify_cond_and_lookup_avail_expr (tree, stmt_ann_t, int);
-static tree simplify_switch_and_lookup_avail_expr (tree, int);
 static tree find_equivalent_equality_comparison (tree);
 static void record_range (tree, basic_block);
 static bool extract_range_from_cond (tree, tree *, tree *, int *);
@@ -2120,67 +2119,6 @@ simplify_cond_and_lookup_avail_expr (tree stmt,
   return 0;
 }
 
-/* STMT is a SWITCH_EXPR for which we could not trivially determine its
-   result.  This routine attempts to find equivalent forms of the
-   condition which we may be able to optimize better.  */
-
-static tree
-simplify_switch_and_lookup_avail_expr (tree stmt, int insert)
-{
-  tree cond = SWITCH_COND (stmt);
-  tree def, to, ti;
-
-  /* The optimization that we really care about is removing unnecessary
-     casts.  That will let us do much better in propagating the inferred
-     constant at the switch target.  */
-  if (TREE_CODE (cond) == SSA_NAME)
-    {
-      def = SSA_NAME_DEF_STMT (cond);
-      if (TREE_CODE (def) == MODIFY_EXPR)
-       {
-         def = TREE_OPERAND (def, 1);
-         if (TREE_CODE (def) == NOP_EXPR)
-           {
-             int need_precision;
-             bool fail;
-
-             def = TREE_OPERAND (def, 0);
-
-#ifdef ENABLE_CHECKING
-             /* ??? Why was Jeff testing this?  We are gimple...  */
-             gcc_assert (is_gimple_val (def));
-#endif
-
-             to = TREE_TYPE (cond);
-             ti = TREE_TYPE (def);
-
-             /* If we have an extension that preserves value, then we
-                can copy the source value into the switch.  */
-
-             need_precision = TYPE_PRECISION (ti);
-             fail = false;
-             if (TYPE_UNSIGNED (to) && !TYPE_UNSIGNED (ti))
-               fail = true;
-             else if (!TYPE_UNSIGNED (to) && TYPE_UNSIGNED (ti))
-               need_precision += 1;
-             if (TYPE_PRECISION (to) < need_precision)
-               fail = true;
-
-             if (!fail)
-               {
-                 SWITCH_COND (stmt) = def;
-                 mark_stmt_modified (stmt);
-
-                 return lookup_avail_expr (stmt, insert);
-               }
-           }
-       }
-    }
-
-  return 0;
-}
-
-
 /* CONST_AND_COPIES is a table which maps an SSA_NAME to the current
    known value for that SSA_NAME (or NULL if no value is known).  
 
@@ -2473,9 +2411,6 @@ eliminate_redundant_computations (tree stmt, stmt_ann_t ann)
      the hash table, simplify the condition and try again.  */
   if (! cached_lhs && TREE_CODE (stmt) == COND_EXPR)
     cached_lhs = simplify_cond_and_lookup_avail_expr (stmt, ann, insert);
-  /* Similarly for a SWITCH_EXPR.  */
-  else if (!cached_lhs && TREE_CODE (stmt) == SWITCH_EXPR)
-    cached_lhs = simplify_switch_and_lookup_avail_expr (stmt, insert);
 
   opt_stats.num_exprs_considered++;
 
index e3978d8c2a24e49022c4b938e17dd689a00b523d..2d89494ca73906108da3160cfa41f81dea574b18 100644 (file)
@@ -739,6 +739,61 @@ simplify_not_neg_expr (tree stmt)
     }
 }
 
+/* STMT is a SWITCH_EXPR for which we attempt to find equivalent forms of
+   the condition which we may be able to optimize better.  */
+
+static void
+simplify_switch_expr (tree stmt)
+{
+  tree cond = SWITCH_COND (stmt);
+  tree def, to, ti;
+
+  /* The optimization that we really care about is removing unnecessary
+     casts.  That will let us do much better in propagating the inferred
+     constant at the switch target.  */
+  if (TREE_CODE (cond) == SSA_NAME)
+    {
+      def = SSA_NAME_DEF_STMT (cond);
+      if (TREE_CODE (def) == MODIFY_EXPR)
+       {
+         def = TREE_OPERAND (def, 1);
+         if (TREE_CODE (def) == NOP_EXPR)
+           {
+             int need_precision;
+             bool fail;
+
+             def = TREE_OPERAND (def, 0);
+
+#ifdef ENABLE_CHECKING
+             /* ??? Why was Jeff testing this?  We are gimple...  */
+             gcc_assert (is_gimple_val (def));
+#endif
+
+             to = TREE_TYPE (cond);
+             ti = TREE_TYPE (def);
+
+             /* If we have an extension that preserves value, then we
+                can copy the source value into the switch.  */
+
+             need_precision = TYPE_PRECISION (ti);
+             fail = false;
+             if (TYPE_UNSIGNED (to) && !TYPE_UNSIGNED (ti))
+               fail = true;
+             else if (!TYPE_UNSIGNED (to) && TYPE_UNSIGNED (ti))
+               need_precision += 1;
+             if (TYPE_PRECISION (to) < need_precision)
+               fail = true;
+
+             if (!fail)
+               {
+                 SWITCH_COND (stmt) = def;
+                 update_stmt (stmt);
+               }
+           }
+       }
+    }
+}
+
 /* Main entry point for the forward propagation optimizer.  */
 
 static void
@@ -788,6 +843,11 @@ tree_ssa_forward_propagate_single_use_vars (void)
              else
                bsi_next (&bsi);
            }
+         else if (TREE_CODE (stmt) == SWITCH_EXPR)
+           {
+             simplify_switch_expr (stmt);
+             bsi_next (&bsi);
+           }
          else if (TREE_CODE (stmt) == COND_EXPR)
            {
              forward_propagate_into_cond (stmt);