public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable
@ 2020-08-19 13:26 gabravier at gmail dot com
  2020-08-19 13:30 ` [Bug tree-optimization/96708] " gabravier at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2020-08-19 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96708
           Summary: Failure to optimize max pattern with comparison when
                    using a temporary variable
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

bool f(int a, int b)
{
    int tmp = (a < b) ? b : a;
    return tmp >= a;
}

This can be optimized to `return true;`. This transformation is done by LLVM,
but not by GCC.

PS: This is probably related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95926.

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

* [Bug tree-optimization/96708] Failure to optimize max pattern with comparison when using a temporary variable
  2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
@ 2020-08-19 13:30 ` gabravier at gmail dot com
  2020-08-24 20:12 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2020-08-19 13:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
PS: This especially affects, for example, C++ code that uses std::max, which
fails to optimize properly compared to, for example, a `max` macro.

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

* [Bug tree-optimization/96708] Failure to optimize max pattern with comparison when using a temporary variable
  2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
  2020-08-19 13:30 ` [Bug tree-optimization/96708] " gabravier at gmail dot com
@ 2020-08-24 20:12 ` pinskia at gcc dot gnu.org
  2020-08-25 11:09 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-08-24 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

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/96708] Failure to optimize max pattern with comparison when using a temporary variable
  2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
  2020-08-19 13:30 ` [Bug tree-optimization/96708] " gabravier at gmail dot com
  2020-08-24 20:12 ` pinskia at gcc dot gnu.org
@ 2020-08-25 11:09 ` rguenth at gcc dot gnu.org
  2020-12-01 23:29 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-25 11:09 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |easyhack
   Last reconfirmed|                            |2020-08-25
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

  _4 = MAX_EXPR <a_2(D), b_3(D)>;
  _7 = a_2(D) <= _4;
  return _7;

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

* [Bug tree-optimization/96708] Failure to optimize max pattern with comparison when using a temporary variable
  2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-08-25 11:09 ` rguenth at gcc dot gnu.org
@ 2020-12-01 23:29 ` cvs-commit at gcc dot gnu.org
  2020-12-01 23:29 ` law at redhat dot com
  2023-09-11  2:21 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-01 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <law@gcc.gnu.org>:

https://gcc.gnu.org/g:abef36919f741c8e4f7380b2c2ffbc6ad97c2b6b

commit r11-5631-gabef36919f741c8e4f7380b2c2ffbc6ad97c2b6b
Author: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com>
Date:   Tue Dec 1 16:26:59 2020 -0700

    Optimize max/min pattern with comparison

    gcc/
            PR tree-optimization/96708
            * match.pd: New pattern for comparing X with MAX (X, Y)
            or MIN (X, y).

    gcc/testsuite
            * gcc.dg/pr96708-negative.c: New test.
            * gcc.dg/pr96708-positive.c: New test.

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

* [Bug tree-optimization/96708] Failure to optimize max pattern with comparison when using a temporary variable
  2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2020-12-01 23:29 ` cvs-commit at gcc dot gnu.org
@ 2020-12-01 23:29 ` law at redhat dot com
  2023-09-11  2:21 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: law at redhat dot com @ 2020-12-01 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at redhat dot com
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Jeffrey A. Law <law at redhat dot com> ---
Should be fixed with Eugene's patch on the trunk

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

* [Bug tree-optimization/96708] Failure to optimize max pattern with comparison when using a temporary variable
  2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
                   ` (4 preceding siblings ...)
  2020-12-01 23:29 ` law at redhat dot com
@ 2023-09-11  2:21 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-11  2:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note this was mostly fixed for GCC 11 but had missed the :c on the cmp and that
was fully fixed in GCC 14, see PR 111346 for that. What that means is sometimes
we would not optimize always to 0/1 and keep around the comparison.

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

end of thread, other threads:[~2023-09-11  2:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 13:26 [Bug tree-optimization/96708] New: Failure to optimize max pattern with comparison when using a temporary variable gabravier at gmail dot com
2020-08-19 13:30 ` [Bug tree-optimization/96708] " gabravier at gmail dot com
2020-08-24 20:12 ` pinskia at gcc dot gnu.org
2020-08-25 11:09 ` rguenth at gcc dot gnu.org
2020-12-01 23:29 ` cvs-commit at gcc dot gnu.org
2020-12-01 23:29 ` law at redhat dot com
2023-09-11  2:21 ` 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).