From: Martin Liska Date: Thu, 16 Jun 2016 16:05:25 +0000 (+0200) Subject: Introduce fortran loop preheader X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=68fa96d6257baa572dad70a23259670be1542efb;p=gcc.git Introduce fortran loop preheader * predict.def: Add fortran loop preheader predictor. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Properly fold IFN_BUILTIN_EXPECT with a known constant argument. * trans-stmt.c (gfc_trans_simple_do): Predict the edge. * gfortran.dg/predict-1.f90: New test. From-SVN: r237533 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 52fa6747043..4d6fdf65d6c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-06-16 Martin Liska + + * predict.def: Add fortran loop preheader predictor. + * gimple-fold.c (gimple_fold_stmt_to_constant_1): Properly + fold IFN_BUILTIN_EXPECT with a known constant argument. + 2016-06-16 Martin Liska * predict.def: Add 'Fortran' to display text of all diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9ba15543080..7150f84841e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,7 @@ +2016-06-16 Martin Liska + + * trans-stmt.c (gfc_trans_simple_do): Predict the edge. + 2016-06-16 Martin Liska * trans-array.c (gfc_array_allocate): Do not generate expect diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 7d3cf8cae5a..84bf749780d 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -1938,7 +1938,9 @@ gfc_trans_simple_do (gfc_code * code, stmtblock_t *pblock, tree dovar, else cond = fold_build2_loc (loc, GE_EXPR, boolean_type_node, dovar, to); - tmp = fold_build3_loc (loc, COND_EXPR, void_type_node, cond, tmp, + + tmp = fold_build3_loc (loc, COND_EXPR, void_type_node, + gfc_likely (cond, PRED_FORTRAN_LOOP_PREHEADER), tmp, build_empty_stmt (loc)); gfc_add_expr_to_block (pblock, tmp); diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 885367e9114..fa03e8916a3 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -5250,6 +5250,14 @@ gimple_fold_stmt_to_constant_1 (gimple *stmt, tree (*valueize) (tree), case IFN_UBSAN_CHECK_MUL: subcode = MULT_EXPR; break; + case IFN_BUILTIN_EXPECT: + { + tree arg0 = gimple_call_arg (stmt, 0); + tree op0 = (*valueize) (arg0); + if (TREE_CODE (op0) == INTEGER_CST) + return op0; + return NULL_TREE; + } default: return NULL_TREE; } diff --git a/gcc/predict.def b/gcc/predict.def index 3e3a43a1079..a0d0ba923a2 100644 --- a/gcc/predict.def +++ b/gcc/predict.def @@ -199,3 +199,9 @@ DEF_PREDICTOR (PRED_FORTRAN_INVALID_BOUND, "Fortran invalid bound", \ which in turn has an optional argument. */ DEF_PREDICTOR (PRED_FORTRAN_ABSENT_DUMMY, "Fortran absent dummy", \ HITRATE (60), 0) + +/* Fortran DO statement generates a pre-header guard: + empty = (step > 0 ? to < from : to > from), which can be predicted + to be very likely. */ +DEF_PREDICTOR (PRED_FORTRAN_LOOP_PREHEADER, "Fortran loop preheader", \ + HITRATE (99), 0) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eb84aebab6d..3dfb452358d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-06-16 Martin Liska + + * gfortran.dg/predict-1.f90: New test. + 2016-06-16 Uros Bizjak PR target/71242 diff --git a/gcc/testsuite/gfortran.dg/predict-1.f90 b/gcc/testsuite/gfortran.dg/predict-1.f90 new file mode 100644 index 00000000000..81f0436fba4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/predict-1.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! { dg-options "-O2 -fdump-tree-profile_estimate" } + +subroutine test(block, array) +integer :: i, block(9), array(2) + +do i = array(1), array(2) + block(i) = i +end do +end subroutine test + +! { dg-final { scan-tree-dump-times "Fortran loop preheader heuristics of edge\[^:\]*: 99.0%" 1 "profile_estimate" } }