dmd simple loop disassembly - redundant instruction?

Chris Cain clcain at uncg.edu
Wed Dec 25 04:43:04 PST 2013


On Wednesday, 25 December 2013 at 12:03:08 UTC, Ivan Kazmenko 
wrote:
> Now, I am not exactly fluent in assembler, but the "mov ECX, 
> EDX" seems unnecessary.  The ECX register is explicitly used 
> three times in the whole program, and it looks like this 
> instruction can at least be moved out of the loop, if not 
> removed completely.
>  Is it indeed a bug, or there's some reason here?  And if the 
> former, where do I report it - at 
> http://d.puremagic.com/issues/, as with the front-end?

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.


More information about the Digitalmars-d-learn mailing list