KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q234511: FIX: VC++ 6.0 Compiler Does Not Remove Unneeded Instructions

Article: Q234511
Product(s): Microsoft C Compiler
Version(s): 6.0
Operating System(s): 
Keyword(s): kbCompiler kbVC600QFE kbDSupport kbVS600sp4fix kbVS600sp5fix
Last Modified: 20-MAY-2002

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0 
- Microsoft Visual C++, 32-bit Professional Edition, version 6.0 
- Microsoft Visual C++, 32-bit Learning Edition, version 6.0 
-------------------------------------------------------------------------------

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://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
(http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS)

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      | 
+------------------------------------------------------------------+


STATUS
======

Microsoft has confirmed this to be a bug in the Microsoft products listed at the
beginning of this article. This bug was corrected in the next service pack for
Visual Studio 6.0.

For additional information about Visual Studio service packs, click the article
numbers below to view the articles in the Microsoft Knowledge Base:

  Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

  Q194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed

You can download the latest Visual Studio service pack from the following
Microsoft Web site:

  Visual Studio Product Updates
  (http://msdn.microsoft.com/vstudio/downloads/updates.asp)

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: sp4 code generation performance slow codegen

======================================================================
Keywords          : kbCompiler kbVC600QFE kbDSupport kbVS600sp4fix kbVS600sp5fix 
Technology        : kbVCsearch kbAudDeveloper kbVC600 kbVC32bitSearch
Version           : :6.0
Issue type        : kbbug
Solution Type     : kbfix

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.