From 84d30ffba33100ae1353a4fcee14df2cab791e73 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 20 Dec 2013 13:50:10 -0500
Subject: [PATCH 73/88] Concretize gimple_cond_set_{lhs|rhs}

gcc/
	* gimple.h (gimple_cond_set_lhs): Require a gimple_cond.
	(gimple_cond_set_rhs): Likewise.

	* tree-parloops.c (transform_to_exit_first_loop): Convert locals
	"cond_stmt" and "cond_nit" to gimple_cond, adding checked casts,
	since the existing code assumes that code is GIMPLE_COND.  Convert
	"stmt" to a gimple_assign.
	(create_parallel_loop): Likewise for "cond_stmt".

	* tree-ssa-loop-im.c (rewrite_bittest): Replace check for code
	GIMPLE_COND with a dyn_cast, adding new local "cond_stmt".
---
 gcc/gimple.h           |  6 ++----
 gcc/tree-parloops.c    | 12 +++++++-----
 gcc/tree-ssa-loop-im.c | 19 ++++++++++++-------
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/gcc/gimple.h b/gcc/gimple.h
index 1639579..eae7b60 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3037,9 +3037,8 @@ gimple_cond_lhs_ptr (const_gimple gs)
    conditional statement GS.  */
 
 static inline void
-gimple_cond_set_lhs (gimple gs, tree lhs)
+gimple_cond_set_lhs (gimple_cond gs, tree lhs)
 {
-  GIMPLE_CHECK (gs, GIMPLE_COND);
   gimple_set_op (gs, 0, lhs);
 }
 
@@ -3068,9 +3067,8 @@ gimple_cond_rhs_ptr (const_gimple gs)
    conditional statement GS.  */
 
 static inline void
-gimple_cond_set_rhs (gimple gs, tree rhs)
+gimple_cond_set_rhs (gimple_cond gs, tree rhs)
 {
-  GIMPLE_CHECK (gs, GIMPLE_COND);
   gimple_set_op (gs, 1, rhs);
 }
 
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index f5823a6..ac37b0f 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -1499,14 +1499,15 @@ transform_to_exit_first_loop (struct loop *loop,
   edge exit = single_dom_exit (loop), hpred;
   tree control, control_name, res, t;
   gimple_phi phi, nphi;
-  gimple cond_stmt, stmt, cond_nit;
+  gimple_assign stmt;
+  gimple_cond cond_stmt, cond_nit;
   tree nit_1;
 
   split_block_after_labels (loop->header);
   orig_header = single_succ (loop->header);
   hpred = single_succ_edge (loop->header);
 
-  cond_stmt = last_stmt (exit->src);
+  cond_stmt = as_a <gimple_cond> (last_stmt (exit->src));
   control = gimple_cond_lhs (cond_stmt);
   gcc_assert (gimple_cond_rhs (cond_stmt) == nit);
 
@@ -1586,7 +1587,7 @@ transform_to_exit_first_loop (struct loop *loop,
   /* Initialize the control variable to number of iterations
      according to the rhs of the exit condition.  */
   gimple_stmt_iterator gsi = gsi_after_labels (ex_bb);
-  cond_nit = last_stmt (exit->src);
+  cond_nit = as_a <gimple_cond> (last_stmt (exit->src));
   nit_1 =  gimple_cond_rhs (cond_nit);
   nit_1 = force_gimple_operand_gsi (&gsi,
 				  fold_convert (TREE_TYPE (control_name), nit_1),
@@ -1610,7 +1611,8 @@ create_parallel_loop (struct loop *loop, tree loop_fn, tree data,
   tree t, param;
   gimple_omp_parallel omp_par_stmt;
   gimple omp_return_stmt1, omp_return_stmt2;
-  gimple phi, cond_stmt;
+  gimple phi;
+  gimple_cond cond_stmt;
   gimple_omp_for for_stmt;
   gimple_omp_continue omp_cont_stmt;
   tree cvar, cvar_init, initvar, cvar_next, cvar_base, type;
@@ -1654,7 +1656,7 @@ create_parallel_loop (struct loop *loop, tree loop_fn, tree data,
 
   /* Extract data for GIMPLE_OMP_FOR.  */
   gcc_assert (loop->header == single_dom_exit (loop)->src);
-  cond_stmt = last_stmt (loop->header);
+  cond_stmt = as_a <gimple_cond> (last_stmt (loop->header));
 
   cvar = gimple_cond_lhs (cond_stmt);
   cvar_base = SSA_NAME_VAR (cvar);
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 8ee47fc..07823ca 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -914,6 +914,7 @@ rewrite_bittest (gimple_stmt_iterator *bsi)
   gimple stmt1;
   gimple_assign stmt2;
   gimple use_stmt;
+  gimple_cond cond_stmt;
   tree lhs, name, t, a, b;
   use_operand_p use;
 
@@ -922,13 +923,15 @@ rewrite_bittest (gimple_stmt_iterator *bsi)
 
   /* Verify that the single use of lhs is a comparison against zero.  */
   if (TREE_CODE (lhs) != SSA_NAME
-      || !single_imm_use (lhs, &use, &use_stmt)
-      || gimple_code (use_stmt) != GIMPLE_COND)
+      || !single_imm_use (lhs, &use, &use_stmt))
     return stmt;
-  if (gimple_cond_lhs (use_stmt) != lhs
-      || (gimple_cond_code (use_stmt) != NE_EXPR
-	  && gimple_cond_code (use_stmt) != EQ_EXPR)
-      || !integer_zerop (gimple_cond_rhs (use_stmt)))
+  cond_stmt = dyn_cast <gimple_cond> (use_stmt);
+  if (!cond_stmt)
+    return stmt;
+  if (gimple_cond_lhs (cond_stmt) != lhs
+      || (gimple_cond_code (cond_stmt) != NE_EXPR
+	  && gimple_cond_code (cond_stmt) != EQ_EXPR)
+      || !integer_zerop (gimple_cond_rhs (cond_stmt)))
     return stmt;
 
   /* Get at the operands of the shift.  The rhs is TMP1 & 1.  */
@@ -976,7 +979,9 @@ rewrite_bittest (gimple_stmt_iterator *bsi)
       /* Replace the SSA_NAME we compare against zero.  Adjust
 	 the type of zero accordingly.  */
       SET_USE (use, name);
-      gimple_cond_set_rhs (use_stmt, build_int_cst_type (TREE_TYPE (name), 0));
+      gimple_cond_set_rhs (cond_stmt,
+			   build_int_cst_type (TREE_TYPE (name),
+					       0));
 
       /* Don't use gsi_replace here, none of the new assignments sets
 	 the variable originally set in stmt.  Move bsi to stmt1, and
-- 
1.8.5.3

