public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102385] [12 Regression] ICE: in single_pred_edge, at basic-block.h:350 under "-O2 -fno-toplevel-reorder -fno-tree-ch -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-loop-ivcanon -fpredictive-commoning" since r12-2429-g62acc72a957b5614
Date: Fri, 08 Oct 2021 12:18:46 +0000	[thread overview]
Message-ID: <bug-102385-4-OxXiJrY6Ym@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102385-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102385

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Sandiford <rsandifo@gcc.gnu.org>:

https://gcc.gnu.org/g:0ee3dc6052361290c92bba492cc0a9e556b31055

commit r12-4250-g0ee3dc6052361290c92bba492cc0a9e556b31055
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Mon Oct 4 23:55:43 2021 +0100

    loop: Fix profile updates after unrolling [PR102385]

    In g:62acc72a957b5614 I'd stopped the unroller from using
    an epilogue loop in cases where the iteration count was
    known to be a multiple of the unroll factor.  The epilogue
    and non-epilogue cases still shared this (preexisting) code
    to update the edge frequencies:

      basic_block exit_bb = single_pred (loop->latch);
      new_exit = find_edge (exit_bb, rest);
      new_exit->probability = profile_probability::always ()
                                   .apply_scale (1, new_est_niter + 1);
      [etc]

    But of course (in hindsight) that only makes sense for the
    epilogue case, where we've already moved the main loop's exit edge
    to be a sibling of the latch edge.  For the non-epilogue case,
    the exit edge stays (and needs to stay) in its original position.

    I don't really understand what the code is trying to do for
    the epilogue case.  It has:

          /* Ensure that the frequencies in the loop match the new estimated
             number of iterations, and change the probability of the new
             exit edge.  */

          profile_count freq_h = loop->header->count;
          profile_count freq_e = (loop_preheader_edge (loop))->count ();
          if (freq_h.nonzero_p ())
            {
              ...
              scale_loop_frequencies (loop, freq_e.probability_in (freq_h));
            }

    Here, freq_e.probability_in (freq_h) is freq_e / freq_h, so for the
    header block, this has the effect of:

      new header count = freq_h * (freq_e / freq_h)

    i.e. we say that the header executes exactly as often as the
    preheader edge, which would only make sense if the loop never
    iterates.  Also, after setting the probability of the nonexit edge
    (correctly) to new_est_niter / (new_est_niter + 1), the code does:

        scale_bbs_frequencies (&loop->latch, 1, prob);

    for this new probability.  I think that only makes sense if the
    nonexit edge was previously unconditional (100%).  But the code
    carefully preserved the probability of the original exit edge
    when creating the new one.

    All I'm trying to do here though is fix the mess I created
    and get the probabilities right for the non-epilogue case.
    Things are simpler there since we don't have to worry about
    loop versioning.  Hopefully the comments explain the approach.

    The function's current interface implies that it can cope with
    multiple exit edges and that the function only needs the iteration
    count relative to one of those edges in order to work correctly.
    In practice that's not the case: it assumes there is exactly one
    exit edge and all current callers also ensure that the exit test
    dominates the latch.  I think the function is easier to follow
    if we remove the implied generality.

    gcc/
            PR tree-optimization/102385
            * predict.h (change_edge_frequency): Declare.
            * predict.c (change_edge_frequency): New function.
            * tree-ssa-loop-manip.h (tree_transform_and_unroll_loop): Remove
            edge argument.
            (tree_unroll_loop): Likewise.
            * gimple-loop-jam.c (tree_loop_unroll_and_jam): Update accordingly.
            * tree-predcom.c (pcom_worker::tree_predictive_commoning_loop):
            Likewise.
            * tree-ssa-loop-prefetch.c (loop_prefetch_arrays): Likewise.
            * tree-ssa-loop-manip.c (tree_unroll_loop): Likewise.
            (tree_transform_and_unroll_loop): Likewise.  Use single_dom_exit
            to retrieve the exit edges.  Make all the old profile update code
            conditional on !single_loop_p -- the case it was written for --
            and use a different approach for the single-loop case.

    gcc/testsuite/
            * gcc.dg/pr102385.c: New test.

  parent reply	other threads:[~2021-10-08 12:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17  7:15 [Bug tree-optimization/102385] New: ICE: in single_pred_edge, at basic-block.h:350 under "-O2 -fno-toplevel-reorder -fno-tree-ch -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-loop-ivcanon -fpredictive-commoning" suochenyao at 163 dot com
2021-09-17  7:29 ` [Bug tree-optimization/102385] [12 Regression] " rguenth at gcc dot gnu.org
2021-09-17 10:10 ` [Bug tree-optimization/102385] [12 Regression] ICE: in single_pred_edge, at basic-block.h:350 under "-O2 -fno-toplevel-reorder -fno-tree-ch -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-loop-ivcanon -fpredictive-commoning" since r12-2429-g62acc72a957b5614 marxin at gcc dot gnu.org
2021-09-30 22:34 ` pinskia at gcc dot gnu.org
2021-09-30 22:34 ` pinskia at gcc dot gnu.org
2021-09-30 22:35 ` pinskia at gcc dot gnu.org
2021-09-30 22:36 ` pinskia at gcc dot gnu.org
2021-10-04 18:41 ` rsandifo at gcc dot gnu.org
2021-10-08 12:18 ` cvs-commit at gcc dot gnu.org [this message]
2021-10-08 12:20 ` rsandifo at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102385-4-OxXiJrY6Ym@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).