[OT] compiler optimisations

via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 23 05:47:04 PDT 2015


Interestingly only clang understands that an upcast will prevent 
the overflow:

int foo(unsigned int a)
{
	if (a > 5)
		return ((unsigned long long)a * 3) / 3;
	else
		return 0;
}

Is compiled to compact code in clang:

	xorl	%eax, %eax
	cmpl	$5, %edi
	cmoval	%edi, %eax
	retq




More information about the Digitalmars-d mailing list