improvements to folly::doNotOptimizeAway v2016.10.31.00
authorNathan Bronson <ngbronson@fb.com>
Mon, 31 Oct 2016 01:12:26 +0000 (18:12 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Mon, 31 Oct 2016 01:23:28 +0000 (18:23 -0700)
commit81d9192f8afdf53fcbc7bf572f8ce638516380f8
treeaa4266bbd21ec14634039ddbb332e6240099be59
parentcc4533454c08dc9db6c09ae22c7a1a003711a69f
improvements to folly::doNotOptimizeAway

Summary:
A common failure mode for folly::doNotOptimizeAway is to pass it a
pointer to a complex object that the caller wants to ensure is fully
calculated, which doesn't actually ensure that.  Also, the GCC and
MSVC implementations used inline assembly with an in-out parameter,
which causes a store.  A survey of many usages of doNotOptimizeAway
found only 1 that relies on this make-unpredictable behavior.

This diff makes doNotOptimizeAway(&x) equivalent to doNotOptimizeAway(x)
for GCC and clang, and makes it a read-only sink.  For the rare
case that the benchmark wants to disable subexpression elimination,
constant propagation, or power reduction, there is a new function
makeUnpredictable.  It also merges the clang and GCC implementations,
removing a potential bias in our microbenchmarks.

Reviewed By: davidtgoldblatt

Differential Revision: D4074670

fbshipit-source-id: 43f02e7fe149147bb172babe77787dea06e098fa
folly/Benchmark.h
folly/test/BenchmarkTest.cpp