C++ standards question
Ian Lance Taylor
iant@google.com
Thu Feb 7 16:11:00 GMT 2013
On Thu, Feb 7, 2013 at 12:01 AM, John Fine <johnsfine@verizon.net> wrote:
> I haven't tried constructing a small test case. I fixed the problem by
> changing to
> if ( expression of *p ) *((char volatile*)p) = '-';
>
> I am a skilled enough asm programmer to have zero doubt that I correctly
> interpreted the compiled code. It did have that "optimization".
>
> I don't know what else in that C++ function might have given the compiler
> permission to make that optimization. I don't think anything did. I know
> there was no unconditional write to *p in C++ code and there was an
> unconditional write to *p in the asm code.
Despite Jay's skepticism, GCC used to produce speculative stores, so
certainly at least one compiler acted that way. It's a natural
optimization in the single-threaded world. Stores are much cheaper
than conditional branches.
Ian
> Jay wrote:
>>
>> This sounds like a bug. But I am skeptical that any compiler has this bug.
>> Do you have a small test case that demonstrates it? Compilers aren't
>> bug-free (nothing is) but there are FAR more bugs in compiler input than
>> compilers themselves.
>> - Jay
>>
>> On Feb 3, 2013, at 9:34 PM, "Mailaripillai, Kannan Jeganathan"
>> <kannanmj@hp.com> wrote:
>>
>>
>>>>
>>>> if ( expression of *p ) *p = '-';
>>>>
>>>> The optimizer changes that to the equivalent of
>>>>
>>>> *p = (expression of *p ) ? '-' : *p;
>>>>
>>>> Is that a valid optimization?
>>>>
>>
>>
>>
More information about the Gcc-help
mailing list