Hi! On the testcase below we ICE since my PR48343 patch. The problem is that update_cfg_for_uncondjump delete_insns the noop move, if the insn to be deleted is last_combined_insn (which can be both if it is i3 or when retrying and undobuf.other_insn happens to be last_combined_insn), next propagate_for_debug won't find the deleted insn in the stream and thus will search through the whole rest of the function and crash on dereferencing NULL NEXT_INSN. The following patch fixes it, bootstrapped/regtested on x86_64-linux and i686-linux (also with the patch attached after it), but it is mainly for discussion what to do. The propagate_for_debug change alone could fix it, we should never fall through into next basic block. We are unforuntately not deleting just jumps (which ought to appear at the end of bbs), but also any other noop moves, which I think is unintentional, we have delete_noop_moves that should clean that up instead (see the second patch). With the second patch, bootstrap succeeded even with gcc_assert (at_end); in update_cfg_for_uncondjump, so either it is always at the end, or at least very often, thus perhaps with the second patch being applied in combine_instructions we could just for INSN_DELETED_P clear last_combined_insn right away, meaning we want to propagate till end of current bb. 2011-04-11 Jakub Jelinek PR rtl-optimization/48549 * combine.c (propagate_for_debug): Also stop after BB_END of this_basic_block. (combine_instructions): If last_combined_insn has been deleted, set last_combined_insn to the next nondebug insn, or NULL if after the end of BB. (try_combine): Handle last_combined_insn being NULL. * g++.dg/opt/pr48549.C: New test. --- gcc/combine.c.jj 2011-04-10 19:05:25.000000000 +0200 +++ gcc/combine.c 2011-04-11 09:13:04.000000000 +0200 @@ -1179,7 +1179,7 @@ combine_instructions (rtx f, unsigned in FOR_EACH_BB (this_basic_block) { - rtx last_combined_insn = NULL_RTX; + rtx last_combined_insn = pc_rtx; optimize_this_for_speed_p = optimize_bb_for_speed_p (this_basic_block); last_call_luid = 0; mem_last_set = -1; @@ -1198,9 +1198,26 @@ combine_instructions (rtx f, unsigned in next = 0; if (NONDEBUG_INSN_P (insn)) { - if (last_combined_insn == NULL_RTX - || DF_INSN_LUID (last_combined_insn) < DF_INSN_LUID (insn)) + if (last_combined_insn == pc_rtx) last_combined_insn = insn; + else if (last_combined_insn) + { + if (INSN_DELETED_P (last_combined_insn)) + { + while (last_combined_insn + != NEXT_INSN (BB_END (this_basic_block)) + && (!NONDEBUG_INSN_P (last_combined_insn) + || INSN_DELETED_P (last_combined_insn))) + last_combined_insn = NEXT_INSN (last_combined_insn); + if (last_combined_insn + == NEXT_INSN (BB_END (this_basic_block))) + last_combined_insn = NULL_RTX; + } + if (last_combined_insn + && DF_INSN_LUID (last_combined_insn) + <= DF_INSN_LUID (insn)) + last_combined_insn = insn; + } /* See if we know about function return values before this insn based upon SUBREG flags. */ @@ -2451,14 +2468,14 @@ propagate_for_debug_subst (rtx from, con static void propagate_for_debug (rtx insn, rtx last, rtx dest, rtx src) { - rtx next, loc; + rtx next, loc, end = NEXT_INSN (BB_END (this_basic_block)); struct rtx_subst_pair p; p.to = src; p.adjusted = false; next = NEXT_INSN (insn); - while (next != last) + while (next != last && next != end) { insn = next; next = NEXT_INSN (insn); @@ -3904,8 +3921,9 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx first = i3; last = undobuf.other_insn; gcc_assert (last); - if (DF_INSN_LUID (last) - < DF_INSN_LUID (last_combined_insn)) + if (last_combined_insn == NULL_RTX + || (DF_INSN_LUID (last) + < DF_INSN_LUID (last_combined_insn))) last = last_combined_insn; } --- gcc/testsuite/g++.dg/opt/pr48549.C.jj 2011-04-11 08:35:03.000000000 +0200 +++ gcc/testsuite/g++.dg/opt/pr48549.C 2011-04-11 08:34:19.000000000 +0200 @@ -0,0 +1,63 @@ +// PR rtl-optimization/48549 +// { dg-do compile } +// { dg-options "-fcompare-debug -O2" } + +void +foo (void *from, void *to) +{ + long offset = reinterpret_cast (to) - reinterpret_cast (from); + if (offset != static_cast (offset)) + *(int *) 0xC0DE = 0; + reinterpret_cast (from)[1] = offset; +} +struct A +{ + A () : a () {} + A (void *x) : a (x) {} + void *bar () { return a; } + void *a; +}; +struct C; +struct D; +struct E : public A +{ + C m1 (int); + D m2 (); + E () {} + E (A x) : A (x) {} +}; +struct C : public E +{ + C () {} + C (void *x) : E (x) {} +}; +struct D : public E +{ + D (void *x) : E (x) {} +}; +C +E::m1 (int x) +{ + return (reinterpret_cast (bar ()) + x); +} +D +E::m2 () +{ + return reinterpret_cast (bar ()); +} +struct B +{ + E a; + unsigned b : 16; + unsigned c : 1; +}; +void +baz (B *x) +{ + for (unsigned i = 0; i < 64; i++) + { + D d = x[i].a.m2 (); + C c = x[i].a.m1 (x[i].c); + foo (d.bar (), c.bar ()); + } +} Jakub