google / google/benchmark

[BUG] DoNotOptimize() doesn't prevent gcc/clang from optimizing out array lookup

Open
#1,432 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
10.4k
Forks
1.8k
Avg merge
2d 4h
Merged PRs (30d)
8

Description

**Describe the bug**
`DoNotOptimize()` doesn't prevent gcc from optimizing out array lookup.

**System**
- x86, godbolt, gcc 12.1, clang 14.0.0, google benchmark 1.6.1

**To reproduce**
See assembly produced for this: https://godbolt.org/z/ahPss8hvY
On `clang -O2` everything is ok - addition and mov from `LUT` array
On `gcc -O2` - mov is missing

**Expected behavior**
`DoNotOptimize()` should prevent gcc from optimizing out array lookup

Edit: example minimisation

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.