public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [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
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20  3:08 UTC (permalink / raw)
  To: gcc-bugs

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 #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The original testcase in comment #0 is fixed in GCC 8, I don't know what caused
the improvement though.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
  2021-07-20  3:08 ` [Bug tree-optimization/80574] GCC fail to optimize nested ternary 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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20  3:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
  2021-07-20  3:08 ` [Bug tree-optimization/80574] GCC fail to optimize nested ternary 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
  2023-07-20 20:49 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-02  4:29 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-05-02  4:29 ` pinskia at gcc dot gnu.org
@ 2023-07-20 20:49 ` pinskia at gcc dot gnu.org
  2023-07-21  4:09 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-20 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
One thing I noticed is that:
  _2 = MAX_EXPR <_6, a3_7(D)>;
  _3 = MAX_EXPR <_2, a3_7(D)>;

Is not optimized at all.

(for minmax (min max)
 (simplify
  (minmax:c (minmax:c@2 @0 @1) @0)
  @2))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-21  4:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #9)
> One thing I noticed is that:
>   _2 = MAX_EXPR <_6, a3_7(D)>;
>   _3 = MAX_EXPR <_2, a3_7(D)>;
> 
> Is not optimized at all.
> 
> (for minmax (min max)
>  (simplify
>   (minmax:c (minmax:c@2 @0 @1) @0)
>   @2))

Submitted the patch for that as
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/625135.html .
Note after that patch we get decent code for the original testcases but it is
not fully optimized at the gimple level.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-21  7:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:6d449531a60b56ed0f4aeb640aa9e46e4ec35208

commit r14-2698-g6d449531a60b56ed0f4aeb640aa9e46e4ec35208
Author: Andrew Pinski <apinski@marvell.com>
Date:   Thu Jul 20 17:36:29 2023 -0700

    MATCH: Add Max<Max<a,b>,a> -> Max<a,b> simplifcation

    This adds a simple match pattern to simplify
    `max<max<a,b>,a>` to `max<a,b>`.  Reassociation handles
    this already (r0-77700-ge969dbde29bfd396259357) but
    seems like we should be able to handle this even before
    reassociation.

    This fixes part of PR tree-optimization/80574 but more
    work is needed fix it the rest of the way. The original
    testcase there is fixed but the RTL level is what fixes
    it the rest of the way.

    OK? Bootstrapped and tested on x86_64-linux-gnu.

    gcc/ChangeLog:

            * match.pd (minmax<minmax<a,b>,a>->minmax<a,b>): New
            transformation.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/reassoc-12.c: Disable all of
            the passes that enables match-and-simplify.
            * gcc.dg/tree-ssa/minmax-23.c: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug tree-optimization/80574] GCC fail to optimize nested ternary
       [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2023-07-21  7:34 ` cvs-commit at gcc dot gnu.org
@ 2023-07-21  7:43 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-21  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the original example in comment #0 is now optimized for GCC 14 but only at
the RTL level rather than the gimple level.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-21  7:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-80574-4@http.gcc.gnu.org/bugzilla/>
2021-07-20  3:08 ` [Bug tree-optimization/80574] GCC fail to optimize nested ternary 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
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

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).