public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
@ 2023-12-31 21:07 pinskia at gcc dot gnu.org
  2023-12-31 21:07 ` [Bug tree-optimization/113186] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-31 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113186
           Summary: [13/14 Regression] `(a^c) & (a^!c)` is not optimized
                    to 0 for bool
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
bool f(bool a, bool c)
{
  bool b = (a^c);
  bool d = (a^!c);
  return b & d;
}
```
This should optimize to 0 but does not since GCC 13. With the C++ front-end, I
suspect since r13-1779-g375668e0508fbe . With the C front-end, it started on
the trunk.

For C have in forwprop1:
  b_7 = a_5(D) ^ c_6(D);
  _11 = a_5(D) ^ c_6(D);
  _12 = a_5(D) == c_6(D);
  _13 = b_7 & _12;

For C++ we have (at -O1):
  b_7 = a_5(D) != c_6(D);
  _1 = ~c_6(D);
  d_8 = _1 != a_5(D);
  _11 = b_7 & d_8;

For C++ at -O2 in forwprop2, we have similar as what with the C front-end.

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

* [Bug tree-optimization/113186] [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
  2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
@ 2023-12-31 21:07 ` pinskia at gcc dot gnu.org
  2023-12-31 21:15 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-31 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Target Milestone|---                         |14.0
   Last reconfirmed|                            |2023-12-31
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am going to fix this next week.

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

* [Bug tree-optimization/113186] [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
  2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
  2023-12-31 21:07 ` [Bug tree-optimization/113186] " pinskia at gcc dot gnu.org
@ 2023-12-31 21:15 ` pinskia at gcc dot gnu.org
  2024-01-01  0:49 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-31 21:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note for `~a != b` (for boolean size) we should just convert that into: `a ==
b` .

And then we would have the form for both C++ and C at -O1 in forwprop1 .

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

* [Bug tree-optimization/113186] [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
  2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
  2023-12-31 21:07 ` [Bug tree-optimization/113186] " pinskia at gcc dot gnu.org
  2023-12-31 21:15 ` pinskia at gcc dot gnu.org
@ 2024-01-01  0:49 ` pinskia at gcc dot gnu.org
  2024-01-01  4:04 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-01  0:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So for the C testcase, we don't need to create a new pattern, just extend
gimple_bitwise_inverted_equal_p to catch `a == b` and `a ^ b` are inverted
equals like we already do for `a == b` and `a != b`.  This allows for other
patterns to work too ...

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

* [Bug tree-optimization/113186] [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
  2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-01-01  0:49 ` pinskia at gcc dot gnu.org
@ 2024-01-01  4:04 ` pinskia at gcc dot gnu.org
  2024-01-04 20:52 ` cvs-commit at gcc dot gnu.org
  2024-01-04 20:52 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-01  4:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2024-January
                   |                            |/641612.html

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2024-January/641612.html

I will fix the regression with the IR from the C++ front-end seperately.

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

* [Bug tree-optimization/113186] [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
  2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-01-01  4:04 ` pinskia at gcc dot gnu.org
@ 2024-01-04 20:52 ` cvs-commit at gcc dot gnu.org
  2024-01-04 20:52 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-04 20:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC 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:97def769e6b28832f5ba4087d6fcdd44e18bf005

commit r14-6927-g97def769e6b28832f5ba4087d6fcdd44e18bf005
Author: Andrew Pinski <quic_apinski@quicinc.com>
Date:   Sun Dec 31 16:38:30 2023 -0800

    Match: Improve inverted_equal_p for bool and `^` and `==` [PR113186]

    For boolean types, `a ^ b` is a valid form for `a != b`. This means for
    gimple_bitwise_inverted_equal_p, we catch some inverted value forms. This
    patch extends inverted_equal_p to allow matching of `^` with the
    corresponding `==`. Note in the testcase provided we used to optimize
    in GCC 12 to just `return 0` where `a == b` was used,
    this allows us to do that again.

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

            PR tree-optimization/113186

    gcc/ChangeLog:

            * gimple-match-head.cc (gimple_bitwise_inverted_equal_p):
            Match `^` with the `==` for 1bit integral types.
            * match.pd (maybe_cmp): Allow for bit_xor for 1bit
            integral types.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/bitops-bool-1.c: New test.

    Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>

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

* [Bug tree-optimization/113186] [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool
  2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-01-04 20:52 ` cvs-commit at gcc dot gnu.org
@ 2024-01-04 20:52 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-04 20:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2024-01-04 20:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-31 21:07 [Bug tree-optimization/113186] New: [13/14 Regression] `(a^c) & (a^!c)` is not optimized to 0 for bool pinskia at gcc dot gnu.org
2023-12-31 21:07 ` [Bug tree-optimization/113186] " pinskia at gcc dot gnu.org
2023-12-31 21:15 ` pinskia at gcc dot gnu.org
2024-01-01  0:49 ` pinskia at gcc dot gnu.org
2024-01-01  4:04 ` pinskia at gcc dot gnu.org
2024-01-04 20:52 ` cvs-commit at gcc dot gnu.org
2024-01-04 20:52 ` 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).