This corresponds to:
  [PATCH 71/89] Concretize gimple_cond_make_{false|true}
  https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01208.html
from the original 89-patch kit

That earlier patch was approved by Jeff:
> OK once prerequisites go in.
in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00863.html

gcc/
        * gimple.h (gimple_cond_make_false): Require a gimple_cond.
        (gimple_cond_make_true): Likewise.

        * tree-cfg.c (fold_cond_expr_cond): Add a checked cast to
        gimple_cond within region guarded by check for GIMPLE_COND.
        * tree-ssa-ccp.c (ccp_fold_stmt): Likewise.

        * tree-loop-distribution.c (generate_loops_for_partition): Replace
        a check for GIMPLE_COND with a dyn_cast<gimple_cond>.
        * tree-ssa-ccp.c (optimize_unreachable): Likewise.
        * tree-ssa-loop-niter.c (number_of_iterations_exit): Likewise.
        * tree-ssa-pre.c (eliminate_dom_walker::before_dom_children):
        Likewise.

        * tree-vrp.c (fold_predicate_in): Add a checked cast to
        gimple_cond.  We must be dealing with a GIMPLE_COND since logic
        at top of the function ensures we only act on GIMPLE_ASSIGN and
        GIMPLE_COND statements, and we're now within a "not a GIMPLE_ASSIGN"
        clause.

        * tree-ssa-loop-ivcanon.c (remove_exits_and_undefined_stmts): Add
        checked cast of elt->stmt to gimple_cond.  The existing code requires
        this to be a GIMPLE_COND, though it's not clear to me how this
        requirement is enforced.
        (remove_redundant_iv_tests): Likewise.
        (try_unroll_loop_completely): Likewise, for the last_stmt of the
        preceding bb along edge_to_cancel.
        * tree-ssa-reassoc.c (maybe_optimize_range_tests): Likewise, for the
        last_stmt of bb.
---
 gcc/ChangeLog.gimple-classes | 34 ++++++++++++++++++++++++++++++++++
 gcc/gimple.h                 |  4 ++--
 gcc/tree-cfg.c               | 11 +++++++----
 gcc/tree-loop-distribution.c |  4 ++--
 gcc/tree-ssa-ccp.c           | 13 +++++++------
 gcc/tree-ssa-loop-ivcanon.c  | 17 +++++++++--------
 gcc/tree-ssa-loop-niter.c    | 10 +++++++---
 gcc/tree-ssa-reassoc.c       | 15 ++++++++-------
 gcc/tree-vrp.c               |  5 +++--
 9 files changed, 79 insertions(+), 34 deletions(-)

diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes
index a046f12..7b03dad 100644
--- a/gcc/ChangeLog.gimple-classes
+++ b/gcc/ChangeLog.gimple-classes
@@ -1,5 +1,39 @@
 2014-10-24  David Malcolm  <dmalc...@redhat.com>
 
+       Concretize gimple_cond_make_{false|true}
+
+       * gimple.h (gimple_cond_make_false): Require a gimple_cond.
+       (gimple_cond_make_true): Likewise.
+
+       * tree-cfg.c (fold_cond_expr_cond): Add a checked cast to
+       gimple_cond within region guarded by check for GIMPLE_COND.
+       * tree-ssa-ccp.c (ccp_fold_stmt): Likewise.
+
+       * tree-loop-distribution.c (generate_loops_for_partition): Replace
+       a check for GIMPLE_COND with a dyn_cast<gimple_cond>.
+       * tree-ssa-ccp.c (optimize_unreachable): Likewise.
+       * tree-ssa-loop-niter.c (number_of_iterations_exit): Likewise.
+       * tree-ssa-pre.c (eliminate_dom_walker::before_dom_children):
+       Likewise.
+
+       * tree-vrp.c (fold_predicate_in): Add a checked cast to
+       gimple_cond.  We must be dealing with a GIMPLE_COND since logic
+       at top of the function ensures we only act on GIMPLE_ASSIGN and
+       GIMPLE_COND statements, and we're now within a "not a GIMPLE_ASSIGN"
+       clause.
+
+       * tree-ssa-loop-ivcanon.c (remove_exits_and_undefined_stmts): Add
+       checked cast of elt->stmt to gimple_cond.  The existing code requires
+       this to be a GIMPLE_COND, though it's not clear to me how this
+       requirement is enforced.
+       (remove_redundant_iv_tests): Likewise.
+       (try_unroll_loop_completely): Likewise, for the last_stmt of the
+       preceding bb along edge_to_cancel.
+       * tree-ssa-reassoc.c (maybe_optimize_range_tests): Likewise, for the
+       last_stmt of bb.
+
+2014-10-24  David Malcolm  <dmalc...@redhat.com>
+
        Concretize locals within expand_omp_for_init_counts
 
        * omp-low.c (expand_omp_for_init_counts): Eliminate local "stmt"
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 6a09975..de1ad22 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3121,7 +3121,7 @@ gimple_cond_false_label (const_gimple gs)
 /* Set the conditional COND_STMT to be of the form 'if (1 == 0)'.  */
 
 static inline void
