From 50910bf842ca2d6bf16655ef3b74a8a34ca8c5f2 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Thu, 23 Mar 2017 14:39:23 +0000 Subject: [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 --- libcxx/include/vector | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libcxx/include') diff --git a/libcxx/include/vector b/libcxx/include/vector index ded057b10c8..8f404dc4211 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -413,8 +413,10 @@ inline _LIBCPP_INLINE_VISIBILITY void __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT { - while (__new_last != __end_) - __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); + pointer __soon_to_be_end = __end_; + while (__new_last != __soon_to_be_end) + __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end)); + __end_ = __new_last; } template -- cgit v1.2.3