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

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