public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101821] New: Redundant xor eax eax
@ 2021-08-08 22:45 llvm at rifkin dot dev
  2021-08-08 22:47 ` [Bug tree-optimization/101821] " llvm at rifkin dot dev
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: llvm at rifkin dot dev @ 2021-08-08 22:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101821
           Summary: Redundant xor eax eax
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: llvm at rifkin dot dev
  Target Milestone: ---

Gcc is generating an unnecessary and redundant xor eax eax in the following
code

#include <bit>
#include <stdint.h>
uint32_t pop(uint32_t n) {
    return std::popcount(n);
}


pop(unsigned int):
        xor     eax, eax
        popcnt  eax, edi
        ret

https://godbolt.org/z/81o1Y6T5x

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

* [Bug tree-optimization/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
@ 2021-08-08 22:47 ` llvm at rifkin dot dev
  2021-08-08 22:53 ` [Bug tree-optimization/101821] Redundant xor eax eax related to popcount intrinsic llvm at rifkin dot dev
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: llvm at rifkin dot dev @ 2021-08-08 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jeremy R. <llvm at rifkin dot dev> ---
This happens with __builtin_popcount as well, not just std::popcount. This
appears to have started in GCC 4.9.2. https://godbolt.org/z/4dGWvT5zr

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

* [Bug tree-optimization/101821] Redundant xor eax eax related to popcount intrinsic
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
  2021-08-08 22:47 ` [Bug tree-optimization/101821] " llvm at rifkin dot dev
@ 2021-08-08 22:53 ` llvm at rifkin dot dev
  2021-08-08 22:53 ` [Bug target/101821] Redundant xor eax eax pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: llvm at rifkin dot dev @ 2021-08-08 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jeremy R. <llvm at rifkin dot dev> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Redundant xor eax eax       |Redundant xor eax eax
                   |related to                  |related to popcount
                   |__builtin_popcount          |intrinsic

--- Comment #2 from Jeremy R. <llvm at rifkin dot dev> ---
Seems to effect all

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
  2021-08-08 22:47 ` [Bug tree-optimization/101821] " llvm at rifkin dot dev
  2021-08-08 22:53 ` [Bug tree-optimization/101821] Redundant xor eax eax related to popcount intrinsic llvm at rifkin dot dev
@ 2021-08-08 22:53 ` pinskia at gcc dot gnu.org
  2021-08-08 22:55 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-08 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |target
            Summary|Redundant xor eax eax       |Redundant xor eax eax
                   |related to popcount         |
                   |intrinsic                   |
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is by design.

/* X86_TUNE_AVOID_FALSE_DEP_FOR_BMI: Avoid false dependency
   for bit-manipulation instructions.  */
DEF_TUNE (X86_TUNE_AVOID_FALSE_DEP_FOR_BMI, "avoid_false_dep_for_bmi",
          m_SANDYBRIDGE | m_CORE_AVX2 | m_GENERIC)

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
                   ` (2 preceding siblings ...)
  2021-08-08 22:53 ` [Bug target/101821] Redundant xor eax eax pinskia at gcc dot gnu.org
@ 2021-08-08 22:55 ` jakub at gcc dot gnu.org
  2021-08-08 22:56 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-08 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is not unnecessary nor redundant, but fully intentional.
See e.g. PR62011.

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
                   ` (3 preceding siblings ...)
  2021-08-08 22:55 ` jakub at gcc dot gnu.org
@ 2021-08-08 22:56 ` pinskia at gcc dot gnu.org
  2021-08-08 23:01 ` llvm at rifkin dot dev
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-08 22:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=62011

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See PR 62011 for more details.

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
                   ` (4 preceding siblings ...)
  2021-08-08 22:56 ` pinskia at gcc dot gnu.org
@ 2021-08-08 23:01 ` llvm at rifkin dot dev
  2021-08-08 23:05 ` llvm at rifkin dot dev
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: llvm at rifkin dot dev @ 2021-08-08 23:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jeremy R. <llvm at rifkin dot dev> ---
Ah thank you @Andrew Pinski @Jakub Jelinek

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
                   ` (5 preceding siblings ...)
  2021-08-08 23:01 ` llvm at rifkin dot dev
@ 2021-08-08 23:05 ` llvm at rifkin dot dev
  2021-08-08 23:12 ` pinskia at gcc dot gnu.org
  2021-08-08 23:21 ` llvm at rifkin dot dev
  8 siblings, 0 replies; 10+ messages in thread
From: llvm at rifkin dot dev @ 2021-08-08 23:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jeremy R. <llvm at rifkin dot dev> ---
Does the false dependency still apply to modern CPUs?

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
                   ` (6 preceding siblings ...)
  2021-08-08 23:05 ` llvm at rifkin dot dev
@ 2021-08-08 23:12 ` pinskia at gcc dot gnu.org
  2021-08-08 23:21 ` llvm at rifkin dot dev
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-08 23:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jeremy R. from comment #7)
> Does the false dependency still apply to modern CPUs?
How modern is modern?

Skylake fixed this for lzcnt and tzcnt.
Cannon Lake (and Ice Lake) fixed this for popcnt.

https://www.intel.com/content/dam/www/public/us/en/documents/specification-updates/desktop-6th-gen-core-family-spec-update.pdf

This is from
https://stackoverflow.com/questions/25078285/replacing-a-32-bit-loop-counter-with-64-bit-introduces-crazy-performance-deviati/54429148#54429148

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

* [Bug target/101821] Redundant xor eax eax
  2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
                   ` (7 preceding siblings ...)
  2021-08-08 23:12 ` pinskia at gcc dot gnu.org
@ 2021-08-08 23:21 ` llvm at rifkin dot dev
  8 siblings, 0 replies; 10+ messages in thread
From: llvm at rifkin dot dev @ 2021-08-08 23:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jeremy R. <llvm at rifkin dot dev> ---
Thank you for the resources and for your insight, it's much appreciated.
Is there interest in updating the intentional false-dependency logic to not
fire for architectures newer than cannonlake?

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

end of thread, other threads:[~2021-08-08 23:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-08 22:45 [Bug tree-optimization/101821] New: Redundant xor eax eax llvm at rifkin dot dev
2021-08-08 22:47 ` [Bug tree-optimization/101821] " llvm at rifkin dot dev
2021-08-08 22:53 ` [Bug tree-optimization/101821] Redundant xor eax eax related to popcount intrinsic llvm at rifkin dot dev
2021-08-08 22:53 ` [Bug target/101821] Redundant xor eax eax pinskia at gcc dot gnu.org
2021-08-08 22:55 ` jakub at gcc dot gnu.org
2021-08-08 22:56 ` pinskia at gcc dot gnu.org
2021-08-08 23:01 ` llvm at rifkin dot dev
2021-08-08 23:05 ` llvm at rifkin dot dev
2021-08-08 23:12 ` pinskia at gcc dot gnu.org
2021-08-08 23:21 ` llvm at rifkin dot dev

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).