diff options
author | Jan Hubicka <jh@suse.cz> | 2023-07-21 13:57:34 +0200 |
---|---|---|
committer | Jan Hubicka <jh@suse.cz> | 2023-07-21 13:57:34 +0200 |
commit | 3038d598529d612391728b1895c21954ddb24306 (patch) | |
tree | 4f55ec17fdada7e8e55ba3406301eebc19c0e768 /gcc | |
parent | 15ec8d5ab5f21997cfa34cdba9f4b2daea40e710 (diff) | |
download | gcc-3038d598529d612391728b1895c21954ddb24306.zip gcc-3038d598529d612391728b1895c21954ddb24306.tar.gz gcc-3038d598529d612391728b1895c21954ddb24306.tar.bz2 |
finite_loop_p tweak
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/tree-ssa-loop-niter.cc | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 3c4e662..a806801 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; } |