public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
@ 2023-09-10 21:11 pinskia at gcc dot gnu.org
  2023-09-10 21:11 ` [Bug tree-optimization/111364] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-10 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111364
           Summary: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

I Noticed this while looking into PR 111346:
```
_Bool test2(int a, int b)
{
        int t = a;
        if (t < b) t = b;
        return t <= a;
}
```
Should be optimized to just:
```
        return a >= b;
```

There is a pattern for constants:
/* MIN (X, C1) < C2 -> X < C2 || C1 < C2  */
But we could do the same when we know C1 == C2 and not constant (for
!HONOR_NANS & !HONOR_SIGNED_ZEROS).

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
@ 2023-09-10 21:11 ` pinskia at gcc dot gnu.org
  2023-09-12  0:14 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-10 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-09-10
             Status|UNCONFIRMED                 |ASSIGNED

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
  2023-09-10 21:11 ` [Bug tree-optimization/111364] " pinskia at gcc dot gnu.org
@ 2023-09-12  0:14 ` pinskia at gcc dot gnu.org
  2023-09-12  0:36 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12  0:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55881
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55881&action=edit
mins testcase

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
  2023-09-10 21:11 ` [Bug tree-optimization/111364] " pinskia at gcc dot gnu.org
  2023-09-12  0:14 ` pinskia at gcc dot gnu.org
@ 2023-09-12  0:36 ` pinskia at gcc dot gnu.org
  2023-09-12  0:36 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12  0:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
diff --git a/gcc/match.pd b/gcc/match.pd
index 51985c1bad4..bf49c167792 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3902,9 +3902,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (maxmin @0 (bit_not @1))))

 /* MIN (X, Y) == X -> X <= Y  */
-(for minmax (min min max max)
-     cmp    (eq  ne  eq  ne )
-     out    (le  gt  ge  lt )
+(for minmax (min min min min max max max max)
+     cmp    (eq  ne  lt  ge  eq  ne  gt  le )
+     out    (le  gt  gt  le  ge  lt  lt  ge )
  (simplify
   (cmp:c (minmax:c @0 @1) @0)
   (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)))

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-09-12  0:36 ` pinskia at gcc dot gnu.org
@ 2023-09-12  0:36 ` pinskia at gcc dot gnu.org
  2023-09-12  5:36 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12  0:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55882
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55882&action=edit
max testcase

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-09-12  0:36 ` pinskia at gcc dot gnu.org
@ 2023-09-12  5:36 ` pinskia at gcc dot gnu.org
  2023-09-12 15:40 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12  5:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55884
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55884&action=edit
Full patch which I am testing

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-09-12  5:36 ` pinskia at gcc dot gnu.org
@ 2023-09-12 15:40 ` pinskia at gcc dot gnu.org
  2023-09-13 12:07 ` cvs-commit at gcc dot gnu.org
  2023-09-13 12:08 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12 15:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2023-Septemb
                   |                            |er/630075.html

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/630075.html

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-09-12 15:40 ` pinskia at gcc dot gnu.org
@ 2023-09-13 12:07 ` cvs-commit at gcc dot gnu.org
  2023-09-13 12:08 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-13 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 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:06bedc3860d3e61857d72ffe699f79ed5c92855f

commit r14-3922-g06bedc3860d3e61857d72ffe699f79ed5c92855f
Author: Andrew Pinski <apinski@marvell.com>
Date:   Tue Sep 12 05:16:06 2023 +0000

    MATCH: [PR111364] Add some more minmax cmp operand simplifications

    This adds a few more minmax cmp operand simplifications which were missed
before.
    `MIN(a,b) < a` -> `a > b`
    `MIN(a,b) >= a` -> `a <= b`
    `MAX(a,b) > a` -> `a < b`
    `MAX(a,b) <= a` -> `a >= b`

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

    Note gcc.dg/pr96708-negative.c needed to updated to remove the
    check for MIN/MAX as they have been optimized (correctly) away.

            PR tree-optimization/111364

    gcc/ChangeLog:

            * match.pd (`MIN (X, Y) == X`): Extend
            to min/lt, min/ge, max/gt, max/le.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/minmaxcmp-1.c: New test.
            * gcc.dg/tree-ssa/minmaxcmp-2.c: New test.
            * gcc.dg/pr96708-negative.c: Update testcase.
            * gcc.dg/pr96708-positive.c: Add comment about `return 0`.

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

* [Bug tree-optimization/111364] `MAX_EXPR<a, b> <= a` is not optimized to `a >= b`
  2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-09-13 12:07 ` cvs-commit at gcc dot gnu.org
@ 2023-09-13 12:08 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-13 12:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-09-13 12:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-10 21:11 [Bug tree-optimization/111364] New: `MAX_EXPR<a, b> <= a` is not optimized to `a >= b` pinskia at gcc dot gnu.org
2023-09-10 21:11 ` [Bug tree-optimization/111364] " pinskia at gcc dot gnu.org
2023-09-12  0:14 ` pinskia at gcc dot gnu.org
2023-09-12  0:36 ` pinskia at gcc dot gnu.org
2023-09-12  0:36 ` pinskia at gcc dot gnu.org
2023-09-12  5:36 ` pinskia at gcc dot gnu.org
2023-09-12 15:40 ` pinskia at gcc dot gnu.org
2023-09-13 12:07 ` cvs-commit at gcc dot gnu.org
2023-09-13 12:08 ` 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).