public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102402] Seemingly suboptimal optimization of jmp/cmovcc for conditionally loading constants
Date: Sat, 18 Sep 2021 18:35:05 +0000	[thread overview]
Message-ID: <bug-102402-4-nEUXVJDK2V@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102402-4@http.gcc.gnu.org/bugzilla/>

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
          Component|target                      |tree-optimization
   Last reconfirmed|                            |2021-09-18
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, note the best code is generated by:
void ClearModM1(struct MusicPlayerTrack *track, uint8_t modT)
{
    int t =0;
    if (track->modT == 0)
        t = 3;
    else
        t = 12;
    track->flags |= t;
}

This is then a gimple level issue where:
  if (_1 == 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870913]:
  _3 = pretmp_6 | 3;
  goto <bb 5>; [100.00%]

  <bb 4> [local count: 536870913]:
  _5 = pretmp_6 | 12;

  <bb 5> [local count: 1073741824]:
  # cstore_12 = PHI <_3(3), _5(4)>
is not transformed into:
    if (track->modT == 0)
        t = 3;
    else
        t = 12;
cstore_12 = pretmp_6  | t;

There is also a sinking issue though I don't know if has a wider effect (and
does not matter in this case really).
Take:
void ClearModM1(struct MusicPlayerTrack *track, uint8_t modT)
{
    int t =0;
    int t2 = track->modT;
    int t1 = track->flags;
    if (t2 == 0)
        t = 3;
    else
        t = 12;
    track->flags = t1|t;
}
The load for track->flags is not sunk after the if.

      reply	other threads:[~2021-09-18 18:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18 18:17 [Bug target/102402] New: " gabravier at gmail dot com
2021-09-18 18:35 ` pinskia at gcc dot gnu.org [this message]

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-102402-4-nEUXVJDK2V@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).