Cleaned up C++

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 23 07:55:26 PDT 2015


On 23 April 2015 at 16:28, via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Wednesday, 22 April 2015 at 22:26:45 UTC, John Colvin wrote:
>>
>> On Wednesday, 22 April 2015 at 21:59:48 UTC, Ola Fosheim Grøstad wrote:
>>>
>>> On Wednesday, 22 April 2015 at 20:36:12 UTC, John Colvin wrote:
>>>>
>>>> Is it even possible to contrive a case where
>>>> 1) The default initialisation stores are technically dead and
>>>> 2) Modern compilers can't tell they are dead and elide them and
>>>> 3) Doing the initialisation has a significant performance impact?
>>>>
>>>> The boring example is "extra code causes instruction cache misses".
>>>
>>>
>>> Allocation of large arrays.
>>
>>
>> That doesn't really answer the question without some more context.
>
>
> I think it does.
>
> Compilers cannot tell what goes on because they cannot figure out nontrivial
> loop invariants without guidance. You need something like a theorem prover
> (coq?)...
>

There are two states each local variable can be assigned.
1. Used
2. Read

int a = 1;  // a = Used
return a;  // a = Read
printf("%d\n", a);  // a = Read
int b = a;  // b = Used, a = Read
int c = void; // c = Unused

If a variable is unused, it's a dead variable.  If a variable is used
but not read, it's a dead variable. Simple. :-)



More information about the Digitalmars-d mailing list