public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands
@ 2020-04-30 12:52 gabravier at gmail dot com
  2020-04-30 12:53 ` [Bug tree-optimization/94884] " gabravier at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94884
           Summary: Failure to recognize that result of or is always
                    superior to operands
           Product: gcc
           Version: 10.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 decide() __attribute((const));

inline unsigned getXOrY(unsigned x, unsigned y)
{
    return decide() ? y : x;
}

bool f(unsigned x, unsigned y)
{
    return (x | y) >= getXOrY(x, y);
}

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

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
@ 2020-04-30 12:53 ` gabravier at gmail dot com
  2020-04-30 12:54 ` gabravier at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 12:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
`f` can also be translated to `return true;` when it's this :

bool f(unsigned x, unsigned y)
{
    return (x & y) <= getXOrY(x, y);
}

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
  2020-04-30 12:53 ` [Bug tree-optimization/94884] " gabravier at gmail dot com
@ 2020-04-30 12:54 ` gabravier at gmail dot com
  2020-04-30 12:55 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
Also when it is this :

bool f(unsigned x, unsigned y)
{
    return x <= (x | ~y);
}

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
  2020-04-30 12:53 ` [Bug tree-optimization/94884] " gabravier at gmail dot com
  2020-04-30 12:54 ` gabravier at gmail dot com
@ 2020-04-30 12:55 ` rguenth at gcc dot gnu.org
  2021-08-03 23:25 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-30 12:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-04-30
           Keywords|                            |missed-optimization

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

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-04-30 12:55 ` rguenth at gcc dot gnu.org
@ 2021-08-03 23:25 ` pinskia at gcc dot gnu.org
  2021-08-03 23:25 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 23:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Part of this is:

bool f1_part0(unsigned x, unsigned y)
{
    unsigned t1 = x;
    unsigned t = (x | y);
    return t >= t1;
}

Should be optimized to true.

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-08-03 23:25 ` pinskia at gcc dot gnu.org
@ 2021-08-03 23:25 ` pinskia at gcc dot gnu.org
  2021-08-03 23:28 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 23:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (4 preceding siblings ...)
  2021-08-03 23:25 ` pinskia at gcc dot gnu.org
@ 2021-08-03 23:28 ` pinskia at gcc dot gnu.org
  2023-08-23  0:37 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 23:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |101590

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The comment #4 is recorded in PR 101590, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101590#c2.
So I will double check this when I go implement that one fully.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101590
[Bug 101590] (len & - N) <= len is not optimized to 1

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (5 preceding siblings ...)
  2021-08-03 23:28 ` pinskia at gcc dot gnu.org
@ 2023-08-23  0:37 ` pinskia at gcc dot gnu.org
  2023-10-27  7:50 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-23  0:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine.

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (6 preceding siblings ...)
  2023-08-23  0:37 ` pinskia at gcc dot gnu.org
@ 2023-10-27  7:50 ` cvs-commit at gcc dot gnu.org
  2023-10-27  7:50 ` pinskia at gcc dot gnu.org
  2023-10-27  7:51 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-27  7:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 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:a5e69e94591ae282857d59e868ff6cea7306c802

commit r14-4965-ga5e69e94591ae282857d59e868ff6cea7306c802
Author: Andrew Pinski <apinski@marvell.com>
Date:   Tue Sep 12 18:24:22 2023 -0700

    MATCH: Simplify `(X &| B) CMP X` if possible [PR 101590]

    I noticed we were missing these simplifications so let's add them.

    This adds the following simplifications:
    U & N <= U  -> true
    U & N >  U  -> false
    When U is known to be as non-negative.

    When N is also known to be non-negative, this is also true:
    U | N <  U  -> false
    U | N >= U  -> true

    When N is a negative integer, the result flips and we get:
    U | N <  U  -> true
    U | N >= U  -> false

    We could extend this later on to be the case where we know N
    is nonconstant but is known to be negative.

    Bootstrapped and tested on x86_64-linux-gnu with no regressions.

            PR tree-optimization/101590
            PR tree-optimization/94884

    gcc/ChangeLog:

            * match.pd (`(X BIT_OP Y) CMP X`): New pattern.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/bitcmp-1.c: New test.
            * gcc.dg/tree-ssa/bitcmp-2.c: New test.
            * gcc.dg/tree-ssa/bitcmp-3.c: New test.
            * gcc.dg/tree-ssa/bitcmp-4.c: New test.
            * gcc.dg/tree-ssa/bitcmp-5.c: New test.
            * gcc.dg/tree-ssa/bitcmp-6.c: New test.

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (7 preceding siblings ...)
  2023-10-27  7:50 ` cvs-commit at gcc dot gnu.org
@ 2023-10-27  7:50 ` pinskia at gcc dot gnu.org
  2023-10-27  7:51 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-27  7:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94884
Bug 94884 depends on bug 101590, which changed state.

Bug 101590 Summary: (len & - N) <= len is not optimized to 1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101590

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

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

* [Bug tree-optimization/94884] Failure to recognize that result of or is always superior to operands
  2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
                   ` (8 preceding siblings ...)
  2023-10-27  7:50 ` pinskia at gcc dot gnu.org
@ 2023-10-27  7:51 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-27  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2023-10-27  7:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 12:52 [Bug tree-optimization/94884] New: Failure to recognize that result of or is always superior to operands gabravier at gmail dot com
2020-04-30 12:53 ` [Bug tree-optimization/94884] " gabravier at gmail dot com
2020-04-30 12:54 ` gabravier at gmail dot com
2020-04-30 12:55 ` rguenth at gcc dot gnu.org
2021-08-03 23:25 ` pinskia at gcc dot gnu.org
2021-08-03 23:25 ` pinskia at gcc dot gnu.org
2021-08-03 23:28 ` pinskia at gcc dot gnu.org
2023-08-23  0:37 ` pinskia at gcc dot gnu.org
2023-10-27  7:50 ` cvs-commit at gcc dot gnu.org
2023-10-27  7:50 ` pinskia at gcc dot gnu.org
2023-10-27  7:51 ` 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).