Another missed memset in std::vector initialization.
authorChandler Carruth <chandlerc@gmail.com>
Sun, 9 Jan 2011 11:29:57 +0000 (11:29 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 9 Jan 2011 11:29:57 +0000 (11:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123116 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/README.txt

index 7d90795aa3b062438af920787dcb478c945eba4b..9ecd2ffc199c2fa4b93cdcb601d9433e17c2a35e 100644 (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.
+
+//===---------------------------------------------------------------------===//