public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/67962] Optimization opportunity with conditional swap to two MIN/MAX in phiopt
Date: Fri, 21 Jul 2023 08:26:11 +0000	[thread overview]
Message-ID: <bug-67962-4-LU7LF6j8tQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-67962-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Mine, but for gcc 13.  The main problem I see if two cmov might be slower
> than a branch on x86_64 processors.

Two cmov definitely, a min/max pair not.

Now, phiopt will turn

  <bb 2> :
  if (y_16(D) < x_17(D))
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :

  <bb 4> :
  # x_14 = PHI <x_17(D)(2), y_16(D)(3)>
  if (y_16(D) < x_17(D))
    goto <bb 5>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 5> :

  <bb 6> :
  # y_15 = PHI <y_16(D)(2), x_17(D)(3)>

into the desired pair but fails for the equivalent

  <bb 2> :
  if (y_16(D) < x_17(D))
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :

  <bb 4> :
  # x_14 = PHI <x_17(D)(2), y_16(D)(3)>
  # y_15 = PHI <y_16(D)(2), x_17(D)(3)>

We do value-replacement for more than one PHI but not others, not exactly
sure why.  We could dry-run convert all PHIs and only if that succeeds
and the condition goes away perform the transforms.  Of course some
transforms might still not be profitable then.

      parent reply	other threads:[~2023-07-21  8:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 11:06 [Bug c++/67962] New: Optimization opportunity with conditional swap morwenn29 at hotmail dot fr
2015-10-14 11:44 ` [Bug tree-optimization/67962] Optimization opportunity with conditional swap to two MIN/MAX in phiopt rguenth at gcc dot gnu.org
2021-08-30  5:45 ` pinskia at gcc dot gnu.org
2023-07-21  8:26 ` rguenth 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-67962-4-LU7LF6j8tQ@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).