From: Ajit Agarwal <aagarwa1@linux.ibm.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
bergner@linux.ibm.com, Jeff Law <jeffreyalaw@gmail.com>,
Richard Biener <richard.guenther@gmail.com>
Subject: [PATCH v2] rs6000: suboptimal code for returning bool value on target ppc
Date: Sun, 19 Mar 2023 17:15:47 +0530 [thread overview]
Message-ID: <e77f9c93-af16-a548-8d6b-d1954a11f02f@linux.ibm.com> (raw)
Hello All:
This patch eliminates unncessary zero extension with ree pass.
Bootstrapped and regtested on powerpc64-linux-gnu.
Thanks & Regards
Ajit
rs6000: suboptimal code for returning bool value on
target ppc.
Eliminate unnecessary redundantzero extension.
2023-03-19 Ajit Kumar Agarwal <aagarwa1@linux.ibm.com>
gcc/ChangeLog:
* ree.cc: Add support of AND opcode to eliminate unnecessary
zero extension.
---
gcc/ree.cc | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/gcc/ree.cc b/gcc/ree.cc
index 413aec7c8eb..d09f55149b1 100644
--- a/gcc/ree.cc
+++ b/gcc/ree.cc
@@ -319,7 +319,7 @@ combine_set_extension (ext_cand *cand, rtx_insn *curr_insn, rtx *orig_set)
{
rtx orig_src = SET_SRC (*orig_set);
machine_mode orig_mode = GET_MODE (SET_DEST (*orig_set));
- rtx new_set;
+ rtx new_set = NULL_RTX;
rtx cand_pat = single_set (cand->insn);
/* If the extension's source/destination registers are not the same
@@ -370,7 +370,7 @@ combine_set_extension (ext_cand *cand, rtx_insn *curr_insn, rtx *orig_set)
{
/* Only IF_THEN_ELSE of phi-type copies are combined. Otherwise,
in general, IF_THEN_ELSE should not be combined. */
- return false;
+ return true;
}
else
{
@@ -713,12 +713,15 @@ merge_def_and_ext (ext_cand *cand, rtx_insn *def_insn, ext_state *state)
if (sub_rtx == NULL)
return false;
- if (GET_MODE (SET_DEST (*sub_rtx)) == ext_src_mode
+ bool copy_needed
+ = (REGNO (SET_DEST (cand->expr)) != REGNO (XEXP (SET_SRC (cand->expr), 0)));
+
+ if (!copy_needed || (GET_MODE (SET_DEST (*sub_rtx)) == ext_src_mode
|| ((state->modified[INSN_UID (def_insn)].kind
- == (cand->code == ZERO_EXTEND
+ == (cand->code == ZERO_EXTEND || cand->code == AND
? EXT_MODIFIED_ZEXT : EXT_MODIFIED_SEXT))
&& state->modified[INSN_UID (def_insn)].mode
- == ext_src_mode))
+ == ext_src_mode)))
{
if (GET_MODE_UNIT_SIZE (GET_MODE (SET_DEST (*sub_rtx)))
>= GET_MODE_UNIT_SIZE (cand->mode))
@@ -744,7 +747,8 @@ merge_def_and_ext (ext_cand *cand, rtx_insn *def_insn, ext_state *state)
static inline rtx
get_extended_src_reg (rtx src)
{
- while (GET_CODE (src) == SIGN_EXTEND || GET_CODE (src) == ZERO_EXTEND)
+ while (GET_CODE (src) == SIGN_EXTEND || GET_CODE (src) == ZERO_EXTEND
+ || GET_CODE (src) == AND)
src = XEXP (src, 0);
gcc_assert (REG_P (src));
return src;
@@ -993,7 +997,7 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state)
machine_mode mode;
if (state->modified[INSN_UID (cand->insn)].kind
- != (cand->code == ZERO_EXTEND
+ != (cand->code == ZERO_EXTEND || cand->code == AND
? EXT_MODIFIED_ZEXT : EXT_MODIFIED_SEXT)
|| state->modified[INSN_UID (cand->insn)].mode != cand->mode
|| (set == NULL_RTX))
@@ -1052,7 +1056,7 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state)
{
ext_modified *modified = &state->modified[INSN_UID (def_insn)];
if (modified->kind == EXT_MODIFIED_NONE)
- modified->kind = (cand->code == ZERO_EXTEND ? EXT_MODIFIED_ZEXT
+ modified->kind = (cand->code == ZERO_EXTEND || cand->code == AND ? EXT_MODIFIED_ZEXT
: EXT_MODIFIED_SEXT);
if (copy_needed)
@@ -1106,7 +1110,7 @@ add_removable_extension (const_rtx expr, rtx_insn *insn,
mode = GET_MODE (dest);
if (REG_P (dest)
- && (code == SIGN_EXTEND || code == ZERO_EXTEND)
+ && (code == SIGN_EXTEND || code == ZERO_EXTEND || code == AND)
&& REG_P (XEXP (src, 0)))
{
rtx reg = XEXP (src, 0);
--
2.31.1
reply other threads:[~2023-03-19 11:45 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=e77f9c93-af16-a548-8d6b-d1954a11f02f@linux.ibm.com \
--to=aagarwa1@linux.ibm.com \
--cc=bergner@linux.ibm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=richard.guenther@gmail.com \
--cc=segher@kernel.crashing.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).