Message ID | 20190530212655.GD19695@tucnak |
---|---|
State | New |
Headers | show |
Series | Fix ICE in ssa_create_duplicates (PR tree-optimization/90671) | expand |
On Thu, 30 May 2019, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs on the trunk, because both gsi_split_seq_after > and gsi_insert_seq_after have assertions that the split is not after > gsi_end_p iterator or insertion is not after such an iterator. > > My understanding of Alex' change is that it wants to hide any added > debug stmts temporarily from create_block_for_threading duplication, so that > it remains just in one of the blocks. Now, template_last_to_copy is > initialized using last_bb (template_block), if that block is initially > completely empty, template_last_to_copy will be gsi_end_p, gsi_stmt on it > NULL, so I think in that case we can't split any sequence anywhere, we > simply want to hide the whole sequence from the block duplication and put it > in afterwards. > > The following patch does that. Bootstrapped/regtested on x86_64-linux and > i686-linux, ok for trunk? OK. Richard. > 2019-05-30 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/90671 > * tree-ssa-threadupdate.c (ssa_create_duplicates): If > template_block used to be empty on the first call, don't use > gsi_split_seq_after and gsi_insert_seq_after, but remember whole > seq with bb_seq and set it with set_bb_seq. > > * gcc.dg/torture/pr90671.c: New test. > > --- gcc/tree-ssa-threadupdate.c.jj 2019-05-23 12:57:15.522512319 +0200 > +++ gcc/tree-ssa-threadupdate.c 2019-05-30 10:15:44.718468219 +0200 > @@ -1142,12 +1142,25 @@ ssa_create_duplicates (struct redirectio > gimple_seq seq = NULL; > if (gsi_stmt (local_info->template_last_to_copy) > != gsi_stmt (gsi_last_bb (local_info->template_block))) > - seq = gsi_split_seq_after (local_info->template_last_to_copy); > + { > + if (gsi_end_p (local_info->template_last_to_copy)) > + { > + seq = bb_seq (local_info->template_block); > + set_bb_seq (local_info->template_block, NULL); > + } > + else > + seq = gsi_split_seq_after (local_info->template_last_to_copy); > + } > create_block_for_threading (local_info->template_block, rd, 0, > &local_info->duplicate_blocks); > if (seq) > - gsi_insert_seq_after (&local_info->template_last_to_copy, > - seq, GSI_SAME_STMT); > + { > + if (gsi_end_p (local_info->template_last_to_copy)) > + set_bb_seq (local_info->template_block, seq); > + else > + gsi_insert_seq_after (&local_info->template_last_to_copy, > + seq, GSI_SAME_STMT); > + } > > /* Go ahead and wire up outgoing edges and update PHIs for the duplicate > block. */ > --- gcc/testsuite/gcc.dg/torture/pr90671.c.jj 2019-05-30 10:20:13.686068207 +0200 > +++ gcc/testsuite/gcc.dg/torture/pr90671.c 2019-05-30 10:19:50.815442342 +0200 > @@ -0,0 +1,16 @@ > +/* PR tree-optimization/90671 */ > +/* { dg-do compile } */ > +/* { dg-additional-options "-w -g" } */ > + > +int a; > + > +int > +main () > +{ > + int b, c; > + for (c = 0; c < 2; c++) > + while (a) > + if (b) > + break; > + return 0; > +} > > Jakub >
--- gcc/tree-ssa-threadupdate.c.jj 2019-05-23 12:57:15.522512319 +0200 +++ gcc/tree-ssa-threadupdate.c 2019-05-30 10:15:44.718468219 +0200 @@ -1142,12 +1142,25 @@ ssa_create_duplicates (struct redirectio gimple_seq seq = NULL; if (gsi_stmt (local_info->template_last_to_copy) != gsi_stmt (gsi_last_bb (local_info->template_block))) - seq = gsi_split_seq_after (local_info->template_last_to_copy); + { + if (gsi_end_p (local_info->template_last_to_copy)) + { + seq = bb_seq (local_info->template_block); + set_bb_seq (local_info->template_block, NULL); + } + else + seq = gsi_split_seq_after (local_info->template_last_to_copy); + } create_block_for_threading (local_info->template_block, rd, 0, &local_info->duplicate_blocks); if (seq) - gsi_insert_seq_after (&local_info->template_last_to_copy, - seq, GSI_SAME_STMT); + { + if (gsi_end_p (local_info->template_last_to_copy)) + set_bb_seq (local_info->template_block, seq); + else + gsi_insert_seq_after (&local_info->template_last_to_copy, + seq, GSI_SAME_STMT); + } /* Go ahead and wire up outgoing edges and update PHIs for the duplicate block. */ --- gcc/testsuite/gcc.dg/torture/pr90671.c.jj 2019-05-30 10:20:13.686068207 +0200 +++ gcc/testsuite/gcc.dg/torture/pr90671.c 2019-05-30 10:19:50.815442342 +0200 @@ -0,0 +1,16 @@ +/* PR tree-optimization/90671 */ +/* { dg-do compile } */ +/* { dg-additional-options "-w -g" } */ + +int a; + +int +main () +{ + int b, c; + for (c = 0; c < 2; c++) + while (a) + if (b) + break; + return 0; +}