diff options
author | Richard Biener <rguenther@suse.de> | 2020-09-04 12:18:38 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2020-09-04 12:22:29 +0200 |
commit | fab77644842869adc8871e133e4c3f4c35b2b245 (patch) | |
tree | 8c0551b4af84ec3767be87c5816467e8e976c56b /gcc | |
parent | b898878032a5bbba0d1a981db6399664181531e9 (diff) | |
download | gcc-fab77644842869adc8871e133e4c3f4c35b2b245.zip gcc-fab77644842869adc8871e133e4c3f4c35b2b245.tar.gz gcc-fab77644842869adc8871e133e4c3f4c35b2b245.tar.bz2 |
tree-optimization/96931 - clear ctrl-altering flag more aggressively
The testcase shows that we fail to clear gimple_call_ctrl_altering_p
when the last abnormal edge goes away, causing an edge insert to
a loop header edge when we have preheaders to split the edge
unnecessarily.
The following addresses this by more aggressively clearing the
flag in cleanup_call_ctrl_altering_flag.
2020-09-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/96931
* tree-cfgcleanup.c (cleanup_call_ctrl_altering_flag): If
there's a fallthru edge and no abnormal edge the call is
no longer control-altering.
(cleanup_control_flow_bb): Pass down the BB to
cleanup_call_ctrl_altering_flag.
* gcc.dg/pr96931.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/pr96931.c | 19 | ||||
-rw-r--r-- | gcc/tree-cfgcleanup.c | 22 |
2 files changed, 39 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/pr96931.c b/gcc/testsuite/gcc.dg/pr96931.c new file mode 100644 index 0000000..94b8a11 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96931.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fpredictive-commoning -fno-tree-loop-im" } */ + +int bl; + +void +p3 (void); + +void __attribute__ ((returns_twice)) +ie (void) +{ + p3 (); + + bl = 0; + for (;;) + ++bl; + + ie (); +} diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 4763cd4..f8169ee 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -209,7 +209,7 @@ cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) to updated gimple_call_flags. */ static void -cleanup_call_ctrl_altering_flag (gimple *bb_end) +cleanup_call_ctrl_altering_flag (basic_block bb, gimple *bb_end) { if (!is_gimple_call (bb_end) || !gimple_call_ctrl_altering_p (bb_end)) @@ -220,6 +220,24 @@ cleanup_call_ctrl_altering_flag (gimple *bb_end) && !(flags & ECF_LOOPING_CONST_OR_PURE)) || (flags & ECF_LEAF)) gimple_call_set_ctrl_altering (bb_end, false); + else + { + edge_iterator ei; + edge e; + bool found = false; + FOR_EACH_EDGE (e, ei, bb->succs) + if (e->flags & EDGE_FALLTHRU) + found = true; + else if (e->flags & EDGE_ABNORMAL) + { + found = false; + break; + } + /* If there's no abnormal edge and a fallthru edge the call + isn't control-altering anymore. */ + if (found) + gimple_call_set_ctrl_altering (bb_end, false); + } } /* Try to remove superfluous control structures in basic block BB. Returns @@ -243,7 +261,7 @@ cleanup_control_flow_bb (basic_block bb) stmt = gsi_stmt (gsi); /* Try to cleanup ctrl altering flag for call which ends bb. */ - cleanup_call_ctrl_altering_flag (stmt); + cleanup_call_ctrl_altering_flag (bb, stmt); if (gimple_code (stmt) == GIMPLE_COND || gimple_code (stmt) == GIMPLE_SWITCH) |