-gimple_cond_make_false (gimple gs)
+gimple_cond_make_false (gimple_cond gs)
 {
   gimple_cond_set_lhs (gs, boolean_true_node);
   gimple_cond_set_rhs (gs, boolean_false_node);
@@ -3132,7 +3132,7 @@ gimple_cond_make_false (gimple gs)
 /* Set the conditional COND_STMT to be of the form 'if (1 == 1)'.  */
 
 static inline void
-gimple_cond_make_true (gimple gs)
+gimple_cond_make_true (gimple_cond gs)
 {
   gimple_cond_set_lhs (gs, boolean_true_node);
   gimple_cond_set_rhs (gs, boolean_true_node);
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 4de42a8..f17b342 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -591,13 +591,16 @@ fold_cond_expr_cond (void)
 
       if (stmt && gimple_code (stmt) == GIMPLE_COND)
        {
+         gimple_cond cond_stmt = as_a <gimple_cond> (stmt);
          location_t loc = gimple_location (stmt);
          tree cond;
          bool zerop, onep;
 
          fold_defer_overflow_warnings ();
-         cond = fold_binary_loc (loc, gimple_cond_code (stmt), 
boolean_type_node,
-                             gimple_cond_lhs (stmt), gimple_cond_rhs (stmt));
+         cond = fold_binary_loc (loc, gimple_cond_code (cond_stmt),
+                                 boolean_type_node,
+                                 gimple_cond_lhs (cond_stmt),
+                                 gimple_cond_rhs (cond_stmt));
          if (cond)
            {
              zerop = integer_zerop (cond);
@@ -610,9 +613,9 @@ fold_cond_expr_cond (void)
                                          stmt,
                                          WARN_STRICT_OVERFLOW_CONDITIONAL);
          if (zerop)
-           gimple_cond_make_false (stmt);
+           gimple_cond_make_false (cond_stmt);
          else if (onep)
-           gimple_cond_make_true (stmt);
+           gimple_cond_make_true (cond_stmt);
        }
     }
 }
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index bed8bf1..a6cd30f 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -680,9 +680,9 @@ generate_loops_for_partition (struct loop *loop, 
partition_t partition,
            {
              /* Choose an arbitrary path through the empty CFG part
                 that this unnecessary control stmt controls.  */
-             if (gimple_code (stmt) == GIMPLE_COND)
+             if (gimple_cond cond_stmt = dyn_cast <gimple_cond> (stmt))
                {
-                 gimple_cond_make_false (stmt);
+                 gimple_cond_make_false (cond_stmt);
                  update_stmt (stmt);
                }
              else if (gimple_code (stmt) == GIMPLE_SWITCH)
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 3a5632f..9be5b73 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -2061,6 +2061,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
     {
     case GIMPLE_COND:
       {
+       gimple_cond cond_stmt = as_a <gimple_cond> (stmt);
        ccp_prop_value_t val;
        /* Statement evaluation will handle type mismatches in constants
           more gracefully than the final propagation.  This allows us to
@@ -2080,9 +2081,9 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
          }
 
        if (integer_zerop (val.value))
-         gimple_cond_make_false (stmt);
+         gimple_cond_make_false (cond_stmt);
        else
-         gimple_cond_make_true (stmt);
+         gimple_cond_make_true (cond_stmt);
 
        return true;
       }
@@ -2588,15 +2589,15 @@ optimize_unreachable (gimple_stmt_iterator i)
        continue;
 
       stmt = gsi_stmt (gsi);
-      if (gimple_code (stmt) == GIMPLE_COND)
+      if (gimple_cond cond_stmt = dyn_cast <gimple_cond> (stmt))
        {
          if (e->flags & EDGE_TRUE_VALUE)
-           gimple_cond_make_false (stmt);
+           gimple_cond_make_false (cond_stmt);
          else if (e->flags & EDGE_FALSE_VALUE)
-           gimple_cond_make_true (stmt);
+           gimple_cond_make_true (cond_stmt);
          else
            gcc_unreachable ();
-         update_stmt (stmt);
+         update_stmt (cond_stmt);
        }
       else
        {
diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c
index 00cbf8f..b70f118 100644
--- a/gcc/tree-ssa-loop-ivcanon.c
+++ b/gcc/tree-ssa-loop-ivcanon.c
@@ -521,11 +521,12 @@ remove_exits_and_undefined_stmts (struct loop *loop, 
unsigned int npeeled)
          if (!loop_exit_edge_p (loop, exit_edge))
            exit_edge = EDGE_SUCC (bb, 1);
          gcc_checking_assert (loop_exit_edge_p (loop, exit_edge));
+         gimple_cond cond_stmt = as_a <gimple_cond> (elt->stmt);
          if (exit_edge->flags & EDGE_TRUE_VALUE)
-           gimple_cond_make_true (elt->stmt);
+           gimple_cond_make_true (cond_stmt);
          else
-           gimple_cond_make_false (elt->stmt);
-         update_stmt (elt->stmt);
+           gimple_cond_make_false (cond_stmt);
+         update_stmt (cond_stmt);
          changed = true;
        }
     }
@@ -574,11 +575,12 @@ remove_redundant_iv_tests (struct loop *loop)
              fprintf (dump_file, "Removed pointless exit: ");
              print_gimple_stmt (dump_file, elt->stmt, 0, 0);
            }
+         gimple_cond cond_stmt = as_a <gimple_cond> (elt->stmt);
          if (exit_edge->flags & EDGE_TRUE_VALUE)
-           gimple_cond_make_false (elt->stmt);
+           gimple_cond_make_false (cond_stmt);
          else
-           gimple_cond_make_true (elt->stmt);
-         update_stmt (elt->stmt);
+           gimple_cond_make_true (cond_stmt);
+         update_stmt (cond_stmt);
          changed = true;
        }
     }
@@ -658,7 +660,6 @@ try_unroll_loop_completely (struct loop *loop,
                            location_t locus)
 {
   unsigned HOST_WIDE_INT n_unroll, ninsns, max_unroll, unr_insns;
-  gimple cond;
   struct loop_size size;
   bool n_unroll_found = false;
   edge edge_to_cancel = NULL;
@@ -855,7 +856,7 @@ try_unroll_loop_completely (struct loop *loop,
   /* Remove the conditional from the last copy of the loop.  */
   if (edge_to_cancel)
     {
-      cond = last_stmt (edge_to_cancel->src);
+      gimple_cond cond = as_a <gimple_cond> (last_stmt (edge_to_cancel->src));
       if (edge_to_cancel->flags & EDGE_TRUE_VALUE)
        gimple_cond_make_false (cond);
       else
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 025c1f9..2179462 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1922,7 +1922,8 @@ number_of_iterations_exit (struct loop *loop, edge exit,
                           struct tree_niter_desc *niter,
                           bool warn, bool every_iteration)
 {
-  gimple stmt;
+  gimple last;
+  gimple_cond stmt;
   tree type;
   tree op0, op1;
   enum tree_code code;
@@ -1935,8 +1936,11 @@ number_of_iterations_exit (struct loop *loop, edge exit,
     return false;
 
   niter->assumptions = boolean_false_node;
-  stmt = last_stmt (exit->src);
-  if (!stmt || gimple_code (stmt) != GIMPLE_COND)
+  last = last_stmt (exit->src);
+  if (!last)
+    return false;
+  stmt = dyn_cast <gimple_cond> (last);
+  if (!stmt)
     return false;
 
   /* We want the condition for staying inside loop.  */
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 5b951d7..2512e91 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -3040,18 +3040,19 @@ maybe_optimize_range_tests (gimple stmt)
              && bbinfo[idx].op == NULL_TREE
              && ops[bbinfo[idx].first_idx]->op != NULL_TREE)
            {
-             stmt = last_stmt (bb);
+             gimple_cond cond_stmt = as_a <gimple_cond> (last_stmt (bb));
              if (integer_zerop (ops[bbinfo[idx].first_idx]->op))
-               gimple_cond_make_false (stmt);
+               gimple_cond_make_false (cond_stmt);
              else if (integer_onep (ops[bbinfo[idx].first_idx]->op))
-               gimple_cond_make_true (stmt);
+               gimple_cond_make_true (cond_stmt);
              else
                {
-                 gimple_cond_set_code (stmt, NE_EXPR);
-                 gimple_cond_set_lhs (stmt, ops[bbinfo[idx].first_idx]->op);
-                 gimple_cond_set_rhs (stmt, boolean_false_node);
+                 gimple_cond_set_code (cond_stmt, NE_EXPR);
+                 gimple_cond_set_lhs (cond_stmt,
+                                      ops[bbinfo[idx].first_idx]->op);
+                 gimple_cond_set_rhs (cond_stmt, boolean_false_node);
                }
-             update_stmt (stmt);
+             update_stmt (cond_stmt);
            }
          if (bb == first_bb)
            break;
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index bd4fff6..afd54bf 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -9671,10 +9671,11 @@ fold_predicate_in (gimple_stmt_iterator *si)
       else
        {
          gcc_assert (gimple_code (stmt) == GIMPLE_COND);
+         gimple_cond cond_stmt = as_a <gimple_cond> (stmt);
          if (integer_zerop (val))
-           gimple_cond_make_false (stmt);
+           gimple_cond_make_false (cond_stmt);
          else if (integer_onep (val))
-           gimple_cond_make_true (stmt);
+           gimple_cond_make_true (cond_stmt);
          else
            gcc_unreachable ();
        }
-- 
1.8.5.3

Reply via email to