public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor
@ 2022-01-28 23:16 Darrell.Wright at gmail dot com
2022-01-28 23:33 ` [Bug tree-optimization/104276] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Darrell.Wright at gmail dot com @ 2022-01-28 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
Bug ID: 104276
Summary: Fail to eliminate deadstore from vector constructor
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Darrell.Wright at gmail dot com
Target Milestone: ---
clang is unable to remove the memset in code like
std::vector<int> foo() {
auto result = std::vector<int>(SZ);
int *ptr = result.data();
for (std::size_t n = 0; n < SZ; ++n) {
ptr[n] = static_cast<int>( n );
}
return result;
}
https://gcc.godbolt.org/z/5cbKejfqr
This is unaffected if the value is set during resize. That may result in
inlining of the memset but does not eliminate it.
However for code that uses blessed methods like memset subsequently
std::vector<int> foo() {
auto result = std::vector<int>(SZ);
std::memset(result.data(), 5, sizeof(int) * SZ);
return result;
}
https://gcc.godbolt.org/z/Kfs9x8Pe9
It is. This seems to be the usecase of resize_and_overwrite in future string.
Is there a way to formulate the code to do this. Or, and I think a better way,
is there a builtin or could there be that lets the compiler assume that the
memory will be subsequently written to? e.g. `__bultin_assume_set( void *
dest, size_t count )` ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] Fail to eliminate deadstore from vector constructor
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
@ 2022-01-28 23:33 ` pinskia at gcc dot gnu.org
2022-01-28 23:33 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-28 23:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] Fail to eliminate deadstore from vector constructor
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
2022-01-28 23:33 ` [Bug tree-optimization/104276] " pinskia at gcc dot gnu.org
@ 2022-01-28 23:33 ` pinskia at gcc dot gnu.org
2022-01-28 23:35 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-28 23:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Full testcase:
#include <cstdint>
#include <iterator>
#include <type_traits>
#include <vector>
#include <cstring>
#define SZ 4096
std::vector<int> foo() {
auto result = std::vector<int>(SZ);
int *ptr = result.data();
for (std::size_t n = 0; n < SZ; ++n) {
ptr[n] = static_cast<int>( n );
}
return result;
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] Fail to eliminate deadstore from vector constructor
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
2022-01-28 23:33 ` [Bug tree-optimization/104276] " pinskia at gcc dot gnu.org
2022-01-28 23:33 ` pinskia at gcc dot gnu.org
@ 2022-01-28 23:35 ` pinskia at gcc dot gnu.org
2022-01-28 23:37 ` Darrell.Wright at gmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-28 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>clang is unable to remove the memset in code like
I think you mean GCC there :).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] Fail to eliminate deadstore from vector constructor
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
` (2 preceding siblings ...)
2022-01-28 23:35 ` pinskia at gcc dot gnu.org
@ 2022-01-28 23:37 ` Darrell.Wright at gmail dot com
2022-01-28 23:40 ` [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Darrell.Wright at gmail dot com @ 2022-01-28 23:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
--- Comment #3 from Darrell Wright <Darrell.Wright at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> >clang is unable to remove the memset in code like
>
> I think you mean GCC there :).
:) both are true. This optimization would remove the need for things like
resize_and_overwrite which means we all win
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
` (3 preceding siblings ...)
2022-01-28 23:37 ` Darrell.Wright at gmail dot com
@ 2022-01-28 23:40 ` pinskia at gcc dot gnu.org
2022-01-28 23:44 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-28 23:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Fail to eliminate deadstore |memset is not elimited when
|from vector constructor |followed by a store loop
| |writing to that memory
| |location
Last reconfirmed| |2022-01-28
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Simplified C testcase (without std::vector usage):
#define SZ 4096
void foo1(int *a) {
__builtin_memset(a, 0, sizeof(int)*SZ);
for (int n = 0; n < SZ; ++n) {
a[n] = n;
}
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
` (4 preceding siblings ...)
2022-01-28 23:40 ` [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location pinskia at gcc dot gnu.org
@ 2022-01-28 23:44 ` pinskia at gcc dot gnu.org
2022-01-28 23:45 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-28 23:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Exact duplicate of PR 28134.
*** This bug has been marked as a duplicate of bug 28134 ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
` (5 preceding siblings ...)
2022-01-28 23:44 ` pinskia at gcc dot gnu.org
@ 2022-01-28 23:45 ` pinskia at gcc dot gnu.org
2022-01-31 8:15 ` rguenth at gcc dot gnu.org
2022-07-15 19:14 ` Darrell.Wright at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-28 23:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |NEW
Resolution|DUPLICATE |---
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually not an exact sorry still only related.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
` (6 preceding siblings ...)
2022-01-28 23:45 ` pinskia at gcc dot gnu.org
@ 2022-01-31 8:15 ` rguenth at gcc dot gnu.org
2022-07-15 19:14 ` Darrell.Wright at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-31 8:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
DSE could in theory prune live-bytes from a store inside a loop by looking at
SCEV / niter info. That'll cost though, and it's not clear where it would
nicely fit.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
` (7 preceding siblings ...)
2022-01-31 8:15 ` rguenth at gcc dot gnu.org
@ 2022-07-15 19:14 ` Darrell.Wright at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: Darrell.Wright at gmail dot com @ 2022-07-15 19:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104276
--- Comment #8 from Darrell Wright <Darrell.Wright at gmail dot com> ---
What about something like a __builtin_overwrite( ptr, size_t ) that tells the
compiler that the range specified will be written. It forms a contract to do
so with the compiler and would allow the memset to be eliminated or augmented
to part of the range
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-07-15 19:14 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28 23:16 [Bug c++/104276] New: Fail to eliminate deadstore from vector constructor Darrell.Wright at gmail dot com
2022-01-28 23:33 ` [Bug tree-optimization/104276] " pinskia at gcc dot gnu.org
2022-01-28 23:33 ` pinskia at gcc dot gnu.org
2022-01-28 23:35 ` pinskia at gcc dot gnu.org
2022-01-28 23:37 ` Darrell.Wright at gmail dot com
2022-01-28 23:40 ` [Bug tree-optimization/104276] memset is not elimited when followed by a store loop writing to that memory location pinskia at gcc dot gnu.org
2022-01-28 23:44 ` pinskia at gcc dot gnu.org
2022-01-28 23:45 ` pinskia at gcc dot gnu.org
2022-01-31 8:15 ` rguenth at gcc dot gnu.org
2022-07-15 19:14 ` Darrell.Wright at gmail dot com
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).