dmd simple loop disassembly - redundant instruction?

Ivan Kazmenko gassa at mail.ru
Wed Dec 25 21:56:02 PST 2013


On Wednesday, 25 December 2013 at 14:51:11 UTC, bearophile wrote:
> ldc2 optimizes the useless loop away:
>
> __Dmain:
> 	xorl	%eax, %eax
> 	ret
>
> If I modify the code returning some value from the int main:
>     return a[7];
>
> ldc2 gives the loop code:
>
> LBB0_1:
> 	movl	%eax, 12(%esp,%eax,4)
> 	incl	%eax
> 	cmpl	$1000000, %eax
> 	jne	LBB0_1
>
> If I use iota ldc2 copiles the loop to exactly the same asm:
>
> foreach (i; MAX_N.iota)

Glad to know that!  But what about DMD?  Anyone?..

If someone with better knowledge in assembly confirms the 
instruction is unnecessary, I'll file a bug report (at 
http://d.puremagic.com/issues/ I presume).

Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list