diff options
author | Richard Biener <rguenther@suse.de> | 2018-04-26 12:18:58 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2018-04-26 12:18:58 +0000 |
commit | 1c53fa8ca9912f6acf8c3c8cec31d647bd8ba691 (patch) | |
tree | f4f5507e0f552943eaa12d63ed635e309b424b20 /gcc/tree-ssa-loop-ch.c | |
parent | ae05281f4ac17db1d602bdd59d3fdd5acc3752ff (diff) | |
download | gcc-1c53fa8ca9912f6acf8c3c8cec31d647bd8ba691.zip gcc-1c53fa8ca9912f6acf8c3c8cec31d647bd8ba691.tar.gz gcc-1c53fa8ca9912f6acf8c3c8cec31d647bd8ba691.tar.bz2 |
re PR libstdc++/85116 (std::min_element does not optimize well with inlined predicate)
2018-04-26 Richard Biener <rguenther@suse.de>
PR tree-optimization/85116
* tree-ssa-loop-ch.c (do_while_loop_p): A do-while loop should
have a loop exit from the single latch predecessor. Remove
case of header with just condition.
(ch_base::copy_headers): Exclude infinite loops from any
processing.
(pass_ch::execute): Record exits.
* gcc.dg/tree-ssa/copy-headers-2.c: New testcase.
* gcc.dg/tree-ssa/copy-headers-3.c: Likewise.
* gcc.dg/tree-ssa/copy-headers-4.c: Likewise.
* gcc.dg/tree-ssa/loadpre6.c: Adjust.
From-SVN: r259672
Diffstat (limited to 'gcc/tree-ssa-loop-ch.c')
-rw-r--r-- | gcc/tree-ssa-loop-ch.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/gcc/tree-ssa-loop-ch.c b/gcc/tree-ssa-loop-ch.c index 488999d..6b5c82c 100644 --- a/gcc/tree-ssa-loop-ch.c +++ b/gcc/tree-ssa-loop-ch.c @@ -165,17 +165,28 @@ do_while_loop_p (struct loop *loop) return false; } - /* If the header contains just a condition, it is not a do-while loop. */ - stmt = last_and_only_stmt (loop->header); - if (stmt - && gimple_code (stmt) == GIMPLE_COND) + /* If the latch does not have a single predecessor, it is not a + do-while loop. */ + if (!single_pred_p (loop->latch)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Loop %i is not do-while loop: latch has multiple " + "predecessors.\n", loop->num); + return false; + } + + /* If the latch predecessor doesn't exit the loop, it is not a + do-while loop. */ + if (!loop_exits_from_bb_p (loop, single_pred (loop->latch))) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, - "Loop %i is not do-while loop: " - "header contains just condition.\n", loop->num); + "Loop %i is not do-while loop: latch predecessor " + "does not exit loop.\n", loop->num); return false; } + if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Loop %i is do-while loop\n", loop->num); @@ -305,8 +316,9 @@ ch_base::copy_headers (function *fun) /* If the loop is already a do-while style one (either because it was written as such, or because jump threading transformed it into one), we might be in fact peeling the first iteration of the loop. This - in general is not a good idea. */ - if (!process_loop_p (loop)) + in general is not a good idea. Also avoid touching infinite loops. */ + if (!loop_has_exit_edges (loop) + || !process_loop_p (loop)) continue; /* Iterate the header copying up to limit; this takes care of the cases @@ -392,6 +404,15 @@ ch_base::copy_headers (function *fun) split_edge (loop_preheader_edge (loop)); split_edge (loop_latch_edge (loop)); + if (dump_file && (dump_flags & TDF_DETAILS)) + { + if (do_while_loop_p (loop)) + fprintf (dump_file, "Loop %d is now do-while loop.\n", loop->num); + else + fprintf (dump_file, "Loop %d is still not do-while loop.\n", + loop->num); + } + changed = true; } @@ -409,7 +430,8 @@ unsigned int pass_ch::execute (function *fun) { loop_optimizer_init (LOOPS_HAVE_PREHEADERS - | LOOPS_HAVE_SIMPLE_LATCHES); + | LOOPS_HAVE_SIMPLE_LATCHES + | LOOPS_HAVE_RECORDED_EXITS); unsigned int res = copy_headers (fun); |