Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard.
2016-07-15 Richard Biener <rguent...@suse.de> PR tree-optimization/71881 * tree-loop-distribution.c (destroy_loop): Remove blocks in reverse DOM order to make debug temp generation happy. * gcc.dg/torture/pr71881.c: New testcase. Index: gcc/tree-loop-distribution.c =================================================================== *** gcc/tree-loop-distribution.c (revision 238364) --- gcc/tree-loop-distribution.c (working copy) *************** destroy_loop (struct loop *loop) *** 888,900 **** cancel_loop_tree (loop); rescan_loop_exit (exit, false, true); ! for (i = 0; i < nbbs; i++) { /* We have made sure to not leave any dangling uses of SSA names defined in the loop. With the exception of virtuals. Make sure we replace all uses of virtual defs that will remain outside of the loop with the bare symbol as delete_basic_block will release them. */ for (gphi_iterator gsi = gsi_start_phis (bbs[i]); !gsi_end_p (gsi); gsi_next (&gsi)) { --- 891,905 ---- cancel_loop_tree (loop); rescan_loop_exit (exit, false, true); ! i = nbbs; ! do { /* We have made sure to not leave any dangling uses of SSA names defined in the loop. With the exception of virtuals. Make sure we replace all uses of virtual defs that will remain outside of the loop with the bare symbol as delete_basic_block will release them. */ + --i; for (gphi_iterator gsi = gsi_start_phis (bbs[i]); !gsi_end_p (gsi); gsi_next (&gsi)) { *************** destroy_loop (struct loop *loop) *** 912,917 **** --- 917,924 ---- } delete_basic_block (bbs[i]); } + while (i != 0); + free (bbs); set_immediate_dominator (CDI_DOMINATORS, dest, Index: gcc/testsuite/gcc.dg/torture/pr71881.c =================================================================== *** gcc/testsuite/gcc.dg/torture/pr71881.c (revision 0) --- gcc/testsuite/gcc.dg/torture/pr71881.c (working copy) *************** *** 0 **** --- 1,25 ---- + /* { dg-do compile } */ + /* { dg-additional-options "-g" } */ + + int a, b, c, d, *e, f, g; + + int fn1 () + { + char h[2]; + int i = 0; + for (; i < 2; i++) + { + if (c) + for (*e = 0; *e;) + { + int j[f]; + i = *e; + } + h[i] = 0; + } + for (; a;) + return h[0]; + for (b = 0; b;) + i = g = (1 & i) < d; + return 0; + }