aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2020-04-02 10:46:20 +0200
committerRichard Biener <rguenther@suse.de>2020-04-02 16:53:21 +0200
commit75efe9cb1f8938a713ce540dc3b27bc2afcd3fae (patch)
tree69f0c6905f576eeedd84101d3bfb66a72a2c4331 /gcc
parent54af95767e887d63dc332731738e642536d87a48 (diff)
downloadgcc-75efe9cb1f8938a713ce540dc3b27bc2afcd3fae.zip
gcc-75efe9cb1f8938a713ce540dc3b27bc2afcd3fae.tar.gz
gcc-75efe9cb1f8938a713ce540dc3b27bc2afcd3fae.tar.bz2
c/94392 - only enable -ffinite-loops for C++
This does away with enabling -ffinite-loops at -O2+ for all languages and instead enables it selectively for C++ only. It also makes -ffinite-loops loop-private at CFG construction time fixing correctness issues with inlining. 2020-04-02 Richard Biener <rguenther@suse.de> PR c/94392 * c-opts.c (c_common_post_options): Enable -ffinite-loops for -O2 and C++11 or newer. * common.opt (ffinite-loops): Initialize to zero. * opts.c (default_options_table): Remove OPT_ffinite_loops entry. * cfgloop.h (loop::finite_p): New member. * cfgloopmanip.c (copy_loop_info): Copy finite_p. * ipa-icf-gimple.c (func_checker::compare_loops): Compare finite_p. * lto-streamer-in.c (input_cfg): Stream finite_p. * lto-streamer-out.c (output_cfg): Likewise. * tree-cfg.c (replace_loop_annotate): Initialize finite_p from flag_finite_loops at CFG build time. * tree-ssa-loop-niter.c (finite_loop_p): Check the loops finite_p flag instead of flag_finite_loops. * doc/invoke.texi (ffinite-loops): Adjust documentation of default setting. * gcc.dg/torture/pr94392.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-opts.c4
-rw-r--r--gcc/cfgloop.h4
-rw-r--r--gcc/cfgloopmanip.c1
-rw-r--r--gcc/common.opt2
-rw-r--r--gcc/doc/invoke.texi3
-rw-r--r--gcc/ipa-icf-gimple.c2
-rw-r--r--gcc/lto-streamer-in.c1
-rw-r--r--gcc/lto-streamer-out.c1
-rw-r--r--gcc/opts.c1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr94392.c22
-rw-r--r--gcc/tree-cfg.c3
-rw-r--r--gcc/tree-ssa-loop-niter.c2
15 files changed, 72 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8a30281..4250204 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,24 @@
2020-04-02 Richard Biener <rguenther@suse.de>
+ PR c/94392
+ * common.opt (ffinite-loops): Initialize to zero.
+ * opts.c (default_options_table): Remove OPT_ffinite_loops
+ entry.
+ * cfgloop.h (loop::finite_p): New member.
+ * cfgloopmanip.c (copy_loop_info): Copy finite_p.
+ * ipa-icf-gimple.c (func_checker::compare_loops): Compare
+ finite_p.
+ * lto-streamer-in.c (input_cfg): Stream finite_p.
+ * lto-streamer-out.c (output_cfg): Likewise.
+ * tree-cfg.c (replace_loop_annotate): Initialize finite_p
+ from flag_finite_loops at CFG build time.
+ * tree-ssa-loop-niter.c (finite_loop_p): Check the loops
+ finite_p flag instead of flag_finite_loops.
+ * doc/invoke.texi (ffinite-loops): Adjust documentation of
+ default setting.
+
+2020-04-02 Richard Biener <rguenther@suse.de>
+
PR debug/94450
* dwarf2out.c (dwarf2out_early_finish): Remove code emitting
DW_TAG_imported_unit.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 38406a8..92aed0e 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-02 Richard Biener <rguenther@suse.de>
+
+ PR c/94392
+ * c-opts.c (c_common_post_options): Enable -ffinite-loops
+ for -O2 and C++11 or newer.
+
2020-03-28 Patrick Palka <ppalka@redhat.com>
* c.opt: Add -fconcepts-diagnostics-depth.
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 6b6c754..58ba094 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -989,6 +989,10 @@ c_common_post_options (const char **pfilename)
SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_new_ttp,
cxx_dialect >= cxx17);
+ /* C++11 guarantees forward progress. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_finite_loops,
+ optimize >= 2 && cxx_dialect >= cxx11);
+
if (cxx_dialect >= cxx11)
{
/* If we're allowing C++0x constructs, don't warn about C++98
diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 1c49a8b..18b404e 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -226,6 +226,10 @@ public:
/* True if the loop is part of an oacc kernels region. */
unsigned in_oacc_kernels_region : 1;
+ /* True if the loop is known to be finite. This is a localized
+ flag_finite_loops or similar pragmas state. */
+ unsigned finite_p : 1;
+
/* The number of times to unroll the loop. 0 means no information given,
just do what we always do. A value of 1 means do not unroll the loop.
A value of USHRT_MAX means unroll with no specific unrolling factor.
diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c
index c937556..50c7267 100644
--- a/gcc/cfgloopmanip.c
+++ b/gcc/cfgloopmanip.c
@@ -1023,6 +1023,7 @@ copy_loop_info (class loop *loop, class loop *target)
target->dont_vectorize = loop->dont_vectorize;
target->force_vectorize = loop->force_vectorize;
target->in_oacc_kernels_region = loop->in_oacc_kernels_region;
+ target->finite_p = loop->finite_p;
target->unroll = loop->unroll;
target->owned_clique = loop->owned_clique;
}
diff --git a/gcc/common.opt b/gcc/common.opt
index 4368910..bb2ea4c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1490,7 +1490,7 @@ Common Report Var(flag_finite_math_only) Optimization SetByCombined
Assume no NaNs or infinities are generated.
ffinite-loops
-Common Report Var(flag_finite_loops) Optimization
+Common Report Var(flag_finite_loops) Optimization Init(0)
Assume that loops with an exit will terminate and not loop indefinitely.
ffixed-
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e9e1683..e3e652f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10432,7 +10432,8 @@ Assume that a loop with an exit will eventually take the exit and not loop
indefinitely. This allows the compiler to remove loops that otherwise have
no side-effects, not considering eventual endless looping as such.
-This option is enabled by default at @option{-O2}.
+This option is enabled by default at @option{-O2} for C++ with -std=c++11
+or higher.
@item -ftree-dominator-opts
@opindex ftree-dominator-opts
diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 3e5b2d4..d306fec 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -395,6 +395,8 @@ func_checker::compare_loops (basic_block bb1, basic_block bb2)
return return_false_with_msg ("dont_vectorize");
if (l1->force_vectorize != l2->force_vectorize)
return return_false_with_msg ("force_vectorize");
+ if (l1->finite_p != l2->finite_p)
+ return return_false_with_msg ("finite_p");
if (l1->unroll != l2->unroll)
return return_false_with_msg ("unroll");
if (!compare_variable_decl (l1->simduid, l2->simduid))
diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
index 9566e5e..244f5b8 100644
--- a/gcc/lto-streamer-in.c
+++ b/gcc/lto-streamer-in.c
@@ -821,6 +821,7 @@ input_cfg (class lto_input_block *ib, class data_in *data_in,
loop->owned_clique = streamer_read_hwi (ib);
loop->dont_vectorize = streamer_read_hwi (ib);
loop->force_vectorize = streamer_read_hwi (ib);
+ loop->finite_p = streamer_read_hwi (ib);
loop->simduid = stream_read_tree (ib, data_in);
place_new_loop (fn, loop);
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index a219c1d..52ef947 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -1950,6 +1950,7 @@ output_cfg (struct output_block *ob, struct function *fn)
streamer_write_hwi (ob, loop->owned_clique);
streamer_write_hwi (ob, loop->dont_vectorize);
streamer_write_hwi (ob, loop->force_vectorize);
+ streamer_write_hwi (ob, loop->finite_p);
stream_write_tree (ob, loop->simduid, true);
}
diff --git a/gcc/opts.c b/gcc/opts.c
index 5dc7d65..d4df862 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -478,7 +478,6 @@ static const struct default_options default_options_table[] =
{ OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
{ OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
{ OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
- { OPT_LEVELS_2_PLUS, OPT_ffinite_loops, NULL, 1 },
{ OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
{ OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
{ OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 16940b4..c3803b6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-02 Richard Biener <rguenther@suse.de>
+
+ PR c/94392
+ * gcc.dg/torture/pr94392.c: New testcase.
+
2020-04-02 Jakub Jelinek <jakub@redhat.com>
PR target/94435
diff --git a/gcc/testsuite/gcc.dg/torture/pr94392.c b/gcc/testsuite/gcc.dg/torture/pr94392.c
new file mode 100644
index 0000000..373f18c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr94392.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-skip-if "finite loops" { *-*-* } { "-ffinite-loops" } } */
+/* { dg-skip-if "LTO optimizes the test" { *-*-* } { "-flto" } } */
+/* { dg-additional-options "-fdump-tree-optimized" } */
+
+int a, b;
+
+int
+main()
+{
+ while (1)
+ {
+ /* Try really hard. */
+ if (a != b)
+ return 1;
+ }
+ return 0;
+}
+
+/* ISO C does not guarantee forward progress like C++ does so we
+ cannot assume the loop is finite and optimize it to return 1. */
+/* { dg-final { scan-tree-dump "if" "optimized" } } */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index f7b817d..e99fb9f 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -324,6 +324,9 @@ replace_loop_annotate (void)
/* Then look into the latch, if any. */
if (loop->latch)
replace_loop_annotate_in_block (loop->latch, loop);
+
+ /* Push the global flag_finite_loops state down to individual loops. */
+ loop->finite_p = flag_finite_loops;
}
/* Remove IFN_ANNOTATE. Safeguard for the case loop->latch == NULL. */
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 6e6df0bf..7d61ef0 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2834,7 +2834,7 @@ finite_loop_p (class loop *loop)
return true;
}
- if (flag_finite_loops)
+ if (loop->finite_p)
{
unsigned i;
vec<edge> exits = get_loop_exit_edges (loop);