C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fwd: Use of volatile as function argument should not be deprecated.

From: Bo Persson <bo_at_[hidden]>
Date: Sat, 11 Jun 2022 08:39:44 +0200
On 2022-06-10 at 23:09, Arthur O'Dwyer via Std-Proposals wrote:
> On Fri, Jun 10, 2022 at 4:43 PM Lénárd Szolnoki <cpp_at_[hidden]
> <mailto:cpp_at_[hidden]>> wrote:
>
> [...] The thing is, if I have a library funciton called
> "DoNotOptimize", but
> it fails to be an optimization barrier in some circumstances, then it's
> not a very good abstraction. Wouldn't it be nice if this could be a
> similar optimization barrier, LTO enabled or not? [...]
>
> [...] I'm interested in optimization
> barriers in general, or maybe even more generally fine grained control
> of optimization hints/options within the code.
>
> > [...] All I'm saying is, if your goal is simply
> > to mystify the optimizing compiler as to whether a particular
> > variable is dead or whether a particular write to it can be hoisted,
> > literally all you have to do is escape that variable's address into a
> > different translation unit (which is exactly what
> > benchmark::DoNotOptimize does).
>
> Again, with LTO disabled.
>
>
> I think I need to re-post this paragraph.
>
> Here's another way to look at it: *"Optimization barrier" is not a
> first-class principle.* Instead, the fundamental organizing principle is
> *"The tool can't optimize what it can't see."* So, if you really really
> want something not to be optimized, then you simply mentally reduce the
> problem to "How can I make my optimizing tool /not see/ this function?"

So perhaps what we need is a [[dont_look]] directive?

Received on 2022-06-11 06:40:16