From: Jan Hubicka <hubicka@ucw.cz>
To: Richard Biener <rguenther@suse.de>
Cc: Hongtao Liu <crazylht@gmail.com>, gcc-patches@gcc.gnu.org
Subject: Re: Loop-ch improvements, part 3
Date: Tue, 22 Aug 2023 14:03:20 +0200 [thread overview]
Message-ID: <ZOSkCPZ+CBAgr8Tt@kam.mff.cuni.cz> (raw)
In-Reply-To: <nycvar.YFH.7.77.849.2308220745030.12935@jbgna.fhfr.qr>
>
> We seem to peel one iteration for no good reason. The loop is
> a do-while loop already. The key is we see the first iteration
> exit condition is known not taken and then:
>
> Registering value_relation (path_oracle) (iter.24_6 > iter.24_5) (root:
> bb2)
> Stmt is static (constant in the first iteration)
> Analyzing: if (iter.24_6 != 16)
> Registering killing_def (path_oracle) iter.24_6
> Registering value_relation (path_oracle) (iter.24_6 > iter.24_5) (root:
> bb2)
> Will eliminate peeled conditional in bb 3.
> Duplicating bb 3 is a win; it has zero cost
> Not duplicating bb 5: it is single succ.
> Copying headers of loop 1
> Will duplicate bb 3
> Duplicating header of the loop 1 up to edge 3->4
> Loop 1 is do-while loop
> Loop 1 is now do-while loop.
> Exit count: 0 (estimated locally)
> Entry count: 10631108 (estimated locally)
> Peeled all exits: decreased number of iterations of loop 1 by 1.
>
> and that's because of
>
> /* If the static exit fully optimize out, it is win to "duplicate"
> it.
>
> TODO: Even if duplication costs some size we may opt to do so in case
> exit probability is significant enough (do partial peeling). */
> if (static_exit)
> return code_size_cost ? ch_possible_zero_cost : ch_win;
>
> IMHO we're over aggressively apply early peeling here. That holds
> generally, not only for OMP simd loops (which we could identify).
>
> Why are we doing this game for single-block do-while loops?
It seems I just wrongly updated the old conditional. Sorry for that.
It should be:
diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc
index 6cdb87a762f..8142add4bec 100644
--- a/gcc/tree-ssa-loop-ch.cc
+++ b/gcc/tree-ssa-loop-ch.cc
@@ -464,7 +464,7 @@ should_duplicate_loop_header_p (basic_block header, class loop *loop,
TODO: Even if duplication costs some size we may opt to do so in case
exit probability is significant enough (do partial peeling). */
if (static_exit)
- return code_size_cost ? ch_possible_zero_cost : ch_win;
+ return !code_size_cost ? ch_possible_zero_cost : ch_possible;
/* We was not able to prove that conditional will be eliminated. */
int insns = estimate_num_insns (last, &eni_size_weights);
So the heuristics knows that if there is no code produced "peeling" is
good idea since it eliminates one conditional for free. Otherwise it
should know that peeling is possible but only done if it produces
do-while-loop
As TODO says it would make to duplicate also if the exit likely avoids
entering the loop (which would be cheaper than peeling full first
iteration), but that can be done incrementally.
I am testing the fix.
Honza
next prev parent reply other threads:[~2023-08-22 12:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 12:22 Jan Hubicka
2023-07-17 9:17 ` Richard Biener
2023-08-22 5:24 ` Hongtao Liu
2023-08-22 7:53 ` Richard Biener
2023-08-22 12:03 ` Jan Hubicka [this message]
2023-08-23 8:34 ` Jan Hubicka
2023-08-23 8:58 ` Richard Biener
2023-07-20 7:09 loop-ch " Jan Hubicka
2023-07-20 13:03 ` Richard Biener
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=ZOSkCPZ+CBAgr8Tt@kam.mff.cuni.cz \
--to=hubicka@ucw.cz \
--cc=crazylht@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/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).