> gcc/ChangeLog > 2012-05-04 Dehao Chen <de...@google.com> > > * predict.c (find_qualified_ssa_name): New > (find_ssa_name_in_expr): New > (find_ssa_name_in_assign_stmt): New > (is_comparison_with_loop_invariant_p): New > (is_bound_expr_similar): New > (predict_iv_comparison): New > (predict_loops): Add heuristic for loop-nested branches that compare an > induction variable to a loop bound variable. > * predict.def (PRED_LOOP_IV_COMPARE): New macro > > gcc/testsuite/ChangeLog > 2012-05-04 Dehao Chen <de...@google.com> > > * gcc.dg/predict-1.c: Check if LOOP_IV_COMPARE static predict > heuristic is working properly. > * gcc.dg/predict-2.c: Likewise. > * gcc/dg/predict-3.c: Likewise. > * gcc/dg/predict-4.c: Likewise. > * gcc/dg/predict-5.c: Likewise. > * gcc/dg/predict-6.c: Likewise. > > Index: gcc/predict.c > =================================================================== > --- gcc/predict.c (revision 187140) > +++ gcc/predict.c (working copy) > @@ -946,6 +946,358 @@ > } > } > > +/* Check if T1 and T2 satisfy the IV_COMPARE condition. > + Return the SSA_NAME if the condition satisfies, NULL otherwise. > + > + T1 and T2 should be one of the following cases: > + 1. T1 is SSA_NAME, T2 is NULL > + 2. T1 is SSA_NAME, T2 is INTEGER_CST between [-4, 4] > + 3. T2 is SSA_NAME, T1 is INTEGER_CST between [-4, 4] */ > + > +static tree > +strips_small_constant (tree t1, tree t2) > +{ > + tree ret = NULL; > + int value = 0; > + > + if (!t1) > + return NULL; > + else if (TREE_CODE (t1) == SSA_NAME) > + ret = t1; > + else if (TREE_CODE (t1) == INTEGER_CST && host_integerp (t1, 0))
host_integer_p will check TREE_CODE (t1) == INTEGER_CST for you. > + /* If loop bound, base and compare bound are all constents, we can constants. > + calculate the probability directly. */ > + if (TREE_CODE (loop_bound_var) == INTEGER_CST > + && TREE_CODE (compare_var) == INTEGER_CST > + && TREE_CODE (compare_base) == INTEGER_CST > + && host_integerp (loop_bound_var, 0) > + && host_integerp (compare_var, 0) > + && host_integerp (compare_base, 0)) Again host_integerp will test that for you. > + probability = (double) REG_BR_PROB_BASE * compare_count / loop_count; > + predict_edge (then_edge, PRED_LOOP_IV_COMPARE, probability); > + return; > + } > + > + if (expr_coherent_p (loop_bound_var, compare_var)) You probably want to thave two predictor, one when the probability is known declared as first match predictor with high probability and one when probability is unknown combined the usual way... Otherwise the patch seems good to me. Honza