-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fixed LTO issue on no discard variable #1761
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
2100c61 to
675d242
Compare
src/benchmark.cc
Outdated
|
|
||
| // FIXME: Verify if LTO still messes this up? | ||
| void UseCharPointer(char const volatile* const v) { | ||
| //forces compiler to issue instruction by assigning dummy value to a volatile preventing LTO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We want to escape the pointer `v` so that the compiler can not eliminate computations
// that produced it. To do that, we escape the pointer by storing it into a volatile variable,
// since generally, volatile store, is not something the compiler is allowed to elide.
LebedevRI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this works, at least better than the original: https://godbolt.org/z/v1493hd81
|
I'll merge after #1761 unbreaks the CI... |
|
Yes, I was having an issue where my code was optimized away and the benchmark::DoNotOptimize failed to prevent optimization. With this it works for my case, now my statistics are more accurate. |
|
@tmiguelf thank you! |
Fixed LTO issue on no discard variable.
Tested on MSVC