public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern
@ 2021-02-11  8:21 gabravier at gmail dot com
  2021-02-11 14:06 ` [Bug tree-optimization/99069] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2021-02-11  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99069
           Summary: Failure to optimize bool selection pattern
           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(bool x, bool y)
{
    return (x ? y : false) ? x : false;
}

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

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

* [Bug tree-optimization/99069] Failure to optimize bool selection pattern
  2021-02-11  8:21 [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern gabravier at gmail dot com
@ 2021-02-11 14:06 ` rguenth at gcc dot gnu.org
  2021-07-20  6:05 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-11 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, but phiopt2 turns it into

bool f (bool x, bool y)
{
  bool _5;
  bool _6;

  <bb 2> [local count: 1073741824]:
  _5 = x_2(D) & y_3(D);
  _6 = -_5;
  return _6;

and we end up with

_Z1fbb:
.LFB0:
        .cfi_startproc
        andl    %edi, %esi
        movl    %esi, %eax
        andl    $1, %eax
        ret

which is optimal.  On GIMPLE we fail to elide -bool to bool I guess.

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

* [Bug tree-optimization/99069] Failure to optimize bool selection pattern
  2021-02-11  8:21 [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern gabravier at gmail dot com
  2021-02-11 14:06 ` [Bug tree-optimization/99069] " rguenth at gcc dot gnu.org
@ 2021-07-20  6:05 ` pinskia at gcc dot gnu.org
  2021-07-20  6:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20  6:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-20
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
           Severity|normal                      |enhancement

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

I have a patch for this already.

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

* [Bug tree-optimization/99069] Failure to optimize bool selection pattern
  2021-02-11  8:21 [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern gabravier at gmail dot com
  2021-02-11 14:06 ` [Bug tree-optimization/99069] " rguenth at gcc dot gnu.org
  2021-07-20  6:05 ` pinskia at gcc dot gnu.org
@ 2021-07-20  6:05 ` pinskia at gcc dot gnu.org
  2021-07-20  6:15 ` pinskia at gcc dot gnu.org
  2023-06-07  2:43 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20  6:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

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

* [Bug tree-optimization/99069] Failure to optimize bool selection pattern
  2021-02-11  8:21 [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2021-07-20  6:05 ` pinskia at gcc dot gnu.org
@ 2021-07-20  6:15 ` pinskia at gcc dot gnu.org
  2023-06-07  2:43 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20  6:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is the same as PR 89263 really so closing as a dup.

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

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

* [Bug tree-optimization/99069] Failure to optimize bool selection pattern
  2021-02-11  8:21 [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-07-20  6:15 ` pinskia at gcc dot gnu.org
@ 2023-06-07  2:43 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-07  2:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:64d90d06d2db43538c8a45adbb3d74842f7868ae

commit r14-1597-g64d90d06d2db43538c8a45adbb3d74842f7868ae
Author: Andrew Pinski <apinski@marvell.com>
Date:   Wed May 24 07:08:45 2023 +0000

    Add match patterns for `a ? onezero : onezero` where one of the two
operands are constant

    This adds a match pattern that are for boolean values
    that optimizes `a ? onezero : 0` to `a & onezero` and
    `a ? 1 : onezero` to `a | onezero`.

    This was reported a few times and I thought I would finally
    add the match pattern for this.

    This hits a few times in GCC itself too.

    Notes on the testcases:
    * phi-opt-2.c: This now is optimized to `a & b` in phiopt rather than
ifcombine
    * phi-opt-25b.c: The test part that was failing was parity which now gets
`x & y` treatment.
    * ssa-thread-21.c: there is no longer a threading opportunity, so need to
disable phiopt.
      Note PR 109957 is filed for the now missing optimization in that testcase
too.

    gcc/ChangeLog:

            PR tree-optimization/89263
            PR tree-optimization/99069
            PR tree-optimization/20083
            PR tree-optimization/94898
            * match.pd: Add patterns to optimize `a ? onezero : onezero` with
            one of the operands are constant.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/phi-opt-2.c: Adjust the testcase.
            * gcc.dg/tree-ssa/phi-opt-25b.c: Adjust the testcase.
            * gcc.dg/tree-ssa/ssa-thread-21.c: Disable phiopt.
            * gcc.dg/tree-ssa/phi-opt-27.c: New test.
            * gcc.dg/tree-ssa/phi-opt-28.c: New test.
            * gcc.dg/tree-ssa/phi-opt-29.c: New test.
            * gcc.dg/tree-ssa/phi-opt-30.c: New test.
            * gcc.dg/tree-ssa/phi-opt-31.c: New test.
            * gcc.dg/tree-ssa/phi-opt-32.c: New test.

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11  8:21 [Bug tree-optimization/99069] New: Failure to optimize bool selection pattern gabravier at gmail dot com
2021-02-11 14:06 ` [Bug tree-optimization/99069] " rguenth at gcc dot gnu.org
2021-07-20  6:05 ` pinskia at gcc dot gnu.org
2021-07-20  6:05 ` pinskia at gcc dot gnu.org
2021-07-20  6:15 ` pinskia at gcc dot gnu.org
2023-06-07  2:43 ` cvs-commit 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).