Open gizlu opened 2 years ago
Update: Removing const
specifier from array definition triggers this bug also on clang.
See https://godbolt.org/z/fETxqYaqn
Just a note.
There are special cases for GCC but even applying the same rules for clang, it still optimizes away.
It looks like just doing something with the passed variable prevents GCC from optimizing it. GCC seems to sense that the generated assembly is empty.
https://godbolt.org/z/esd8hE6T9
This works:
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DNO(Tp const& value) {
asm volatile("xor %0, %0" : : "r,m"(value) : "memory");
}
Describe the bug
DoNotOptimize()
doesn't prevent gcc from optimizing out array lookup.System
To reproduce See assembly produced for this: https://godbolt.org/z/ahPss8hvY On
clang -O2
everything is ok - addition and mov fromLUT
array Ongcc -O2
- mov is missingExpected behavior
DoNotOptimize()
should prevent gcc from optimizing out array lookupEdit: example minimisation