http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56181
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> 2013-02-05
16:33:45 UTC ---
Hmm, maybe I should have put it this way: we don't want to duplicate a BB,
which may be a preheader. Does it sound sane? Thus, something like
--- a/gcc/tracer.c
+++ b/gcc/tracer.c
@@ -217,6 +217,21 @@ find_trace (basic_block bb, basic_block *trace)
return i;
}
+/* Return true if basic block BB may be a preheader. */
+
+static bool
+maybe_preheader_p (basic_block bb)
+{
+ edge e;
+ edge_iterator ei;
+
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ if (e->dest->loop_father->header == e->dest)
+ return true;
+
+ return false;
+}
+
/* Look for basic blocks in frequency order, construct traces and tail
duplicate
if profitable. */
@@ -310,7 +325,8 @@ tail_duplicate (void)
not profitable and it might create a loop with multiple
entries or at least rotate the loop. */
&& (!current_loops
- || bb2->loop_father->header != bb2))
+ || bb2->loop_father->header != bb2)
+ && !maybe_preheader_p (bb2))
{
edge e;
basic_block copy;