linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 8/8] avoid creating unneeded phi-sources
Date: Thu, 13 Apr 2017 18:55:51 +0200	[thread overview]
Message-ID: <20170413165551.2785-9-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170413165551.2785-1-luc.vanoostenryck@gmail.com>

In rewrite_load_instruction(), it's tested if the dominators
are in fact all the same and if they are, as there is then no
need for a phi-node, the newly created OP_PHISRCs are killed
and the unique dominator is used in place of the phi-node.

But in this case, it's a waste to have created the OP_PHISRCs
as they are destroyed just after being created.

Fix this by basically switching the order 'creating phi sources'
and 'checking for uniqueness'. If the dominators are found to be
all the same then use this unique dominator as the loaded value
and no OP_PHISRC need to be created.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 flow.c                          | 17 ++++++++---------
 validation/loop-linearization.c | 30 +++++++++++++++---------------
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/flow.c b/flow.c
index d705abe2e..317074545 100644
--- a/flow.c
+++ b/flow.c
@@ -440,9 +440,7 @@ void rewrite_load_instruction(struct instruction *insn, struct instruction_list
 {
 	struct pseudo_list *dominators;
 	struct instruction *dom;
-	pseudo_t new, phi;
-
-	dominators = add_load_dominators(insn, doms, ident);
+	pseudo_t new;
 
 	/*
 	 * Check for somewhat common case of duplicate
@@ -456,17 +454,18 @@ void rewrite_load_instruction(struct instruction *insn, struct instruction_list
 	} END_FOR_EACH_PTR(dom);
 
 	/*
-	 * All the same pseudo - mark the phi-nodes unused
-	 * and convert the load into a LNOP and replace the
-	 * pseudo.
+	 * All the same pseudo - convert the load into a pseudo.
 	 */
-	FOR_EACH_PTR(dominators, phi) {
-		kill_instruction(phi->def);
-	} END_FOR_EACH_PTR(phi);
 	convert_load_instruction(insn, new);
 	return;
 
 complex_phi:
+	/*
+	 * Not identical pseudos - create a phisrc for each
+	 * dominators and convert the load into a phi-node.
+	 */
+	dominators = add_load_dominators(insn, doms, ident);
+
 	/* We leave symbol pseudos with a bogus usage list here */
 	if (insn->src->type != PSEUDO_SYM)
 		kill_use(&insn->src);
diff --git a/validation/loop-linearization.c b/validation/loop-linearization.c
index d53366bde..ab731dc15 100644
--- a/validation/loop-linearization.c
+++ b/validation/loop-linearization.c
@@ -39,11 +39,11 @@ static int fdo(void)
 ffor:
 .L0:
 	<entry-point>
-	phisrc.32   %phi5(i) <- $0
+	phisrc.32   %phi3(i) <- $0
 	br          .L4
 
 .L4:
-	phi.32      %r1(i) <- %phi5(i), %phi6(i)
+	phi.32      %r1(i) <- %phi3(i), %phi4(i)
 	setlt.32    %r2 <- %r1(i), $10
 	cbr         %r2, .L1, .L3
 
@@ -58,7 +58,7 @@ ffor:
 
 .L2:
 	add.32      %r7 <- %r1(i), $1
-	phisrc.32   %phi6(i) <- %r7
+	phisrc.32   %phi4(i) <- %r7
 	br          .L4
 
 .L3:
@@ -73,11 +73,11 @@ ffor:
 fwhile:
 .L8:
 	<entry-point>
-	phisrc.32   %phi11(i) <- $0
+	phisrc.32   %phi7(i) <- $0
 	br          .L12
 
 .L12:
-	phi.32      %r8(i) <- %phi11(i), %phi12(i)
+	phi.32      %r8(i) <- %phi7(i), %phi8(i)
 	setlt.32    %r9 <- %r8(i), $10
 	cbr         %r9, .L9, .L11
 
@@ -87,51 +87,51 @@ fwhile:
 	cbr         %r11, .L14, .L13
 
 .L13:
-	phisrc.32   %phi7(return) <- $0
+	phisrc.32   %phi5(return) <- $0
 	br          .L15
 
 .L14:
 	add.32      %r14 <- %r8(i), $1
-	phisrc.32   %phi12(i) <- %r14
+	phisrc.32   %phi8(i) <- %r14
 	br          .L12
 
 .L11:
-	phisrc.32   %phi8(return) <- $1
+	phisrc.32   %phi6(return) <- $1
 	br          .L15
 
 .L15:
-	phi.32      %r12 <- %phi7(return), %phi8(return)
+	phi.32      %r12 <- %phi5(return), %phi6(return)
 	ret.32      %r12
 
 
 fdo:
 .L16:
 	<entry-point>
-	phisrc.32   %phi16(i) <- $0
+	phisrc.32   %phi11(i) <- $0
 	br          .L17
 
 .L17:
-	phi.32      %r15(i) <- %phi16(i), %phi17(i)
+	phi.32      %r15(i) <- %phi11(i), %phi12(i)
 	push.32     %r15(i)
 	call.32     %r16 <- p
 	cbr         %r16, .L18, .L20
 
 .L20:
-	phisrc.32   %phi13(return) <- $0
+	phisrc.32   %phi9(return) <- $0
 	br          .L22
 
 .L18:
 	add.32      %r19 <- %r15(i), $1
 	setlt.32    %r20 <- %r15(i), $10
-	phisrc.32   %phi17(i) <- %r19
+	phisrc.32   %phi12(i) <- %r19
 	cbr         %r20, .L17, .L19
 
 .L19:
-	phisrc.32   %phi14(return) <- $1
+	phisrc.32   %phi10(return) <- $1
 	br          .L22
 
 .L22:
-	phi.32      %r17 <- %phi13(return), %phi14(return)
+	phi.32      %r17 <- %phi9(return), %phi10(return)
 	ret.32      %r17
 
 
-- 
2.12.0


  parent reply	other threads:[~2017-04-13 16:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 16:55 [PATCH 0/8] avoid creating orphaned OP_PHISRCs Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 1/8] extract add_dominator() from find_dominating_parents() Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 2/8] add helper add_load_dominators() Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 3/8] remove test on initial phi->ident Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 4/8] avoid phisrc orphaned by simplify_loads() Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 5/8] avoid phisrc orphaned by find_dominating_stores() Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 6/8] integrate add_load_dominators() into rewrite_load_instruction() Luc Van Oostenryck
2017-04-13 16:55 ` [PATCH 7/8] check duplicated phi-nodes directly on dominators Luc Van Oostenryck
2017-04-13 16:55 ` Luc Van Oostenryck [this message]
2017-05-18 17:04 ` [PATCH 0/8] avoid creating orphaned OP_PHISRCs Luc Van Oostenryck

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=20170413165551.2785-9-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.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 NNTP newsgroup(s).