BUG: Visual C++ 6.0 Compiler Does Not Remove Some Unneeded Instruction

ID: Q234511


The information in this article applies to:


SYMPTOMS

The Visual C++ 6.0 compiler does not remove certain unneeded temporary instructions, which can slow down code execution.


RESOLUTION

A supported fix for Visual C++ 6.0 that corrects this problem is now available from Microsoft, but it has not been fully regression tested and should be applied only to systems experiencing this specific problem.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information on support costs, please go to the following address on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.asp

The English version of this fix should have the following file attributes or later:

Name Size Date Time Version# Platform
c1xx.dll 1,169KB 6/4/99 11:01 PM 12.00.8520.0 x86

NOTE: If this product was already installed on your computer when you purchased it from the Original Equipment Manufacturer (OEM) and you need this fix, please call the Pay Per Incident number listed on the above Web site. If you contact Microsoft to obtain this fix, a fee may be charged. This fee is refundable if it is determined that you only require the fix you requested. However, this fee is non-refundable if you request additional technical support, if your no-charge technical support period has expired, or if you are not eligible for standard no-charge technical support.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Behavior

Compile the following code with /O2 in Visual C++ 6.0:

#include <time.h>
#include <stdio.h> 

class boo
{
 	int a;
 	int b;
 	int c;
 	int d;

public:
 	boo():
	  a(0), b(0), c(0), d(0) {}

 	boo(int x):
	  a(x), b(x), c(x), d(x) {}
};

boo fun(int x)
{
 	if (x)
 		return boo(x);
 	else
 		return boo();
}

void main()
{
	time_t   start, finish; 
	double   elapsed_time;
         
 	int i;
	 time( &start );
 	for (i=0; i<200000000; i++)
 	{
 		fun(0);
 	}
 	for (i=0; i<200000000; i++)
 	{
 		fun(10);
 	}
	time( &finish );
	elapsed_time = difftime( finish, start );
	printf( "\nProgram takes %6.0f seconds.\n", elapsed_time );
} 
And compare the following snippet of the generated code:

; 21   :  	if (x)

	mov	ecx, DWORD PTR _x$[esp-4]
	test	ecx, ecx
	je	SHORT $L622

; 22   :  		return boo(x);

	mov	eax, DWORD PTR ___$ReturnUdt$[esp-4]
	mov	edx, eax
	mov	DWORD PTR [edx], ecx
	mov	DWORD PTR [edx+4], ecx
	mov	DWORD PTR [edx+8], ecx
	mov	DWORD PTR [edx+12], ecx

; 25   : }

	ret	0
$L622:

; 23   :  	else
; 24   :  		return boo();

	mov	eax, DWORD PTR ___$ReturnUdt$[esp-4]
	push	ebx
	mov	ebx, eax
	xor	ecx, ecx
	xor	edx, edx
	push	esi
	mov	DWORD PTR [ebx], ecx
	xor	esi, esi
	push	edi
	xor	edi, edi
	mov	DWORD PTR [ebx+4], edx
	mov	DWORD PTR [ebx+8], esi
	mov	DWORD PTR [ebx+12], edi
	pop	edi
	pop	esi
	pop	ebx

; 25   : }

	ret	0 
With that generated by Visual C++ 5.0 when compiled with /O2:

; 21   :  	if (x)

	mov	ecx, DWORD PTR _x$[esp-4]

; 22   :  		return boo(x);

	mov	eax, DWORD PTR ___$ReturnUdt$[esp-4]
	xor	edx, edx
	cmp	ecx, edx
	je	SHORT $L547
	mov	DWORD PTR [eax], ecx
	mov	DWORD PTR [eax+4], ecx
	mov	DWORD PTR [eax+8], ecx
	mov	DWORD PTR [eax+12], ecx

; 25   : }

	ret	0
$L547:

; 23   :  	else
; 24   :  		return boo();

	mov	DWORD PTR [eax], edx
	mov	DWORD PTR [eax+4], edx
	mov	DWORD PTR [eax+8], edx
	mov	DWORD PTR [eax+12], edx

; 25   : }

	ret	0 
The Visual C++ 6.0 version of the code contains more instructions, which can slow down program execution. The executable built with Visual C++ 6.0 runs slower than the one built with Visual C++ 5.0 on a comparable system.

Additional query words: code generation performance slow codegen


Keywords          : kbCompiler kbVC600QFE kbDSupport 
Version           : winnt:6.0
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: July 2, 1999