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/80574] GCC fail to optimize nested ternary
Date: Tue, 02 May 2023 04:29:25 +0000	[thread overview]
Message-ID: <bug-80574-4-CBd66MTVSJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-80574-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|8.0                         |---

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #7)
> The original testcase in comment #0 is fixed in GCC 8, I don't know what
> caused the improvement though.

Well actually if you use the C++ front-end, it still fails.

for f2_signed, we start out as:
  _1 = MAX_EXPR <a3_4(D), a2_5(D)>;
  if (_1 >= a1_6(D))
    goto <bb 3>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 3> :
  if (a3_4(D) < a2_5(D))
    goto <bb 6>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 4> :

  <bb 6> :
  # iftmp.5_2 = PHI <a3_4(D)(4), a1_6(D)(2), a2_5(D)(3)>
  return iftmp.5_2;

phiopt1 transforms it to:
  _1 = MAX_EXPR <a3_4(D), a2_5(D)>;
  if (_1 >= a1_6(D))
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  _3 = MAX_EXPR <a3_4(D), a2_5(D)>;

  <bb 4> :
  # iftmp.12_2 = PHI <_3(3), a1_6(D)(2)>

Which is perfect.
But then we don't exactly patch that _1 and _3 are the same though we do try to
simplify it at least on the trunk:
phiopt match-simplify trying:
        _1 >= a1_6(D) ? _3 : a1_6(D)

phiopt match-simplify trying:
        _1 < a1_6(D) ? a1_6(D) : _3

What happens afterwards is fre (or is it pre) figures out _1 and _3 are the
same and get:
  if (_1 >= a1_6(D))
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :

  <bb 4> :
  # iftmp.12_2 = PHI <_1(3), a1_6(D)(2)>

Which then phiopt2 is able to simplify.
So if we iterate phiopt and fre we should able to handle all of these but that
is NOT a reasonable solution.
I have to think of a good way of solving these really.

  parent reply	other threads:[~2023-05-02  4:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
2021-07-20  3:08 ` pinskia at gcc dot gnu.org
2021-07-20  3:08 ` pinskia at gcc dot gnu.org
2023-05-02  4:29 ` pinskia at gcc dot gnu.org [this message]
2023-07-20 20:49 ` pinskia at gcc dot gnu.org
2023-07-21  4:09 ` pinskia at gcc dot gnu.org
2023-07-21  7:34 ` cvs-commit at gcc dot gnu.org
2023-07-21  7:43 ` 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-80574-4-CBd66MTVSJ@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).