summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers/sequences
diff options
context:
space:
mode:
authorBruce Mitchener <bruce.mitchener@gmail.com>2017-03-23 14:39:23 +0000
committerBruce Mitchener <bruce.mitchener@gmail.com>2017-03-23 14:39:23 +0000
commit50910bf842ca2d6bf16655ef3b74a8a34ca8c5f2 (patch)
tree3ee815b5ba84ca2567840b9429ba853858aa1dfc /libcxx/test/std/containers/sequences
parentc53e96cb0739f2f6efa62b254c04021520fa289b (diff)
downloadbcm5719-llvm-50910bf842ca2d6bf16655ef3b74a8a34ca8c5f2.tar.gz
bcm5719-llvm-50910bf842ca2d6bf16655ef3b74a8a34ca8c5f2.zip
[libcxx] Improve code generation for vector::clear().
Summary: By manipulating a local variable in the loop, when the loop can be optimized away (due to no non-trivial destructors), this lets it be fully optimized away and we modify the __end_ separately. This results in a substantial improvement in the generated code. Prior to this change, this would be generated (on x86_64): movq (%rdi), %rdx movq 8(%rdi), %rcx cmpq %rdx, %rcx je LBB2_2 leaq -12(%rcx), %rax subq %rdx, %rax movabsq $-6148914691236517205, %rdx ## imm = 0xAAAAAAAAAAAAAAAB mulq %rdx shrq $3, %rdx notq %rdx leaq (%rdx,%rdx,2), %rax leaq (%rcx,%rax,4), %rax movq %rax, 8(%rdi) And after: movq (%rdi), %rax movq %rax, 8(%rdi) This brings this in line with what other implementations do. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25241 llvm-svn: 298601
Diffstat (limited to 'libcxx/test/std/containers/sequences')
-rw-r--r--libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
new file mode 100644
index 00000000000..5f053eb8565
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// void clear();
+
+#include <vector>
+#include <cassert>
+
+#include "min_allocator.h"
+#include "asan_testing.h"
+
+int main()
+{
+ {
+ int a[] = {1, 2, 3};
+ std::vector<int> c(a, a+3);
+ c.clear();
+ assert(c.empty());
+ LIBCPP_ASSERT(c.__invariants());
+ LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+ }
+#if TEST_STD_VER >= 11
+ {
+ int a[] = {1, 2, 3};
+ std::vector<int, min_allocator<int>> c(a, a+3);
+ c.clear();
+ assert(c.empty());
+ LIBCPP_ASSERT(c.__invariants());
+ LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+ }
+#endif
+}
OpenPOWER on IntegriCloud