dmd simple loop disassembly - redundant instruction?

Ivan Kazmenko gassa at mail.ru
Wed Dec 25 05:19:57 PST 2013


On Wednesday, 25 December 2013 at 12:43:05 UTC, Chris Cain wrote:
> Did you try something like:
>
> for(immutable i; 0..MAX_N)
>     a[i] = i;
>
> too? One thing to note is that, technically, i is a _copy_ of 
> the iterated number. So things like
>
> for(i; 0..5)
>    i++;
>
> have no effect (it will loop 5 times regardless). Indeed, in 
> your case, this could be optimized out, but in general the 
> extra instruction is technically correct. I don't know if 
> making i immutable would change things, but it might give the 
> compiler enough of a hint to do the correct optimization here.

Thanks, that sounded reasonable.  Still, in this particular case, 
the generated assembly remained the same.


More information about the Digitalmars-d-learn mailing list