public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not
@ 2020-09-03 14:06 gabravier at gmail dot com
  2020-09-03 14:49 ` [Bug tree-optimization/96923] " gabravier at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gabravier at gmail dot com @ 2020-09-03 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96923
           Summary: Failure to optimize a select-related bool pattern to
                    or+not
           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 f2(_Bool a, _Bool b)
{
    return !a ? !b : 0;
}

This can be optimized to `return !(a | b);`. This transformation is done by
LLVM, but not by GCC.

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
@ 2020-09-03 14:49 ` gabravier at gmail dot com
  2020-09-06 23:45 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: gabravier at gmail dot com @ 2020-09-03 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
_Bool f2(_Bool a, _Bool b)
{
    return a ? !b : 1;
}

This similar pattern can be optimized to `return !(a & b);`. This
transformation is done by LLVM, but not by GCC.

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
  2020-09-03 14:49 ` [Bug tree-optimization/96923] " gabravier at gmail dot com
@ 2020-09-06 23:45 ` pinskia at gcc dot gnu.org
  2020-09-06 23:47 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-09-06 23:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
  2020-09-03 14:49 ` [Bug tree-optimization/96923] " gabravier at gmail dot com
  2020-09-06 23:45 ` pinskia at gcc dot gnu.org
@ 2020-09-06 23:47 ` pinskia at gcc dot gnu.org
  2021-06-01 21:02 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-09-06 23:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |25290

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note if we spell out the ?:, this would require PR 25290 too.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25290
[Bug 25290] PHI-OPT could be rewritten so that is uses match

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-09-06 23:47 ` pinskia at gcc dot gnu.org
@ 2021-06-01 21:02 ` pinskia at gcc dot gnu.org
  2021-06-01 21:40 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-01 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-06-01
     Ever confirmed|0                           |1

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine, I have a patch which implements this.
It needs https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571616.html first.
I will be posting this once I write some testcases and do a bootstrap/test
cycle.

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-06-01 21:02 ` pinskia at gcc dot gnu.org
@ 2021-06-01 21:40 ` pinskia at gcc dot gnu.org
  2021-06-01 23:19 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-01 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 50905
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50905&action=edit
Patch which is in testing (needs testcases)

As I said for the case in this PR, it needs
https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571616.html too.

If you change !b to b; that is "!a ? b : 0", this patch will optimize it.  The
other patch is needed to allow to move !b out of the conditional.

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
                   ` (4 preceding siblings ...)
  2021-06-01 21:40 ` pinskia at gcc dot gnu.org
@ 2021-06-01 23:19 ` pinskia at gcc dot gnu.org
  2021-06-01 23:49 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-01 23:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> Created attachment 50905 [details]
> Patch which is in testing (needs testcases)
> 
> As I said for the case in this PR, it needs
> https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571616.html too.
> 
> If you change !b to b; that is "!a ? b : 0", this patch will optimize it. 
> The other patch is needed to allow to move !b out of the conditional.

This patch has one bug in it where we need a convert added.
BUT then we run into a different missed optimization issue.
  _51 = p2_22 <= prephitmp_122;
  _44 = (logical(kind=4)) _51;
  _37 = p2_22 > prephitmp_122;
  _49 = (logical(kind=4)) _37;
  _38 = _49 & found_p_63;
  _46 = _38 | _44;

This is really just:
_51 = p2_22 <= prephitmp_122;
_44 = (logical(kind=4)) _51;
_46 = found_p_63| _44;

That is we don't optimize:
(a & ~b) | b into a | b if ~b has been converted already.

The other thing I noticed is the cast should not be really needed but nothing
removes it; I will look at that later.

Note I could rewrite the pattern to do the simplification of the constants
manually but I want to try to avoid that.

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
                   ` (5 preceding siblings ...)
  2021-06-01 23:19 ` pinskia at gcc dot gnu.org
@ 2021-06-01 23:49 ` pinskia at gcc dot gnu.org
  2023-05-24  0:01 ` pinskia at gcc dot gnu.org
  2023-07-31 17:14 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-01 23:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |100864

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This depends on PR 100864 if I don't want to write out the 4 patterns.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100864
[Bug 100864] (a&!b) | b is not opimized to a | b for conditionals

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
                   ` (6 preceding siblings ...)
  2021-06-01 23:49 ` pinskia at gcc dot gnu.org
@ 2023-05-24  0:01 ` pinskia at gcc dot gnu.org
  2023-07-31 17:14 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-24  0:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Ok, this in the end is a dup of bug 89263.

*** This bug has been marked as a duplicate of bug 89263 ***

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

* [Bug tree-optimization/96923] Failure to optimize a select-related bool pattern to or+not
  2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
                   ` (7 preceding siblings ...)
  2023-05-24  0:01 ` pinskia at gcc dot gnu.org
@ 2023-07-31 17:14 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-31 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

Bug 100864 Summary: (a&!b) | b is not opimized to a | b for comparisons
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100864

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

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

end of thread, other threads:[~2023-07-31 17:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 14:06 [Bug tree-optimization/96923] New: Failure to optimize a select-related bool pattern to or+not gabravier at gmail dot com
2020-09-03 14:49 ` [Bug tree-optimization/96923] " gabravier at gmail dot com
2020-09-06 23:45 ` pinskia at gcc dot gnu.org
2020-09-06 23:47 ` pinskia at gcc dot gnu.org
2021-06-01 21:02 ` pinskia at gcc dot gnu.org
2021-06-01 21:40 ` pinskia at gcc dot gnu.org
2021-06-01 23:19 ` pinskia at gcc dot gnu.org
2021-06-01 23:49 ` pinskia at gcc dot gnu.org
2023-05-24  0:01 ` pinskia at gcc dot gnu.org
2023-07-31 17:14 ` 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).