public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jskumari at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/103784] suboptimal code for returning bool value on target ppc
Date: Sun, 05 Mar 2023 11:48:39 +0000	[thread overview]
Message-ID: <bug-103784-4-HDgtBHstt5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103784-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103784

--- Comment #10 from Surya Kumari Jangala <jskumari at gcc dot gnu.org> ---
After the expand pass, we have a single return bb which first zero extends r117
(this reg holds the return value which has been set by predecessor blocks).
Zero extension is done because r117 is of mode QI and we want to change the
mode to DI. After zero extension, r117 is copied to r3.

The input RTL to the peephole2 pass is similar, ie, the writing of value to r3
occurs in predecessor BBs while zero extension of r3 happens in the return bb.
So we cannot do any peephole optimization to get rid of the unnecessary zero
extension.
Note that when return value is written into r3, it has mode QI. Later in the
return bb, r3 is zero extended to convert it's mode into DI.

However, after the bbro (basic block reordering) pass, we have 2 return BBs.
And in each BB, the return value is copied into r3 (in QI mode), and then r3 is
zero extended. Note that bbro occurs after peephole2.
We can do another peephole after bbro, and get rid of the unnecessary zero
extension.
However, we need not always get an opportunity to do a peephole. That is, the
instructions that write into r3 and zero extend r3 can be in different BBs.

A possible solution to this issue would be to have a separate pass that can
remove the zero extends.

In brief, the new pass can do the following:

Fist create webs.
Then find definitions (that is, writes into registers) that reach zero extend
insns.
Mark such definitions (to indicate that the value is going to be zero extended
later on), and then at the time of assembly generation (final pass),
definitions which have been marked should be converted to assembly instructions
which work on the extended mode (for example, with -m64, the generated assembly
should work on the entire 64bit register instead of just a part of it.).
If we generate such assembly instructions, then the zero extend instruction can
be removed, ie, no assembly need be generated.

Note that for definitions that reach zero extends as well as other uses, we
cannot remove the zero extends.

  parent reply	other threads:[~2023-03-05 11:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21  1:42 [Bug target/103784] New: " guihaoc at gcc dot gnu.org
2021-12-21  1:46 ` [Bug target/103784] " pinskia at gcc dot gnu.org
2021-12-21  2:35 ` guihaoc at gcc dot gnu.org
2021-12-21  2:43 ` pinskia at gcc dot gnu.org
2021-12-21  3:02 ` guihaoc at gcc dot gnu.org
2023-01-04 14:07 ` segher at gcc dot gnu.org
2023-01-04 14:08 ` segher at gcc dot gnu.org
2023-01-04 14:13 ` segher at gcc dot gnu.org
2023-01-05 16:34 ` jskumari at gcc dot gnu.org
2023-03-01  4:04 ` jskumari at gcc dot gnu.org
2023-03-05 11:48 ` jskumari at gcc dot gnu.org [this message]
2023-03-05 15:41 ` dje at gcc dot gnu.org
2023-03-05 19:27 ` segher at gcc dot gnu.org
2023-03-06  8:14 ` jskumari at gcc dot gnu.org
2023-03-16  9:52 ` rguenth at gcc dot gnu.org
2023-04-11 17:07 ` aagarwa at gcc dot gnu.org
2023-07-20 11:15 ` jskumari at gcc dot gnu.org
2023-08-31  8:03 ` aagarwa at gcc dot gnu.org

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=bug-103784-4-HDgtBHstt5@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).