public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: gcc-patches@gcc.gnu.org
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Subject: [PATCH] cfgcleanup: Ignore clobbers in bb_is_just_return
Date: Thu, 18 May 2017 21:20:00 -0000	[thread overview]
Message-ID: <8852455d0f86e667cf5adab3310fde9153b29286.1495140549.git.segher@kernel.crashing.org> (raw)

The function bb_is_just_return finds if the BB it is asked about does
just a return and nothing else.  It currently does not allow clobbers
in the block either, which we of course can allow just fine.

This patch changes that.  Bootstrapped and tested on powerpc64-linux
{-m32,-m64} (and tested that the new test fails before the patch, too).
Is this okay for trunk?


Segher


2017-05-18  Segher Boessenkool  <segher@kernel.crashing.org>

	* cfgcleanup.c (bb_is_just_return): Allow CLOBBERs.

gcc/testsuite/
	* gcc.target/powerpc/conditional-return.c: New testcase.

---
 gcc/cfgcleanup.c                                      | 14 ++++++++------
 gcc/testsuite/gcc.target/powerpc/conditional-return.c | 15 +++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/conditional-return.c

diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index f68a964..3e1406c 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -2666,7 +2666,7 @@ trivially_empty_bb_p (basic_block bb)
 
 /* Return true if BB contains just a return and possibly a USE of the
    return value.  Fill in *RET and *USE with the return and use insns
-   if any found, otherwise NULL.  */
+   if any found, otherwise NULL.  All CLOBBERs are ignored.  */
 
 static bool
 bb_is_just_return (basic_block bb, rtx_insn **ret, rtx_insn **use)
@@ -2680,13 +2680,15 @@ bb_is_just_return (basic_block bb, rtx_insn **ret, rtx_insn **use)
   FOR_BB_INSNS (bb, insn)
     if (NONDEBUG_INSN_P (insn))
       {
-	if (!*ret && ANY_RETURN_P (PATTERN (insn)))
+	rtx pat = PATTERN (insn);
+
+	if (!*ret && ANY_RETURN_P (pat))
 	  *ret = insn;
-	else if (!*ret && !*use && GET_CODE (PATTERN (insn)) == USE
-	    && REG_P (XEXP (PATTERN (insn), 0))
-	    && REG_FUNCTION_VALUE_P (XEXP (PATTERN (insn), 0)))
+	else if (!*ret && !*use && GET_CODE (pat) == USE
+	    && REG_P (XEXP (pat, 0))
+	    && REG_FUNCTION_VALUE_P (XEXP (pat, 0)))
 	  *use = insn;
-	else
+	else if (GET_CODE (pat) != CLOBBER)
 	  return false;
       }
 
diff --git a/gcc/testsuite/gcc.target/powerpc/conditional-return.c b/gcc/testsuite/gcc.target/powerpc/conditional-return.c
new file mode 100644
index 0000000..6b3ef5f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/conditional-return.c
@@ -0,0 +1,15 @@
+/* Check that a conditional return is used.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -w" } */
+
+/* { dg-final { scan-assembler {\mbeqlr\M} } } */
+
+
+int f(int x)
+{
+	if (x)
+		return x + 31;
+
+	return;
+}
-- 
1.9.3

             reply	other threads:[~2017-05-18 20:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-18 21:20 Segher Boessenkool [this message]
2017-05-22  3:47 ` Jeff Law

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=8852455d0f86e667cf5adab3310fde9153b29286.1495140549.git.segher@kernel.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=gcc-patches@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).