This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Add support for #pragma GCC unroll v2


On Wed, Nov 22, 2017 at 11:46 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> this is a revised version of:
>   https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01452.html
>
> with the following changes:
>  1. integration of Bernhard's patch for the Fortran front-end,
>  2. Sandra's fix for the documentation,
>  3. minor tweaks to the C and C++ front-end,
>  4. change at the GIMPLE level for the cunrolli pass,
>  5. change at the RTL level with a fix for a thinko,
>  6. More testcases for all languages.
>
> This makes it so that the presence of a pragma GCC unroll doesn't have a
> global effect on the function: at the GIMPLE level, the cunrolli pass is no
> longer forced, so that the unrolling is done by the first activated pass
> (cunroll at -O1, cunrolli at -O2 and above); at the RTL level, this was
> already the case but the code no longer fiddles with the unrolling flag.
>
> Tested on x86_64-suse-linux, OK for the mainline?

The middle-end, testsuite and boilerplate changes in the FEs are ok.

Pragma support in the FEs need FE maintainer approval.

Thanks,
Richard,

>
> 2017-11-22  Mike Stump  <mikestump@comcast.net>
>             Eric Botcazou  <ebotcazou@adacore.com>
>             Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
>
> ChangeLog/
>         * doc/extend.texi (Loop-Specific Pragmas): Document pragma GCC unroll.
>         * doc/generic.texi (ANNOTATE_EXPR): Document 3rd operand.
>         * cfgloop.h (struct loop): Add unroll field.
>         * function.h (struct function): Add has_unroll bitfield.
>         * gimplify.c (gimple_boolify) <ANNOTATE_EXPR>: Deal with unroll kind.
>         (gimplify_expr) <ANNOTATE_EXPR>: Propagate 3rd operand.
>         * loop-init.c (pass_loop2::gate): Return true if cfun->has_unroll.
>         (pass_rtl_unroll_loops::gate): Likewise.
>         * loop-unroll.c (decide_unrolling): Tweak note message.  Skip loops
>         for which loop->unroll==1.
>         (decide_unroll_constant_iterations): Use note for consistency and
>         take loop->unroll into account.  Return early if loop->unroll is set.
>         Fix thinko in existing test.
>         (decide_unroll_runtime_iterations): Use note for consistency and
>         take loop->unroll into account.
>         (decide_unroll_stupid): Likewise.
>         * lto-streamer-in.c (input_cfg): Read loop->unroll.
>         * lto-streamer-out.c (output_cfg): Write loop->unroll.
>         * tree-cfg.c (replace_loop_annotate_in_block) <annot_expr_unroll_kind>
>         New.
>         (replace_loop_annotate) <annot_expr_unroll_kind>: Likewise.
>         (print_loop): Print loop->unroll if set.
>         * tree-core.h (enum annot_expr_kind): Add annot_expr_unroll_kind.
>         * tree-inline.c (copy_loops): Copy unroll and set cfun->has_unroll.
>         * tree-pretty-print.c (dump_generic_node) <annot_expr_unroll_kind>:
>         New.
>         * tree-ssa-loop-ivcanon.c (try_unroll_loop_completely): Bail out if
>         loop->unroll is set and smaller than the trip count.  Otherwise bypass
>         entirely the heuristics if loop->unroll is set.  Remove dead note.
>         Fix off-by-one bug in other node.
>         (try_peel_loop): Bail out if loop->unroll is set.  Fix formatting.
>         (tree_unroll_loops_completely_1): Force unrolling if loop->unroll
>         is greater than 1.
>         (tree_unroll_loops_completely): Make static.
>         (pass_complete_unroll::execute): Use correct type for variable.
>         (pass_complete_unrolli::execute): Fix formatting.
>         * tree.def (ANNOTATE_EXPR): Add 3rd operand.
>
> ada/ChangeLog:
>         * gcc-interface/trans.c (gnat_gimplify_stmt) <LOOP_STMT>: Add 3rd
>         operand to ANNOTATE_EXPR and pass unrolling hints.
>
> c-family/ChangeLog:
>         * c-pragma.c (init_pragma): Register pragma GCC unroll.
>         * c-pragma.h (enum pragma_kind): Add PRAGMA_UNROLL.
>
> c/ChangeLog:
>         * c-parser.c (c_parser_while_statement): Add unroll parameter and
>         build ANNOTATE_EXPR if present.  Add 3rd operand to ANNOTATE_EXPR.
>         (c_parser_do_statement): Likewise.
>         (c_parser_for_statement): Likewise.
>         (c_parser_statement_after_labels): Adjust calls to above.
>         (c_parse_pragma_ivdep): New static function.
>         (c_parser_pragma_unroll): Likewise.
>         (c_parser_pragma) <PRAGMA_IVDEP>: Add support for pragma Unroll.
>         <PRAGMA_UNROLL>: New case.
>
> cp/ChangeLog:
>         * constexpr.c (cxx_eval_constant_expression) <ANNOTATE_EXPR>: Remove
>         assertion on 2nd operand.
>         (potential_constant_expression_1): Likewise.
>         * cp-array-notation.c (create_an_loop): Adjut call to finish_for_cond.
>         * cp-tree.h (cp_convert_range_for): Adjust prototype.
>         (finish_while_stmt_cond): Likewise.
>         (finish_do_stmt): Likewise.
>         (finish_for_cond): Likewise.
>         * init.c (build_vec_init): Adjut call to finish_for_cond.
>         * parser.c (cp_parser_statement): Adjust call to
>         cp_parser_iteration_statement.
>         (cp_parser_for): Add unroll parameter and pass it in calls to
>         cp_parser_range_for and cp_parser_c_for.
>         (cp_parser_c_for): Add unroll parameter and pass it in call to
>         finish_for_cond.
>         (cp_parser_range_for): Add unroll parameter and pass it in call to
>         cp_convert_range_for.
>         (cp_convert_range_for): Add unroll parameter and pass it in call to
>         finish_for_cond.
>         (cp_parser_iteration_statement): Add unroll parameter and pass it in
>         calls to finish_while_stmt_cond, finish_do_stmt and cp_parser_for.
>         (cp_parser_pragma_ivdep): New static function.
>         (cp_parser_pragma_unroll): Likewise.
>         (cp_parser_pragma) <PRAGMA_IVDEP>: Add support for pragma Unroll.
>         <PRAGMA_UNROLL>: New case.
>         * pt.c (tsubst_expr): Adjut calls to finish_for_cond,
>         cp_convert_range_for, finish_while_stmt_cond and finish_do_stmt.
>         <ANNOTATE_EXPR>: Propagate 3rd operand.
>         * semantics.c (finish_while_stmt_cond): Add unroll parameter and
>         build ANNOTATE_EXPR if present.  Add 3rd operand to ANNOTATE_EXPR.
>         (finish_do_stmt): Likewise.
>         (finish_for_cond): Likewise.
>
> fortran/ChangeLog:
>         * array.c (gfc_copy_iterator): Copy unroll field.
>         * decl.c (directive_unroll): New global variable.
>         (gfc_match_gcc_unroll): New function.
>         * gfortran.h (gfc_iterator]): Add unroll field.
>         (directive_unroll): Declare:
>         * match.c (gfc_match_do): Use memset to initialize the iterator.
>         * match.h (gfc_match_gcc_unroll): New prototype.
>         * parse.c (decode_gcc_attribute): Match "unroll".
>         (parse_do_block): Set iterator's unroll.
>         (parse_executable): Diagnose misplaced unroll directive.
>         * trans-stmt.c (gfc_trans_simple_do) Annotate loop condition with
>         annot_expr_unroll_kind.
>         (gfc_trans_do): Likewise.
>         (gfc_trans_forall_loop): Add 3rd operand to ANNOTATE_EXPR.
>
> testsuite/ChangeLog:
>         * c-c++-common/unroll-1.c: New test.
>         * c-c++-common/unroll-2.c: Likewise.
>         * c-c++-common/unroll-3.c: Likewise.
>         * c-c++-common/unroll-4.c: Likewise.
>         * c-c++-common/unroll-5.c: Likewise.
>         * testsuite/gcc.dg/pr64277.c: Adjust scan.
>         * gcc.dg/tree-prof/unroll-1.c: Use detailed dump and adjust scan.
>         * gcc.dg/tree-ssa/cunroll-1.c: Adjust scan.
>         * gcc.dg/tree-ssa/cunroll-12.c: Likewise.
>         * gcc.dg/tree-ssa/cunroll-13.c: Likewise.
>         * gcc.dg/tree-ssa/cunroll-14.c: Likewise.
>         * gcc.dg/tree-ssa/cunroll-2.c: Likewise.
>         * gcc.dg/tree-ssa/cunroll-3.c: Likewise.
>         * gcc.dg/tree-ssa/cunroll-5.c: Likewise.
>         * gcc.dg/tree-ssa/loop-1.c: Likewise.
>         * gcc.dg/tree-ssa/loop-23.c: Likewise.
>         * gcc.dg/tree-ssa/pr61743-1.c: Likewise.
>         * gcc.dg/tree-ssa/pr61743-2.c: Likewise.
>         * gcc.dg/unroll-2.c (foo): Adjust message.
>         (foo2): Likewise.
>         * gcc.dg/unroll-3.c: Adjust scan.
>         * gcc.dg/unroll-4.c: Likewise.
>         * gcc.dg/unroll-5.c: Likewise.
>         * gcc.dg/unroll-7.c: Use detailed dump and adjust scan.
>         * gfortran.dg/directive_unroll_1.f90: New test.
>         * gfortran.dg/directive_unroll_2.f90: Likewise.
>         * gfortran.dg/directive_unroll_3.f90: Lkewise.
>         * gfortran.dg/directive_unroll_4.f90: Likewise.
>         * gfortran.dg/directive_unroll_5.f90: Likewise.
>         * gnat.dg/unroll1.ad[sb]: New test.
>         * gnat.dg/unroll2.ad[sb]: Likewise.
>         * gnat.dg/unroll3.ad[sb]: Likewise.
>
>  ada/gcc-interface/trans.c                    |   25 +-
>  c-family/c-pragma.c                          |    4
>  c-family/c-pragma.h                          |    1
>  c/c-parser.c                                 |  160 ++++++++++++---
>  cfgloop.h                                    |    5
>  cp/constexpr.c                               |    2
>  cp/cp-array-notation.c                       |    2
>  cp/cp-tree.h                                 |    9
>  cp/init.c                                    |    2
>  cp/parser.c                                  |  129 ++++++++++--
>  cp/pt.c                                      |   16 -
>  cp/semantics.c                               |   42 +++-
>  doc/extend.texi                              |   18 +
>  doc/generic.texi                             |    2
>  fortran/array.c                              |    1
>  fortran/decl.c                               |   38 +++
>  fortran/gfortran.h                           |    2
>  fortran/match.c                              |    2
>  fortran/match.h                              |    1
>  fortran/parse.c                              |   13 +
>  fortran/trans-stmt.c                         |   15 +
>  function.h                                   |    5
>  gimplify.c                                   |    4
>  loop-init.c                                  |    6
>  loop-unroll.c                                |  107 ++++++----
>  lto-streamer-in.c                            |    1
>  lto-streamer-out.c                           |    1
>  testsuite/c-c++-common/unroll-1.c            |   41 +++
>  testsuite/c-c++-common/unroll-2.c            |   41 +++
>  testsuite/c-c++-common/unroll-3.c            |   41 +++
>  testsuite/c-c++-common/unroll-4.c            |   20 +
>  testsuite/c-c++-common/unroll-5.c            |   29 ++
>  testsuite/gcc.dg/pr64277.c                   |    2
>  testsuite/gcc.dg/tree-prof/unroll-1.c        |    4
>  testsuite/gcc.dg/tree-ssa/cunroll-1.c        |    2
>  testsuite/gcc.dg/tree-ssa/cunroll-12.c       |    2
>  testsuite/gcc.dg/tree-ssa/cunroll-13.c       |    2
>  testsuite/gcc.dg/tree-ssa/cunroll-14.c       |    2
>  testsuite/gcc.dg/tree-ssa/cunroll-2.c        |    2
>  testsuite/gcc.dg/tree-ssa/cunroll-3.c        |    2
>  testsuite/gcc.dg/tree-ssa/cunroll-5.c        |    2
>  testsuite/gcc.dg/tree-ssa/loop-1.c           |    2
>  testsuite/gcc.dg/tree-ssa/loop-23.c          |    3
>  testsuite/gcc.dg/tree-ssa/pr61743-1.c        |    4
>  testsuite/gcc.dg/tree-ssa/pr61743-2.c        |    4
>  testsuite/gcc.dg/unroll-2.c                  |    4
>  testsuite/gcc.dg/unroll-3.c                  |    2
>  testsuite/gcc.dg/unroll-4.c                  |    2
>  testsuite/gcc.dg/unroll-5.c                  |    2
>  testsuite/gcc.dg/unroll-7.c                  |    4
>  testsuite/gfortran.dg/directive_unroll_1.f90 |   52 +++++
>  testsuite/gfortran.dg/directive_unroll_2.f90 |   52 +++++
>  testsuite/gfortran.dg/directive_unroll_3.f90 |   52 +++++
>  testsuite/gfortran.dg/directive_unroll_4.f90 |   29 ++
>  testsuite/gfortran.dg/directive_unroll_5.f90 |   38 +++
>  testsuite/gnat.dg/unroll1.adb                |   27 ++
>  testsuite/gnat.dg/unroll1.ads                |    9
>  testsuite/gnat.dg/unroll2.adb                |   26 ++
>  testsuite/gnat.dg/unroll2.ads                |    9
>  testsuite/gnat.dg/unroll3.adb                |   26 ++
>  testsuite/gnat.dg/unroll3.ads                |    9
>  tree-cfg.c                                   |    8
>  tree-core.h                                  |    1
>  tree-inline.c                                |    5
>  tree-pretty-print.c                          |    4
>  tree-ssa-loop-ivcanon.c                      |  278 +++++++++++++------------
>  tree.def                                     |    5
>  67 files changed, 1165 insertions(+), 297 deletions(-)
>
> --
> Eric Botcazou


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]