public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112905] New: [missed optimization] fail to reduce a loop that increments two locations of the same buffer
@ 2023-12-07 12:51 AceSrc at outlook dot com
  2023-12-07 13:23 ` [Bug tree-optimization/112905] " rguenth at gcc dot gnu.org
  2023-12-07 19:18 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: AceSrc at outlook dot com @ 2023-12-07 12:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112905
           Summary: [missed optimization] fail to reduce a loop that
                    increments two locations of the same buffer
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: AceSrc at outlook dot com
  Target Milestone: ---

Previously, I posted a question in Stackoverflow about loop optimization
(https://stackoverflow.com/questions/77618348/why-does-gcc-fail-to-reduce-a-loop-that-increments-two-locations-of-the-same-buf),
and the answer suggests me to post a [missed optimization] report here.

The question is about GCC does not optimize the following C++ codes into
`counter[A] += n; counter[B] += n;`. In contrast, GCC optimizes the loop into
`counter[A] += n` if `++counter[B]` is deleted. 

```
unsigned int getid();
void foo(unsigned int *counter, unsigned int n) {
        unsigned int A = getid();
        unsigned int B = getid();
        for (unsigned int i = 0; i < n; i++) {
            ++counter[A];
            ++counter[B];
        }
}
```

LLVM has the same behavior.

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

* [Bug tree-optimization/112905] [missed optimization] fail to reduce a loop that increments two locations of the same buffer
  2023-12-07 12:51 [Bug c++/112905] New: [missed optimization] fail to reduce a loop that increments two locations of the same buffer AceSrc at outlook dot com
@ 2023-12-07 13:23 ` rguenth at gcc dot gnu.org
  2023-12-07 19:18 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-07 13:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-12-07
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |tree-optimization

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is that store-motion cannot cope with this as A could be equal to B
which would invalidate the transform it would do.  And that's the enabler
and why it works with just a single update.

Confirmed.

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

* [Bug tree-optimization/112905] [missed optimization] fail to reduce a loop that increments two locations of the same buffer
  2023-12-07 12:51 [Bug c++/112905] New: [missed optimization] fail to reduce a loop that increments two locations of the same buffer AceSrc at outlook dot com
  2023-12-07 13:23 ` [Bug tree-optimization/112905] " rguenth at gcc dot gnu.org
@ 2023-12-07 19:18 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-07 19:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org
           Severity|normal                      |enhancement

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

end of thread, other threads:[~2023-12-07 19:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 12:51 [Bug c++/112905] New: [missed optimization] fail to reduce a loop that increments two locations of the same buffer AceSrc at outlook dot com
2023-12-07 13:23 ` [Bug tree-optimization/112905] " rguenth at gcc dot gnu.org
2023-12-07 19:18 ` 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).