Another missed memset in std::vector initialization.

llvm-svn: 123116
This commit is contained in:
Chandler Carruth 2011-01-09 11:29:57 +00:00
parent 8a00d8175b
commit 82e6f6a325
1 changed files with 19 additions and 0 deletions

View File

@ -2230,3 +2230,22 @@ Then, the really painful one is the second memset, of the same memory, to the
same value.
//===---------------------------------------------------------------------===//
clang -O3 -fno-exceptions currently compiles this code:
struct S {
unsigned short m1, m2;
unsigned char m3, m4;
};
void f(int N) {
std::vector<S> v(N);
extern void sink(void*); sink(&v);
}
into poor code for zero-initializing 'v' when N is >0. The problem is that
S is only 6 bytes, but each element is 8 byte-aligned. We generate a loop and
4 stores on each iteration. If the struct were 8 bytes, this gets turned into
a memset.
//===---------------------------------------------------------------------===//