public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants
@ 2020-08-18 21:16 gabravier at gmail dot com
  2020-08-18 21:27 ` [Bug tree-optimization/96691] Failure to optimize bitwise " gabravier at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2020-08-18 21:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96691
           Summary: Failure to optimize not+or+xor with constants to
                    and+xor with bitwise not-ed constants
           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: ---

int f(int x)
{
    return (~x | 123) ^ 321;
}

This can be optimized to `return (x & ~123) ^ ~321;` (and the same
transformation can be applied with any constants replacing 123 and 321). This
transformation is done by LLVM, but not by GCC.

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

* [Bug tree-optimization/96691] Failure to optimize bitwise not+or+xor with constants to and+xor with bitwise not-ed constants
  2020-08-18 21:16 [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants gabravier at gmail dot com
@ 2020-08-18 21:27 ` gabravier at gmail dot com
  2020-08-25 10:51 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2020-08-18 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
int f(int x)
{
    return (~x & 123) ^ 321;
}

A very similar transformation can be done with this code, transforming it to
`return (x & 123) ^ 314;` (according to LLVM), and a similar transformation
should be possible with other constants, though I can't identify myself the
exact transformation you'd need to generalise this to all constants.

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

* [Bug tree-optimization/96691] Failure to optimize bitwise not+or+xor with constants to and+xor with bitwise not-ed constants
  2020-08-18 21:16 [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants gabravier at gmail dot com
  2020-08-18 21:27 ` [Bug tree-optimization/96691] Failure to optimize bitwise " gabravier at gmail dot com
@ 2020-08-25 10:51 ` rguenth at gcc dot gnu.org
  2021-01-12 20:30 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-25 10:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-08-25
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

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

* [Bug tree-optimization/96691] Failure to optimize bitwise not+or+xor with constants to and+xor with bitwise not-ed constants
  2020-08-18 21:16 [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants gabravier at gmail dot com
  2020-08-18 21:27 ` [Bug tree-optimization/96691] Failure to optimize bitwise " gabravier at gmail dot com
  2020-08-25 10:51 ` rguenth at gcc dot gnu.org
@ 2021-01-12 20:30 ` jakub at gcc dot gnu.org
  2021-01-13 18:56 ` cvs-commit at gcc dot gnu.org
  2021-01-13 20:32 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-12 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(~x | 123) ^ 321 can't be replaced by (x | 123) ^ ~321, that is not equivalent.
I think the equivalencies this is based on are that for any X, C, D
((~X | C) ^ D) == ((X | C) ^ (~D ^ C))
and
((~X & C) ^ D) == ((X & C) ^ (D ^ C))
so if C and D are integral constants (scalar or vector), we should simplify it
that way, and furthermore I'd say we should simplify
(X | Y) ^ (~Z ^ Y)
into
(~X | Y) ^ Z
as the latter has fewer operations.

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

* [Bug tree-optimization/96691] Failure to optimize bitwise not+or+xor with constants to and+xor with bitwise not-ed constants
  2020-08-18 21:16 [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2021-01-12 20:30 ` jakub at gcc dot gnu.org
@ 2021-01-13 18:56 ` cvs-commit at gcc dot gnu.org
  2021-01-13 20:32 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-13 18:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:8fc183ccd0628465205b8a88c29ab69bfe74a08a

commit r11-6651-g8fc183ccd0628465205b8a88c29ab69bfe74a08a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jan 13 19:54:49 2021 +0100

    match.pd: Fold (~X | C) ^ D into (X | C) ^ (~D ^ C) if (~D ^ C) can be
simplified [PR96691]

    These simplifications are only simplifications if the (~D ^ C) or (D ^ C)
    expressions fold into gimple vals, but in that case they decrease number of
    operations by 1.

    2021-01-13  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/96691
            * match.pd ((~X | C) ^ D -> (X | C) ^ (~D ^ C),
            (~X & C) ^ D -> (X & C) ^ (D ^ C)): New simplifications if
            (~D ^ C) or (D ^ C) can be simplified.

            * gcc.dg/tree-ssa/pr96691.c: New test.

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

* [Bug tree-optimization/96691] Failure to optimize bitwise not+or+xor with constants to and+xor with bitwise not-ed constants
  2020-08-18 21:16 [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-01-13 18:56 ` cvs-commit at gcc dot gnu.org
@ 2021-01-13 20:32 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-13 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2021-01-13 20:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-18 21:16 [Bug tree-optimization/96691] New: Failure to optimize not+or+xor with constants to and+xor with bitwise not-ed constants gabravier at gmail dot com
2020-08-18 21:27 ` [Bug tree-optimization/96691] Failure to optimize bitwise " gabravier at gmail dot com
2020-08-25 10:51 ` rguenth at gcc dot gnu.org
2021-01-12 20:30 ` jakub at gcc dot gnu.org
2021-01-13 18:56 ` cvs-commit at gcc dot gnu.org
2021-01-13 20:32 ` jakub 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).