-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Deprecate constant reference API to DoNotOptimize. #1493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think the description is missing some code examples. |
The compiler assume that a constant reference, even though escaped via asm volatile, is unchanged. The const-ref interface is deprecated to discourage new uses of it, as subtle compiler optimizations (invariant hoisting, etc.) can occur. Within microbenchmarks for Abseil's hashtables, BM_FindMiss_Hot (https://github.com/google/fleetbench/blob/c0eaa90671d6cc99eb065864e74f0175bee24a5d/fleetbench/swissmap/hot_swissmap_benchmark.cc#L48) has a `const uint32_t key` is passed to to the lookup of a hashtable. With the `key` marked `const`, LLVM hoists part of the lookup calculation outside of the loop. With the `const` removed, this hoisting does not occur.
Done. |
do any of our tests now trigger this deprecation message? |
Thanks, but i would like to see a more self-contained example on godbolt where said hoisting can be observed. |
I'm asking because in general const-ness of the pointer does not give any breathing room to the compiler. |
https://gcc.godbolt.org/z/EG4PdT9G6 is about as minimal as i can get it on short order that shows the effect with the current code. |
Thanks! I haven't tried running that yet, but what is the observation there? |
Also, we have a bit of documentation problem. There, In the What happens if you do |
it's the hoisting of the i should note, we've applied this patch internally already as it had significant impact across our internal benchmarks. |
The const-reference API to DoNotOptimize was deprecated with google#1493. Some examples in the user guide are using exactly that deprecated interface. This fixes that by passing non-const lvalues instead. Fixes google#1566
--- Manual changes: --- 1) Updated version of google_benchmark to fix windows compile error. New range: https://chromium.googlesource.com/external/github.com/google/benchmark/+log/e8baf26..b177433 2) Remove unused sleep.[cc|h] from BUILD.gn. (Removed here: google/benchmark#1549) 3) Fix deprecation warnings (treated as errors) in allocation_perf.cc. benchmark::DoNotOptimize has deprecated overloads due to google/benchmark#1493. Bug: 1425054 --- Original message generated by autoroll: --- Rolling v8/third_party/google_benchmark/src: https://chromium.googlesource.com/external/github.com/google/benchmark/+log/e8baf26..efc89f0 link to benchmark directly for tests that aren't link_main_test (#1576) (dominic) https://chromium.googlesource.com/external/github.com/google/benchmark/+/efc89f0 Convert uses of `const char*` to `std::string` (#1567) (dominic) https://chromium.googlesource.com/external/github.com/google/benchmark/+/46d3c84 add '@' to correctly reference build file for libpfm (#1575) (dominic) https://chromium.googlesource.com/external/github.com/google/benchmark/+/68aa190 Address warnings on NVIDIA nvc++ (#1573) (Henrique Bucher) https://chromium.googlesource.com/external/github.com/google/benchmark/+/9f7dc38 simplify setting C++ standard (Dominic Hamon) https://chromium.googlesource.com/external/github.com/google/benchmark/+/1b507cb [FR] Provide public accessors to benchmark name and arguments #1551 (#1563) (Mike Apodaca) https://chromium.googlesource.com/external/github.com/google/benchmark/+/f32748c use std::string for skip messages (#1571) (dominic) https://chromium.googlesource.com/external/github.com/google/benchmark/+/060d762 [FR] state.SkipWithMessage #963 (#1564) (Mike Apodaca) https://chromium.googlesource.com/external/github.com/google/benchmark/+/adb0d3d ... Change-Id: I69218b84b88fb1da25e740d7fb623528d526b85b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4429376 Reviewed-by: Toon Verwaest <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]> Cr-Commit-Position: refs/heads/main@{#87139}
…#35459) ### Rationale for this change Google Benchmark 1.6.1 added `benchmark::MemoryManager::Stop(Result&)` and deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark 1.8.0 dropped deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark deprecated `DoNotOptimize(const &)`: google/benchmark#1493 ### What changes are included in this PR? We can always use `benchmark::MemoryManager::Stop(Result&)` by requiring Google Benchmark 1.6.1 or later. Don't use deprecated `DoNotOptimize(const &)`. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * Closes: #35458 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
… later (apache#35459) ### Rationale for this change Google Benchmark 1.6.1 added `benchmark::MemoryManager::Stop(Result&)` and deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark 1.8.0 dropped deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark deprecated `DoNotOptimize(const &)`: google/benchmark#1493 ### What changes are included in this PR? We can always use `benchmark::MemoryManager::Stop(Result&)` by requiring Google Benchmark 1.6.1 or later. Don't use deprecated `DoNotOptimize(const &)`. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * Closes: apache#35458 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
… later (apache#35459) ### Rationale for this change Google Benchmark 1.6.1 added `benchmark::MemoryManager::Stop(Result&)` and deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark 1.8.0 dropped deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark deprecated `DoNotOptimize(const &)`: google/benchmark#1493 ### What changes are included in this PR? We can always use `benchmark::MemoryManager::Stop(Result&)` by requiring Google Benchmark 1.6.1 or later. Don't use deprecated `DoNotOptimize(const &)`. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * Closes: apache#35458 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
… later (apache#35459) ### Rationale for this change Google Benchmark 1.6.1 added `benchmark::MemoryManager::Stop(Result&)` and deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark 1.8.0 dropped deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark deprecated `DoNotOptimize(const &)`: google/benchmark#1493 ### What changes are included in this PR? We can always use `benchmark::MemoryManager::Stop(Result&)` by requiring Google Benchmark 1.6.1 or later. Don't use deprecated `DoNotOptimize(const &)`. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * Closes: apache#35458 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…#35459) ### Rationale for this change Google Benchmark 1.6.1 added `benchmark::MemoryManager::Stop(Result&)` and deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark 1.8.0 dropped deprecated `benchmark::MemoryManager::Stop(Result*)`. Google Benchmark deprecated `DoNotOptimize(const &)`: google/benchmark#1493 ### What changes are included in this PR? We can always use `benchmark::MemoryManager::Stop(Result&)` by requiring Google Benchmark 1.6.1 or later. Don't use deprecated `DoNotOptimize(const &)`. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * Closes: #35458 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
This patch breaks using DoNotOptimize with rvalue (see #1584) |
… operands (#79924) Modify #77393 to clear shadow memory using `llvm.memset.*` when the size is large, similar to `shouldUseBZeroPlusStoresToInitialize` in clang for `-ftrivial-auto-var-init=`. The intrinsic, if lowered to libcall, will use the msan interceptor. The instruction selector lowers a `StoreInst` to multiple stores, not utilizing `memset`. When the size is large (e.g. `store { [100 x i32] } zeroinitializer, ptr %12, align 1`), the generated code will be long (and `CodeGenPrepare::optimizeInst` will even crash for a huge size). ``` // Test stack size template <class T> void DoNotOptimize(const T& var) { // deprecated by google/benchmark#1493 asm volatile("" : "+m"(const_cast<T&>(var))); } int main() { using LargeArray = std::array<int, 1000000>; auto large_stack = []() { DoNotOptimize(LargeArray()); }; /////// CodeGenPrepare::optimizeInst triggers an assertion failure when creating an integer type with a bit width>2**23 large_stack(); } ```
The compiler assume that a constant reference, even though escaped via asm
volatile, is unchanged. The const-ref interface is deprecated to discourage
new uses of it, as subtle compiler optimizations (invariant hoisting, etc.) can
occur.
Within microbenchmarks for Abseil's hashtables, BM_FindMiss_Hot
(https://github.com/google/fleetbench/blob/c0eaa90671d6cc99eb065864e74f0175bee24a5d/fleetbench/swissmap/hot_swissmap_benchmark.cc#L48)
has a
const uint32_t key
is passed to to the lookup of a hashtable.With the
key
markedconst
, LLVM hoists part of the lookupcalculation outside of the loop.
With the
const
removed, this hoisting does not occur.