public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE in ssa_create_duplicates (PR tree-optimization/90671)
@ 2019-05-30 21:42 Jakub Jelinek
  2019-05-30 21:54 ` Jakub Jelinek
  2019-05-31  8:38 ` Richard Biener
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2019-05-30 21:42 UTC (permalink / raw)
  To: Richard Biener, Jeff Law, lxo; +Cc: gcc-patches

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?

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-31  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-30 21:42 [PATCH] Fix ICE in ssa_create_duplicates (PR tree-optimization/90671) Jakub Jelinek
2019-05-30 21:54 ` Jakub Jelinek
2019-05-31  8:38 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).