Jarrett Billingsley wrote:
On Tue, Jun 2, 2009 at 8:10 AM, bearophile <bearophileh...@lycos.com> wrote:
Walter Bright:
Dead assignment elimination is compiler technology from the 70's !<
I'd like to see this technology used for arrays too. So in the following two adjacent 
lines of code "a" doesn't get initialized to zero before being initialized 
again to 5:

void main() {
   auto a = new int[10];
   a[] = 5;
   printf("%d\n", a[3]);
}

As far as I know, LDC already does this.

It doesn't. The runtime call that allocates the array initializes it (to 0 in this case), and then the array assignment overwrites that initialization.

In this case the array doesn't escape the function, so it does get stack-allocated by a custom optimization pass (and the initialization is turned into an LLVM memset intrinsic), but LLVM still can't "look into" the call that does the array assignment to know it will always overwrite the entire array so the memset isn't necessary.

Reply via email to