* finite_loop_p tweak
@ 2023-07-21 11:44 Jan Hubicka
2023-07-21 11:48 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jan Hubicka @ 2023-07-21 11:44 UTC (permalink / raw)
To: gcc-patches
Hi,
we have finite_p flag in loop structure. finite_loop_p already know to
use it, but we also may set the flag when we prove loop to be finite by
SCEV analysis to avoid duplicated work.
Bootstrapped/regtested x86_64-linux, OK?
gcc/ChangeLog:
* tree-ssa-loop-niter.cc (finite_loop_p): Reorder to do cheap
tests first; update finite_p flag.
diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 3c4e66291fb..e5985bee235 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -3338,24 +3338,6 @@ finite_loop_p (class loop *loop)
widest_int nit;
int flags;
- flags = flags_from_decl_or_type (current_function_decl);
- if ((flags & (ECF_CONST|ECF_PURE)) && !(flags & ECF_LOOPING_CONST_OR_PURE))
- {
- if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, "Found loop %i to be finite: it is within pure or const function.\n",
- loop->num);
- return true;
- }
-
- if (loop->any_upper_bound
- || max_loop_iterations (loop, &nit))
- {
- if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, "Found loop %i to be finite: upper bound found.\n",
- loop->num);
- return true;
- }
-
if (loop->finite_p)
{
unsigned i;
@@ -3368,11 +3350,36 @@ finite_loop_p (class loop *loop)
{
if (dump_file)
fprintf (dump_file, "Assume loop %i to be finite: it has an exit "
- "and -ffinite-loops is on.\n", loop->num);
+ "and -ffinite-loops is on or loop was
+ " previously finite.\n",
+ loop->num);
return true;
}
}
+ flags = flags_from_decl_or_type (current_function_decl);
+ if ((flags & (ECF_CONST|ECF_PURE)) && !(flags & ECF_LOOPING_CONST_OR_PURE))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file,
+ "Found loop %i to be finite: it is within "
+ "pure or const function.\n",
+ loop->num);
+ loop->finite_p = true;
+ return true;
+ }
+
+ if (loop->any_upper_bound
+ /* Loop with no normal exit will not pass max_loop_iterations. */
+ || (!loop->finite_p && max_loop_iterations (loop, &nit)))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Found loop %i to be finite: upper bound found.\n",
+ loop->num);
+ loop->finite_p = true;
+ return true;
+ }
+
return false;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: finite_loop_p tweak
2023-07-21 11:44 finite_loop_p tweak Jan Hubicka
@ 2023-07-21 11:48 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-07-21 11:48 UTC (permalink / raw)
To: Jan Hubicka; +Cc: gcc-patches
On Fri, Jul 21, 2023 at 1:45 PM Jan Hubicka via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
> we have finite_p flag in loop structure. finite_loop_p already know to
> use it, but we also may set the flag when we prove loop to be finite by
> SCEV analysis to avoid duplicated work.
>
> Bootstrapped/regtested x86_64-linux, OK?
OK
> gcc/ChangeLog:
>
> * tree-ssa-loop-niter.cc (finite_loop_p): Reorder to do cheap
> tests first; update finite_p flag.
>
> diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
> index 3c4e66291fb..e5985bee235 100644
> --- a/gcc/tree-ssa-loop-niter.cc
> +++ b/gcc/tree-ssa-loop-niter.cc
> @@ -3338,24 +3338,6 @@ finite_loop_p (class loop *loop)
> widest_int nit;
> int flags;
>
> - flags = flags_from_decl_or_type (current_function_decl);
> - if ((flags & (ECF_CONST|ECF_PURE)) && !(flags & ECF_LOOPING_CONST_OR_PURE))
> - {
> - if (dump_file && (dump_flags & TDF_DETAILS))
> - fprintf (dump_file, "Found loop %i to be finite: it is within pure or const function.\n",
> - loop->num);
> - return true;
> - }
> -
> - if (loop->any_upper_bound
> - || max_loop_iterations (loop, &nit))
> - {
> - if (dump_file && (dump_flags & TDF_DETAILS))
> - fprintf (dump_file, "Found loop %i to be finite: upper bound found.\n",
> - loop->num);
> - return true;
> - }
> -
> if (loop->finite_p)
> {
> unsigned i;
> @@ -3368,11 +3350,36 @@ finite_loop_p (class loop *loop)
> {
> if (dump_file)
> fprintf (dump_file, "Assume loop %i to be finite: it has an exit "
> - "and -ffinite-loops is on.\n", loop->num);
> + "and -ffinite-loops is on or loop was
> + " previously finite.\n",
> + loop->num);
> return true;
> }
> }
>
> + flags = flags_from_decl_or_type (current_function_decl);
> + if ((flags & (ECF_CONST|ECF_PURE)) && !(flags & ECF_LOOPING_CONST_OR_PURE))
> + {
> + if (dump_file && (dump_flags & TDF_DETAILS))
> + fprintf (dump_file,
> + "Found loop %i to be finite: it is within "
> + "pure or const function.\n",
> + loop->num);
> + loop->finite_p = true;
> + return true;
> + }
> +
> + if (loop->any_upper_bound
> + /* Loop with no normal exit will not pass max_loop_iterations. */
> + || (!loop->finite_p && max_loop_iterations (loop, &nit)))
> + {
> + if (dump_file && (dump_flags & TDF_DETAILS))
> + fprintf (dump_file, "Found loop %i to be finite: upper bound found.\n",
> + loop->num);
> + loop->finite_p = true;
> + return true;
> + }
> +
> return false;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-21 11:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 11:44 finite_loop_p tweak Jan Hubicka
2023-07-21 11:48 ` Richard Biener
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).