Introduce fortran loop preheader
authorMartin Liska <mliska@suse.cz>
Thu, 16 Jun 2016 16:05:25 +0000 (18:05 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 16 Jun 2016 16:05:25 +0000 (16:05 +0000)
* 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

gcc/ChangeLog
gcc/fortran/ChangeLog
gcc/fortran/trans-stmt.c
gcc/gimple-fold.c
gcc/predict.def
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/predict-1.f90 [new file with mode: 0644]

index 52fa67470437ce48442242b32b98ac2837998478..4d6fdf65d6c4a0149ae83d91b98b3eddae1578a0 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-16  Martin Liska  <mliska@suse.cz>
+
+       * 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  <mliska@suse.cz>
 
        * predict.def: Add 'Fortran' to display text of all
index 9ba155430802df01ec264f47c5ea7e617a3181d8..7150f84841edf99c04e8b11f8bafa09eaf4542ae 100644 (file)
@@ -1,3 +1,7 @@
+2016-06-16  Martin Liska  <mliska@suse.cz>
+
+       * trans-stmt.c (gfc_trans_simple_do): Predict the edge.
+
 2016-06-16  Martin Liska  <mliska@suse.cz>
 
        * trans-array.c (gfc_array_allocate): Do not generate expect
index 7d3cf8cae5aef7c449179acfaa8bbf46e9bf8c13..84bf749780d616c43673d3ccafba3c09e66f8f68 100644 (file)
@@ -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);
 
index 885367e911494a4a03bb24a532f5e73fecd7a1b1..fa03e8916a3dc7997b8a76f4159494ad7af8f83e 100644 (file)
@@ -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;
              }
index 3e3a43a1079ac36b1b1156cd8c82e31017275e5d..a0d0ba923a23b5339d8d4e3542dd65ac7483b185 100644 (file)
@@ -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)
index eb84aebab6db1efdc97e31dbb543666f507d7551..3dfb452358db71cd1dbe7f164a4147e93895eadf 100644 (file)
@@ -1,3 +1,7 @@
+2016-06-16  Martin Liska  <mliska@suse.cz>
+
+       * gfortran.dg/predict-1.f90: New test.
+
 2016-06-16  Uros Bizjak  <ubizjak@gmail.com>
 
        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 (file)
index 0000000..81f0436
--- /dev/null
@@ -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" } }