Hi! On this testcase we ICE starting from http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181188 because one of the basic blocks we add to bb_tail has EDGE_ABNORMAL edge (computed goto) from a basic block that doesn't need prologue. We try to duplicate the basic block and finally redirect that EDGE_ABNORMAL edge, which ICEs.
Fixed by not putting basic blocks into bb_tail if they have complex edges from basic blocks that don't need prologue. In x8_64/i686 bootstraps/regtests this only affected compile/pr51495.c, compile/pr28489.c, torture/pr42462.C and execute/980526-1.c testcases. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-12-12 Jakub Jelinek <ja...@redhat.com> PR rtl-optimization/51495 * function.c (thread_prologue_and_epilogue_insns): Don't add to bb_tail basic blocks that have EDGE_COMPLEX predecessor edges from basic blocks not needing prologue. * gcc.c-torture/compile/pr51495.c: New test. --- gcc/function.c.jj 2011-12-11 22:02:37.000000000 +0100 +++ gcc/function.c 2011-12-12 14:31:01.821624702 +0100 @@ -5956,9 +5956,22 @@ thread_prologue_and_epilogue_insns (void FOR_EACH_EDGE (e, ei, tmp_bb->preds) if (single_succ_p (e->src) && !bitmap_bit_p (&bb_on_list, e->src->index) - && can_duplicate_block_p (e->src) - && bitmap_set_bit (&bb_tail, e->src->index)) - VEC_quick_push (basic_block, vec, e->src); + && can_duplicate_block_p (e->src)) + { + edge pe; + edge_iterator pei; + + /* If there is predecessor of e->src which doesn't + need prologue and the edge is complex, + we might not be able to redirect the branch + to a copy of e->src. */ + FOR_EACH_EDGE (pe, pei, e->src->preds) + if ((pe->flags & EDGE_COMPLEX) != 0 + && !bitmap_bit_p (&bb_flags, pe->src->index)) + break; + if (pe == NULL && bitmap_set_bit (&bb_tail, e->src->index)) + VEC_quick_push (basic_block, vec, e->src); + } } /* Now walk backwards from every block that is marked as needing --- gcc/testsuite/gcc.c-torture/compile/pr51495.c.jj 2011-12-12 14:32:45.047017210 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr51495.c 2011-12-12 14:32:15.000000000 +0100 @@ -0,0 +1,14 @@ +/* PR rtl-optimization/51495 */ + +void bar (void); + +int +foo (int i) +{ + static const void *const table[] = { &&begin, &&end }; + goto *(table[i]); +begin: + bar (); +end: + return 0; +} Jakub