public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94889] New: Negate function not getting optimised to negate call
@ 2020-04-30 14:32 satanichiya at waifu dot club
  2020-04-30 14:42 ` [Bug c/94889] " gabravier at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: satanichiya at waifu dot club @ 2020-04-30 14:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94889
           Summary: Negate function not getting optimised to negate call
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: satanichiya at waifu dot club
  Target Milestone: ---

int func(int x)
{
    for(int i=0;i<sizeof(int)*8;i++)
    {
        x ^= (int)1<<i;
    }
    return x;
}

Does not get optimised to just a negate instruction

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

* [Bug c/94889] Negate function not getting optimised to negate call
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
@ 2020-04-30 14:42 ` gabravier at gmail dot com
  2020-04-30 14:52 ` [Bug c/94889] Negate function not getting optimised to bitwise not satanichiya at waifu dot club
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 14:42 UTC (permalink / raw)
  To: gcc-bugs

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

Gabriel Ravier <gabravier at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gabravier at gmail dot com

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
For some reason, I can reproduce this, but only if `-mavx2` is not present.
Having AVX2 enabled somehow ends up makes it so this is optimized to a `return
~x`.

(Also, this means that it is a bitwise not and not a negate that this should
optimize down to)

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

* [Bug c/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
  2020-04-30 14:42 ` [Bug c/94889] " gabravier at gmail dot com
@ 2020-04-30 14:52 ` satanichiya at waifu dot club
  2020-04-30 14:57 ` satanichiya at waifu dot club
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: satanichiya at waifu dot club @ 2020-04-30 14:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Gooby <satanichiya at waifu dot club> ---
Meant to say NOT, excuse me

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

* [Bug c/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
  2020-04-30 14:42 ` [Bug c/94889] " gabravier at gmail dot com
  2020-04-30 14:52 ` [Bug c/94889] Negate function not getting optimised to bitwise not satanichiya at waifu dot club
@ 2020-04-30 14:57 ` satanichiya at waifu dot club
  2020-04-30 15:14 ` gabravier at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: satanichiya at waifu dot club @ 2020-04-30 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Gooby <satanichiya at waifu dot club> ---
Meant to say NOT, excuse me

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

* [Bug c/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
                   ` (2 preceding siblings ...)
  2020-04-30 14:57 ` satanichiya at waifu dot club
@ 2020-04-30 15:14 ` gabravier at gmail dot com
  2020-04-30 19:50 ` [Bug tree-optimization/94889] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 15:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Gabriel Ravier <gabravier at gmail dot com> ---
Investigated it a bit.

It looks like with `-mavx2` the pcom pass decides to vectorize the loop, and it
then later gets mowed down into a `~`.

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

* [Bug tree-optimization/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
                   ` (3 preceding siblings ...)
  2020-04-30 15:14 ` gabravier at gmail dot com
@ 2020-04-30 19:50 ` pinskia at gcc dot gnu.org
  2020-05-01  7:04 ` schwab@linux-m68k.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-30 19:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
          Component|c                           |tree-optimization

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

* [Bug tree-optimization/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
                   ` (4 preceding siblings ...)
  2020-04-30 19:50 ` [Bug tree-optimization/94889] " pinskia at gcc dot gnu.org
@ 2020-05-01  7:04 ` schwab@linux-m68k.org
  2021-08-22  0:25 ` pinskia at gcc dot gnu.org
  2023-10-12  3:46 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: schwab@linux-m68k.org @ 2020-05-01  7:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
Note that 1<<31 is undefined.

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

* [Bug tree-optimization/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
                   ` (5 preceding siblings ...)
  2020-05-01  7:04 ` schwab@linux-m68k.org
@ 2021-08-22  0:25 ` pinskia at gcc dot gnu.org
  2023-10-12  3:46 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22  0:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-22
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

Note two related testcases:
int negone(int x)
{
    for(int i=0;i<sizeof(int)*8;i++)
    {
        x |= (int)1<<i;
    }
    return x;
}
int zero(int x)
{
    for(int i=0;i<sizeof(int)*8;i++)
    {
        x &= (int)1<<i;
    }
    return x;
}

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

* [Bug tree-optimization/94889] Negate function not getting optimised to bitwise not
  2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
                   ` (6 preceding siblings ...)
  2021-08-22  0:25 ` pinskia at gcc dot gnu.org
@ 2023-10-12  3:46 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-12  3:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.0

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
final value replacement:
  x_11 = PHI <x_7(3)>
 with expr: ~x_4(D)
 final stmt:
  x_11 = ~x_4(D);


All fixed in GCC 13 for all 3 testcases even.

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

end of thread, other threads:[~2023-10-12  3:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 14:32 [Bug c/94889] New: Negate function not getting optimised to negate call satanichiya at waifu dot club
2020-04-30 14:42 ` [Bug c/94889] " gabravier at gmail dot com
2020-04-30 14:52 ` [Bug c/94889] Negate function not getting optimised to bitwise not satanichiya at waifu dot club
2020-04-30 14:57 ` satanichiya at waifu dot club
2020-04-30 15:14 ` gabravier at gmail dot com
2020-04-30 19:50 ` [Bug tree-optimization/94889] " pinskia at gcc dot gnu.org
2020-05-01  7:04 ` schwab@linux-m68k.org
2021-08-22  0:25 ` pinskia at gcc dot gnu.org
2023-10-12  3:46 ` 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).