public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ktkachov at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/67635] [SH] ifcvt missed optimization
Date: Mon, 19 Oct 2015 16:06:00 -0000	[thread overview]
Message-ID: <bug-67635-4-hpp1RKJyg6@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-67635-4@http.gcc.gnu.org/bugzilla/>

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

ktkachov at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ktkachov at gcc dot gnu.org

--- Comment #2 from ktkachov at gcc dot gnu.org ---
I had a look at:
unsigned int test_03 (unsigned int x)
{
  return x > 0 ? x + 1 : x;
}

The cse1 pass transforms this into something not quite comfortable for ifcvt.
Basically, it transforms the RTL equivalent of:

compare (x, 0);
if (x > 0)
  temp := x + 1;
else
  temp := x;
return temp;

into:
compare (x, 0);
if (x > 0)
  temp := x + 1;
else
  temp := 0;
return temp;

which is a valid transformation to make as far as cse is concerned.
Unfortunately, when ifcvt comes along, it's asked to optimise a conditional
select between '0' and 'x + 1', which is not something it can do with an
addc-style pattern.

I initially thought of looking into the condition to see if it contains x (so
that we can deduce that the 'else' arm could actually be replaced with x,
undoing the cse in that case), but the condition rtl contains a comparison with
the T-register, rather than the original comparison with 0.

Perhaps we can consider teaching cse to not transform these kinds of
expressions (c ? x : x + a) if the target has a store_flag/addcc instruction of
the appropriate mode?

But I'm not familiar with the cse code, so I don't know how easy/clean that is


  parent reply	other threads:[~2015-10-19 16:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19  4:09 [Bug rtl-optimization/67635] New: " olegendo at gcc dot gnu.org
2015-09-30 12:49 ` [Bug rtl-optimization/67635] " olegendo at gcc dot gnu.org
2015-10-19 16:06 ` ktkachov at gcc dot gnu.org [this message]
2015-10-21 13:51 ` olegendo at gcc dot gnu.org
2023-08-08  7:02 ` pinskia 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-67635-4-hpp1RKJyg6@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).