public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/marxin/heads/loop-unswitching-switch)] WIP changes.
Date: Tue, 31 Aug 2021 14:33:54 +0000 (GMT)	[thread overview]
Message-ID: <20210831143354.7F4C33857C56@sourceware.org> (raw)

https://gcc.gnu.org/g:9a2cb6a46aac3bf69e7158d876d1f6391c7d7229

commit 9a2cb6a46aac3bf69e7158d876d1f6391c7d7229
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Aug 31 11:50:33 2021 +0200

    WIP changes.

Diff:
---
 gcc/tree-ssa-loop-unswitch.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
index c2100489b7f..c7cf0223501 100644
--- a/gcc/tree-ssa-loop-unswitch.c
+++ b/gcc/tree-ssa-loop-unswitch.c
@@ -391,14 +391,25 @@ tree_unswitch_single_loop (class loop *loop, int num)
 	      tree lab = gimple_switch_label (gs, 1);
 	      basic_block dest = label_to_block (cfun, CASE_LABEL (lab));
 	      edge e = find_edge (gimple_bb (stmt), dest);
+	      unsigned nlabels = gimple_switch_num_labels (gs);
+	      for (unsigned i = 1; i < nlabels - 1; i++)
+		{
+		  tree next_label = gimple_switch_label (gs, i + 1);
+		  gimple_switch_set_label (gs, i, next_label);
+		  basic_block next_dest
+		    = label_to_block (cfun, CASE_LABEL (next_label));
+
+		  /* Shared edge among multiple cases.  */ 
+		  if (e != NULL && e->dest == next_dest)
+		    e = NULL;
+		}
 	      // modifying the CFG here may play havoc on things like
 	      // dominators and we really would like to prevent doing
 	      // full update_ssa for each individual unswitching as well
-	      remove_edge (e);
-	      if (gimple_switch_num_labels (gs) > 1)
-		gimple_switch_set_label (gs, 1,
-					 gimple_switch_label (gs, gimple_switch_num_labels (gs) - 1));
-	      gimple_switch_set_num_labels (gs, gimple_switch_num_labels (gs) - 1);
+	      if (e != NULL)
+		remove_edge (e);
+
+	      gimple_switch_set_num_labels (gs, nlabels  - 1);
 	      end_recording_case_labels ();
 	      /* Update based on the adjusted switch.  */
 	      cond = tree_may_unswitch_on (bbs[i], loop);
@@ -406,7 +417,7 @@ tree_unswitch_single_loop (class loop *loop, int num)
 	  changed = true;
 	}
       // As said, it's a bit hackish to do it this way.  */
-      if (TREE_CODE (cond) == INTEGER_CST)
+      if (cond == NULL_TREE || TREE_CODE (cond) == INTEGER_CST)
 	;
       /* Do not unswitch too much.  */
       else if (num > param_max_unswitch_level)
@@ -524,8 +535,10 @@ tree_unswitch_single_loop (class loop *loop, int num)
   free_original_copy_tables ();
 
   /* Invoke itself on modified loops.  */
-  tree_unswitch_single_loop (nloop, num + 1);
-  tree_unswitch_single_loop (loop, num + 1);
+  if (nloop->aux != (void *)0xa5a5a5a5a5a5a5a5)
+    tree_unswitch_single_loop (nloop, num + 1);
+  if (loop->aux != (void *)0xa5a5a5a5a5a5a5a5)
+    tree_unswitch_single_loop (loop, num + 1);
   free (bbs);
   return true;
 }


                 reply	other threads:[~2021-08-31 14:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210831143354.7F4C33857C56@sourceware.org \
    --to=marxin@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).