summaryrefslogtreecommitdiffstats
path: root/libcxx/benchmarks/vector_operations.bench.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2019-07-28 04:37:02 +0000
committerEric Fiselier <eric@efcs.ca>2019-07-28 04:37:02 +0000
commitd4ace50ed0e5e761385a5d55845ee25ad12f41bb (patch)
tree8cb41ce4bcf231908549216834d2af03c03f50f2 /libcxx/benchmarks/vector_operations.bench.cpp
parent197c08d64ee53e8754bf31ef5f341375a08a3cd1 (diff)
downloadbcm5719-llvm-d4ace50ed0e5e761385a5d55845ee25ad12f41bb.tar.gz
bcm5719-llvm-d4ace50ed0e5e761385a5d55845ee25ad12f41bb.zip
Fix PR35637: suboptimal codegen for `vector<unsigned char>`.
The optimizer is petulant and temperamental. In this case LLVM failed to lower the the "insert at end" loop used by`vector<unsigned char>` to a `memset` despite `memset` being substantially faster over a range of bytes. LLVM has the ability to lower loops to `memset` whet appropriate, but the odd nature of libc++'s loops prevented the optimization from taking places. This patch addresses the issue by rewriting the loops from the form `do [ ... --__n; } while (__n > 0);` to instead use a for loop over a pointer range (For example: `for (auto *__i = ...; __i < __e; ++__i)`). This patch also rewrites the asan annotations to unposion all additional memory at the start of the loop instead of once per iterations. This could potentially permit false negatives where the constructor of element N attempts to access element N + 1 during its construction. The before and after results for the `BM_ConstructSize/vector_byte/5140480_mean` benchmark (run 5 times) are: -------------------------------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------------------------------- Before ------ BM_ConstructSize/vector_byte/5140480_mean 12530140 ns 12469693 ns N/A BM_ConstructSize/vector_byte/5140480_median 12512818 ns 12445571 ns N/A BM_ConstructSize/vector_byte/5140480_stddev 106224 ns 107907 ns 5 ----- After ----- BM_ConstructSize/vector_byte/5140480_mean 167285 ns 166500 ns N/A BM_ConstructSize/vector_byte/5140480_median 166749 ns 166069 ns N/A BM_ConstructSize/vector_byte/5140480_stddev 3242 ns 3184 ns 5 llvm-svn: 367183
Diffstat (limited to 'libcxx/benchmarks/vector_operations.bench.cpp')
-rw-r--r--libcxx/benchmarks/vector_operations.bench.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libcxx/benchmarks/vector_operations.bench.cpp b/libcxx/benchmarks/vector_operations.bench.cpp
index a2c4e5dbbc0..c41259eaac3 100644
--- a/libcxx/benchmarks/vector_operations.bench.cpp
+++ b/libcxx/benchmarks/vector_operations.bench.cpp
@@ -13,6 +13,14 @@ using namespace ContainerBenchmarks;
constexpr std::size_t TestNumInputs = 1024;
+BENCHMARK_CAPTURE(BM_ConstructSize,
+ vector_byte,
+ std::vector<unsigned char>{})->Arg(5140480);
+
+BENCHMARK_CAPTURE(BM_ConstructSizeValue,
+ vector_byte,
+ std::vector<unsigned char>{}, 0)->Arg(5140480);
+
BENCHMARK_CAPTURE(BM_ConstructIterIter,
vector_char,
std::vector<char>{},
OpenPOWER on IntegriCloud