> On Jun 15, 2017, at 2:23 AM, David Brown <david@xxxxxxxxxxxxxxx> wrote: > > On 14/06/17 18:56, Andrew Haley wrote: >> On 14/06/17 17:40, David Barto wrote: >>> Thanks for that. Can you point to the relevant portion of the standard that >>> I can then quote back to my Boss who is quite concerned about this? >> >> 1.9 Program execution [intro.execution] >> >> The semantic descriptions in this International Standard define a >> parameterized nondeterministic abstract machine. This International >> Standard places no requirement on the structure of conforming >> implementations. In particular, they need not copy or emulate the >> structure of the abstract machine. Rather, conforming implementations >> are required to emulate (only) the observable behavior of the abstract >> machine as explained below.5 >> >> 5) This provision is sometimes called the “as-if” rule, because an >> implementation is free to disregard any requirement of this >> International Standard as long as the result is as if the requirement >> had been obeyed, as far as can be determined from the observable >> behavior of the program. For instance, an actual implementation need >> not evaluate part of an expression if it can deduce that its value is >> not used and that no side effects affecting the observable behavior of >> the program are produced. >> >>> And if there is such a flag to disable the “Optimization” performed here >>> what would I enable? >> >> I have no idea. >> > > There is "-fsched-spec-load" and "-fsched-spec-load-dangerous" that > might be relevant, but I did not think these were enabled by default. > Maybe "-fno-sched-spec" ? "-fhoist-adjecent-loads" ? > > > If you need to avoid this optimisation in this one case, you can force > the "f20type == URI" to have a side effect by using a cast to volatile > (such as Linux's ACCESS_ONCE macro) on URI. > > But gcc can do this sort of re-arrangement at any time, in any place. > It is fine for the compiler to do something with undefined behaviour as > long as the compiler knows what will actually happen (so it can add two > ints that overflow, but it can't dereference a null pointer), and when > the results of the undefined behaviour are not used. In this particular > case the compiler will want to schedule reading the URI as early as > possible, so that it has made its way through caches and into the cpu > for when it is needed. > Fantastic! I will try these suggestions to see what the result is. I knew that this list would be handy some day. Thanks for all your help and support in getting a quick and accurate solution that I can present to my boss. David David Barto barto@xxxxxxxxxxxxxxxxxxxxxx Sometimes, my best code does nothing. Most of the rest of it has bugs.