Skip to content

Conversation

@tmiguelf
Copy link
Contributor

@tmiguelf tmiguelf commented Mar 5, 2024

Fixed LTO issue on no discard variable.
Tested on MSVC

@tmiguelf tmiguelf requested a review from LebedevRI March 5, 2024 20:30
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
Copy link
Collaborator

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.

@tmiguelf tmiguelf requested a review from LebedevRI March 5, 2024 22:49
Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LebedevRI
Copy link
Collaborator

I'll merge after #1761 unbreaks the CI...

@tmiguelf
Copy link
Contributor Author

tmiguelf commented Mar 5, 2024

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.

@LebedevRI LebedevRI merged commit 654d8d6 into google:main Mar 6, 2024
@LebedevRI
Copy link
Collaborator

@tmiguelf thank you!

@tmiguelf tmiguelf deleted the feature/LTO_fix branch March 6, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants